PG_RECEIVEWAL(1)
π pg_receivewal β stream write-ahead logs from a PostgreSQL server
okay bestie, welcome to pg_receivewal, aka the little goblin that slurps up your write-ahead log in real time π§β¨ (and yes, the manual is PG_RECEIVEWAL(1), we're fancy here).
β¨ SYNOPSIS β¨
pg_receivewal [option...]
πΈ DESCRIPTION πΈ
So pg_receivewal streams the write-ahead log from a running PostgreSQL cluster. It uses the streaming replication protocol to grab it and just... writes it into a local directory of files πΎ. That directory can straight-up be your archive location when you're doing a restore with point-in-time recovery (peep Section 26.3). iconic behavior honestly.
Here's the part that eats: pg_receivewal streams the WAL in real time as the server generates it, and it does not wait for segments to complete the way archive_command and archive_library do π. Which means β say it with me β you do not need to set archive_timeout when you're using pg_receivewal. periodt.
But ngl, there's a catch π. Unlike the WAL receiver of a PostgreSQL standby server, pg_receivewal by default only flushes WAL data when a WAL file is closed. If you want it flushing in real time, you gotta pass --synchronous. And because pg_receivewal doesn't apply WAL, you should not let it become a synchronous standby when synchronous_commit equals remote_apply π. If it does, it'll look like a standby that never catches up and it will cause transaction commits to block. To dodge that whole situation, you should either configure an appropriate value for synchronous_standby_names, or specify an application_name for pg_receivewal that does not match it, or change the value of synchronous_commit to something other than remote_apply. pick your fighter π«Ά
The write-ahead log is streamed over a regular PostgreSQL connection using the replication protocol. The connection must be made with a user having REPLICATION permissions (see Section 22.2) or a superuser, and pg_hba.conf must permit the replication connection. The server also needs max_wal_senders set high enough to leave at least one session available for the stream β don't leave your girl hanging π
.
π where does the streaming even start π
The starting point of the write-ahead log streaming is calculated when pg_receivewal starts, in this order:
- First, scan the directory where the WAL segment files are written and find the newest completed segment file, using as the starting point the beginning of the next WAL segment file.
- If a starting point cannot be calculated with the previous method, and if a replication slot is used, an extra
READ_REPLICATION_SLOTcommand is issued to retrieve the slot'srestart_lsnto use as the starting point. This option is only available when streaming write-ahead logs from PostgreSQL 15 and up. (sorry to the older girlies π) - If a starting point cannot be calculated with the previous method, the latest WAL flush location is used as reported by the server from an
IDENTIFY_SYSTEMcommand.
π¦ connection drama π¦
If the connection is lost, or if it cannot be initially established, with a non-fatal error, pg_receivewal will retry the connection indefinitely and reestablish streaming as soon as possible π₯. To avoid this behavior, use the -n parameter. very "I'll wait for you" of it.
In the absence of fatal errors, pg_receivewal will run until terminated by the SIGINT signal (Ctrl+C).
β¨ OPTIONS β¨
-Ddirectory` β Directory to write the output to. π This parameter is required. no directory, no vibes.- *
--directory=directory* ** β same thing, long-form bestie. -Elsn,--endpos=lsn** β Automatically stop replication and exit with normal exit status0when receiving reaches the specified LSN. If there is a record with LSN exactly equal tolsn, the record **will be processed. so precise π--if-not-existsβ Do not error out when--create-slotis specified and a slot with the specified name already exists. no drama, no crash β¨-n,--no-loopβ Don't loop on connection errors. Instead, exit right away with an error. blunt queen π--no-syncβ This option causespg_receivewalto not force WAL data to be flushed to disk. This is faster, but means that a subsequent operating system crash can leave the WAL segments corrupt π. Generally, this option is useful for testing but should not be used when doing WAL archiving on a production deployment.
This option is incompatible with --synchronous. pick one, bestie.
- *
-s*interval,--status-interval=interval** β Specifies the number of seconds between status packets sent back to the server. This allows for easier monitoring of the progress from server. A value of zero disables the periodic status updates completely, although an update will still be sent when requested by the server, to avoid timeout disconnect. The default value is10seconds. π - *
-S*slotname,--slot=slotname** β Requirepg_receivewalto use an existing replication slot (see Section 27.2.6). When this option is used,pg_receivewalwill report a flush position to the server, indicating when each segment has been synchronized to disk so that the server can remove that segment if it is not otherwise needed. When the replication client ofpg_receivewalis configured on the server as a synchronous standby, then using a replication slot will report the flush position to the server, but only when a WAL file is closed. Therefore, that configuration will cause transactions on the primary to wait for a long time and effectively not work satisfactorily π. The option--synchronous(see below) must be specified in addition to make this work correctly. --synchronousβ Flush the WAL data to disk immediately after it has been received. Also send a status packet back to the server immediately after flushing, regardless of--status-interval. This option should be specified if the replication client ofpg_receivewalis configured on the server as a synchronous standby, to ensure that timely feedback is sent to the server. slay, timely feedback π-v,--verboseβ Enables verbose mode. she talks more now π£οΈ- *
-Z*level,-Zmethod[:detail],--compress=level,--compress=*method*[:*detail*]** β Enables compression of write-ahead logs. The compression method can be set togzip,lz4(if PostgreSQL was compiled with--with-lz4) ornonefor no compression. A compression detail string can optionally be specified. If the detail string is an integer, it specifies the compression level. Otherwise, it should be a comma-separated list of items, each of the formkeywordorkeyword=value. Currently, the only supported keyword islevel. If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm,gzipcompression will be used if the level is greater than0, and no compression will be used if the level is0. The suffix.gzwill automatically be added to all filenames when usinggzip, and the suffix.lz4is added when usinglz4`. π
π the connection-parameters corner π
The following command-line options control the database connection parameters.
-dconnstr,--dbname=connstr** β Specifies parameters used to connect to the server, as a connection string; these will override any conflicting command line options. The option is called--dbnamefor consistency with other client applications, but becausepg_receivewaldoesn't connect to any particular database in the cluster, database name in the connection string will be **ignored. she's not here for your databases bestie π- *
-h*host,--host=host** β 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 thePGHOSTenvironment 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 thePGPORTenvironment variable, if set, or a compiled-in default. - *
-U*username,--username=username** β User name to connect as. -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.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. very hands-off π-W,--passwordβ Forcepg_receivewalto prompt for a password before connecting to a database. This option is never essential, sincepg_receivewalwill automatically prompt for a password if the server demands password authentication. However,pg_receivewalwill waste a connection attempt finding out that the server wants a password. In some cases it is worth typing-Wto avoid the extra connection attempt. save yourself the round trip π«Ά
π slot management era π
pg_receivewal can perform one of the two following actions in order to control physical replication slots:
--create-slotβ Create a new physical replication slot with the name specified in--slot, then exit. β¨ new slot who dis--drop-slotβ Drop the replication slot with the name specified in--slot, then exit. π bye bestie
β other options β
Other options are also available:
-V,--versionβ Print thepg_receivewalversion and exit.-?,--helpβ Show help aboutpg_receivewalcommand line arguments, and exit.
π EXIT STATUS π
pg_receivewal will exit with status 0 when terminated by the SIGINT 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 π
This utility, like most other PostgreSQL utilities, uses the environment variables supported by libpq (see Section 34.15).
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never. aesthetic diagnostics, we love to see it π¨
π NOTES π
When using pg_receivewal instead of archive_command or archive_library as the main WAL backup method, it is strongly recommended to use replication slots π«Ά. Otherwise, the server is free to recycle or remove write-ahead log files before they are backed up, because it does not have any information, either from archive_command or archive_library or the replication slots, about how far the WAL stream has been archived.
Note, however, that a replication slot will fill up the server's disk space if the receiver does not keep up with fetching the WAL data. π no cap, watch your disk.
pg_receivewal will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster. considerate icon π
π EXAMPLES π
To stream the write-ahead log from the server at mydbserver and store it in the local directory /usr/local/pgsql/archive:
$ pg_receivewal -h mydbserver -D /usr/local/pgsql/archive
look at her go π§β¨
πΈ SEE ALSO πΈ
later bestie π this page came straight from the PostgreSQL 15.19 Documentation, dated 2026 β go stream some WAL and stay iconic.
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms