Bagian berikut memberikan langkah-langkah untuk mengonfigurasi server utama AlloyDB Omni untuk replikasi, mengonfigurasi server replika, dan memverifikasi status replikasi di server utama.
Mengonfigurasi server utama untuk replikasi
Perbarui setelan jaringan atau firewall host server utama Anda sehingga
mengizinkan traffic masuk dari host server replika melalui port TCP
5432.
Tambahkan baris berikut dalam file /var/alloydb/config/pg_hba.conf:
DATA_DIR: jalur sistem file yang ingin digunakan replika ini untuk direktori datanya.
PORT: port TCP yang Anda inginkan agar AlloyDB Omni menerima koneksi. Jika Anda tidak
memberikan nilai ini, AlloyDB Omni akan menerapkan nilai default
5432.
SOURCE_IP: alamat IP instance AlloyDB Omni utama yang akan direplikasi.
SOURCE_PORT: port TCP instance AlloyDB Omni utama
yang akan direplikasi. Jika Anda tidak
memberikan nilai ini, AlloyDB Omni akan menerapkan nilai default
5432.
Pastikan replika memiliki konektivitas jaringan ke server utama:
pingSOURCE_IP
Mulai replika Anda:
sudoalloydbdatabase-serverstart
Memverifikasi status replikasi di server utama
Untuk memverifikasi bahwa replikasi dikonfigurasi dengan benar, jalankan perintah berikut di host server primer:
dockerexec-itpg-servicepsql-hlocalhost-Ualloydbadmin-c"select * from pg_stat_replication"
Tabel output berisi satu baris untuk setiap replika yang terhubung ke server database
utama Anda.
Setelah Anda menyiapkan replikasi, semua penyisipan, pembaruan, dan penghapusan baris di server database utama Anda akan dapat dibaca di replika Anda dalam hitungan detik.
[[["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-04 UTC."],[[["\u003cp\u003eAlloyDB Omni replica servers offer read-only clones of the primary database, enhancing read throughput and availability by continuously updating with the primary server's data.\u003c/p\u003e\n"],["\u003cp\u003eConfiguring a primary server for replication involves updating network/firewall settings to allow ingress traffic from the replica and modifying the \u003ccode\u003e/var/alloydb/config/pg_hba.conf\u003c/code\u003e file to permit connections.\u003c/p\u003e\n"],["\u003cp\u003eCreating a replica server requires installing AlloyDB Omni and using the \u003ccode\u003ealloydb database-server install\u003c/code\u003e command with specific flags, including the data directory, port, source IP, and source port of the primary server.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure the replica is correctly set up, network connectivity to the primary server must be confirmed via a \u003ccode\u003eping\u003c/code\u003e command, and the replica must be started using \u003ccode\u003esudo alloydb database-server start\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eReplication status can be verified on the primary server using a \u003ccode\u003edocker exec\u003c/code\u003e command that checks the \u003ccode\u003epg_stat_replication\u003c/code\u003e table, and once configured, changes on the primary server reflect on the replica within seconds.\u003c/p\u003e\n"]]],[],null,["# Create a read-only replica\n\nSelect a documentation version: 15.5.2keyboard_arrow_down\n\n- [Current (16.8.0)](/alloydb/omni/current/docs/set-up-read-replica)\n- [16.8.0](/alloydb/omni/16.8.0/docs/set-up-read-replica)\n- [16.3.0](/alloydb/omni/16.3.0/docs/set-up-read-replica)\n- [15.12.0](/alloydb/omni/15.12.0/docs/set-up-read-replica)\n- [15.7.1](/alloydb/omni/15.7.1/docs/set-up-read-replica)\n- [15.7.0](/alloydb/omni/15.7.0/docs/set-up-read-replica)\n- [15.5.5](/alloydb/omni/15.5.5/docs/set-up-read-replica)\n- [15.5.4](/alloydb/omni/15.5.4/docs/set-up-read-replica)\n- [15.5.2](/alloydb/omni/15.5.2/docs/set-up-read-replica)\n\n\u003cbr /\u003e\n\nTo increase read throughput and availability, you can create an AlloyDB Omni replica server for an existing AlloyDB Omni server. A replica server provides a read-only clone of your primary database server. It continuously updates its own data to reflect changes to your primary server's data.\n\n\u003cbr /\u003e\n\nThe following sections provide steps to configure your\nAlloyDB Omni primary server for replication, configure the\nreplica server, and verify replication status on the primary server.\n\n\n| The information on this page applies only to AlloyDB Omni for containers. It does not apply to AlloyDB Omni for Kubernetes.\n\n\u003cbr /\u003e\n\nConfigure your primary server for replication\n---------------------------------------------\n\n1. Update the network or firewall settings of your primary server's host so\n that it allows ingress traffic from the replica server's host through TCP\n port `5432`.\n\n2. Add the following lines in the `/var/alloydb/config/pg_hba.conf` file:\n\n host all alloydbreplica \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e trust\n host replication alloydbreplica \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e trust\n host alloydbmetadata alloydbmetadata \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e trust\n\n Replace \u003cvar translate=\"no\"\u003eIP_RANGE\u003c/var\u003e with the IP range, in CIDR notation, of\n the subnet where your replica machine is located. For example,\n `203.0.113.0/24`.\n3. Restart your primary server:\n\n sudo alloydb database-server stop\n sudo alloydb database-server start\n\nCreate and configure the replica server\n---------------------------------------\n\nTo create and configure an AlloyDB Omni replica server, complete\nthe following steps:\n\n1. [Install\n AlloyDB Omni](/alloydb/omni/15.5.2/docs/install) onto the system\n you want to host the replica.\n\n When you run the `alloydb\n database-server install` command, include the flags that are specific\n to creating a replica: \n\n sudo alloydb database-server install \\\n --data-dir=\u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e \\\n --pg-port=\u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e \\\n --replica-source-ip=\u003cvar translate=\"no\"\u003eSOURCE_IP\u003c/var\u003e \\\n --replica-source-port=\u003cvar translate=\"no\"\u003eSOURCE_PORT\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDATA_DIR\u003c/var\u003e: the file system path you want this replica\n to use for its data directory.\n\n - \u003cvar translate=\"no\"\u003ePORT\u003c/var\u003e: the TCP port that you want\n AlloyDB Omni to accept connections on. If you don't\n provide this value, then AlloyDB Omni applies a default\n value of `5432`.\n\n - \u003cvar translate=\"no\"\u003eSOURCE_IP\u003c/var\u003e: the IP address of the primary\n AlloyDB Omni instance to replicate from.\n\n - \u003cvar translate=\"no\"\u003eSOURCE_PORT\u003c/var\u003e: the TCP port of the primary\n AlloyDB Omni instance to replicate from. If you don't\n provide this value, then AlloyDB Omni applies a default\n value of `5432`.\n\n2. Ensure the replica has network connectivity to the primary server:\n\n ping \u003cvar translate=\"no\"\u003eSOURCE_IP\u003c/var\u003e\n\n3. Start your replica:\n\n sudo alloydb database-server start\n\nVerify replication status on the primary server\n-----------------------------------------------\n\nTo verify replication is configured properly, run the following command on the\nprimary server's host: \n\n docker exec -it pg-service psql -h localhost -U alloydbadmin -c \"select * from pg_stat_replication\"\n\nThe output table contains one row for every replica connected to your primary\ndatabase server.\n\nAfter you set up replication, all inserts, updates, and deletions to rows in\nyour primary database server become readable on your replica within seconds."]]