A function for duplicating a logical replication slot

pg_copy_logical_replication_slot() is a system function for copying an existing logical replication slot.

pg_copy_logical_replication_slot() was added in PostgreSQL 12.


pg_copy_logical_replication_slot ( src_slot_name name, dst_slot_name name [, temporary boolean [, plugin name ]] ) →
        record ( slot_name name, lsn pg_lsn )

The copied logical slot starts from the same LSN as the source logical slot. If omitted, the temporary and plugin parameters are copied from the source slot.

Change history


Basic usage example for :

postgres=# SELECT * FROM pg_create_logical_replication_slot('test_slot_1', 'test_decoding');
  slot_name  |    lsn    
 test_slot_1 | 0/14A6458
(1 row)

postgres=# SELECT * FROM pg_copy_logical_replication_slot('test_slot_1', 'test_slot_2');
  slot_name  |    lsn    
 test_slot_2 | 0/14A6458
(1 row)

Attempting to copy a logical replication slot when the destination slot already exists:

postgres=# SELECT * FROM pg_copy_logical_replication_slot('test_slot_1', 'test_slot_2');
ERROR:  replication slot "test_slot_2" already exists

Attempting to copy a non-existent logical replication slot:

postgres=# SELECT * FROM pg_copy_logical_replication_slot('test_slot_99', 'test_slot_3');
ERROR:  replication slot "test_slot_99" does not exist


Logical replication, Replication, Replication slots, System function

See also

pg_create_logical_replication_slot(), pg_drop_replication_slot(), pg_copy_physical_replication_slot()