This page describes how to set up a high availability configuration for
AlloyDB Omni. This page only covers creating a new
AlloyDB Omni instance in a high availability configuration. It
doesn't cover converting existing instances to high availability.
In this guide, we deploy a three node
Patroni cluster with
AlloyDB Omni and a three node cluster etcd as
the configuration store. In the front of the cluster, we use
HAProxy in a managed instance group for the
floating IP address so that the failover is transparent to clients.
The initial configuration for this setup is shown in the following diagram:
Figure 1. Configuration where HAProxy manages the connection between clients
and the primary node.
If an outage occurs, the configuration changes to the following diagram:
Figure 2. Updated configuration where the failed primary node is replaced by
the standby node.
If the number of clients that connect to the database becomes an issue and you
have performance issues due to the high number of simultaneous database
connections, we recommend that you add application-side connection pooling. If
you can't do that, then you can add database-side connection pooling using a
tool like PgBouncer.
Deployment
In Cloud Shell and after cloning the Cloud Solutions repository, navigate
to the terraform directory.
cd cloud-solutions/projects/alloydbomni-ha-patroni-etcd/terraform
Create and edit a terraform.tfvars file. In the file, set values for the
following variables.
Run the Terraform script to create all the resources.
terraform init && terraform apply
This script creates and configures the following:
Three nodes for your etcd cluster
Three nodes for your Patroni cluster
One node for HAProxy
Configuring Patroni to be synchronous
To make Patroni use only synchronous replication in your three nodes cluster,
add configuration items like synchronous_mode, synchronous_node_count,
synchronous_commit, and synchronous_standby_names in the bootstrap section
in your Patroni configuration files. The Patroni configuration is defined in the
startup script template
and in the /alloydb/config/patroni.yml file on the Patroni nodes. To use
synchronous replication, your Patroni bootstrap configuration should look as
follows:
When synchronous_mode is turned on, Patroni uses synchronous replication
between its primary and the other replicas. The parameter
synchronous_node_count is used by Patroni to manage the number of synchronous
standby replicas. Patroni manages precise number of synchronous standby
replicas based on parameter synchronous_node_count and adjusts the state in
the configuration store and in the synchronous_standby_names as members join
and leave. For more information about synchronous replication, see the
Replication modes
section in Patroni's documentation.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-25 UTC."],[[["\u003cp\u003eThis guide explains how to set up a new high availability configuration for AlloyDB Omni, using a three-node Patroni cluster and a three-node etcd cluster.\u003c/p\u003e\n"],["\u003cp\u003eHAProxy in a managed instance group is implemented to manage the floating IP address, ensuring transparent failover for clients connecting to the database.\u003c/p\u003e\n"],["\u003cp\u003eDeployment requires cloning a repository, configuring a \u003ccode\u003eterraform.tfvars\u003c/code\u003e file with project details, and running a Terraform script to create the necessary nodes and resources.\u003c/p\u003e\n"],["\u003cp\u003eThe guide details how to configure Patroni for synchronous replication, using settings like \u003ccode\u003esynchronous_mode\u003c/code\u003e, \u003ccode\u003esynchronous_node_count\u003c/code\u003e, and \u003ccode\u003esynchronous_standby_names\u003c/code\u003e to ensure data consistency across nodes.\u003c/p\u003e\n"],["\u003cp\u003eConnection pooling, either application-side or database-side with PgBouncer, is recommended to manage a high number of simultaneous database connections and to improve performance.\u003c/p\u003e\n"]]],[],null,["# Create a high availability setup\n\nSelect a documentation version: 15.7.1keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/high-availability/setup)\n- [16.8.0](/alloydb/omni/16.8.0/docs/high-availability/setup)\n- [16.3.0](/alloydb/omni/16.3.0/docs/high-availability/setup)\n- [15.12.0](/alloydb/omni/15.12.0/docs/high-availability/setup)\n- [15.7.1](/alloydb/omni/15.7.1/docs/high-availability/setup)\n- [15.7.0](/alloydb/omni/15.7.0/docs/high-availability/setup)\n\n\u003cbr /\u003e\n\n| **Note:** Your use of AlloyDB Omni is subject to the agreement between you and Google that governs Google Cloud offerings. If you do not have a Google Cloud account, or have not otherwise entered into an agreement with Google that governs Google Cloud offerings, please do not proceed or download this software until you have done so. To create a Google Cloud account, see [the Google Cloud homepage](/docs/get-started).\n\n\u003cbr /\u003e\n\nThis page describes how to set up a high availability configuration for\nAlloyDB Omni. This page only covers creating a new\nAlloyDB Omni instance in a high availability configuration. It\ndoesn't cover converting existing instances to high availability.\n\nBefore you begin\n----------------\n\n1. Read the\n [High availability and data resilience](/alloydb/omni/15.7.1/docs/high-availability/overview).\n\n2. If you don't already have one, create a Google Cloud project.\n\n3. Ensure that billing is enabled for your project.\n\n4. Open Cloud Shell in the Google Cloud console.\n\n5. In the Google Cloud console, clone the following source repository.\n\n git clone https://github.com/GoogleCloudPlatform/cloud-solutions.git\n\nInstallation\n------------\n\nIn this guide, we deploy a three node\n[Patroni](https://patroni.readthedocs.io/en/latest/) cluster with\nAlloyDB Omni and a three node cluster [etcd](https://etcd.io/) as\nthe configuration store. In the front of the cluster, we use\n[HAProxy](https://www.haproxy.org/) in a managed instance group for the\nfloating IP address so that the failover is transparent to clients.\n\nThe initial configuration for this setup is shown in the following diagram:\n\n**Figure 1.** Configuration where HAProxy manages the connection between clients\nand the primary node.\n\nIf an outage occurs, the configuration changes to the following diagram:\n\n**Figure 2.** Updated configuration where the failed primary node is replaced by\nthe standby node.\n\nIf the number of clients that connect to the database becomes an issue and you\nhave performance issues due to the high number of simultaneous database\nconnections, we recommend that you add application-side connection pooling. If\nyou can't do that, then you can add database-side connection pooling using a\ntool like PgBouncer.\n\nDeployment\n----------\n\n1. In Cloud Shell and after cloning the Cloud Solutions repository, navigate\n to the terraform directory.\n\n ```\n cd cloud-solutions/projects/alloydbomni-ha-patroni-etcd/terraform\n ```\n2. Create and edit a `terraform.tfvars` file. In the file, set values for the\n following variables.\n\n project_id = \"\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\"\n region = \"\u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e\"\n zones = \"\u003cvar translate=\"no\"\u003eZONES\u003c/var\u003e\"\n node_count = 3\n cluster_name = \"\u003cvar translate=\"no\"\u003eCLUSTER_NAME\u003c/var\u003e\"\n replication_user_password = \"\u003cvar translate=\"no\"\u003eREPLICATION_USER_PASSWORD\u003c/var\u003e\"\n postgres_super_user_password = \"\u003cvar translate=\"no\"\u003ePG_SUPER_USER_PASSWORD\u003c/var\u003e\"\n\n Descriptions for each variable can be found on GitHub in the\n [variables configuration file](https://github.com/GoogleCloudPlatform/cloud-solutions/blob/main/projects/alloydbomni-ha-patroni-etcd/terraform/variables.tf).\n3. Run the Terraform script to create all the resources.\n\n ```\n terraform init && terraform apply\n ```\n\n This script creates and configures the following:\n - Three nodes for your etcd cluster\n\n - Three nodes for your Patroni cluster\n\n - One node for HAProxy\n\n### Configuring Patroni to be synchronous\n\nTo make Patroni use only synchronous replication in your three nodes cluster,\nadd configuration items like `synchronous_mode`, `synchronous_node_count`,\n`synchronous_commit`, and `synchronous_standby_names` in the bootstrap section\nin your Patroni configuration files. The Patroni configuration is defined in the\n[startup script template](https://github.com/GoogleCloudPlatform/cloud-solutions/blob/main/projects/alloydbomni-ha-patroni-etcd/terraform/scripts/patroni_startup.tftpl)\nand in the `/alloydb/config/patroni.yml` file on the Patroni nodes. To use\nsynchronous replication, your Patroni bootstrap configuration should look as\nfollows: \n\n bootstrap:\n dcs:\n ttl: 30\n loop_wait: 10\n retry_timeout: 10\n maximum_lag_on_failover: 1048576\n synchronous_mode: true\n synchronous_node_count: 2\n postgresql:\n use_pg_rewind: true\n use_slots: true\n parameters:\n hot_standby: \"on\"\n wal_keep_segments: 20\n max_wal_senders: 8\n max_replication_slots: 8\n synchronous_commit: remote_apply\n synchronous_standby_names: '*'\n\nWhen `synchronous_mode` is turned on, Patroni uses synchronous replication\nbetween its primary and the other replicas. The parameter\n`synchronous_node_count` is used by Patroni to manage the number of synchronous\nstandby replicas. Patroni manages precise number of synchronous standby\nreplicas based on parameter `synchronous_node_count` and adjusts the state in\nthe configuration store and in the `synchronous_standby_names` as members join\nand leave. For more information about synchronous replication, see the\n[Replication modes](https://patroni.readthedocs.io/en/latest/replication_modes.html)\nsection in Patroni's documentation.\n\nWhat's next\n-----------\n\n- [Test your high availability setup](/alloydb/omni/15.7.1/docs/high-availability/test)"]]