Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Install PostgreSQL

The postgres kit deploys PostgreSQL on K8s db nodes via the CloudNativePG (CNPG) operator. Data is persisted on PersistentVolumes — stopping and restarting preserves your dataset.

Prerequisites

  • Cluster is up (easy-db-lab up) with at least one db node

Quick Start

easy-db-lab kit install postgres
easy-db-lab postgres start

Flags

FlagDefaultDescription
--version17PostgreSQL major version (e.g. 17, 16)
--instances1Number of PostgreSQL instances; values > 1 deploy a primary and read replicas
--size10TiStorage size per db node (e.g. 100Gi)

Managing PostgreSQL

# Start PostgreSQL
easy-db-lab postgres start

# Stop PostgreSQL (data is preserved)
easy-db-lab postgres stop

# Remove operator and delete all PersistentVolumes
easy-db-lab postgres uninstall

start

  1. Creates PersistentVolumes on db nodes via platform-pvs
  2. Applies the CNPG Cluster custom resource
  3. Waits for all pods to reach Ready
  4. Applies the NodePort service for external access

stop

Deletes the CNPG Cluster CR and the NodePort service. PersistentVolumes are retained — running postgres start again resumes from the existing dataset.

uninstall

Deletes PersistentVolumes and uninstalls the CNPG operator Helm release.

Connecting

The PostgreSQL primary is exposed as a NodePort on port 30432 of each db node.

# JDBC URL
jdbc:postgresql://<db-node-ip>:30432/postgres

# psql via SOCKS5 proxy or port-forward
kubectl port-forward svc/postgres-nodeport 5432:5432
psql -h localhost -U postgres postgres

The default user is postgres with password postgres (stored in the postgres-credentials K8s Secret).

Running SQL

Use the built-in sql capability to execute queries directly:

easy-db-lab postgres sql "SELECT version()"
easy-db-lab postgres sql --file query.sql

Extensions

PostgreSQL extensions that require custom container images are activated at install time via --extension on kit install postgres. Each extension installs as a separate named instance (e.g. postgres-duckdb) that starts and stops independently.

Listing available extensions

easy-db-lab postgres extensions

Outputs a table of alias names, image templates, shared_preload_libraries, and CREATE EXTENSION statements.

Built-in aliases

AliasDescription
duckdbDuckDB analytical query engine via pg_duckdb
postgisGeospatial types and functions
timescaledbTime-series storage and query optimization

Example

# Install with an extension
easy-db-lab kit install postgres --extension duckdb

# Start, stop, and use the named instance
easy-db-lab postgres-duckdb start
easy-db-lab postgres-duckdb sql "SELECT duckdb_version()"
easy-db-lab postgres-duckdb stop

Versioning

Built-in alias images use __PG_MAJOR__ as a placeholder for the PostgreSQL major version (e.g. 17). This is substituted automatically from the --version flag set at install time.

Presto Integration

When both postgres and presto are running, Presto automatically exposes a postgres catalog using the PostgreSQL JDBC connector pointed at the CNPG primary service. No manual configuration is needed.

easy-db-lab kit install postgres
easy-db-lab postgres start

easy-db-lab kit install presto
easy-db-lab presto start

# postgres catalog is available automatically
easy-db-lab presto sql "SHOW CATALOGS"