I copied both the base backup and the WAL files from my primary Postgres database to a standby database and tried to restore from them but I'm getting this error:
PostgreSQL Database directory appears to contain a database; Skipping initialization
LOG: database system was shut down at 2024-02-16 19:38:58 UTC
LOG: starting archive recovery
LOG: restored log file "000000010000000000000001" from archive
LOG: invalid primary checkpoint record
LOG: restored log file "000000010000000000000001" from archive
LOG: invalid secondary checkpoint record
PANIC: could not locate a valid checkpoint record
LOG: startup process (PID 26) was terminated by signal 6: Aborted
LOG: aborting startup due to startup process failure
LOG: database system is shut down
I tried adding a checkpoint after inserting a bunch of records into a table but I'm still getting the same error.
The general flow of my script is:
# Set the postgresql.conf values (i.e.: archive_command)
...
# Set the recovery.conf values (i.e.: restore_command)
...
# Create a base backup
docker exec primary-db pg_basebackup -h localhost -p 5432 -U postgres -D /var/lib/postgresql/data/basebackup -Ft -z -P -X fetch
# Populate the database tables with new records
...
# Create a checkpoint
docker exec primary-db psql postgres -U postgres -c "CHECKPOINT;"
# Copy the base backup
cp -a $PRIMARY/basebackup/. $REPLICA/wal/
# Copy the WAL files
cp -a $PRIMARY/wal/. $REPLICA/wal/
# Restart the standby database to start the restoration
docker restart replica-db
I have the base backup and the WAL files all inside the same directory. I'm not sure if the base backup should be stored somewhere else. What am I doing wrong here?
data/
including thepostgresql.conf
and thepg_xlog/
and all of those. Should I untar that file and replace the existing files/folders?