pg_create_physical_replication_slot()

创建物理复制槽的函数

pg_create_physical_replication_slot() 是一个用于创建物理复制槽的系统函数。

pg_create_physical_replication_slot()PostgreSQL 9.4 中添加。

用法

PostgreSQL 10 及更高版本

pg_create_physical_replication_slot ( slot_name name [, immediately_reserve boolean, temporary boolean ] )
        → record ( slot_name name, lsn pg_lsn )

PostgreSQL 9.6:

pg_create_physical_replication_slot ( slot_name name [, immediately_reserve boolean )
        → record ( slot_name name, lsn pg_lsn )

PostgreSQL 9.4PostgreSQL 9.5

pg_create_physical_replication_slot ( slot_name name )
        → record ( slot_name name, lsn pg_lsn )

槽名只能包含小写字母、数字和下划线的组合,最多 63 个字符 (NAMEDATALEN)。如果名称超过此限制,则会静默截断为 63 个字符。

如果提供 immediately_reserve 参数并将其设置为 TRUE,则将从最新的 检查点 保留 WAL。

如果提供临时参数并将其设置为 TRUE,则复制槽将不会永久存储,而只在当前会话期间可用。

更改历史

示例

使用 pg_create_physical_replication_slot() 创建复制槽

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

创建复制槽并确保从创建槽的时间点保留 WAL

postgres=# SELECT cc.checkpoint_lsn,
                  cprs.*
             FROM pg_control_checkpoint() cc,
                  pg_create_physical_replication_slot(
                    slot_name := 'bar',
                    immediately_reserve := TRUE
                  ) cprs;
 checkpoint_lsn | slot_name |    lsn    
----------------+-----------+-----------
 0/30004E8      | bar       | 0/30004B0
(1 row)

创建一个临时复制槽;请注意,pg_replslot 目录中的槽文件只会在当前会话期间持续存在。

postgres=# SELECT * FROM pg_create_physical_replication_slot('tmp_slot', temporary := TRUE);
 slot_name | lsn 
-----------+-----
 tmp_slot  | 
(1 row)

postgres=# SELECT pg_ls_dir('./pg_replslot');
 pg_ls_dir 
-----------
 tmp_slot
(1 row)

postgres=# \c - postgres
You are now connected to database "postgres" as user "postgres".
postgres=# SELECT pg_ls_dir('./pg_replslot');
 pg_ls_dir 
-----------
(0 rows)

尝试创建一个名称为 64 个字符或更多字符的复制槽

postgres=# SELECT * FROM pg_create_physical_replication_slot(repeat('x', 100));
                            slot_name                            | lsn 
-----------------------------------------------------------------+-----
 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 
(1 row)

尝试创建一个包含无效字符的复制槽名称

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

分类

复制复制槽系统函数WAL

另请参阅

pg_replication_slotspg_copy_physical_replication_slot()pg_drop_replication_slot()pg_create_logical_replication_slot()

反馈

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