Skip to content

Commit

Permalink
add --ignore-canceling-statement-due-to-conflict-with-recovery flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Pospisek committed Jan 24, 2025
1 parent 7d58c0b commit c9de222
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions usr/sbin/dump_postgres_dbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Based on http://forritan.blogspot.ch/2012/10/postgresql-backup-script.html

help() {
echo 'usage: dump_postgres_dbs [--ignore-not-accepting-connections] [--ignore-does-not-exist] [--no-clusters] [/path/to/backup/dir]'
echo 'usage: dump_postgres_dbs [--ignore-canceling-statement-due-to-conflict-with-recovery] [--ignore-not-accepting-connections] [--ignore-does-not-exist] [--no-clusters] [/path/to/backup/dir]'
echo ' dump_postgres_dbs --help'
echo
echo ' --ignore-not-accepting-connections'
Expand All @@ -17,6 +17,12 @@ help() {
echo ' Ignore pg_dump errors resulting from DBs that do not'
echo ' exist.'
echo
echo ' --ignore-canceling-statement-due-to-conflict-with-recovery'
echo
echo ' Ignore error of DB being changed while dumping and dump'
echo ' getting aborted.'
echo ' see https://www.postgresql.org/docs/current/hot-standby.html#HOT-STANDBY-CONFLICT'
echo
echo ' --no-cluster'
echo
echo ' DBs have been crated with low level tools: no'
Expand All @@ -31,9 +37,10 @@ help() {
}

[ "$1" == "--help" ] && help
[ "$1" == "--ignore-not-accepting-connections" ] && NOT_ACCEPTING_CONNECTIONS=IGNORE && shift
[ "$1" == "--ignore-does-not-exist" ] && DOES_NOT_EXIST=IGNORE && shift
[ "$1" == "--no-clusters" ] && NO_CLUSTERS=true && shift
[ "$1" == "--ignore-canceling-statement-due-to-conflict-with-recovery" ] && CONFLICT_WITH_RECOVERY=IGNORE && shift
[ "$1" == "--ignore-not-accepting-connections" ] && NOT_ACCEPTING_CONNECTIONS=IGNORE && shift
[ "$1" == "--ignore-does-not-exist" ] && DOES_NOT_EXIST=IGNORE && shift
[ "$1" == "--no-clusters" ] && NO_CLUSTERS=true && shift

set -e # stop on error

Expand Down Expand Up @@ -109,6 +116,12 @@ while read cluster; do
[ "$NOT_ACCEPTING_CONNECTIONS" == "IGNORE" ]; then
log "Dump of $databasename IGNORED - was disabled before we could dump it"

# pg_dump: error: Error message from server: ERROR: canceling statement due to conflict with recovery
# see https://www.postgresql.org/docs/current/hot-standby.html#HOT-STANDBY-CONFLICT
elif echo "$pg_dump_output" | grep -q "canceling statement due to conflict with recovery" && \
[ "$CONFLICT_WITH_RECOVERY" == "IGNORE" ]; then
log "Dump of $databasename IGNORED - DB (WAL) changed during dump"

else
log "Dump of $databasename FAILED"
error=1
Expand Down

0 comments on commit c9de222

Please sign in to comment.