For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

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:

bash

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:

bash

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:

  1. List the PostgreSQL pods in the cluster together with their roles:

    bash

    The ROLE column shows primary for exactly one pod and replica for the others. The postgres-operator.crunchydata.com/instance label limits the list to the PostgreSQL pods.

  2. Check the state of the cluster with Patroni, which runs inside every PostgreSQL pod. Run the following command in the database container of any PostgreSQL pod:

    bash

    The output lists every member of the cluster. For example:

    text

    A healthy cluster shows exactly one Leader in the running state and every replica in the streaming state with both Lag columns close to 0. The first Lag column 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 the TL column.

  3. Execute the following SQL query on the primary pod to see the replication connections from the PostgreSQL side:

    bash

    The output contains one row per read replica. For example:

    text

    The state column shows streaming for 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.