Validate the PostgreSQL cluster
After you applied the Cennso PostgreSQL CRs to the target cluster, the PostgreSQL cluster is deployed. It consists of the multiple instances specified by spec.instances of the PostgreSQLInstance CR.
One of the PostgreSQL instances is the primary instance that accepts both reads and writes. The others are read replicas only. You can differentiate them by the postgres-operator.crunchydata.com/role label. This label has the value primary for the PostgreSQL instance selected as the primary instance and replica for the read replicas.
This document describes the validation procedures after your PostgreSQL cluster is up and running.
Connect to the PostgreSQL cluster
Applications must use PgBouncerOpens in a new tab instead of connecting directly to a pod or a service. The Cennso Database extension exposes two kinds of PgBouncer endpoints:
In-cluster endpoint
The Cennso PostgreSQL Instance creates a Kubernetes Service that routes traffic to all PgBouncer pods. Applications running in the same cluster must use this Service as the PostgreSQL endpoint. The endpoint is reachable through the following endpoints:
{POSTGRESQL-INSTANCE-NAME}-pgbouncer:5432{POSTGRESQL-INSTANCE-NAME}-pgbouncer.{POSTGRESQL-CLUSTER-NAMESPACE}.svc.cluster.local:5432
The {POSTGRESQL-INSTANCE-NAME} is the value specified in the metadata.name of the PostgreSQLInstance CR, and the {POSTGRESQL-CLUSTER-NAMESPACE} is the value of its spec.namespace.
For example, to connect from a Pod in the same cluster as the default database user, run:
Connections to PgBouncer are always encrypted. A connection with sslmode=disable is rejected.
The password for the default database user is stored in the {POSTGRESQL-INSTANCE-NAME}-pguser-{POSTGRESQL-INSTANCE-NAME} Kubernetes Secret in the same namespace as the PostgreSQL cluster. You can retrieve it with:
The same Secret also holds a ready-to-use connection string for PgBouncer in the pgbouncer-uri key.
External endpoint
By default, the PgBouncer Service is of the ClusterIP type and is reachable only from inside the cluster. To reach the PostgreSQL cluster from the outside, set spec.proxy.pgBouncer.expose.type of the PostgreSQLInstance CR to NodePort or LoadBalancer. For more information, see the PgBouncer configuration section of the Cennso PostgreSQL Instance document.
Validate replication state
Once the primary and the read replicas are ready, you can check the replication status:
List the PostgreSQL pods in the cluster together with their roles:
bashThe
ROLEcolumn showsprimaryfor exactly one pod andreplicafor the others. Thepostgres-operator.crunchydata.com/instancelabel limits the list to the PostgreSQL pods.Check the state of the cluster with Patroni, which runs inside every PostgreSQL pod. Run the following command in the
databasecontainer of any PostgreSQL pod:bashThe output lists every member of the cluster. For example:
textA healthy cluster shows exactly one
Leaderin therunningstate and every replica in thestreamingstate with bothLagcolumns close to0. The firstLagcolumn shows how far the replica is behind the primary in receiving WAL. The second column shows how far it is behind in replaying WAL. All members share the same timeline in theTLcolumn.Execute the following SQL query on the primary pod to see the replication connections from the PostgreSQL side:
bashThe output contains one row per read replica. For example:
textThe
statecolumn showsstreamingfor every read replica. This means that you have a fully working and ready-to-use PostgreSQL cluster.
If a member of the cluster is unhealthy, see the Troubleshoot using Patroni document.