PG_RECEIVEWAL(1)
โจ NAME โจ
pg_receivewal โ stream write-ahead logs from a PostgreSQL server ๐ (this is the page for PG_RECEIVEWAL(1), bestie, pull up a chair)
๐ SYNOPSIS ๐
pg_receivewal [option...]
๐ฆ DESCRIPTION ๐ฆ
okay so pg_receivewal is the girl who streams the write-ahead log straight off a running PostgreSQL cluster. She streams it using the streaming replication protocol and writes it out to a local directory full of files. That directory? It can literally be your archive location for doing a restore with point-in-time recovery (peep Section 25.3). ๐
pg_receivewal streams the WAL in real time, like, as it's being generated on the server โ she does not wait around for segments to complete the way archive_command and archive_library do. Which means: you do not need to set archive_timeout when you're using pg_receivewal. no cap. ๐ซถ
But here's the thing โ unlike the WAL receiver of a PostgreSQL standby server, pg_receivewal by default only flushes WAL data when a WAL file is closed. You gotta specify the --synchronous option to get WAL data flushed in real time. And since 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'll cause transaction commits to block. ๐ญ To dodge that whole situation, either configure an appropriate value for synchronous_standby_names, or specify an application_name for pg_receivewal that doesn't match it, or change the value of synchronous_commit to something other than remote_apply. Pick your fighter. ๐
The write-ahead log gets streamed over a regular PostgreSQL connection and uses the replication protocol. The connection must be made with a user having REPLICATION permissions (see Section 21.2) or a superuser, and pg_hba.conf must permit the replication connection. The server also has to be configured with max_wal_senders set high enough to leave at least one session available for the stream. slay. โจ
So where does the streaming even start? The starting point of the write-ahead log streaming is calculated when pg_receivewal starts:
- 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 can't 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. - If a starting point still can't be calculated with the previous method, the latest WAL flush location is used as reported by the server from an
IDENTIFY_SYSTEMcommand.
If the connection is lost, or if it can't be initially established, with a non-fatal error, pg_receivewal will retry the connection indefinitely and reestablish streaming as soon as possible. Wanna skip that whole behaviour? Use the -n parameter. ๐
And in the absence of fatal errors, pg_receivewal will run until it's terminated by the SIGINT (Control+C) or SIGTERM signal. periodt.
๐ OPTIONS ๐
-D directory,--directory=directoryโ Directory to write the output to. ๐๏ธ
This parameter is required. like, actually required bestie.
-E lsn,--endpos=lsnโ Automatically stop replication and exit with normal exit status0when receiving reaches the specified LSN.
If there's a record with LSN exactly equal to lsn, the record will be processed.
--if-not-existsโ Do not error out when--create-slotis specified and a slot with the specified name already exists. no drama, no error. ๐-n,--no-loopโ Don't loop on connection errors. Instead, exit right away with an error. ๐ช--no-syncโ This option causespg_receivewalto not force WAL data to be flushed to disk. It's faster, but it means 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, babe.
-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 26.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's not otherwise needed.
When the replication client of pg_receivewal is 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's 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 of pg_receivewal is configured on the server as a synchronous standby, to ensure that timely feedback is sent to the server. ๐ซ
-v,--verboseโ Enables verbose mode. she's chatty now. ๐ฃ๏ธ-Z level,-Z method[:detail],--compress=level,--compress=method[:detail]โ Enables compression of write-ahead logs. ๐๏ธ
The compression method can be set to gzip, lz4 (if PostgreSQL was compiled with --with-lz4) or none for 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 form keyword or keyword=value. Currently, the only supported keyword is level.
If no compression level is specified, the default compression level will be used. If only a level is specified without mentioning an algorithm, gzip compression will be used if the level is greater than 0, and no compression will be used if the level is 0.
The suffix .gz will automatically be added to all filenames when using gzip, and the suffix .lz4 is added when using lz4. ๐
The following command-line options control the database connection parameters. ๐
-d connstr,--dbname=connstrโ Specifies parameters used to connect to the server, as a connection string; these will override any conflicting command line options.
This option is called --dbname for consistency with other client applications, but because pg_receivewal doesn't connect to any particular database in the cluster, any database name included in the connection string will be ignored by the server. However, a database name supplied that way overrides the default database name (replication) for purposes of looking up the replication connection's password in ~/.pgpass. Similarly, middleware or proxies used in connecting to PostgreSQL might utilize the name for purposes such as connection routing. ๐
-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's 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 isn't 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. ๐ค-W,--passwordโ Forcepg_receivewalto prompt for a password before connecting to a database.
This option is never essential, since pg_receivewal will automatically prompt for a password if the server demands password authentication. However, pg_receivewal will waste a connection attempt finding out that the server wants a password. In some cases it's worth typing -W to avoid the extra connection attempt.
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.--drop-slotโ Drop the replication slot with the name specified in--slot, then exit.
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 or SIGTERM signal. (That is the normal way to end it. Hence it's 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 32.15).
The environment variable PG_COLOR specifies whether to use color in diagnostic messages. Possible values are always, auto and never. ๐
โญ NOTES โญ
When using pg_receivewal instead of archive_command or archive_library as the main WAL backup method, it's strongly recommended to use replication slots. Otherwise the server is free to recycle or remove write-ahead log files before they're backed up, because it doesn't 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 doesn't keep up with fetching the WAL data. ๐
pg_receivewal will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster. ๐ซถ
โจ EXAMPLES โจ
Okay bestie, let's make it real. Say you wanna stream the write-ahead log off a server called mydbserver and dump it into your local directory /usr/local/pgsql/archive โ literally that's it, one line, no drama:
$ pg_receivewal -h mydbserver -D /usr/local/pgsql/archive
That's the whole thing. -h tells it who to talk to, -D tells it where to put the goods, and it just... goes. Continuous. Endlessly. Like a girl who never stops texting back. ๐
๐ธ SEE ALSO ๐ธ
pg_basebackup(1)โ its sibling, its ride-or-die, the other half of the backup duo ๐ซถ
And that's the page, bestie!! This whole thing is PostgreSQL 18.6, dated 2026, filed under PG_RECEIVEWAL(1). Go forth and stream your WAL, you absolute icon. ๐๐ฆโจ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql-server 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql-server 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql-server 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql-server 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms