Skip to main content
When you create a PostgresCluster, PGO automatically provisions PostgreSQL users and databases and stores the resulting connection credentials in Kubernetes Secrets. You can declare additional users in the spec, control which databases each user can access, choose a password format, and customize authentication rules by writing directly to pg_hba.conf through the spec.authentication field.

Default user and database

PGO creates one PostgreSQL user and one database by default, both named after the PostgresCluster resource. For a cluster named hippo, this means:
  • PostgreSQL user: hippo
  • PostgreSQL database: hippo
  • Credentials Secret: hippo-pguser-hippo
The default user has full privileges on the default database. You can disable this behavior by setting spec.users to an empty list ([]), which instructs PGO to create no users at all.

Reading connection credentials

PGO stores connection details for each user in a Secret named <cluster>-pguser-<username>. The Secret contains the following keys:
The dbname, uri, and jdbc-uri keys are only populated when at least one database is listed in spec.users[].databases. If no database is specified, those keys are absent.
If PGBouncer is enabled on the cluster, additional keys are added automatically: To retrieve credentials for the default user:

Creating additional users

Declare extra users in spec.users. Each entry requires a name and optionally lists databases, role attributes, and a password format:
Removing a user from spec.users does not drop the PostgreSQL role or revoke database access. You must run DROP ROLE manually if you want to remove the user from PostgreSQL.

User field reference

The options and databases fields are ignored for the built-in postgres superuser.

Customizing authentication rules (pg_hba.conf)

PGO writes pg_hba.conf based on mandatory rules it controls (for monitoring, PgBouncer, and replication) plus any rules you define in spec.authentication.rules. Rules are evaluated in the order they appear; the first match determines whether and how the connection authenticates. When spec.authentication.rules is omitted or empty, PGO applies a default that accepts encrypted connections from any user with a password. To customize rules, set spec.authentication:
Each rule supports these fields drawn from PostgresHBARuleSpec:
The trust method is blocked by PGO validation and will cause the PostgresCluster to be rejected. Use scram-sha-256 for password-based authentication.

Example: require certificate authentication

Example: raw HBA line

For advanced cases where you need a line not expressible via structured fields, use the hba key:
Rules written using hba are inserted verbatim into pg_hba.conf without validation. Include files (include, include_if_exists, include_dir) are not permitted.