Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Setup master server:
- Create a user for the replication:
- ```
- $ psql postgres
- postgres=# CREATE USER replica REPLICATION LOGIN ENCRYPTED PASSWORD 'so-secret';
- ```
- Change your postgres.conf:
- ```
- $ sudo vim /etc/postgresql/10/main/postgresql.conf
- ```
- Set this:
- ```
- listen_addresses = '*'
- wal_level = replica
- max_wal_senders = 3
- wal_keep_segments = 64
- ```
- Change your pg_hba.conf:
- ```
- $ sudo vim /etc/postgresql/10/main/pg_hba.conf
- ```
- Add at the end of the file:
- ```
- host replication replica <slave-ip-address>/32 md5
- ```
- Restart your master server:
- ```
- $ sudo systemctl restart postgresql
- ```
- # Setup slave server:
- Stop postgres server:
- ```
- $ sudo systemctl stop postgresql
- ```
- As postgres user:
- ```
- $ sudo -i
- $ su - postgres
- $ rm -rf /var/lib/postgresql/10/main/*
- $ pg_basebackup -h <master-ip-address> -D /var/lib/postgresql/10/main/ -P -U replica --wal-method=stream
- Password: so-secret
- $ vim /var/lib/postgresql/10/main/recovery.conf
- ```
- Add this:
- ```
- standby_mode = 'on'
- primary_conninfo = 'host=<master-ip-address> port=5432 user=replica password=so-secret'
- trigger_file = '/tmp/MasterNow'
- ```
- Start postgres:
- ```
- $ sudo systemctl start postgresql
- ```
Add Comment
Please, Sign In to add comment