To set up streaming replication in PostgreSQL, you need to perform the following steps:
- Set up the master server and the standby server. The master server is the primary server that will receive all the write operations, while the standby server will receive a copy of all the changes made on the master server and will be used for failover in case the master server becomes unavailable.
- On the master server, edit the
postgresql.conf
configuration file and set thewal_level
parameter tohot_standby
. This will enable the master server to keep a sufficient amount of transaction log data (WAL) to allow the standby server to connect and apply the changes. - Restart the master server for the changes to take effect.
- On the standby server, edit the
postgresql.conf
configuration file and set thehot_standby
parameter toon
. This will enable the standby server to connect to the master server and start receiving the changes. - In the
recovery.conf
file on the standby server, add the following lines to specify the connection details for the master server: