Skip to content

Commit 494558f

Browse files
committed
Remove the postmaster.pid file prior to pgBackRest restore
This commit removes the postmaster.pid file, if it exists, from the PGDATA directory before attempting a restore. This allows the restore to be tried more than once without causing an error due to the presence of the file in subsequent attempts or in scenarios where the file is otherwise present. Issue: [sc-15157]
1 parent a8ab53c commit 494558f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/pgbackrest/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,16 @@ func RestoreCommand(pgdata string, args ...string) []string {
197197
// - https://www.postgresql.org/docs/current/hot-standby.html
198198
// - https://www.postgresql.org/docs/current/app-pgcontroldata.html
199199

200+
// The postmaster.pid file is removed, if it exists, before attempting a restore.
201+
// This allows the restore to be tried more than once without the causing an
202+
// error due to the presence of the file in subsequent attempts.
203+
200204
// The 'pg_ctl' timeout is set to a very large value (1 year) to ensure there
201205
// are no timeouts when starting or stopping Postgres.
202206

203207
const restoreScript = `declare -r pgdata="$1" opts="$2"
204208
install --directory --mode=0700 "${pgdata}"
209+
rm -f "${pgdata}/postmaster.pid"
205210
eval "pgbackrest restore ${opts}"
206211
rm -f "${pgdata}/patroni.dynamic.json"
207212
export PGDATA="${pgdata}" PGHOST='/tmp'

0 commit comments

Comments
 (0)