[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Create a high availability setup\n\nSelect a documentation version: 16.8.0keyboard_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/16.8.0/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](/alloydb/omni/16.8.0/docs/high-availability/(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/16.8.0/docs/high-availability/test)"]]