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.
Before you begin
Before you proceed, install and set up AlloyDB Omni using the RPM package. For more information, see Install AlloyDB Omni for Linux.
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 the primary server's Postgres port.
Create a replication user:
psql -h localhost -U postgres -c "create user REPLICA_USER with replication password 'PASSWORD'; grant pg_read_all_settings to REPLICA_USER;"Add the following lines in the
/DATA_DIR/pg_hba.conffile of the primary server beforehost all all all scram-sha-256that exists in the file:host alloydbmetadata alloydbmetadata IP_RANGE trust host replication REPLICA_USER IP_RANGE scram-sha-256Replace the following:
IP_RANGE: the IP range, in CIDR notation, of the subnet where your replica machine is located. For example,203.0.113.0/24.DATA_DIR: the data directory path of the primary server.
Restart your primary server:
sudo systemctl restart alloydbomniPG_VERSION
Create and configure the replica server
To create and configure an AlloyDB Omni replica server, complete the following steps:
Ensure the replica has network connectivity to the primary server:
ping SOURCE_IPReplace
SOURCE_IPwith the IP address of the primary AlloyDB Omni instance to replicate from.Ensure the replica can connect to the primary server:
psql "host=SOURCE_IP user=REPLICA_USER replication=1" -c "IDENTIFY_SYSTEM;"The output should look similar to the following:
systemid | timeline | xlogpos | dbname ---------------------+----------+-----------+-------- 7376500460465963036 | 1 | 0/454B670 | (1 row)The replica must have a persistent storage location on disk:
pg_basebackup \ --pgdata=DATA_DIR \ --checkpoint=fast \ --host="SOURCE_IP" \ --port="SOURCE_PORT" \ --username=REPLICA_USER \ --create-slot \ --write-recovery-conf \ --slot="SLOT_NAME"Replace the following:
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 of5432.SLOT_NAME: the label for the name of the replication slot.DATA_DIR: the data directory path for the replica server.
Start your replica instance:
sudo systemctl start alloydbomniPG_VERSION
Verify replication status on the primary server
To verify replication is configured properly, run the following command on the primary server's host:
psql -h localhost -U postgres -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.