Select a documentation version: <button class="button button-with-icon cloud-select-dropdown__button button-primary" aria-haspopup="true">15.5.2</button>

- [Current (18.4.0)](https://docs.cloud.google.com/alloydb/omni/containers/current/docs/set-up-read-replica.md.txt)
- [18.4.0](https://docs.cloud.google.com/alloydb/omni/containers/18.4.0/docs/set-up-read-replica.md.txt)
- [18.3.0](https://docs.cloud.google.com/alloydb/omni/containers/18.3.0/docs/set-up-read-replica.md.txt)
- [18.1.0](https://docs.cloud.google.com/alloydb/omni/containers/18.1.0/docs/set-up-read-replica.md.txt)
- [17.10.0](https://docs.cloud.google.com/alloydb/omni/containers/17.10.0/docs/set-up-read-replica.md.txt)
- [17.9.0](https://docs.cloud.google.com/alloydb/omni/containers/17.9.0/docs/set-up-read-replica.md.txt)
- [17.7.0](https://docs.cloud.google.com/alloydb/omni/containers/17.7.0/docs/set-up-read-replica.md.txt)
- [17.5.0](https://docs.cloud.google.com/alloydb/omni/containers/17.5.0/docs/set-up-read-replica.md.txt)
- [16.14.0](https://docs.cloud.google.com/alloydb/omni/containers/16.14.0/docs/set-up-read-replica.md.txt)
- [16.13.0](https://docs.cloud.google.com/alloydb/omni/containers/16.13.0/docs/set-up-read-replica.md.txt)
- [16.11.0](https://docs.cloud.google.com/alloydb/omni/containers/16.11.0/docs/set-up-read-replica.md.txt)
- [16.9.0](https://docs.cloud.google.com/alloydb/omni/containers/16.9.0/docs/set-up-read-replica.md.txt)
- [16.8.0](https://docs.cloud.google.com/alloydb/omni/containers/16.8.0/docs/set-up-read-replica.md.txt)
- [16.3.0](https://docs.cloud.google.com/alloydb/omni/containers/16.3.0/docs/set-up-read-replica.md.txt)
- [15.18.0](https://docs.cloud.google.com/alloydb/omni/containers/15.18.0/docs/set-up-read-replica.md.txt)
- [15.17.0](https://docs.cloud.google.com/alloydb/omni/containers/15.17.0/docs/set-up-read-replica.md.txt)
- [15.15.0](https://docs.cloud.google.com/alloydb/omni/containers/15.15.0/docs/set-up-read-replica.md.txt)
- [15.13.0](https://docs.cloud.google.com/alloydb/omni/containers/15.13.0/docs/set-up-read-replica.md.txt)
- [15.12.0](https://docs.cloud.google.com/alloydb/omni/containers/15.12.0/docs/set-up-read-replica.md.txt)
- [15.7.1](https://docs.cloud.google.com/alloydb/omni/containers/15.7.1/docs/set-up-read-replica.md.txt)
- [15.7.0](https://docs.cloud.google.com/alloydb/omni/containers/15.7.0/docs/set-up-read-replica.md.txt)
- [15.5.5](https://docs.cloud.google.com/alloydb/omni/containers/15.5.5/docs/set-up-read-replica.md.txt)
- [15.5.4](https://docs.cloud.google.com/alloydb/omni/containers/15.5.4/docs/set-up-read-replica.md.txt)
- [15.5.2](https://docs.cloud.google.com/alloydb/omni/containers/15.5.2/docs/set-up-read-replica.md.txt)

<br />

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.

<br />

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.


> [!CAUTION]
> The information on this page applies only to AlloyDB Omni for containers. It does not apply to AlloyDB Omni for Kubernetes.

<br />

## 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
       host alloydbmetadata    alloydbmetadata    IP_RANGE trust

   Replace <var translate="no">IP_RANGE</var> with the IP range, in CIDR notation, of
   the subnet where your replica machine is located. For example,
   `203.0.113.0/24`.
3. Restart your primary server:

   ```bash
   sudo alloydb database-server stop
   sudo alloydb database-server start
   ```

## Create and configure the replica server

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

1. [Install
   AlloyDB Omni](https://docs.cloud.google.com/alloydb/omni/containers/15.5.2/docs/install) onto the system
   you want to host the replica.

   When you run the `alloydb
   database-server install` command, include the flags that are specific
   to creating a replica:

   ```bash
   sudo alloydb database-server install \
     --data-dir=DATA_DIR \
     --pg-port=PORT \
     --replica-source-ip=SOURCE_IP \
     --replica-source-port=SOURCE_PORT
   ```

   Replace the following:
   - `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`.

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

   ```bash
   ping SOURCE_IP
   ```
3. Start your replica:

   ```bash
   sudo alloydb database-server start
   ```

## Verify replication status on the primary server

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

```bash
  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.