4 pg_receivewal — stream write-ahead logs from a PostgreSQL server
8 pg_receivewal [option...]
12 pg_receivewal is used to stream the write-ahead log from a running
13 PostgreSQL cluster. The write-ahead log is streamed using the streaming
14 replication protocol, and is written to a local directory of files.
15 This directory can be used as the archive location for doing a restore
16 using point-in-time recovery (see Section 25.3).
18 pg_receivewal streams the write-ahead log in real time as it's being
19 generated on the server, and does not wait for segments to complete
20 like archive_command and archive_library do. For this reason, it is not
21 necessary to set archive_timeout when using pg_receivewal.
23 Unlike the WAL receiver of a PostgreSQL standby server, pg_receivewal
24 by default flushes WAL data only when a WAL file is closed. The option
25 --synchronous must be specified to flush WAL data in real time. Since
26 pg_receivewal does not apply WAL, you should not allow it to become a
27 synchronous standby when synchronous_commit equals remote_apply. If it
28 does, it will appear to be a standby that never catches up, and will
29 cause transaction commits to block. To avoid this, you should either
30 configure an appropriate value for synchronous_standby_names, or
31 specify application_name for pg_receivewal that does not match it, or
32 change the value of synchronous_commit to something other than
35 The write-ahead log is streamed over a regular PostgreSQL connection
36 and uses the replication protocol. The connection must be made with a
37 user having REPLICATION permissions (see Section 21.2) or a superuser,
38 and pg_hba.conf must permit the replication connection. The server must
39 also be configured with max_wal_senders set high enough to leave at
40 least one session available for the stream.
42 The starting point of the write-ahead log streaming is calculated when
44 1. First, scan the directory where the WAL segment files are written
45 and find the newest completed segment file, using as the starting
46 point the beginning of the next WAL segment file.
47 2. If a starting point cannot be calculated with the previous method,
48 and if a replication slot is used, an extra READ_REPLICATION_SLOT
49 command is issued to retrieve the slot's restart_lsn to use as the
50 starting point. This option is only available when streaming
51 write-ahead logs from PostgreSQL 15 and up.
52 3. If a starting point cannot be calculated with the previous method,
53 the latest WAL flush location is used as reported by the server
54 from an IDENTIFY_SYSTEM command.
56 If the connection is lost, or if it cannot be initially established,
57 with a non-fatal error, pg_receivewal will retry the connection
58 indefinitely, and reestablish streaming as soon as possible. To avoid
59 this behavior, use the -n parameter.
61 In the absence of fatal errors, pg_receivewal will run until terminated
62 by the SIGINT (Control+C) or SIGTERM signal.
68 Directory to write the output to.
70 This parameter is required.
74 Automatically stop replication and exit with normal exit status
75 0 when receiving reaches the specified LSN.
77 If there is a record with LSN exactly equal to lsn, the record
81 Do not error out when --create-slot is specified and a slot with
82 the specified name already exists.
86 Don't loop on connection errors. Instead, exit right away with
90 This option causes pg_receivewal to not force WAL data to be
91 flushed to disk. This is faster, but means that a subsequent
92 operating system crash can leave the WAL segments corrupt.
93 Generally, this option is useful for testing but should not be
94 used when doing WAL archiving on a production deployment.
96 This option is incompatible with --synchronous.
99 --status-interval=interval
100 Specifies the number of seconds between status packets sent back
101 to the server. This allows for easier monitoring of the progress
102 from server. A value of zero disables the periodic status
103 updates completely, although an update will still be sent when
104 requested by the server, to avoid timeout disconnect. The
105 default value is 10 seconds.
109 Require pg_receivewal to use an existing replication slot (see
110 Section 26.2.6). When this option is used, pg_receivewal will
111 report a flush position to the server, indicating when each
112 segment has been synchronized to disk so that the server can
113 remove that segment if it is not otherwise needed.
115 When the replication client of pg_receivewal is configured on
116 the server as a synchronous standby, then using a replication
117 slot will report the flush position to the server, but only when
118 a WAL file is closed. Therefore, that configuration will cause
119 transactions on the primary to wait for a long time and
120 effectively not work satisfactorily. The option --synchronous
121 (see below) must be specified in addition to make this work
125 Flush the WAL data to disk immediately after it has been
126 received. Also send a status packet back to the server
127 immediately after flushing, regardless of --status-interval.
129 This option should be specified if the replication client of
130 pg_receivewal is configured on the server as a synchronous
131 standby, to ensure that timely feedback is sent to the server.
135 Enables verbose mode.
140 --compress=method[:detail]
141 Enables compression of write-ahead logs.
143 The compression method can be set to gzip, lz4 (if PostgreSQL
144 was compiled with --with-lz4) or none for no compression. A
145 compression detail string can optionally be specified. If the
146 detail string is an integer, it specifies the compression level.
147 Otherwise, it should be a comma-separated list of items, each of
148 the form keyword or keyword=value. Currently, the only supported
151 If no compression level is specified, the default compression
152 level will be used. If only a level is specified without
153 mentioning an algorithm, gzip compression will be used if the
154 level is greater than 0, and no compression will be used if the
157 The suffix .gz will automatically be added to all filenames when
158 using gzip, and the suffix .lz4 is added when using lz4.
160 The following command-line options control the database connection
165 Specifies parameters used to connect to the server, as a
166 connection string; these will override any conflicting command
169 This option is called --dbname for consistency with other client
170 applications, but because pg_receivewal doesn't connect to any
171 particular database in the cluster, any database name included
172 in the connection string will be ignored by the server. However,
173 a database name supplied that way overrides the default database
174 name (replication) for purposes of looking up the replication
175 connection's password in ~/.pgpass. Similarly, middleware or
176 proxies used in connecting to PostgreSQL might utilize the name
177 for purposes such as connection routing.
181 Specifies the host name of the machine on which the server is
182 running. If the value begins with a slash, it is used as the
183 directory for the Unix domain socket. The default is taken from
184 the PGHOST environment variable, if set, else a Unix domain
185 socket connection is attempted.
189 Specifies the TCP port or local Unix domain socket file
190 extension on which the server is listening for connections.
191 Defaults to the PGPORT environment variable, if set, or a
196 User name to connect as.
200 Never issue a password prompt. If the server requires password
201 authentication and a password is not available by other means
202 such as a .pgpass file, the connection attempt will fail. This
203 option can be useful in batch jobs and scripts where no user is
204 present to enter a password.
208 Force pg_receivewal to prompt for a password before connecting
211 This option is never essential, since pg_receivewal will
212 automatically prompt for a password if the server demands
213 password authentication. However, pg_receivewal will waste a
214 connection attempt finding out that the server wants a password.
215 In some cases it is worth typing -W to avoid the extra
218 pg_receivewal can perform one of the two following actions in order to
219 control physical replication slots:
222 Create a new physical replication slot with the name specified
223 in --slot, then exit.
226 Drop the replication slot with the name specified in --slot,
229 Other options are also available:
233 Print the pg_receivewal version and exit.
237 Show help about pg_receivewal command line arguments, and exit.
241 pg_receivewal will exit with status 0 when terminated by the SIGINT or
242 SIGTERM signal. (That is the normal way to end it. Hence it is not an
243 error.) For fatal errors or other signals, the exit status will be
248 This utility, like most other PostgreSQL utilities, uses the
249 environment variables supported by libpq (see Section 32.15).
251 The environment variable PG_COLOR specifies whether to use color in
252 diagnostic messages. Possible values are always, auto and never.
256 When using pg_receivewal instead of archive_command or archive_library
257 as the main WAL backup method, it is strongly recommended to use
258 replication slots. Otherwise, the server is free to recycle or remove
259 write-ahead log files before they are backed up, because it does not
260 have any information, either from archive_command or archive_library or
261 the replication slots, about how far the WAL stream has been archived.
262 Note, however, that a replication slot will fill up the server's disk
263 space if the receiver does not keep up with fetching the WAL data.
265 pg_receivewal will preserve group permissions on the received WAL files
266 if group permissions are enabled on the source cluster.
270 To stream the write-ahead log from the server at mydbserver and store
271 it in the local directory /usr/local/pgsql/archive:
272 $ pg_receivewal -h mydbserver -D /usr/local/pgsql/archive