Set up primary-standby replication for Postgres

By default, Edge installs all Postgres nodes in primary mode. However, in production systems with multiple Postgres nodes, you configure them to use primary-standby replication so that if the primary node fails, the standby node can continue to serve traffic.

If the primary node ever fails, you can promote the standby server to the primary. See Handling a PostgreSQL Database Failover for more information.

Configure Primary-Standby Replication at install time

You can configure primary-standby replication at install time by including the following properties in the config file for the two Postgres nodes:

PG_MASTER=IP_OR_DNS_OF_NEW_PRIMARY
PG_STANDBY=IP_OR_DNS_OF_NEW_STANDBY

The installer automatically configures the two Postgres node to function as primary-standby with replication.

Configure Primary-Standby Replication after installation

You can configure primary-standby replication after installation by using the following procedure:

  1. Identify which Postgre node will be the primary and which will be the standby server.
  2. On the primary node, edit the config file to set:
    PG_MASTER=IP_OR_DNS_OF_NEW_PRIMARY
    PG_STANDBY=IPorDNSofNewStandby
  3. Enable replication on the new primary:
    /opt/apigee/apigee-service/bin/apigee-service apigee-postgresql setup-replication-on-master -f configFile
  4. On the standby node, edit the config file to set:
    PG_MASTER=IP_OR_DNS_OF_NEW_PRIMARY
    PG_STANDBY=IPorDNSofNewStandby
  5. Stop the standby node:
    /opt/apigee/apigee-service/bin/apigee-service apigee-postgresql stop
  6. On the standby node, delete any existing Postgres data:
    rm -rf /opt/apigee/data/apigee-postgresql/
  7. Configure the standby node:
    /opt/apigee/apigee-service/bin/apigee-service apigee-postgresql setup-replication-on-standby -f configFile

Test Primary-Standby Replication

On completion of replication, verify the replication status by issuing the following scripts on both servers. The system should display identical results on both servers to ensure a successful replication:

  1. On the primary node, run:
    /opt/apigee/apigee-service/bin/apigee-service apigee-postgresql postgres-check-master

    Validate that it says it is the primary.

  2. On the standby node:
    /opt/apigee/apigee-service/bin/apigee-service apigee-postgresql postgres-check-standby

    Validate that it says it is the standby.