table of contents
PG_RECEIVEXLOG(1) | PostgreSQL 9.2.24 Documentation | PG_RECEIVEXLOG(1) |
NAME¶
pg_receivexlog - streams transaction logs from a PostgreSQL cluster
SYNOPSIS¶
pg_receivexlog [option...]
DESCRIPTION¶
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 Section 24.3, “Continuous Archiving and Point-in-Time Recovery (PITR)”, in the documentation).
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 Section 20.2, “Role Attributes”, in the documentation), 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.
OPTIONS¶
The following command-line options control the location and format of the output.
-D directory, --directory=directory
This parameter is required.
The following command-line options control the running of the program.
-n, --no-loop
-v, --verbose
The following command-line options control the database connection parameters.
-h host, --host=host
-p port, --port=port
-s interval, --status-interval=interval
-U username, --username=username
-w, --no-password
-W, --password
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, --version
-?, --help
ENVIRONMENT¶
This utility, like most other PostgreSQL utilities, uses the environment variables supported by libpq (see Section 31.14, “Environment Variables”, in the documentation).
NOTES¶
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.
EXAMPLES¶
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
SEE ALSO¶
2017-11-06 | PostgreSQL 9.2.24 |