Skip to content

Commit 8a63976

Browse files
committed
"Disable archive_command initially and update it after stanza creation"
1 parent da2757b commit 8a63976

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

scripts/backup-functions.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,23 @@ EOF
388388
fi
389389

390390
log "INFO" "Pgbackrest stanza created successfully"
391+
392+
# Now update the archive_command to use pgbackrest
393+
log "INFO" "Updating archive_command in postgresql.conf..."
394+
local pgdata="${PGDATA:-/var/lib/postgresql/data}"
395+
396+
# Update the archive_command to use pgbackrest
397+
sed -i "s|archive_command = '/bin/true'|archive_command = 'pgbackrest --stanza=${stanza_name} archive-push %p'|g" "$pgdata/postgresql.conf"
398+
399+
# Reload PostgreSQL configuration
400+
log "INFO" "Reloading PostgreSQL configuration..."
401+
su-exec postgres pg_ctl reload -D "$pgdata"
402+
403+
# Verify the archive_command was updated
404+
log "INFO" "Verifying archive_command configuration..."
405+
archive_cmd_check=$(su-exec postgres psql -d "$pg_database" -t -c "SHOW archive_command;" 2>/dev/null | sed 's/^[ \t]*//;s/[ \t]*$//')
406+
log "INFO" "Current archive_command: $archive_cmd_check"
407+
391408
return 0
392409
}
393410

scripts/docker-entrypoint.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ start_postgresql() {
6969
# Enable WAL archiving for pgBackRest (CRITICAL for backup functionality)
7070
echo "wal_level = replica" >> "$PGDATA/postgresql.conf"
7171
echo "archive_mode = on" >> "$PGDATA/postgresql.conf"
72-
echo "archive_command = 'pgbackrest --stanza=${PGBACKREST_STANZA:-main} archive-push %p'" >> "$PGDATA/postgresql.conf"
72+
# Initially disable archive_command until stanza is created
73+
echo "archive_command = '/bin/true'" >> "$PGDATA/postgresql.conf"
7374
echo "max_wal_senders = 3" >> "$PGDATA/postgresql.conf"
7475
echo "wal_keep_size = 1GB" >> "$PGDATA/postgresql.conf"
7576

@@ -163,7 +164,7 @@ EOSQL
163164
echo "wal_level = replica" >> "$PGDATA/postgresql.conf"
164165
fi
165166
if ! grep -q "archive_command" "$PGDATA/postgresql.conf"; then
166-
echo "archive_command = 'pgbackrest --stanza=${PGBACKREST_STANZA:-main} archive-push %p'" >> "$PGDATA/postgresql.conf"
167+
echo "archive_command = '/bin/true'" >> "$PGDATA/postgresql.conf"
167168
fi
168169

169170
# Start PostgreSQL again

0 commit comments

Comments
 (0)