Before you begin
Make sure that you have a functioning AlloyDB Omni cluster deployed and that the orchestrator is installed on your control node. You must also make sure that port 6432 is open on your load balancer or database nodes to allow incoming traffic to PgBouncer.
Prepare resource specification
Create a resource specification file, for example, pgbouncer_spec.yaml that defines the PgBouncer resource. This file describes the connection pooler and its association with your database cluster.
PgBouncer:
metadata:
name: PGBOUNCER_RESOURCE_NAME
spec:
dbclusterRef: CLUSTER_NAME
allowSuperUserAccess: ALLOW_SUPERUSER_ACCESS
serverTLS:
certSecret:
name: CERT_SECRET_NAME
Replace the following:
PGBOUNCER_RESOURCE_NAME: the name of your PgBouncer resource.CLUSTER_NAME: the name of your AlloyDB Omni database cluster. Use the same name you declared when you bootstrapped your cluster.ALLOW_SUPERUSER_ACCESS: specifies whether to allow superuser access to the database. Set this totrueorfalse.CERT_SECRET_NAME: the name of the certificate secret. The secret must contain entries for theca.crtCA certificate, thetls.keyprivate key, and thetls.crtleaf certificate.- The values in this secret are used to populate the
server_tls_ca_file,server_tls_cert_file, andserver_tls_key_filein thepgbouncer.iniconfiguration. - The CA certificate must match the CA that signed the database cluster's leaf certificate.
- The leaf certificate must contain the Common Name
alloydbpgbouncer.
- The values in this secret are used to populate the
Bootstrap PgBouncer
To bootstrap the PgBouncer connection pooler, use Ansible or the AlloyDB Omni orchestrator CLI (alloydbctl).:
Ansible
To bootstrap PgBouncer using Ansible, you use a playbook that uses the google.alloydbomni_orchestrator.bootstrap role:
- Create an Ansible playbook, for example,
bootstrap_pgbouncer.yaml, that points to your Ansible inventory and resource specification:- name: Bootstrap PgBouncer hosts: all vars: ansible_user: SSH_USER ansible_ssh_private_key_file: PATH_TO_KEY roles: - role: google.alloydbomni_orchestrator.bootstrap
Replace the following:
SSH_USER: the username that you use to connect to the nodes in your cluster using SSH.PATH_TO_KEY: the local path to the SSH private key file used to connect to your node.
- Run the playbook from your control node, passing the resource specification as an extra variable:
ansible-playbook -i inventory.yaml bootstrap_pgbouncer.yaml \ -e resource_spec=pgbouncer_spec.yaml
alloydbctl
You can use the alloydbctl command-line utility to apply the PgBouncer configuration directly.
To apply the configuration, execute the apply command and specify both your Ansible inventory and the PgBouncer resource specification:
alloydbctl apply -d deployment_spec.yaml -r pgbouncer_spec.yaml
Verify the deployment
Choose the interface you want to use to verify the status and configuration of your PgBouncer resource:
Ansible
To verify the deployment using Ansible, follow these steps:
-
Create a verification playbook, for example,
verify_pgbouncer.yaml, that uses thegoogle.alloydbomni_orchestrator.statusrole:- name: Verify PgBouncer hosts: localhost connection: local vars: resource_type: PgBouncer resource_name: PGBOUNCER_RESOURCE_NAME roles: - role: google.alloydbomni_orchestrator.status
-
Run the playbook from your control node, passing your inventory file:
ansible-playbook -i inventory.yaml verify_pgbouncer.yaml
alloydbctl
You can use the get command to retrieve the status of your PgBouncer resource:
alloydbctl get -t PgBouncer -n PGBOUNCER_RESOURCE_NAME -d deployment_spec.yaml
Replace PGBOUNCER_RESOURCE_NAME with the name of your PgBouncer resource.
Delete a PgBouncer connection pooler
You can delete the PgBouncer connection pooler using Ansible or the AlloyDB Omni orchestrator command-line interface (CLI):
Ansible
To delete a PgBouncer connection pooler using Ansible, follow these steps:
-
Create an Ansible playbook—for example,
teardown.yaml, that uses thegoogle.alloydbomni_orchestrator.deleterole:- name: Delete PgBouncer hosts: localhost vars: ansible_become: true ansible_user: SSH_USER ansible_ssh_private_key_file: PATH_TO_KEY roles: - role: google.alloydbomni_orchestrator.delete
-
Run the playbook using the
ansible-playbookcommand. You must pass the followingresource_name:ansible-playbook -i "DEPLOYMENT_SPEC" teardown.yaml \ -e resource_type=PgBouncer -e resource_name="PGBOUNCER_RESOURCE_NAME"
alloydbctl
To delete your PgBouncer resource, run the alloydbctl delete command:
alloydbctl delete -d "DEPLOYMENT_SPEC" -t PgBouncer -n "PGBOUNCER_RESOURCE_NAME"