postgresql_16:4.12.2.6 Replication Slots
PostgreSQL 16 > Server Administration > High Availability, Load Balancing, and Replication > Log-Shipping Standby Servers > Replication Slots
Replication slots provide an automated way to ensure that the primary does not remove WAL segments until they have been received by all standbys, and that the primary does not remove rows which could cause a recovery conflict (see postgresql_16:4.12.4.2) even when the standby is disconnected.
In lieu of using replication slots, it is possible to prevent the removal of old WAL segments using (see guc-wal-keep-size), or by storing the segments in an archive using (see guc-archive-command) or (see guc-archive-library). However, these methods often result in retaining more WAL segments than required, whereas replication slots retain only the number of segments known to be needed. On the other hand, replication slots can retain so many WAL segments that they fill up the space allocated for pg_wal; (see guc-max-slot-wal-keep-size) limits the size of WAL files retained by replication slots.
Similarly, (see guc-hot-standby-feedback) on its own, without also using a replication slot, provides protection against relevant rows being removed by vacuum, but provides no protection during any time period when the standby is not connected. Replication slots overcome these disadvantages.
Querying and Manipulating Replication Slots
Each replication slot has a name, which can contain lower-case letters, numbers, and the underscore character.
Existing replication slots and their state can be seen in the pg_replication_slots (see postgresql_16:8.3.19) view.
Slots can be created and dropped either via the streaming replication protocol (see (see postgresql_16:8.4.4)) or via SQL functions (see (see postgresql_16:3.6.27.6)).
Configuration Example
You can create a replication slot like this: postgres=# SELECT * FROM pg_create_physical_replication_slot('node_a_slot'); slot_name | lsn -------------+----- node_a_slot | postgres=# SELECT slot_name, slot_type, active FROM pg_replication_slots; slot_name | slot_type | active -------------+-----------+-------- node_a_slot | physical | f (1 row) To configure the standby to use this slot, primary_slot_name should be configured on the standby. Here is a simple example: primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass' primary_slot_name = 'node_a_slot'