4.1. Cloning and replication slots

Replication slots were introduced with LightDB 21 and are designed to ensure that any standby connected to the primary using a replication slot will always be able to retrieve the required WAL files. This removes the need to manually manage WAL file retention by estimating the number of WAL files that need to be maintained on the primary using wal_keep_segments (LightDB 21 and later: wal_keep_size). Do however be aware that if a standby is disconnected, WAL will continue to accumulate on the primary until either the standby reconnects or the replication slot is dropped.

To enable ltcluster to use replication slots, set the boolean parameter use_replication_slots in ltcluster.conf:

       use_replication_slots=true

Replication slots must be enabled in lightdb.conf by setting the parameter max_replication_slots to at least the number of expected standbys (changes to this parameter require a server restart).

When cloning a standby, ltcluster will automatically generate an appropriate slot name, which is stored in the ltcluster.nodes table, and create the slot on the upstream node:

    ltcluster=# SELECT node_id, upstream_node_id, active, node_name, type, priority, slot_name
               FROM ltcluster.nodes ORDER BY node_id;
     node_id | upstream_node_id | active | node_name |  type   | priority |   slot_name
    ---------+------------------+--------+-----------+---------+----------+---------------
           1 |                  | t      | node1     | primary |      100 | ltcluster_slot_1
           2 |                1 | t      | node2     | standby |      100 | ltcluster_slot_2
           3 |                1 | t      | node3     | standby |      100 | ltcluster_slot_3
     (3 rows)

    ltcluster=# SELECT slot_name, slot_type, active, active_pid FROM pg_replication_slots ;
       slot_name   | slot_type | active | active_pid
    ---------------+-----------+--------+------------
     ltcluster_slot_2 | physical  | t      |      23658
     ltcluster_slot_3 | physical  | t      |      23687
    (2 rows)

Note that a slot name will be created by default for the primary but not actually used unless the primary is converted to a standby using e.g. ltcluster standby switchover.

Further information on replication slots in the LightDB documentation: https://www.hs.net/lightdb/docs/html/interactive/warm-standby.html#STREAMING-REPLICATION-SLOTS

Tip

While replication slots can be useful for streaming replication, it's recommended to monitor for inactive slots as these will cause WAL files to build up indefinitely, possibly leading to server failure.