RefLib

Reference library for AI

Back

postgresql_16:4.12.2.4 Setting Up a Standby Server

PostgreSQL 16 > Server Administration > High Availability, Load Balancing, and Replication > Log-Shipping Standby Servers > Setting Up a Standby Server

To set up the standby server, restore the base backup taken from primary server (see (see postgresql_16:4.11.3.4)). Create a file standby.signal (see file-standby-signal) in the standby's cluster data directory. Set (see guc-restore-command) to a simple command to copy files from the WAL archive. If you plan to have multiple standby servers for high availability purposes, make sure that recovery_target_timeline is set to latest (the default), to make the standby server follow the timeline change that occurs at failover to another standby.

Note

(see guc-restore-command) should return immediately if the file does not exist; the server will retry the command again if necessary.

If you want to use streaming replication, fill in (see guc-primary-conninfo) with a libpq connection string, including the host name (or IP address) and any additional details needed to connect to the primary server. If the primary needs a password for authentication, the password needs to be specified in (see guc-primary-conninfo) as well.

If you're setting up the standby server for high availability purposes, set up WAL archiving, connections and authentication like the primary server, because the standby server will work as a primary server after failover.

If you're using a WAL archive, its size can be minimized using the (see guc-archive-cleanup-command) parameter to remove files that are no longer required by the standby server. The pg_archivecleanup utility is designed specifically to be used with archive_cleanup_command in typical single-standby configurations, see (see postgresql_16:7.3.2). Note however, that if you're using the archive for backup purposes, you need to retain files needed to recover from at least the latest base backup, even if they're no longer needed by the standby.

A simple example of configuration is: primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass options=''-c wal_sender_timeout=5000''' restore_command = 'cp /path/to/archive/%f %p' archive_cleanup_command = 'pg_archivecleanup /path/to/archive %r'

You can have any number of standby servers, but if you use streaming replication, make sure you set max_wal_senders high enough in the primary to allow them to be connected simultaneously.

Back