1PG_RECEIVEWAL(1) PostgreSQL 15.4 Documentation PG_RECEIVEWAL(1)
2
3
4
6 pg_receivewal - stream write-ahead logs from a PostgreSQL server
7
9 pg_receivewal [option...]
10
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 26.3).
17
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.
22
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
33 remote_apply.
34
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 22.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.
41
42 The starting point of the write-ahead log streaming is calculated when
43 pg_receivewal starts:
44
45 1. First, scan the directory where the WAL segment files are written
46 and find the newest completed segment file, using as the starting
47 point the beginning of the next WAL segment file.
48
49 2. If a starting point cannot be calculated with the previous method,
50 and if a replication slot is used, an extra READ_REPLICATION_SLOT
51 command is issued to retrieve the slot's restart_lsn to use as the
52 starting point. This option is only available when streaming
53 write-ahead logs from PostgreSQL 15 and up.
54
55 3. If a starting point cannot be calculated with the previous method,
56 the latest WAL flush location is used as reported by the server
57 from an IDENTIFY_SYSTEM command.
58
59 If the connection is lost, or if it cannot be initially established,
60 with a non-fatal error, pg_receivewal will retry the connection
61 indefinitely, and reestablish streaming as soon as possible. To avoid
62 this behavior, use the -n parameter.
63
64 In the absence of fatal errors, pg_receivewal will run until terminated
65 by the SIGINT signal (Control+C).
66
68 -D directory
69 --directory=directory
70 Directory to write the output to.
71
72 This parameter is required.
73
74 -E lsn
75 --endpos=lsn
76 Automatically stop replication and exit with normal exit status 0
77 when receiving reaches the specified LSN.
78
79 If there is a record with LSN exactly equal to lsn, the record will
80 be processed.
81
82 --if-not-exists
83 Do not error out when --create-slot is specified and a slot with
84 the specified name already exists.
85
86 -n
87 --no-loop
88 Don't loop on connection errors. Instead, exit right away with an
89 error.
90
91 --no-sync
92 This option causes pg_receivewal to not force WAL data to be
93 flushed to disk. This is faster, but means that a subsequent
94 operating system crash can leave the WAL segments corrupt.
95 Generally, this option is useful for testing but should not be used
96 when doing WAL archiving on a production deployment.
97
98 This option is incompatible with --synchronous.
99
100 -s interval
101 --status-interval=interval
102 Specifies the number of seconds between status packets sent back to
103 the server. This allows for easier monitoring of the progress from
104 server. A value of zero disables the periodic status updates
105 completely, although an update will still be sent when requested by
106 the server, to avoid timeout disconnect. The default value is 10
107 seconds.
108
109 -S slotname
110 --slot=slotname
111 Require pg_receivewal to use an existing replication slot (see
112 Section 27.2.6). When this option is used, pg_receivewal will
113 report a flush position to the server, indicating when each segment
114 has been synchronized to disk so that the server can remove that
115 segment if it is not otherwise needed.
116
117 When the replication client of pg_receivewal is configured on the
118 server as a synchronous standby, then using a replication slot will
119 report the flush position to the server, but only when a WAL file
120 is closed. Therefore, that configuration will cause transactions on
121 the primary to wait for a long time and effectively not work
122 satisfactorily. The option --synchronous (see below) must be
123 specified in addition to make this work correctly.
124
125 --synchronous
126 Flush the WAL data to disk immediately after it has been received.
127 Also send a status packet back to the server immediately after
128 flushing, regardless of --status-interval.
129
130 This option should be specified if the replication client of
131 pg_receivewal is configured on the server as a synchronous standby,
132 to ensure that timely feedback is sent to the server.
133
134 -v
135 --verbose
136 Enables verbose mode.
137
138 -Z level
139 -Z method[:detail]
140 --compress=level
141 --compress=method[:detail]
142 Enables compression of write-ahead logs.
143
144 The compression method can be set to gzip, lz4 (if PostgreSQL was
145 compiled with --with-lz4) or none for no compression. A compression
146 detail string can optionally be specified. If the detail string is
147 an integer, it specifies the compression level. Otherwise, it
148 should be a comma-separated list of items, each of the form keyword
149 or keyword=value. Currently, the only supported keyword is level.
150
151 If no compression level is specified, the default compression level
152 will be used. If only a level is specified without mentioning an
153 algorithm, gzip compression will be used if the level is greater
154 than 0, and no compression will be used if the level is 0.
155
156 The suffix .gz will automatically be added to all filenames when
157 using gzip, and the suffix .lz4 is added when using lz4.
158
159 The following command-line options control the database connection
160 parameters.
161
162 -d connstr
163 --dbname=connstr
164 Specifies parameters used to connect to the server, as a connection
165 string; these will override any conflicting command line options.
166
167 The option is called --dbname for consistency with other client
168 applications, but because pg_receivewal doesn't connect to any
169 particular database in the cluster, database name in the connection
170 string will be ignored.
171
172 -h host
173 --host=host
174 Specifies the host name of the machine on which the server is
175 running. If the value begins with a slash, it is used as the
176 directory for the Unix domain socket. The default is taken from the
177 PGHOST environment variable, if set, else a Unix domain socket
178 connection is attempted.
179
180 -p port
181 --port=port
182 Specifies the TCP port or local Unix domain socket file extension
183 on which the server is listening for connections. Defaults to the
184 PGPORT environment variable, if set, or a compiled-in default.
185
186 -U username
187 --username=username
188 User name to connect as.
189
190 -w
191 --no-password
192 Never issue a password prompt. If the server requires password
193 authentication and a password is not available by other means such
194 as a .pgpass file, the connection attempt will fail. This option
195 can be useful in batch jobs and scripts where no user is present to
196 enter a password.
197
198 -W
199 --password
200 Force pg_receivewal to prompt for a password before connecting to a
201 database.
202
203 This option is never essential, since pg_receivewal will
204 automatically prompt for a password if the server demands password
205 authentication. However, pg_receivewal will waste a connection
206 attempt finding out that the server wants a password. In some cases
207 it is worth typing -W to avoid the extra connection attempt.
208
209 pg_receivewal can perform one of the two following actions in order to
210 control physical replication slots:
211
212 --create-slot
213 Create a new physical replication slot with the name specified in
214 --slot, then exit.
215
216 --drop-slot
217 Drop the replication slot with the name specified in --slot, then
218 exit.
219
220 Other options are also available:
221
222 -V
223 --version
224 Print the pg_receivewal version and exit.
225
226 -?
227 --help
228 Show help about pg_receivewal command line arguments, and exit.
229
231 pg_receivewal will exit with status 0 when terminated by the SIGINT
232 signal. (That is the normal way to end it. Hence it is not an error.)
233 For fatal errors or other signals, the exit status will be nonzero.
234
236 This utility, like most other PostgreSQL utilities, uses the
237 environment variables supported by libpq (see Section 34.15).
238
239 The environment variable PG_COLOR specifies whether to use color in
240 diagnostic messages. Possible values are always, auto and never.
241
243 When using pg_receivewal instead of archive_command or archive_library
244 as the main WAL backup method, it is strongly recommended to use
245 replication slots. Otherwise, the server is free to recycle or remove
246 write-ahead log files before they are backed up, because it does not
247 have any information, either from archive_command or archive_library or
248 the replication slots, about how far the WAL stream has been archived.
249 Note, however, that a replication slot will fill up the server's disk
250 space if the receiver does not keep up with fetching the WAL data.
251
252 pg_receivewal will preserve group permissions on the received WAL files
253 if group permissions are enabled on the source cluster.
254
256 To stream the write-ahead log from the server at mydbserver and store
257 it in the local directory /usr/local/pgsql/archive:
258
259 $ pg_receivewal -h mydbserver -D /usr/local/pgsql/archive
260
262 pg_basebackup(1)
263
264
265
266PostgreSQL 15.4 2023 PG_RECEIVEWAL(1)