Configuring OpenResty Edge Database High Availability with Interactive Scripts

1. Preamble

If you want to manually configure OpenResty Edge database high availability, please see the documentation: OpenResty Edge Database High Availability

This document demonstrates the use of interactive scripts to configure the OpenResty Edge database for high availability.

2. Configure the Master Server

  • SSH to the Master machine

  • Download the configuration script

curl -O https://openresty.com/client/oredge/openresty-edge-db-ha-master.sh
  • Run the configuration script
sudo bash openresty-edge-db-ha-master.sh

The interaction process is as follows:

[+] Please enter the standby host(like 192.168.0.2): 192.168.122.1
[+] Info: ping 192.168.122.1 succeeded.
[+] Please enter PG data path of master(default '/var/postgres12/data'):
[+] Please enter a username for replication, will create if it doesn't exist (default 'replicator'):
[+] Please enter a password for the user replicator (default [Randomly generate]):
[+] Will restart PG, do you want to continue? [y/N] y
[+] Restarting the openresty-postgresql12 service
[!] Saving Master info to ./postgresql-master.info.20220511025907
------------------------------------
STANDBY_HOST="192.168.122.1"
MASTER_HOST="127.0.0.1"
MASTER_PORT=5432"
USERNAME="replicator"
PASSWORD="TcVch76UzWaUyMJ5-5sWI9mZW3M5zBiv"
PG_DATA_PATH="/var/postgres12/data"
PG_DATA_SIZE="2.8G"
------------------------------------
[+] Info: master setup successfully.

standby host: The address of Standby, such as 192.168.0.2, used to configure access control. master port: The service port of Master, e.g. 5432. username: user for replication, e.g. replicator, or create if it does not exist. password: password of the user to be used for replication, e.g. examplepwd, if the user already exists, the password should be obtained by yourself.

3. Configure the Standby Server

  • SSH to Standby machine

  • Download the configuration script

curl -O https://openresty.com/client/oredge/openresty-edge-db-ha-standby.sh
  • Run the configuration script
sudo bash openresty-edge-db-ha-standby.sh

The interaction process is as follows:

[+] Please make sure you have enough free hard disk space, do you want to continue? [y/N] y
[+] Please enter PG data path of standby(default '/var/postgres12/data'): /mnt/data/test/postgres12/data
[+] Please enter the standby port(default 5432): 5436
[+] Please enter the master host(like 192.168.0.1): 192.168.122.37
[+] Info: ping 192.168.122.37 succeeded.
[+] Please enter the master port(default 5432):
[+] Please enter a username for replication(same as master, default 'replicator'):
[+] Please enter the password of user replicator: TcVch76UzWaUyMJ5-5sWI9mZW3M5zBiv
[+] Info: syncing master data, it may take a long time, please wait patiently
[+] Info: wait for the standby server to start
[+] Info: standby setup successfully.

master host: Master’s service address, such as 192.168.0.1 master port: the service port of Master, such as 5432. username: the user for backup (the same as the one configured in Master), e.g. replicator. password: password of the user to be backed up (same as the one configured in Master), e.g. examplepwd

4. Verification

Execute on the Master Server

/usr/local/openresty-postgresql12/bin/psql -x -c "select * from pg_stat_replication" -U postgres

An execution result similar to the following indicates a successful configuration

-[ RECORD 1 ]----+------------------------------
pid              | 29015
usesysid         | 22228
usename          | replicator
application_name | walreceiver
client_addr      | 192.168.122.1
client_hostname  |
client_port      | 38440
backend_start    | 2022-02-21 23:36:46.418257-08
backend_xmin     | 5222925
state            | streaming
sent_lsn         | 2/C5151CE8
write_lsn        | 2/C5151CE8
flush_lsn        | 2/C5151CE8
replay_lsn       | 2/C5151CE8
write_lag        | 00:00:00.000435
flush_lag        | 00:00:00.001187
replay_lag       | 00:00:00.001394
sync_priority    | 0
sync_state       | async
reply_time       | 2022-02-21 23:42:21.456685-08