pg_create_logical_replication_slot()

用于创建逻辑复制槽的函数

pg_create_logical_replication_slot() 是一个用于创建逻辑复制槽的系统函数。

pg_create_logical_replication_slot() 添加于 PostgreSQL 9.4

用法

PostgreSQL 17 ~

pg_create_logical_replication_slot ( slot_name name, plugin name [, temporary boolean , two_phase boolean , failover boolean ] )
        → record ( slot_name name, lsn pg_lsn )

PostgreSQL 14 ~ PostgreSQL 16

pg_create_logical_replication_slot ( slot_name name, plugin name [, temporary boolean , two_phase boolean ] )
        → record ( slot_name name, lsn pg_lsn )

PostgreSQL 10 ~ PostgreSQL 13

pg_create_logical_replication_slot ( slot_name name, plugin name [, temporary boolean ] )
        → record ( slot_name name, lsn pg_lsn )

PostgreSQL 9.4 ~ PostgreSQL 9.6

pg_create_logical_replication_slot ( slot_name name, plugin name )
        → record ( slot_name name, lsn pg_lsn )

PostgreSQL 16 之前,pg_create_logical_replication_slot() 无法在备机上执行。

更改历史记录

示例

使用 pg_create_logical_replication_slot() 使用 test_decoding 示例输出插件创建逻辑复制槽

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

postgres=# SELECT * FROM pg_replication_slots\gx
-[ RECORD 1 ]-------+--------------
slot_name           | test_slot_1
plugin              | test_decoding
slot_type           | logical
datoid              | 13756
database            | postgres
temporary           | f
active              | f
active_pid          |
xmin                |
catalog_xmin        | 722
restart_lsn         | 0/3000720
confirmed_flush_lsn | 0/3000758
wal_status          | reserved
safe_wal_size       |
two_phase           | f

尝试在备机上执行 pg_create_logical_replication_slot() (PostgreSQL 15 及更早版本)

postgres=# SELECT * FROM pg_create_logical_replication_slot('test_slot_1', 'test_decoding');
ERROR:  logical decoding cannot be used while in recovery

尝试使用包含无效字符的名称创建逻辑复制槽

postgres=# SELECT * FROM pg_create_logical_replication_slot('!"#$ FOO', 'some_plugin');
ERROR:  replication slot name "!"#$ FOO" contains invalid character
HINT:  Replication slot names may only contain lower case letters, numbers, and the underscore character.

尝试使用不存在的插件创建逻辑复制槽

postgres=# SELECT * FROM pg_create_logical_replication_slot('test_slot', 'some_plugin');
ERROR:  could not access file "some_plugin": No such file or directory

分类

逻辑复制复制复制槽系统函数

另请参阅

pg_replication_slotspg_copy_logical_replication_slot()pg_drop_replication_slot()pg_create_physical_replication_slot()

反馈

提交任何关于 "pg_create_logical_replication_slot()" 的评论、建议或更正 此处