Skip to main content

vkdr postgres

Use these commands to manage a PostgreSQL database in your vkdr cluster.

vkdr postgres install

Install a PostgreSQL database in your cluster.

vkdr postgres install [-w] [-p=<admin_password>]

Flags

FlagShorthandDescriptionDefault
--admin-pPostgres admin password(generated)
--wait-wWait until Postgres is readyfalse

Examples

Install PostgreSQL with default settings:

vkdr infra up
vkdr postgres install

Install with a specific admin password and wait for readiness:

vkdr postgres install -p mypassword -w

vkdr postgres remove

Remove PostgreSQL from your cluster.

vkdr postgres remove [-d]

Flags

FlagShorthandDescriptionDefault
--delete-dDelete postgres storage (PVC) after removalfalse

Examples

Remove PostgreSQL but keep data:

vkdr postgres remove

Remove PostgreSQL and delete all data:

vkdr postgres remove -d

vkdr postgres createdb

Create a new database with an optional user/password as its owner.

vkdr postgres createdb [-s] [--drop] [--vault] \
[-a=<admin_password>] -d=<database_name> \
[-p=<password>] [-u=<user_name>] \
[--vault-rotation=<vault_rotation_schedule>]

Flags

FlagShorthandDescriptionDefault
--database-dNew database name(required)
--user-uNew user name(optional)
--password-pNew user's password(optional)
--admin-aAdmin password(optional)
--store-sStore password in Kubernetes secretfalse
--dropDrop database if it existsfalse
--vaultCreate Vault database engine configfalse
--vault-rotationVault secret rotation schedule0 * * * SAT

Examples

Create a simple database:

vkdr postgres createdb -d myapp

Create a database with user and store credentials in Kubernetes secret:

vkdr postgres createdb -d myapp -u myuser -p mypassword -s

Create a database with Vault integration:

vkdr postgres createdb -d myapp -u myuser --vault

vkdr postgres dropdb

Drop a database and its associated secrets in Kubernetes.

vkdr postgres dropdb  -d=<database_name> [-u=<user_name>]

Flags

FlagShorthandDescriptionDefault
--database-dDatabase name to drop(required)
--user-uDatabase user/role name to remove(optional)

Examples

Drop a database:

vkdr postgres dropdb -d myapp

Drop a database and its associated user:

vkdr postgres dropdb -d myapp -u myuser

vkdr postgres listdbs

List all databases managed by the PostgreSQL cluster.

vkdr postgres listdbs [--json]

Flags

FlagDescriptionDefault
--jsonOutput in JSON formatfalse

Examples

List all databases:

vkdr postgres listdbs

List databases in JSON format:

vkdr postgres listdbs --json

vkdr postgres pingdb

Test database connectivity by running a simple SELECT query.

vkdr postgres pingdb  -d=<database_name> -u=<user_name>

Flags

FlagShorthandDescriptionDefault
--database-dDatabase name to test(required)
--user-uDatabase user name for connection(required)

Examples

Test database connectivity:

vkdr postgres pingdb -d myapp -u myuser

vkdr postgres explain

Explain PostgreSQL install formulas and configuration options.

vkdr postgres explain

Complete Example

Here's a complete workflow for setting up PostgreSQL with an application database:

# Start cluster
vkdr infra up

# Install PostgreSQL and wait for it to be ready
vkdr postgres install -w

# Create application database with credentials stored in K8s secret
vkdr postgres createdb -d myapp -u appuser -p apppassword -s

# Verify database is accessible
vkdr postgres pingdb -d myapp -u appuser

# List all databases
vkdr postgres listdbs

# When done, clean up
vkdr postgres dropdb -d myapp -u appuser
vkdr postgres remove -d

Formula Examples

Install Postgres with admin password

vkdr infra up
vkdr postgres install -p mypassword

Create database with user and password

vkdr postgres createdb -d mydb -u myuser -p mypassword -s

The new "user" will own the new database and be granted all permissions on it. If -s is provided the password will be stored in a secret named myuser-pg-secret.

Vault integration

If you have installed Vault, you can use it to generate and store the user's password:

vkdr vault install
vkdr vault init
vkdr postgres install
vkdr postgres createdb -d mydb -u myuser --vault

External Secrets Operator

When both Vault and ESO are installed, storing the password in a secret relies on the ESO+Vault integration:

vkdr eso install
vkdr postgres createdb -d mydb -u myuser --vault -s