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