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 创建(即 pg_create_physical_replication_slot() 执行时 immediately_reserve 设置为 TRUE)。

变更历史

示例

使用 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_copy_physical_replication_slot() 不会在 lsn 列中返回值,即使通过 pg_replication_slots 报告了一个值。

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()" 的任何评论、建议或更正 此处