2 .\" Title: pg_receivewal
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "PG_RECEIVEWAL" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 pg_receivewal \- stream write\-ahead logs from a PostgreSQL server
33 .HP \w'\fBpg_receivewal\fR\ 'u
34 \fBpg_receivewal\fR [\fIoption\fR...]
38 is used to stream the write\-ahead log from a running
40 cluster\&. The write\-ahead 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
44 streams the write\-ahead log in real time as it\*(Aqs being generated on the server, and does not wait for segments to complete like
48 do\&. For this reason, it is not necessary to set
53 Unlike the WAL receiver of a PostgreSQL standby server,
55 by default flushes WAL data only when a WAL file is closed\&. The option
57 must be specified to flush WAL data in real time\&. Since
59 does not apply WAL, you should not allow it to become a synchronous standby when
62 remote_apply\&. If it does, it will appear to be a standby that never catches up, and will cause transaction commits to block\&. To avoid this, you should either configure an appropriate value for
63 synchronous_standby_names, or specify
64 \fIapplication_name\fR
67 that does not match it, or change the value of
68 \fIsynchronous_commit\fR
69 to something other than
72 The write\-ahead log is streamed over a regular
74 connection and uses the replication protocol\&. The connection must be made with a user having
77 Section\ \&21.2) or a superuser, and
79 must permit the replication connection\&. The server must also be configured with
81 set high enough to leave at least one session available for the stream\&.
83 The starting point of the write\-ahead log streaming is calculated when
95 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\&.
106 If a starting point cannot be calculated with the previous method, and if a replication slot is used, an extra
107 \fBREAD_REPLICATION_SLOT\fR
108 command is issued to retrieve the slot\*(Aqs
110 to use as the starting point\&. This option is only available when streaming write\-ahead logs from
123 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
128 If the connection is lost, or if it cannot be initially established, with a non\-fatal error,
130 will retry the connection indefinitely, and reestablish streaming as soon as possible\&. To avoid this behavior, use the
134 In the absence of fatal errors,
136 will run until terminated by the
143 \fB\-D \fR\fB\fIdirectory\fR\fR
145 \fB\-\-directory=\fR\fB\fIdirectory\fR\fR
147 Directory to write the output to\&.
149 This parameter is required\&.
152 \fB\-E \fR\fB\fIlsn\fR\fR
154 \fB\-\-endpos=\fR\fB\fIlsn\fR\fR
156 Automatically stop replication and exit with normal exit status 0 when receiving reaches the specified LSN\&.
158 If there is a record with LSN exactly equal to
159 \fIlsn\fR, the record will be processed\&.
162 \fB\-\-if\-not\-exists\fR
164 Do not error out when
165 \fB\-\-create\-slot\fR
166 is specified and a slot with the specified name already exists\&.
173 Don\*(Aqt loop on connection errors\&. Instead, exit right away with an error\&.
180 to 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\&.
182 This option is incompatible with
186 \fB\-s \fR\fB\fIinterval\fR\fR
188 \fB\-\-status\-interval=\fR\fB\fIinterval\fR\fR
190 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 is 10 seconds\&.
193 \fB\-S \fR\fB\fIslotname\fR\fR
195 \fB\-\-slot=\fR\fB\fIslotname\fR\fR
199 to use an existing replication slot (see
200 Section\ \&26.2.6)\&. When this option is used,
202 will 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\&.
204 When the replication client of
206 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
208 (see below) must be specified in addition to make this work correctly\&.
211 \fB\-\-synchronous\fR
213 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
214 \-\-status\-interval\&.
216 This option should be specified if the replication client of
218 is configured on the server as a synchronous standby, to ensure that timely feedback is sent to the server\&.
225 Enables verbose mode\&.
228 \fB\-Z \fR\fB\fIlevel\fR\fR
230 \fB\-Z \fR\fB\fImethod\fR\fR\fB[:\fR\fB\fIdetail\fR\fR\fB]\fR
232 \fB\-\-compress=\fR\fB\fIlevel\fR\fR
234 \fB\-\-compress=\fR\fB\fImethod\fR\fR\fB[:\fR\fB\fIdetail\fR\fR\fB]\fR
236 Enables compression of write\-ahead logs\&.
238 The compression method can be set to
244 \fB\-\-with\-lz4\fR) or
246 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
249 \fIkeyword=value\fR\&. Currently, the only supported keyword is
252 If no compression level is specified, the default compression level will be used\&. If only a level is specified without mentioning an algorithm,
254 compression will be used if the level is greater than 0, and no compression will be used if the level is 0\&.
258 will automatically be added to all filenames when using
265 The following command\-line options control the database connection parameters\&.
267 \fB\-d \fR\fB\fIconnstr\fR\fR
269 \fB\-\-dbname=\fR\fB\fIconnstr\fR\fR
271 Specifies parameters used to connect to the server, as a
272 connection string; these will override any conflicting command line options\&.
274 This option is called
276 for consistency with other client applications, but because
278 doesn\*(Aqt 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\*(Aqs password in
279 ~/\&.pgpass\&. Similarly, middleware or proxies used in connecting to
281 might utilize the name for purposes such as connection routing\&.
284 \fB\-h \fR\fB\fIhost\fR\fR
286 \fB\-\-host=\fR\fB\fIhost\fR\fR
288 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
290 environment variable, if set, else a Unix domain socket connection is attempted\&.
293 \fB\-p \fR\fB\fIport\fR\fR
295 \fB\-\-port=\fR\fB\fIport\fR\fR
297 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
299 environment variable, if set, or a compiled\-in default\&.
302 \fB\-U \fR\fB\fIusername\fR\fR
304 \fB\-\-username=\fR\fB\fIusername\fR\fR
306 User name to connect as\&.
311 \fB\-\-no\-password\fR
313 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
315 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\&.
324 to prompt for a password before connecting to a database\&.
326 This option is never essential, since
328 will automatically prompt for a password if the server demands password authentication\&. However,
330 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
332 to avoid the extra connection attempt\&.
336 can perform one of the two following actions in order to control physical replication slots:
338 \fB\-\-create\-slot\fR
340 Create a new physical replication slot with the name specified in
341 \fB\-\-slot\fR, then exit\&.
346 Drop the replication slot with the name specified in
347 \fB\-\-slot\fR, then exit\&.
350 Other options are also available:
367 command line arguments, and exit\&.
372 will exit with status 0 when terminated by the
376 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\&.
379 This utility, like most other
381 utilities, uses the environment variables supported by
386 The environment variable
388 specifies whether to use color in diagnostic messages\&. Possible values are
401 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
405 or the replication slots, about how far the WAL stream has been archived\&. Note, however, that a replication slot will fill up the server\*(Aqs disk space if the receiver does not keep up with fetching the WAL data\&.
408 will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster\&.
411 To stream the write\-ahead log from the server at
413 and store it in the local directory
414 /usr/local/pgsql/archive:
420 $ \fBpg_receivewal \-h mydbserver \-D /usr/local/pgsql/archive\fR
426 \fBpg_basebackup\fR(1)