Halaman ini menjelaskan cara menyiapkan konfigurasi ketersediaan tinggi untuk
AlloyDB Omni. Halaman ini hanya membahas cara membuat instance
AlloyDB Omni baru dalam konfigurasi ketersediaan tinggi. Dokumen ini tidak membahas cara mengonversi instance yang ada ke ketersediaan tinggi.
Dalam panduan ini, kita akan men-deploy cluster Patroni tiga node dengan AlloyDB Omni dan etcd tiga node sebagai penyimpanan konfigurasi. Di bagian depan cluster, kita menggunakan
HAProxy dalam grup instance terkelola untuk alamat IP mengambang sehingga failover transparan bagi klien.
Konfigurasi awal untuk penyiapan ini ditunjukkan dalam diagram berikut:
Gambar 1. Konfigurasi saat HAProxy mengelola koneksi antara klien
dan node utama.
Jika terjadi gangguan, konfigurasi akan berubah menjadi diagram berikut:
Gambar 2. Konfigurasi yang diperbarui saat node utama yang gagal digantikan oleh
node standby.
Jika jumlah klien yang terhubung ke database menjadi masalah dan Anda mengalami masalah performa karena banyaknya koneksi database simultan, sebaiknya tambahkan penggabungan koneksi sisi aplikasi. Jika
Anda tidak dapat melakukannya, Anda dapat menambahkan penggabungan koneksi sisi database menggunakan
alat seperti PgBouncer.
Deployment
Di Cloud Shell dan setelah meng-clone repositori Cloud Solutions, buka
direktori terraform.
cd cloud-solutions/projects/alloydbomni-ha-patroni-etcd/terraform
Buat dan edit file terraform.tfvars. Dalam file, tetapkan nilai untuk
variabel berikut.
Jalankan skrip Terraform untuk membuat semua resource.
terraform init && terraform apply
Skrip ini membuat dan mengonfigurasi hal berikut:
Tiga node untuk cluster etcd Anda
Tiga node untuk cluster Patroni Anda
Satu node untuk HAProxy
Mengonfigurasi Patroni agar sinkron
Agar Patroni hanya menggunakan replikasi sinkron di cluster tiga node Anda, tambahkan item konfigurasi seperti synchronous_mode, synchronous_node_count, synchronous_commit, dan synchronous_standby_names di bagian bootstrap dalam file konfigurasi Patroni Anda. Konfigurasi Patroni ditentukan dalam
template skrip startup
dan dalam file /alloydb/config/patroni.yml di node Patroni. Untuk menggunakan replikasi sinkron, konfigurasi bootstrap Patroni Anda akan terlihat sebagai berikut:
Jika synchronous_mode diaktifkan, Patroni menggunakan replikasi sinkron
antara instance utama dan replika lainnya. Parameter
synchronous_node_count digunakan oleh Patroni untuk mengelola jumlah replika standby
sinkron. Patroni mengelola jumlah replika standby sinkron yang tepat berdasarkan parameter synchronous_node_count dan menyesuaikan status di penyimpanan konfigurasi dan di synchronous_standby_names saat anggota bergabung dan keluar. Untuk mengetahui informasi selengkapnya tentang replikasi sinkron, lihat bagian
Mode replikasi
dalam dokumentasi Patroni.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-05 UTC."],[[["\u003cp\u003eThis guide provides instructions for setting up a new AlloyDB Omni instance in a high availability configuration using a three-node Patroni cluster and a three-node etcd cluster.\u003c/p\u003e\n"],["\u003cp\u003eThe setup utilizes HAProxy within a managed instance group to manage the floating IP address, ensuring transparent failover for clients.\u003c/p\u003e\n"],["\u003cp\u003eThe initial configuration includes a primary node managed by HAProxy for client connections, and if an outage occurs, a standby node will replace the failed primary.\u003c/p\u003e\n"],["\u003cp\u003eThe deployment process involves cloning a source repository, configuring a \u003ccode\u003eterraform.tfvars\u003c/code\u003e file with project details, and running a Terraform script to create and configure the required resources.\u003c/p\u003e\n"],["\u003cp\u003ePatroni can be configured for synchronous replication by modifying settings like \u003ccode\u003esynchronous_mode\u003c/code\u003e, \u003ccode\u003esynchronous_node_count\u003c/code\u003e, and \u003ccode\u003esynchronous_standby_names\u003c/code\u003e in the Patroni configuration files.\u003c/p\u003e\n"]]],[],null,["# Create a high availability setup\n\nSelect a documentation version: 16.3.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.3.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.3.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.3.0/docs/high-availability/test)"]]