Create a read-only replica

To 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.

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

  1. 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.

  2. Add the following lines in the /var/alloydb/config/pg_hba.conf file:

    host all         alloydbreplica IP_RANGE trust
    host replication alloydbreplica IP_RANGE trust

    Replace IP_RANGE with the IP range, in CIDR notation, of the subnet where your replica machine is located. For example,

  3. Restart your primary server:

    sudo systemctl restart alloydb-dataplane

Create and configure the replica server

To create and configure an AlloyDB Omni replica server, complete the following steps:

  1. Log in to the system that hosts your replica server and install AlloyDB Omni.

  2. Configure the data directory location on your replica server.

  3. Edit your /var/alloydb/config/dataplane.conf file to include the following directives:


    Replace PRIMARY_IP_ADDRESS with the IP address of your primary AlloyDB Omni server.

  4. Ensure the replica has network connectivity to the primary server:

  5. Start your replica:

    sudo systemctl restart alloydb-dataplane

Verify replication status on the primary server

To verify replication is configured properly, run the following command on the primary server's host:

  docker exec -it pg-service psql -h localhost -U alloydbadmin -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.