The following sections provide steps to configure your
AlloyDB Omni primary server for replication, configure the
replica server, and verify replication status on the primary server.
Configure your primary server for replication
Update the network or firewall settings of your primary server's host so
that it allows ingress traffic from the replica server's host through TCP
port 5432.
Add the following lines in the /var/alloydb/config/pg_hba.conf file:
DATA_DIR: the file system path you want this replica
to use for its data directory.
PORT: the TCP port that you want
AlloyDB Omni to accept connections on. If you don't
provide this value, then AlloyDB Omni applies a default
value of 5432.
SOURCE_IP: the IP address of the primary
AlloyDB Omni instance to replicate from.
SOURCE_PORT: the TCP port of the primary
AlloyDB Omni instance to replicate from. If you don't
provide this value, then AlloyDB Omni applies a default
value of 5432.
Ensure the replica has network connectivity to the primary server:
pingSOURCE_IP
Start your replica:
sudoalloydbdatabase-serverstart
Verify replication status on the primary server
To verify replication is configured properly, run the following command on the
primary server's host:
dockerexec-itpg-servicepsql-hlocalhost-Ualloydbadmin-c"select * from pg_stat_replication"
The output table contains one row for every replica connected to your primary
database server.
After you set up replication, all inserts, updates, and deletions to rows in
your primary database server become readable on your replica within seconds.
[[["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\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."]]