pg_copy_physical_replication_slot()

复制物理复制槽的函数

pg_copy_physical_replication_slot() 是一个用于复制现有物理复制槽的系统函数。

pg_copy_physical_replication_slot()PostgreSQL 12 中引入。

用法

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

要复制的槽必须已使用预留 WAL(即 immediately_reserve 设置为 TRUE 执行了 pg_create_physical_replication_slot())创建。

变更历史

示例

使用 pg_copy_physical_replication_slot() 复制复制槽

postgres=# SELECT * FROM pg_create_physical_replication_slot('foo', immediately_reserve := TRUE);
 slot_name |    lsn    
-----------+-----------
 foo       | 0/30004B0
(1 row)

postgres=# SELECT * FROM pg_copy_physical_replication_slot('foo', 'bar');
 slot_name | lsn 
-----------+-----
 bar       | 
(1 row)

请注意,截至 PostgreSQL 14,即使 pg_replication_slots 报告了 LSN,pg_copy_physical_replication_slot()lsn 列中也不会返回值。

postgres=# SELECT slot_name, slot_type, restart_lsn, wal_status FROM pg_replication_slots;
 slot_name | slot_type | restart_lsn | wal_status 
-----------+-----------+-------------+------------
 foo       | physical  | 0/30004B0   | reserved
 bar       | physical  | 0/30004B0   | reserved
(2 rows)

源复制槽必须已使用预留 WAL 创建

postgres=# SELECT * FROM pg_create_physical_replication_slot('boo');
 slot_name | lsn 
-----------+-----
 boo       | 
(1 row)

postgres=# SELECT * FROM pg_copy_physical_replication_slot('boo', 'baz');
ERROR:  cannot copy a replication slot that doesn't reserve WAL

尝试复制不存在的复制槽

postgres=# SELECT * FROM pg_copy_physical_replication_slot('zoo', 'baz');
ERROR:  replication slot "zoo" does not exist

分类

复制, 复制槽, 系统函数, WAL

另请参阅

pg_create_physical_replication_slot(), pg_drop_replication_slot(), pg_copy_logical_replication_slot()

反馈

提交关于“pg_copy_physical_replication_slot()”的任何评论、建议或更正,请在此处 提交