Skip to content

Instantly share code, notes, and snippets.

@asasmoyo
Last active October 7, 2018 10:14
Show Gist options
  • Save asasmoyo/ea2047cf43621aca1ee1d6f2496ec0ec to your computer and use it in GitHub Desktop.
Save asasmoyo/ea2047cf43621aca1ee1d6f2496ec0ec to your computer and use it in GitHub Desktop.
setup postgresql-10 streaming replication
# /etc/postgresql/10/main/postgresql.conf
include_dir = 'conf.d'
# /etc/postgresql/10/main/conf.d/listen.conf
listen_addresses = '*'
# /etc/postgresql/10/main/conf.d/wal.conf
wal_level = 'replica'
max_wal_senders = 6 # let's set it to 3 * n(slaves)
wal_keep_segments = 500 # number of wal files to keep in master
wal_log_hints = on # needed for pg_rewind
# /etc/postgresql/10/main/conf.d/archive.conf
archive_mode = 'on'
archive_command = '/PATH/TO/store.sh %p'
# /etc/postgresql/10/main/pg_hba.conf
host replication REPLICATOR_USER NETWORK trust
#!/usr/bin/env bash
remotes='IP1 IP2'
remote_user='storer'
target_dir='~/wals'
for dest in $remotes; do
rsync -az $1 $remote_user@$dest:$target_dir/
logger -t replication successfully sent $1 to $dest
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment