Skip to content

Instantly share code, notes, and snippets.

@sharshenov
Last active May 20, 2024 08:50
Show Gist options
  • Save sharshenov/ea63446f65cb7034eda1 to your computer and use it in GitHub Desktop.
Save sharshenov/ea63446f65cb7034eda1 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