pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。
pg_receivexlog — streams transaction logs from a PostgreSQL cluster
pg_receivexlog [option...]
pg_receivexlog is used to stream transaction log from a running PostgreSQL cluster. The transaction log is streamed using the streaming replication protocol, and is written to a local directory of files. This directory can be used as the archive location for doing a restore using point-in-time recovery (see 第 24.3 节).
pg_receivexlog streams the transaction log in real time as it's being generated on the server, and does not wait for segments to complete like archive_command does. For this reason, it is not necessary to set archive_timeout when using pg_receivexlog.
The transaction log is streamed over a regular PostgreSQL connection, and uses the replication protocol. The connection must be made with a superuser or a user having REPLICATION permissions (see 第 20.2 节), and pg_hba.conf must explicitly permit the replication connection. The server must also be configured with max_wal_senders set high enough to leave at least one session available for the stream.
If the connection is lost, or if it cannot be initially established, with a non-fatal error, pg_receivexlog will retry the connection indefinitely, and reestablish streaming as soon as possible. To avoid this behavior, use the -n parameter.
The following command-line options control the location and format of the output.
-D directory--directory=directoryDirectory to write the output to.
This parameter is required.
The following command-line options control the running of the program.
-n--no-loopDon't loop on connection errors. Instead, exit right away with an error.
-v--verboseEnables verbose mode.
The following command-line options control the database connection parameters.
-h host--host=hostSpecifies 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=portSpecifies 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.
-s interval--status-interval=intervalSpecifies the number of seconds between status packets sent back to the server. This is required if replication timeout is configured on the server, and allows for easier monitoring. A value of zero disables the status updates completely. The default value is 10 seconds.
-U username--username=usernameUser name to connect as.
-w--no-passwordNever 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--passwordForce pg_receivexlog to prompt for a password before connecting to a database.
This option is never essential, since pg_receivexlog will automatically prompt for a password if the server demands password authentication. However, pg_receivexlog 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.
Other options are also available:
-V--versionPrint the pg_receivexlog version and exit.
-?--helpShow help about pg_receivexlog command line arguments, and exit.
This utility, like most other PostgreSQL utilities, uses the environment variables supported by libpq (see 第 31.14 节).
When using pg_receivexlog instead of archive_command, the server will continue to recycle transaction log files even if the backups are not properly archived, since there is no command that fails. This can be worked around by having an archive_command that fails when the file has not been properly archived yet, for example:
archive_command = 'sleep 5 && test -f /mnt/server/archivedir/%f'
The initial timeout is necessary because pg_receivexlog works using asynchronous replication and can therefore be slightly behind the master.
To stream the transaction log from the server at mydbserver and store it in the local directory /usr/local/pgsql/archive:
$pg_receivexlog -h mydbserver -D /usr/local/pgsql/archive
译文有误、术语不当或页面显示问题,请到译文仓库 pgsty/pgdoc 报告译文问题。 英文原文本身的问题,请在当前版本的对应页面向上游反馈;上游不再修订已结束维护的版本。