[DRAFT]How to set up database replication locally
Can be used to run backend modules with read/write functionality locally. The current article is oriented towards users with the Windows operating system.
Step-by-step guide
Set up master instance
- Run vagrant box
- Connect to SSH:
- host = 127.0.0.1
- port = 2222
- user = vagrant
- password = vagrant
- Create a role with replication permissions
- sudo -u postgres psql
- CREATE ROLE test WITH REPLICATION PASSWORD 'testpassword' LOGIN;
- \q
- Provide ability to connect to the primary db for replication
- sudo vim /etc/postgresql/12/main/pg_hba.conf
- Append the following line to the end of the file:
host replication test 10.0.2.2/32 md5
- Restart PostgreSQL:
- sudo systemctl restart postgresql@12-main
Set up slave instance
- The current version of PostgreSQL used in FOLIO modules is 12.14. You need to download version 12.14 for Windows by following this link.
- Specify port as 5433 while installation:
- Delete all files from C:\Program Files\PostgreSQL\12\data except these files:
- Temporarily move the remaining files to another directory
- Open CMD
- Go to postgres tools directory :
- cd C:\Program Files\PostgreSQL\12\bin
- Start replication and specify that standby:
- pg_basebackup -h 127.0.0.1 -p 5432 -U test -D "/Program Files/PostgreSQL/12/data" -Fp -Xs -R
- password = testpassword
- Move back temporarily moved files
- Increase connections limit:
- Open postgresql.conf in editor
- max_connections = 1000
- Save and exit
- Start postgres:
- pg_ctl.exe -D "C:\Program Files\PostgreSQL\12\data" start
- Verify that replications is successfully:
- Connect to replica using standart okapi_modules db credentials. Just need to change port from 5432 to 5433
Related articles