Files
postgres/docker-compose.yml
T
magnusandClaude Opus 4.6 a307141068 Fix WAL archive_command failing when segment already exists
pg_basebackup -Xs copies WAL segments to the backup dir, causing
the archive_command to fail on those pre-existing files and block
all subsequent archiving.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 15:54:15 +01:00

52 lines
1.4 KiB
YAML

services:
postgres-db:
image: postgres:18
container_name: postgres-db
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "${PGPORT}:5432"
volumes:
- postgres_data:/var/lib/postgresql
- /data/backup/postgres/wal:/backup/wal
- ./init-replication-hba.sh:/docker-entrypoint-initdb.d/init-replication-hba.sh:ro
command:
- postgres
- -c
- wal_level=replica
- -c
- archive_mode=on
- -c
- archive_command=test -f /backup/wal/%f || cp %p /backup/wal/%f
postgres-backup:
image: postgres:18
container_name: postgres-backup
restart: unless-stopped
depends_on:
- postgres-db
environment:
POSTGRES_USER: ${POSTGRES_USER}
PGPASSWORD: ${POSTGRES_PASSWORD}
volumes:
- /data/backup/postgres:/backup
entrypoint: ["/bin/bash", "-c"]
command:
- |
mkdir -p /backup/wal /backup/full
chown 999:999 /backup/wal
while true; do
STAMP=$$(date +%Y-%m-%d_%H-%M-%S)
echo "Starting full backup: full_$$STAMP"
pg_basebackup -h postgres-db -U "$$POSTGRES_USER" -D "/backup/full/full_$$STAMP" -Fp -Xs -P
echo "Full backup complete: full_$$STAMP"
sleep 604800
done
volumes:
postgres_data: