Quick rundown of the lifecycle of WAL files in a primary/standby setup. Primary- Primary writes WAL logs under
$PGDATA/pg_xlog - This can/should be symlinked to a separate disk for better I/O performance (less contention).
- Primary wal.conf has:
archive_command = '/path/to/archive_script.sh -p %p -f %f' - Should copy WAL file from pg_xlog to another directory (NFS, for example) for longer term storage
- Should copy WAL file to archive directory on standby server (eg /path/to/archive)
- If archive_command returns zero exit status (success), postgres will remove the original WAL file
StandbyPresence of $PGDATA/recovery.conf file means database is in standby recovery restore_command = 'cp /path/to/archive/%f %p' - This copies files from the archive directory to the pg_xlog directory
- Optional if we're also attempting streaming replication (see primary_conninfo)
primary_conninfo points to the primary to connect to primary and get WAL segmentsarchive_cleanup_command will delete files under pg_archive that are no longer needed by the standby serverarchive_cleanup_command = '/usr/pgsql-9.2/bin/pg_archivecleanup /path/to/archive %r' pg_archivecleanup is provided by postgresql.
- WAL file is cleaned up automatically. Per documentation: "In archive recovery or standby mode, the server periodically performs restartpoints which are similar to checkpoints in normal operation: the server forces all its state to disk, updates the pg_control file to indicate that the already-processed WAL data need not be scanned again, and then recycles any old log segment files in pg_xlog directory."
|