Skip to content

Instantly share code, notes, and snippets.

@zismailov
Forked from sharshenov/backup_standby.sh
Created December 5, 2016 16:44
Show Gist options
  • Save zismailov/3c9b9aa7ccc36e379d278c5dbd978090 to your computer and use it in GitHub Desktop.
Save zismailov/3c9b9aa7ccc36e379d278c5dbd978090 to your computer and use it in GitHub Desktop.
Making PostgreSQL backup from standby server
# 1. Pause replication
sudo -u postgres psql -c 'SELECT pg_xlog_replay_pause();'
# 2. Perform backup
sudo -u postgres pg_dump -Fc DBNAME > /path/to/backup
#3. Resume replication
sudo -u postgres psql -c 'SELECT pg_xlog_replay_resume();'
#Keep in mind that running above commands will cause recovery lag on the slave, which might be quite large, depending on you database size. Also, take into account the space WAL segments will take, as they will not be replayed on slave during the pause.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment