The module lifecycle stage: Preview
The module has requirements for installation
Quick start
The managed-postgres module creates a PostgreSQL service, the testdb database and the test-rw user with a generated password.
An administrator must enable the module and create PostgresClass default; the commands require d8 configured to access the cluster.
Create the namespace:
d8 k create namespace postgresSave the following manifest as postgres-example.yaml:
apiVersion: managed-services.deckhouse.io/v1alpha2
kind: Postgres
metadata:
labels:
app.kubernetes.io/name: managed-postgres-operator
name: test
namespace: postgres
spec:
postgresClassName: default
instance:
memory:
size: 1Gi
cpu:
cores: 1
coreFraction: 50%
persistentVolumeClaim:
size: 1Gi
type: Standalone
---
apiVersion: managed-services.deckhouse.io/v1alpha2
kind: PostgresDatabase
metadata:
name: test-testdb
namespace: postgres
spec:
postgres: test
databaseName: testdb
retentionPolicy: Retain
---
apiVersion: managed-services.deckhouse.io/v1alpha2
kind: PostgresUser
metadata:
name: test-test-rw
namespace: postgres
spec:
postgres: test
userName: test-rw
inRoles:
- rw
storeCredsToSecret: test-test-rw-credsApply the manifest and wait for the service and SQL objects to become ready:
d8 k apply -f postgres-example.yamlCheck the readiness conditions:
d8 k wait postgres/test \
--namespace postgres \
--for=condition=Available \
--timeout=10m
d8 k wait postgresdatabase/test-testdb \
--namespace postgres \
--for=condition=Synced \
--timeout=5m
d8 k wait postgresuser/test-test-rw \
--namespace postgres \
--for=condition=Synced \
--timeout=5mAfter successful creation, the service has Available=True; the database and user have Bound and Synced=True.
The password is in Secret test-test-rw-creds; follow the connection example to connect an application.
Configuring the service
Postgres describes compute resources, storage, configuration and service replication. Settings are validated against the associated PostgresClass.
Selecting a class
Set spec.postgresClassName to an existing class name.
The class defines permitted service sizes and parameters that can be overridden.
Ask an administrator to provide a suitable class if the current one does not permit the required configuration.
Selecting a PostgreSQL version
Set the PostgreSQL major version in spec.version when creating Postgres:
spec:
version: "16"The field is immutable after creation. When restoring from PostgresSnapshot, the version must match the snapshot. Allowed versions are listed under limitations.
Allocating resources
Set CPU, memory and disk size in spec.instance:
spec:
instance:
memory:
size: 1Gi
cpu:
cores: 1
coreFraction: "50%"
persistentVolumeClaim:
size: 10Gi
storageClassName: defaultSpecify an existing StorageClass in storageClassName or use the default StorageClass configured in Kubernetes.
Changes must meet the selected PostgresClass’s sizingPolicy.
Configuring replication
spec.type: Standalone creates a service with one PostgreSQL server.
For a service with replicas, specify Cluster, an allowed topology and a replication mode:
spec:
type: Cluster
cluster:
topology: TransZonal
replication: ConsistencyAndAvailabilitySelect the mode according to write acknowledgement requirements:
Availabilityuses asynchronous replication. A replica may lack some acknowledged writes if the primary is lost.Consistencyuses synchronous replication. An unavailable synchronous replica can block write acknowledgement.ConsistencyAndAvailabilityuses synchronous and asynchronous replicas to combine availability and data durability requirements.
Changing PostgreSQL parameters
Set parameters permitted by the class in spec.configuration:
spec:
configuration:
maxConnections: 300
sharedBuffers: 128MiCheck the PostgresClass’s overridableConfiguration and validations constraints before applying changes.
How database and user management works
Databases inside a service are represented by PostgresDatabase, and users with LOGIN by PostgresUser.
Place them in the same namespace as their Postgres. spec.postgres names that Postgres.
The Kubernetes object name can differ from the SQL database or user name.
The controller discovers databases and users in the PostgreSQL catalogue and creates objects with an empty spec and the Unmanaged phase.
This inventory process exposes existing SQL objects without changing their settings, privileges or passwords.
SQL names are stored in status.databaseName and status.userName; status.postgres identifies the service.
How you enable management depends on whether the SQL object exists:
- For a new database or user, create an object with a populated
specand a new SQL name. - For an existing database or user, populate its discovered inventory object’s
spec. This operation is called adoption. - To stop management, clear the entire
spec. The SQL object is preserved and becomesUnmanaged.
Once bound, the controller continuously reconciles declared fields to their spec values.
SQL changes to those fields are reverted during the next reconciliation.
Omitted fields remain unmanaged, except for defaults persisted in spec while the API processes the request.
Inspect the declaration, including those defaults, before adoption.
Changes are asynchronous. Successful d8 k apply confirms API acceptance; check Synced for completion.
When PostgreSQL is unavailable, a read error does not mean the SQL object has disappeared.
Confirmed disappearance of a bound object produces Lost; an empty replacement is not created automatically.
Managing users
PostgresUser manages the password and privileges of a user with LOGIN.
Inventory excludes service roles postgres, streaming_replica, ro, rw, monitoring, okagent, names prefixed with pg_ or cnpg_, and NOLOGIN roles.
Selecting a password source
Every nonempty spec, including adoption, requires exactly one password source:
storeCredsToSecretcreates a Secret with a random password. An existing Secret is reused only if owned by the same PostgresUser.passwordSecretRefreads a plaintext password from a Secret in the same namespace. The default key ispassword. An external Secret remains under application management.hashedPasswordsupplies a ready PostgreSQL password verifier. Its format must matchpasswordEncryption. It does not produce a plaintext password Secret.
Adoption applies the selected source’s password to PostgreSQL.
To preserve the current password, supply that password or its current verifier.
To change sources, remove the previous field and set the new one in a single update. A nonempty spec cannot lose its last password source.
A Secret value is always treated as plaintext, even when it resembles a hash. If the Secret, key or value is missing, the controller preserves the current SQL password and continues applying other declared fields. Creating a new user waits for an available password source.
SCRAM-SHA-256 is the default. On PostgreSQL versions supporting MD5, that algorithm can be selected explicitly.
With plaintext available, changing passwordEncryption recalculates the verifier without changing the password.
For hashedPassword, supply a verifier in the new format in the same update.
A generated Secret contains username, password and host; specify the database separately in the client configuration.
New Data Source Name (DSN) connection strings are not generated; existing DSNs and additional keys are preserved.
Normal Kubernetes access controls protect the Secret; changing its password applies that password to PostgreSQL.
Deleting the Secret triggers recreation with a new password. See the rotation example for verification steps.
When switching sources, the previous generated Secret is removed after the new password is confirmed as applied.
Clearing the entire spec deletes Secrets owned by PostgresUser and preserves the SQL user and password.
A Secret created by that PostgresUser retains its ownership if later referenced through passwordSecretRef.
It is retained while used as a source. External Secrets are not adopted.
Configuring privileges
privileges: Standard is the default, including adoption; the user is maintained with NOCREATEDB and NOCREATEROLE.
Admin grants CREATEDB and CREATEROLE for creating databases and users through SQL.
It does not grant SUPERUSER, REPLICATION or BYPASSRLS. PostgreSQL rules and ADMIN OPTION govern management of other roles.
For Standard, inRoles declares direct memberships in existing roles:
- Omitting the field leaves memberships unmanaged.
inRoles: []revokes all direct memberships.- A nonempty list enforces the exact membership set, including reverting SQL changes.
Built-in ro, rw, monitoring and ordinary business roles are permitted. Service roles and dangerous privilege chains are not granted through this API.
New grants do not include ADMIN OPTION. The entire membership change is atomic: an error preserves previous memberships.
Revocation uses RESTRICT; dependencies require manual resolution. PostgreSQL 15 uses that version’s dependency rules.
Adopting a user
Find the PostgresUser using status.postgres and status.userName, then populate its spec.
The SQL user identity is fixed; the API fills it from status when omitted from the request.
Another object for the same SQL name enters Conflict. A name occupied by a NOLOGIN role also conflicts.
For a bound managed user, LOGIN revoked through SQL is restored.
Follow the user adoption example for the procedure.
Releasing management and deleting users
Clearing the entire spec preserves the user, password and privileges; its owned generated Secret is removed.
Deleting an Unmanaged object preserves the SQL user; inventory can publish the object again.
Deleting a managed PostgresUser runs DROP ROLE. Users do not have a retentionPolicy setting.
Data and object ownership are not changed automatically.
Role dependencies keep deletion pending until resolved manually; Synced reports the cause.
After PostgresUser deletion, Kubernetes deletes its owned Secrets.
Migrating from the Postgres user list
Postgres.spec.users no longer manages users.
Existing SQL users, passwords, privileges and Secrets are preserved; inventory publishes users as Unmanaged.
Populate the matching PostgresUser’s spec to enable management.
Use passwordSecretRef for an existing plaintext Secret or hashedPassword for a ready verifier.
storeCredsToSecret does not adopt an existing foreign Secret.
Managing databases
PostgresDatabase describes an individual database in a PostgreSQL service. Inventory excludes the postgres system database and template databases.
For creation, specify spec.postgres and spec.databaseName; for an existing database, populate its discovered inventory object.
Follow the database adoption example for the procedure.
Configuring ownership and connections
owner names an existing SQL owner role; connectionLimit sets the connection limit.
A new database without owner is created with rw as owner, without enabling ongoing ownership management.
Adopting an existing database without owner preserves its current owner.
Removing a managed field from spec preserves its last PostgreSQL value and stops managing that field.
Any spec field, including connectionLimit: 0 and retentionPolicy, enables database management.
Managing extensions
extensions declares the complete user extension set.
Omitting the field leaves that set unmanaged; extensions: [] requests removal of all unprotected extensions.
Extra extensions are removed with DROP EXTENSION ... CASCADE, including dependent objects and their data.
This also applies to extensions added through SQL outside the declared list.
A declared schema must exist in the database. Create it before applying the declaration.
Without schema, an installed extension retains its schema; PostgreSQL rules apply when installing a new extension.
Partial extension changes are not rolled back on error. The controller retries reconciliation after the cause is resolved.
Releasing management and deleting databases
When deleting a managed PostgresDatabase, Retain preserves the SQL database, while Delete drops it with all data and forcibly terminates active connections.
If PostgreSQL blocks deletion, the object is retained until the cause is resolved.
If omitted, the API persists the policy from PostgresClass.spec.databaseManagement.retentionPolicy, which defaults to Retain.
Later class changes do not change the persisted policy.
Clearing the entire spec preserves the database regardless of policy and returns it to Unmanaged.
Deleting that object preserves the SQL database; inventory can publish the object again.
After Retain, find the inventory object again before adoption.
Migrating from the Postgres database list
Postgres.spec.databases no longer creates or deletes databases.
Existing databases are published as Unmanaged; settings from the old list are not automatically transferred into the new spec.
Populate the matching PostgresDatabase to manage it. Existing Secret DSNs are preserved; the old list does not generate new ones.
Checking the result
Check service availability and the state of its databases and users:
d8 k -n postgres get postgres,postgresdatabases,postgresusers
d8 k -n postgres get postgresuser test-test-rw -o yamlPostgres Available=True indicates service availability for connections.
Database and user state is described by a phase and the Synced condition:
| Phase | Meaning |
|---|---|
Unmanaged |
The SQL object has been discovered and remains unmanaged |
Creating |
The SQL object is being created |
Bound |
The SQL object is bound; check Synced for the application result |
Conflict |
The SQL name is occupied or bound to another object |
Lost |
Disappearance of the bound SQL object is confirmed; no automatic recreation occurs |
Synced=True confirms compliance with the current declaration generation.
Application errors set it to False; observation errors set it to Unknown.
Read reason, message and observedGeneration in status.conditions.
An ordinary Unmanaged object has no Synced condition; a management recovery error can be reported separately.
If an SQL object with the previous name reappears, a bound object in Lost resumes management.
status.observedState reports actual properties: database owner, connection limit, extensions and size; user privileges, direct memberships and password algorithm.
Size is refreshed separately and can reflect an earlier check.
status.appliedPassword acknowledges the declaration generation and applied source version without exposing a password or verifier.
Limitations
Account for these constraints when preparing a declaration:
| Capability | Constraint |
|---|---|
| Object placement | Postgres, its PostgresDatabase and PostgresUser objects, and password sources must share a namespace |
| Identity | A bound object cannot be redirected to another SQL name |
| Users | Only roles with LOGIN are managed |
| PostgreSQL version | Supported values are 15, 16, 17 and 18; the default is 17 |
Admin |
Requires PostgreSQL 16 or later; inRoles must be omitted |
ro and rw |
Retain global privileges through pg_read_all_data and pg_write_all_data; they are not limited to one database |
| Extensions | Versions are observed in status; schema must exist before application |
| Service extensions | Missing plpgsql, pg_stat_statements and pgaudit entries in spec.extensions do not trigger removal |
| Standby | Inventory on the designated primary reads the replicated catalogue; SQL mutations and password Secret creation are not performed |
Troubleshooting
Start with the object’s status.conditions. Correct the cause in the declaration, Secret or PostgreSQL; the controller retries the operation.
| State or error text | Cause | Action |
|---|---|---|
Conflict |
The SQL name exists or is bound to another object | Inspect status.conflictingResource and populate the identified inventory object’s spec |
generated Secret belongs to another owner |
The generated Secret name is occupied by another owner | Choose an unused storeCredsToSecret name or reference an external Secret using passwordSecretRef |
password Secret key is absent or empty |
The source has no password | Populate the external Secret key; use the rotation procedure for a damaged generated Secret |
Lost |
The bound SQL object was removed | Restore it under the same name or explicitly start a new lifecycle: delete the Kubernetes object and apply its manifest again |
| Deletion remains pending | SQL dependencies block deletion | Read the Synced message and resolve dependencies; user data and ownership are not changed automatically |
| Password changed but the application cannot connect | The process still uses the previous password | Check appliedPassword, reload the Secret and open new connections; restart the Pod when using environment variables |
Extension libraries
Use Postgres.spec.extensionVersions to select an exact extension version available in the PostgreSQL image. For PostgreSQL 17, the following fragment enables pgAudit:
spec:
extensionVersions:
- name: pgaudit
version: "17.2"Entries must have unique names. Server-Side Apply merges the list by name. JSON Merge Patch replaces the entire list; include every entry you want to retain. Entry order does not affect preload.
The operator checks the version before applying the configuration. The field does not download another version or execute CREATE EXTENSION. A change to the effective shared_preload_libraries requires a PostgreSQL restart. Removing a list entry removes its request; operator-managed libraries remain enabled. For a standalone instance, a restart interrupts connections.
To create SQL objects, declare the extension in PostgresDatabase.spec.extensions. The webhook checks the available names and required preload settings. For example, pgaudit requires its entry in the parent Postgres, whereas vector does not require preload. The database controller waits for the required library to become active before executing extension SQL.
The operator manages plpgsql and pg_stat_statements automatically. Do not specify them in either extensionVersions or PostgresDatabase.spec.extensions. Before upgrading an existing declaration containing these names, remove their entries; their SQL objects are retained.
Selecting pg_partman in extensionVersions preloads pg_partman_bgw. The SQL extension pg_partman can be declared in PostgresDatabase.spec.extensions without enabling the background worker. Configure the worker separately using the pg_partman_bgw.* PostgreSQL parameters.
The shipped images provide these versions for the following components:
| PostgreSQL | pgaudit | vector | pg_stat_kcache | pg_partman |
|---|---|---|---|---|
| 15 | 1.7.2 | 0.8.1 | 2.3.1 | 4.7.4 |
| 16 | 16.2 | 0.8.1 | 2.3.1 | 4.7.4 |
| 17 | 17.2 | 0.8.1 | 2.3.1 | 5.4.3 |
| 18 | 18.1 | 0.8.1 | 2.3.1 | 5.4.3 |
The Database CRD lists the full set of user-selectable SQL extensions. Availability also depends on the PostgreSQL version. A vector entry in extensionVersions checks its version without adding it to server preload. An image update incompatible with an explicitly selected version is rejected; update the selection to a version provided by the target image.
version selects the component release built from a fixed commit SHA. The SQL extension version in a database is tracked separately and may differ. For PostgreSQL contrib extensions, the component version is the PostgreSQL version in the image — 15.19, 16.15, 17.11, or 18.6 respectively.