Skip to content

Instantly share code, notes, and snippets.

@brutasse
Created September 30, 2014 09:35
Show Gist options
  • Save brutasse/e9a25571bb33dfaa6ecc to your computer and use it in GitHub Desktop.
Save brutasse/e9a25571bb33dfaa6ecc to your computer and use it in GitHub Desktop.

Replication

Sync process is:

  • make a base backup
  • catch up with changes that happened during the base backup using master's WAL files
  • stream

Make sure master's wal_keep_segments is set to a high enough value to allow tracking all changes happening during the base backup. Restart needed when changing this.

On master, pg_hba.conf:

host replication all <slave ip>/24 trust

To reload pg_hba without restarting:

sudo pg_ctlcluster 9.3 main reload

On slave:

  • set hot_standby to "on"
  • stop postgresql service
  • rm -rf postgres's data_directory (/home/postgres/data here).

Then as postgres user (command can hang for a while before showing some output but then displays progress information):

pg_basebackup -h <master ip> -D /home/postgres/main -U postgres -v -P

Create /home/postgres/main/recovery.conf:

standby_mode = 'on'
primary_conninfo = 'host=<master ip> port=5432 user=postgres'

Start postgres.

To monitor state on master:

psql -x -c "select * from pg_stat_replication;" -U postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment