Postgresql 中文操作指南
pg_recvlogical
pg_recvlogical — 控制 PostgreSQL 逻辑解码流
pg_recvlogical — control PostgreSQL logical decoding streams
Description
pg_recvlogical 控制逻辑解码复制槽,并从这些复制槽流式传输数据。
pg_recvlogical controls logical decoding replication slots and streams data from such replication slots.
它创建一个复制模式连接,因此它受到与 pg_receivewal 相同的约束,加上逻辑复制的约束(请参阅 Chapter 49 )。
It creates a replication-mode connection, so it is subject to the same constraints as pg_receivewal, plus those for logical replication (see Chapter 49).
pg_recvlogical 没有逻辑解码 SQL 接口的 peek 和 get 模式的等效项。它在接收到数据时懒惰发送数据重播确认,并在退出干净时发送数据重播确认。若要在槽上检查待处理数据而无需使用它,请使用 pg_logical_slot_peek_changes 。
pg_recvlogical has no equivalent to the logical decoding SQL interface’s peek and get modes. It sends replay confirmations for data lazily as it receives it and on clean exit. To examine pending data on a slot without consuming it, use pg_logical_slot_peek_changes.
在没有致命错误的情况下,pg_recvlogical 将运行,直至被 SIGINT ( Control + C ) 或 SIGTERM 信号终止。
In the absence of fatal errors, pg_recvlogical will run until terminated by the SIGINT (Control+C) or SIGTERM signal.
Options
必须至少指定以下一个选项才能选择一个动作:
At least one of the following options must be specified to select an action:
-
—create-slot
-
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 —two-phase can be specified with —create-slot to enable decoding of prepared transactions.
-
-
—drop-slot
-
Drop the replication slot with the name specified by —slot, then exit.
-
-
—start
-
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 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.
-
—create-slot 和 —start 可以一起指定。 —drop-slot 不能与其他动作组合在一起。
—create-slot and —start can be specified together. —drop-slot cannot be combined with another action.
下面的命令行选项控制输出和其他复制行为的位置和格式:
The following command-line options control the location and format of the output and other replication behavior:
-
-E _lsn—endpos=_lsn
-
In —start mode, automatically stop replication and exit with normal exit status 0 when receiving reaches the specified LSN. If specified when not in —start mode, an error is raised.
-
If there’s a record with LSN exactly equal to lsn, the record will be output.
-
The —endpos option is not aware of transaction boundaries and may truncate output partway through a transaction. Any partially output transaction will not be consumed and will be replayed again when the slot is next read from. Individual messages are never truncated.
-
-
-f _filename—file=_filename
-
Write received and decoded transaction data into this file. Use - for stdout.
-
-
-F _interval_seconds—fsync-interval=_interval_seconds
-
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.
-
-
-I _lsn—startpos=_lsn
-
In —start mode, start replication from the given LSN. For details on the effect of this, see the documentation in Chapter 49 and Section 55.4. Ignored in other modes.
-
-
—if-not-exists
-
Do not error out when —create-slot is specified and a slot with the specified name already exists.
-
-
-n_—no-loop_
-
When the connection to the server is lost, do not retry in a loop, just exit.
-
-
-o _name[role="=value"]—option=_name[=value_]_
-
Pass the option name to the output plugin with, if specified, the option value value. Which options exist and their effects depends on the used output plugin.
-
-
-P _plugin—plugin=_plugin
-
When creating a slot, use the specified logical decoding output plugin. See Chapter 49. This option has no effect if the slot already exists.
-
-
-s _interval_seconds—status-interval=_interval_seconds
-
This option has the same effect as the option of the same name in pg_receivewal. See the description there.
-
-
-S _slot_name—slot=_slot_name
-
In —start mode, use the existing logical replication slot named slot_name. In —create-slot mode, create the slot with this name. In —drop-slot mode, delete the slot with this name.
-
-
-t_—two-phase_
-
Enables decoding of prepared transactions. This option may only be specified with —create-slot
-
-
-v_—verbose_
-
Enables verbose mode.
-
以下命令行选项控制数据库连接参数。
The following command-line options control the database connection parameters.
-
-d _dbname—dbname=_dbname
-
The database to connect to. See the description of the actions for what this means in detail. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options. Defaults to the user name.
-
-
-h _hostname-or-ip—host=_hostname-or-ip
-
Specifies the host name of the machine on which the server is running. If the value begins with a slash, it is used as the directory for the Unix domain socket. The default is taken from the PGHOST environment variable, if set, else a Unix domain socket connection is attempted.
-
-
-p _port—port=_port
-
Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections. Defaults to the PGPORT environment variable, if set, or a compiled-in default.
-
-
-U _user—username=_user
-
User name to connect as. Defaults to current operating system user name.
-
-
-w_—no-password_
-
Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a .pgpass file, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.
-
-
-W_—password_
-
Force pg_recvlogical to prompt for a password before connecting to a database.
-
This option is never essential, since pg_recvlogical will automatically prompt for a password if the server demands password authentication. However, pg_recvlogical will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.
-
以下其他选项可用:
The following additional options are available:
-
-V_—version_
-
Print the pg_recvlogical version and exit.
-
-
-?_—help_
-
Show help about pg_recvlogical command line arguments, and exit.
-
Exit Status
当 pg_recvlogical 被 SIGINT 或 SIGTERM 信号终止时,它将退出,状态码为 0。(这是结束它的正常方式。因此它不是错误。)对于致命错误或其他信号,退出状态将为非零。
pg_recvlogical will exit with status 0 when terminated by the SIGINT or SIGTERM signal. (That is the normal way to end it. Hence it is not an error.) For fatal errors or other signals, the exit status will be nonzero.
Environment
此实用工具与大多数其他 PostgreSQL 实用工具类似,它使用 libpq 所支持的环境变量(请参阅 Section 34.15 )。
This utility, like most other PostgreSQL utilities, uses the environment variables supported by libpq (see Section 34.15).
环境变量 PG_COLOR 指定是否在诊断消息中使用颜色。可能的值是 always 、 auto 和 never 。
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never.
Notes
如果已在源集群上启用组权限,则 pg_recvlogical 将保留收到的 WAL 文件上的组权限。
pg_recvlogical will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster.
Examples
有关示例,请参阅 Section 49.1 。
See Section 49.1 for an example.