2 Connect to the PostgreSQL cluster¶
When the installation is done, we can connect to the cluster.
The pgBouncer component of Percona Distribution for PostgreSQL provides the point of entry to the PostgreSQL cluster. We will use the pgBouncer URI to connect.
The pgBouncer URI is stored in the Secret object, which the Operator generates during the installation.
To connect to PostgreSQL, do the following:
-
List the Secrets objects
kubectl get secrets -n <namespace>The Secrets object we target is named as
<cluster_name>-pguser-<cluster_name>. The<cluster_name>value is the name of your Percona Distribution for PostgreSQL Cluster. The default variant is:cluster1-pguser-cluster1cluster1-pg-db-pguser-cluster1-pg-db -
Retrieve the pgBouncer URI from your secret, decode and pass it as the
PGBOUNCER_URIenvironment variable. Replace the<secret>,<namespace>placeholders with your Secret object and namespace accordingly:PGBOUNCER_URI=$(kubectl get secret <secret> --namespace <namespace> -o jsonpath='{.data.pgbouncer-uri}' | base64 --decode)The following example shows how to pass the pgBouncer URI from the default Secret object
cluster1-pguser-cluster1:PGBOUNCER_URI=$(kubectl get secret cluster1-pguser-cluster1 --namespace <namespace> -o jsonpath='{.data.pgbouncer-uri}' | base64 --decode) -
Create a Pod where you start a container with Percona Distribution for PostgreSQL and connect to the database. The following command does it, naming the Pod
pg-clientand connects you to thecluster1database:kubectl run -i --rm --tty pg-client --image=percona/percona-distribution-postgresql:18.6.1-3 --restart=Never -- psql $PGBOUNCER_URIIt may take some time to create the Pod and connect to the database. As the result, you should see the following sample output:
Expected output
psql (18.6.1-3) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) Type "help" for help. cluster1=>
Congratulations! You have connected to your PostgreSQL cluster.
Next steps¶
Created: September 14, 2023