pg_recvlogical
pg_recvlogical — 控制 PostgreSQL 逻辑解码流
当前查看 PostgreSQL 18.6。
说明
pg_recvlogical — 控制 PostgreSQL 逻辑解码流
- 手册中的可执行程序
- pg_recvlogical
- 程序版本
- 18.6
- 参考清单
- 客户端程序
- 选项定义组
- 24
用法
pg_recvlogical [ option ...]手册中的选项
| 选项与参数 | 说明 |
|---|---|
| --create-slot | 为 --dbname 指定的数据库创建新的逻辑复制槽,名称由 --slot 指定,输出插件由 --plugin 指定。 |
| --drop-slot | 删除由 --slot 指定名称的复制槽,然后退出。 |
| --start | 开始从由 --slot 指定的逻辑复制槽流式传输更改,并持续运行直到被信号终止。如果服务端的更改流因服务器关闭或断开连接而结束,则除非指定了 --no-loop ,否则会循环重试。 |
| -E lsn --endpos= lsn | 在 --start 模式下,当接收达到指定的 LSN 时,自动停止复制,并以正常退出状态 0 退出。如果在非 --start 模式下指定,则会报错。 |
| --enable-failover | 允许将该槽同步到备库。此选项只能与 --create-slot 一起指定。 |
| -f filename --file= filename | 将接收到并解码后的事务数据写入该文件。指定 - 表示写入 stdout 。 |
| -F interval_seconds --fsync-interval= interval_seconds | 指定 pg_recvlogical 应当以多高的频率发起 fsync() 调用,以确保输出文件安全刷盘。 |
| -I lsn --startpos= lsn | 在 --start 模式下,从给定的 LSN 开始复制。关于其影响的详细信息,请参见 第 47 章 和 第 54.4 节 中的说明。在其他模式下会忽略此选项。 |
| --if-not-exists | 当指定 --create-slot 且指定名称的槽已存在时,不报错。 |
| -n --no-loop | 当与服务器的连接丢失时,不要循环重试,直接退出。 |
| -o name [= value ] --option= name [= value ] | 将选项 name 传递给输出插件;如果指定了 value ,则将其用作该选项的值。可用选项及其效果取决于所使用的输出插件。 |
| -P plugin --plugin= plugin | 创建该槽时,使用指定的逻辑解码输出插件。参见 第 47 章 。如果该槽已经存在,则此选项不起作用。 |
| -s interval_seconds --status-interval= interval_seconds | 该选项与 pg_receivewal 中同名选项的效果相同。参见该处说明。 |
| -S slot_name --slot= slot_name | 在 --start 模式下,使用名为 slot_name 的现有逻辑复制槽。在 --create-slot 模式下,以此名称创建该槽。在 --drop-slot 模式下,删除此名称的槽。 |
| -t --enable-two-phase --two-phase (已废弃) | 启用对预备事务的解码。此选项只能与 --create-slot 一起指定。 |
| -v --verbose | 启用详细模式。 |
| -d dbname --dbname= dbname | 要连接到的数据库。其具体含义请参见各操作的说明。 dbname 可以是一个 连接字符串 。如果是这种情况,连接字符串参数将覆盖任何冲突的命令行选项。 |
| -h hostname-or-ip --host= hostname-or-ip | 指定服务器运行所在机器的主机名。如果该值以斜杠开头,则它会被用作 Unix 域套接字的目录。默认值取自 PGHOST 环境变量(如果已设置),否则将尝试 Unix 域套接字连接。 |
| -p port --port= port | 指定服务器监听连接所用的 TCP 端口,或本地 Unix 域套接字文件扩展名。默认值取自 PGPORT 环境变量(如果已设置),否则使用编译时的默认值。 |
| -U user --username= user | 用于连接的用户名。默认为当前操作系统用户名。 |
| -w --no-password | 绝不提示输入密码。如果服务器要求密码认证,而密码又无法通过 .pgpass 文件等其他方式获得,则连接尝试将失败。此选项适用于批处理作业和脚本,因为在这些场景中没有用户在场输入密码。 |
| -W --password | 强制 pg_recvlogical 在连接数据库之前提示输入密码。 |
| -V --version | 打印 pg_recvlogical 的版本并退出。 |
| -? --help | 显示 pg_recvlogical 命令行参数的帮助并退出。 |
手册定义
pg_recvlogical
pg_recvlogical — 控制 PostgreSQL 逻辑解码流
大纲
pg_recvlogical [option...]
说明
pg_recvlogical用于控制逻辑解码复制槽,并从这类复制槽流式传输数据。
它会创建复制模式连接,因此除受到与pg_receivewal相同的约束外,还要满足逻辑复制的相关约束(见第 47 章)。
pg_recvlogical没有与逻辑解码 SQL 接口中 peek 和 get 模式等价的功能。它会在接收数据期间惰性地为这些数据发送重放确认,并在正常退出时发送确认。若要在不消费数据的情况下检查某个槽上的待处理数据,请使用pg_logical_slot_peek_changes。
在没有致命错误的情况下,pg_recvlogical会一直运行,直到收到 SIGINT(Control+C)或 SIGTERM 信号。
当 pg_recvlogical 收到 SIGHUP 信号时,它会关闭当前输出文件,并使用 --file 选项指定的文件名打开一个新文件。这样就可以通过先重命名当前文件,再向 pg_recvlogical 发送 SIGHUP 信号来轮换输出文件。
选项
至少必须指定以下选项之一,以选择要执行的操作:
--create-slot-
为 --dbname 指定的数据库创建新的逻辑复制槽,名称由 --slot 指定,输出插件由 --plugin 指定。
此操作必须指定
--slot和--dbname。--enable-two-phase 和 --enable-failover 选项可以与 --create-slot 一起指定。
--drop-slot-
删除由
--slot指定名称的复制槽,然后退出。此操作必须指定
--slot。 --start-
开始从由
--slot指定的逻辑复制槽流式传输更改,并持续运行直到被信号终止。如果服务端的更改流因服务器关闭或断开连接而结束,则除非指定了--no-loop,否则会循环重试。此操作必须指定
--slot、--dbname和--file。流格式由创建该槽时指定的输出插件决定。
该连接必须连到创建该槽时所用的同一个数据库。
--create-slot和--start可以一同指定。--drop-slot不能与其他操作组合使用。
以下命令行选项控制输出的位置和格式以及其他复制行为:
-Elsn--endpos=lsn-
在
--start模式下,当接收达到指定的 LSN 时,自动停止复制,并以正常退出状态 0 退出。如果在非--start模式下指定,则会报错。如果存在 LSN 恰好等于
lsn的记录,则该记录会被输出。--endpos选项不会感知事务边界,因此可能会在事务中途截断输出。任何只输出了一部分的事务都不会被消费,并会在下次从该槽读取时再次重放。单条消息永远不会被截断。 --enable-failover-
允许将该槽同步到备库。此选项只能与
--create-slot一起指定。 -ffilename--file=filename-
将接收到并解码后的事务数据写入该文件。指定
-表示写入stdout。此参数对于
--start操作是必需的。 -Finterval_seconds--fsync-interval=interval_seconds-
指定pg_recvlogical应当以多高的频率发起
fsync()调用,以确保输出文件安全刷盘。服务器会偶尔要求客户端执行刷盘,并将刷盘位置报告给服务器。除此之外,此设置还会更频繁地执行刷盘。
将间隔指定为
0会完全禁用fsync()调用,但仍会向服务器报告进度。在这种情况下,发生崩溃时可能会丢失数据。 -Ilsn--startpos=lsn-
在
--start模式下,从给定的 LSN 开始复制。关于其影响的详细信息,请参见第 47 章和第 54.4 节中的说明。在其他模式下会忽略此选项。 --if-not-exists-
当指定
--create-slot且指定名称的槽已存在时,不报错。 -n--no-loop-
当与服务器的连接丢失时,不要循环重试,直接退出。
-oname[=value]--option=name[=value]-
将选项
name传递给输出插件;如果指定了value,则将其用作该选项的值。可用选项及其效果取决于所使用的输出插件。 -Pplugin--plugin=plugin-
创建该槽时,使用指定的逻辑解码输出插件。参见第 47 章。如果该槽已经存在,则此选项不起作用。
-sinterval_seconds--status-interval=interval_seconds-
该选项与pg_receivewal中同名选项的效果相同。参见该处说明。
-Sslot_name--slot=slot_name-
在
--start模式下,使用名为slot_name的现有逻辑复制槽。在--create-slot模式下,以此名称创建该槽。在--drop-slot模式下,删除此名称的槽。此参数对于任何一种操作都是必需的。
-t--enable-two-phase--two-phase(已废弃)-
启用对预备事务的解码。此选项只能与
--create-slot一起指定。 -v--verbose-
启用详细模式。
下列命令行选项控制数据库连接参数。
-ddbname--dbname=dbname-
要连接到的数据库。其具体含义请参见各操作的说明。
dbname可以是一个连接字符串。如果是这种情况,连接字符串参数将覆盖任何冲突的命令行选项。此参数在
--create-slot和--start操作中是必需的。 -hhostname-or-ip--host=hostname-or-ip-
指定服务器运行所在机器的主机名。如果该值以斜杠开头,则它会被用作 Unix 域套接字的目录。默认值取自
PGHOST环境变量(如果已设置),否则将尝试 Unix 域套接字连接。 -pport--port=port-
指定服务器监听连接所用的 TCP 端口,或本地 Unix 域套接字文件扩展名。默认值取自
PGPORT环境变量(如果已设置),否则使用编译时的默认值。 -Uuser--username=user-
用于连接的用户名。默认为当前操作系统用户名。
-w--no-password-
绝不提示输入密码。如果服务器要求密码认证,而密码又无法通过
.pgpass文件等其他方式获得,则连接尝试将失败。此选项适用于批处理作业和脚本,因为在这些场景中没有用户在场输入密码。 -W--password-
强制pg_recvlogical在连接数据库之前提示输入密码。
这个选项并非必不可少,因为如果服务器要求密码认证,pg_recvlogical会自动提示输入密码。不过,pg_recvlogical需要先浪费一次连接尝试,才能发现服务器需要密码。在某些情况下,使用
-W来避免这次额外的连接尝试是值得的。
还可以使用下列附加选项:
-V--version-
打印pg_recvlogical的版本并退出。
-?--help-
显示pg_recvlogical命令行参数的帮助并退出。
退出状态
当收到 SIGINT 或 SIGTERM 信号终止时,pg_recvlogical会以状态 0 退出。(这是其正常结束方式,因此不视为错误。)遇到致命错误或其他信号时,退出状态为非零。
环境
与大多数其他PostgreSQL工具一样,此工具也使用libpq支持的环境变量(见第 32.15 节)。
环境变量PG_COLOR指定是否在诊断消息中使用颜色。可能的值为always、auto和never。
注解
如果源集簇启用了组权限,pg_recvlogical会在输出文件上保留这些组权限。
示例
示例请参见第 47.1 节。
相关条目
文档与源码
来源构建
- 版本
- 18.6
- 构建
- https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
- 来源指纹
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8
版本比较
PostgreSQL 18 → 19: 属性变化。
以下差异保留原始字段名与英文源描述。
--- PostgreSQL 18
+++ PostgreSQL 19
@@ -2,21 +2,21 @@
"environment": [],
"options": [
{
- "description": "Create a new logical replication slot with the name specified by --slot , using the output plugin specified by --plugin , for the database specified by --dbname . The --slot and --dbname are required for this action. The --enable-two-phase and --enable-failover options can be specified with --create-slot .",
+ "description": "Create a new logical replication slot with the name specified by --slot , using the output plugin specified by --plugin , for the database specified by --dbname . The --slot and --dbname options are required for this action. The --enable-two-phase and --enable-failover options can be specified with --create-slot .",
"names": [
"--create-slot"
],
"signature": "--create-slot"
},
{
- "description": "Drop the replication slot with the name specified by --slot , then exit. The --slot is required for this action.",
+ "description": "Drop the replication slot with the name specified by --slot , then exit. The --slot option is required for this action.",
"names": [
"--drop-slot"
],
"signature": "--drop-slot"
},
{
- "description": "Begin streaming changes from the logical replication slot specified by --slot , continuing until terminated by a signal. If the server side change stream ends with a server shutdown or disconnect, retry in a loop unless --no-loop is specified. The --slot and --dbname , --file are required for this action. The stream format is determined by the output plugin specified when the slot was created. The connection must be to the same database used to create the slot.",
+ "description": "Begin streaming changes from the logical replication slot specified by --slot , continuing until terminated by a signal. If the server side change stream ends with a server shutdown or disconnect, retry in a loop unless --no-loop is specified. The --slot , --dbname , and --file options are required for this action. The stream format is determined by the output plugin specified when the slot was created. The connection must be to the same database used to create the slot.",
"names": [
"--start"
],
@@ -46,7 +46,7 @@
"signature": "-f filename --file= filename"
},
{
- "description": "Specifies how often pg_recvlogical should issue fsync() calls to ensure the output file is safely flushed to disk. The server will occasionally request the client to perform a flush and report the flush position to the server. This setting is in addition to that, to perform flushes more frequently. Specifying an interval of 0 disables issuing fsync() calls altogether, while still reporting progress to the server. In this case, data could be lost in the event of a crash.",
+ "description": "Specifies how often pg_recvlogical should issue fsync() calls to ensure the output file is safely flushed to disk. The default value is 10 seconds. The server will occasionally request the client to perform a flush and report the flush position to the server. This setting is in addition to that, to perform flushes more frequently. Specifying an interval of 0 disables issuing fsync() calls altogether, while still reporting progress to the server. In this case, data could be lost in the event of a crash.",
"names": [
"-F interval_seconds",
"--fsync-interval= interval_seconds"
@@ -85,7 +85,7 @@
"signature": "-o name [= value ] --option= name [= value ]"
},
{
- "description": "When creating a slot, use the specified logical decoding output plugin. See Chapter 47 . This option has no effect if the slot already exists.",
+ "description": "When creating a slot, use the specified logical decoding output plugin. See Section 47.6 for information about the plugins PostgreSQL provides. The default is test_decoding . This option has no effect if the slot already exists.",
"names": [
"-P plugin",
"--plugin= plugin"
比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。
相关条目
导出 JSON · 返回命令行工具 · 收录范围为 PostgreSQL 10 至 20;最早采样版本不一定是实际引入版本。