]> begriffs open source - ai-pg/blob - full-docs/man1/pg_receivewal.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / pg_receivewal.1
1 '\" t
2 .\"     Title: pg_receivewal
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 pg_receivewal \- stream write\-ahead logs from a PostgreSQL server
32 .SH "SYNOPSIS"
33 .HP \w'\fBpg_receivewal\fR\ 'u
34 \fBpg_receivewal\fR [\fIoption\fR...]
35 .SH "DESCRIPTION"
36 .PP
37 pg_receivewal
38 is used to stream the write\-ahead log from a running
39 PostgreSQL
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
41 Section\ \&25.3)\&.
42 .PP
43 pg_receivewal
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
45 archive_command
46 and
47 archive_library
48 do\&. For this reason, it is not necessary to set
49 archive_timeout
50 when using
51 pg_receivewal\&.
52 .PP
53 Unlike the WAL receiver of a PostgreSQL standby server,
54 pg_receivewal
55 by default flushes WAL data only when a WAL file is closed\&. The option
56 \fB\-\-synchronous\fR
57 must be specified to flush WAL data in real time\&. Since
58 pg_receivewal
59 does not apply WAL, you should not allow it to become a synchronous standby when
60 synchronous_commit
61 equals
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
65 for
66 pg_receivewal
67 that does not match it, or change the value of
68 \fIsynchronous_commit\fR
69 to something other than
70 remote_apply\&.
71 .PP
72 The write\-ahead log is streamed over a regular
73 PostgreSQL
74 connection and uses the replication protocol\&. The connection must be made with a user having
75 REPLICATION
76 permissions (see
77 Section\ \&21.2) or a superuser, and
78 pg_hba\&.conf
79 must permit the replication connection\&. The server must also be configured with
80 max_wal_senders
81 set high enough to leave at least one session available for the stream\&.
82 .PP
83 The starting point of the write\-ahead log streaming is calculated when
84 pg_receivewal
85 starts:
86 .sp
87 .RS 4
88 .ie n \{\
89 \h'-04' 1.\h'+01'\c
90 .\}
91 .el \{\
92 .sp -1
93 .IP "  1." 4.2
94 .\}
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\&.
96 .RE
97 .sp
98 .RS 4
99 .ie n \{\
100 \h'-04' 2.\h'+01'\c
101 .\}
102 .el \{\
103 .sp -1
104 .IP "  2." 4.2
105 .\}
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
109 restart_lsn
110 to use as the starting point\&. This option is only available when streaming write\-ahead logs from
111 PostgreSQL
112 15 and up\&.
113 .RE
114 .sp
115 .RS 4
116 .ie n \{\
117 \h'-04' 3.\h'+01'\c
118 .\}
119 .el \{\
120 .sp -1
121 .IP "  3." 4.2
122 .\}
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
124 IDENTIFY_SYSTEM
125 command\&.
126 .RE
127 .PP
128 If the connection is lost, or if it cannot be initially established, with a non\-fatal error,
129 pg_receivewal
130 will retry the connection indefinitely, and reestablish streaming as soon as possible\&. To avoid this behavior, use the
131 \-n
132 parameter\&.
133 .PP
134 In the absence of fatal errors,
135 pg_receivewal
136 will run until terminated by the
137 SIGINT
138 (Control+C) or
139 SIGTERM
140 signal\&.
141 .SH "OPTIONS"
142 .PP
143 \fB\-D \fR\fB\fIdirectory\fR\fR
144 .br
145 \fB\-\-directory=\fR\fB\fIdirectory\fR\fR
146 .RS 4
147 Directory to write the output to\&.
148 .sp
149 This parameter is required\&.
150 .RE
151 .PP
152 \fB\-E \fR\fB\fIlsn\fR\fR
153 .br
154 \fB\-\-endpos=\fR\fB\fIlsn\fR\fR
155 .RS 4
156 Automatically stop replication and exit with normal exit status 0 when receiving reaches the specified LSN\&.
157 .sp
158 If there is a record with LSN exactly equal to
159 \fIlsn\fR, the record will be processed\&.
160 .RE
161 .PP
162 \fB\-\-if\-not\-exists\fR
163 .RS 4
164 Do not error out when
165 \fB\-\-create\-slot\fR
166 is specified and a slot with the specified name already exists\&.
167 .RE
168 .PP
169 \fB\-n\fR
170 .br
171 \fB\-\-no\-loop\fR
172 .RS 4
173 Don\*(Aqt loop on connection errors\&. Instead, exit right away with an error\&.
174 .RE
175 .PP
176 \fB\-\-no\-sync\fR
177 .RS 4
178 This option causes
179 \fBpg_receivewal\fR
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\&.
181 .sp
182 This option is incompatible with
183 \-\-synchronous\&.
184 .RE
185 .PP
186 \fB\-s \fR\fB\fIinterval\fR\fR
187 .br
188 \fB\-\-status\-interval=\fR\fB\fIinterval\fR\fR
189 .RS 4
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\&.
191 .RE
192 .PP
193 \fB\-S \fR\fB\fIslotname\fR\fR
194 .br
195 \fB\-\-slot=\fR\fB\fIslotname\fR\fR
196 .RS 4
197 Require
198 pg_receivewal
199 to use an existing replication slot (see
200 Section\ \&26.2.6)\&. When this option is used,
201 pg_receivewal
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\&.
203 .sp
204 When the replication client of
205 pg_receivewal
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
207 \-\-synchronous
208 (see below) must be specified in addition to make this work correctly\&.
209 .RE
210 .PP
211 \fB\-\-synchronous\fR
212 .RS 4
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\&.
215 .sp
216 This option should be specified if the replication client of
217 pg_receivewal
218 is configured on the server as a synchronous standby, to ensure that timely feedback is sent to the server\&.
219 .RE
220 .PP
221 \fB\-v\fR
222 .br
223 \fB\-\-verbose\fR
224 .RS 4
225 Enables verbose mode\&.
226 .RE
227 .PP
228 \fB\-Z \fR\fB\fIlevel\fR\fR
229 .br
230 \fB\-Z \fR\fB\fImethod\fR\fR\fB[:\fR\fB\fIdetail\fR\fR\fB]\fR
231 .br
232 \fB\-\-compress=\fR\fB\fIlevel\fR\fR
233 .br
234 \fB\-\-compress=\fR\fB\fImethod\fR\fR\fB[:\fR\fB\fIdetail\fR\fR\fB]\fR
235 .RS 4
236 Enables compression of write\-ahead logs\&.
237 .sp
238 The compression method can be set to
239 gzip,
240 lz4
241 (if
242 PostgreSQL
243 was compiled with
244 \fB\-\-with\-lz4\fR) or
245 none
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
247 \fIkeyword\fR
248 or
249 \fIkeyword=value\fR\&. Currently, the only supported keyword is
250 level\&.
251 .sp
252 If no compression level is specified, the default compression level will be used\&. If only a level is specified without mentioning an algorithm,
253 gzip
254 compression will be used if the level is greater than 0, and no compression will be used if the level is 0\&.
255 .sp
256 The suffix
257 \&.gz
258 will automatically be added to all filenames when using
259 gzip, and the suffix
260 \&.lz4
261 is added when using
262 lz4\&.
263 .RE
264 .PP
265 The following command\-line options control the database connection parameters\&.
266 .PP
267 \fB\-d \fR\fB\fIconnstr\fR\fR
268 .br
269 \fB\-\-dbname=\fR\fB\fIconnstr\fR\fR
270 .RS 4
271 Specifies parameters used to connect to the server, as a
272 connection string; these will override any conflicting command line options\&.
273 .sp
274 This option is called
275 \-\-dbname
276 for consistency with other client applications, but because
277 pg_receivewal
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
280 PostgreSQL
281 might utilize the name for purposes such as connection routing\&.
282 .RE
283 .PP
284 \fB\-h \fR\fB\fIhost\fR\fR
285 .br
286 \fB\-\-host=\fR\fB\fIhost\fR\fR
287 .RS 4
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
289 \fBPGHOST\fR
290 environment variable, if set, else a Unix domain socket connection is attempted\&.
291 .RE
292 .PP
293 \fB\-p \fR\fB\fIport\fR\fR
294 .br
295 \fB\-\-port=\fR\fB\fIport\fR\fR
296 .RS 4
297 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
298 \fBPGPORT\fR
299 environment variable, if set, or a compiled\-in default\&.
300 .RE
301 .PP
302 \fB\-U \fR\fB\fIusername\fR\fR
303 .br
304 \fB\-\-username=\fR\fB\fIusername\fR\fR
305 .RS 4
306 User name to connect as\&.
307 .RE
308 .PP
309 \fB\-w\fR
310 .br
311 \fB\-\-no\-password\fR
312 .RS 4
313 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
314 \&.pgpass
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\&.
316 .RE
317 .PP
318 \fB\-W\fR
319 .br
320 \fB\-\-password\fR
321 .RS 4
322 Force
323 pg_receivewal
324 to prompt for a password before connecting to a database\&.
325 .sp
326 This option is never essential, since
327 pg_receivewal
328 will automatically prompt for a password if the server demands password authentication\&. However,
329 pg_receivewal
330 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
331 \fB\-W\fR
332 to avoid the extra connection attempt\&.
333 .RE
334 .PP
335 pg_receivewal
336 can perform one of the two following actions in order to control physical replication slots:
337 .PP
338 \fB\-\-create\-slot\fR
339 .RS 4
340 Create a new physical replication slot with the name specified in
341 \fB\-\-slot\fR, then exit\&.
342 .RE
343 .PP
344 \fB\-\-drop\-slot\fR
345 .RS 4
346 Drop the replication slot with the name specified in
347 \fB\-\-slot\fR, then exit\&.
348 .RE
349 .PP
350 Other options are also available:
351 .PP
352 \fB\-V\fR
353 .br
354 \fB\-\-version\fR
355 .RS 4
356 Print the
357 pg_receivewal
358 version and exit\&.
359 .RE
360 .PP
361 \fB\-?\fR
362 .br
363 \fB\-\-help\fR
364 .RS 4
365 Show help about
366 pg_receivewal
367 command line arguments, and exit\&.
368 .RE
369 .SH "EXIT STATUS"
370 .PP
371 pg_receivewal
372 will exit with status 0 when terminated by the
373 SIGINT
374 or
375 SIGTERM
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\&.
377 .SH "ENVIRONMENT"
378 .PP
379 This utility, like most other
380 PostgreSQL
381 utilities, uses the environment variables supported by
382 libpq
383 (see
384 Section\ \&32.15)\&.
385 .PP
386 The environment variable
387 \fBPG_COLOR\fR
388 specifies whether to use color in diagnostic messages\&. Possible values are
389 always,
390 auto
391 and
392 never\&.
393 .SH "NOTES"
394 .PP
395 When using
396 pg_receivewal
397 instead of
398 archive_command
399 or
400 archive_library
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
402 archive_command
403 or
404 archive_library
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\&.
406 .PP
407 pg_receivewal
408 will preserve group permissions on the received WAL files if group permissions are enabled on the source cluster\&.
409 .SH "EXAMPLES"
410 .PP
411 To stream the write\-ahead log from the server at
412 mydbserver
413 and store it in the local directory
414 /usr/local/pgsql/archive:
415 .sp
416 .if n \{\
417 .RS 4
418 .\}
419 .nf
420 $ \fBpg_receivewal \-h mydbserver \-D /usr/local/pgsql/archive\fR
421 .fi
422 .if n \{\
423 .RE
424 .\}
425 .SH "SEE ALSO"
426 \fBpg_basebackup\fR(1)