1PG_RECEIVEWAL(1)         PostgreSQL 11.3 Documentation        PG_RECEIVEWAL(1)
2
3
4

NAME

6       pg_receivewal - stream write-ahead logs from a PostgreSQL server
7

SYNOPSIS

9       pg_receivewal [option...]
10

DESCRIPTION

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).
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.
26
27       The write-ahead log is streamed over a regular PostgreSQL connection
28       and uses the replication protocol. The connection must be made with a
29       superuser or a user having REPLICATION permissions (see Section 21.2),
30       and pg_hba.conf must permit the replication connection. The server must
31       also be configured with max_wal_senders set high enough to leave at
32       least one session available for the stream.
33
34       If the connection is lost, or if it cannot be initially established,
35       with a non-fatal error, pg_receivewal will retry the connection
36       indefinitely, and reestablish streaming as soon as possible. To avoid
37       this behavior, use the -n parameter.
38
39       In the absence of fatal errors, pg_receivewal will run until terminated
40       by the SIGINT signal (Control+C).
41

OPTIONS

43       -D directory
44       --directory=directory
45           Directory to write the output to.
46
47           This parameter is required.
48
49       -E lsn
50       --endpos=lsn
51           Automatically stop replication and exit with normal exit status 0
52           when receiving reaches the specified LSN.
53
54           If there is a record with LSN exactly equal to lsn, the record will
55           be processed.
56
57       --if-not-exists
58           Do not error out when --create-slot is specified and a slot with
59           the specified name already exists.
60
61       -n
62       --no-loop
63           Don't loop on connection errors. Instead, exit right away with an
64           error.
65
66       --no-sync
67           This option causes pg_receivewal to not force WAL data to be
68           flushed to disk. This is faster, but means that a subsequent
69           operating system crash can leave the WAL segments corrupt.
70           Generally, this option is useful for testing but should not be used
71           when doing WAL archiving on a production deployment.
72
73           This option is incompatible with --synchronous.
74
75       -s interval
76       --status-interval=interval
77           Specifies the number of seconds between status packets sent back to
78           the server. This allows for easier monitoring of the progress from
79           server. A value of zero disables the periodic status updates
80           completely, although an update will still be sent when requested by
81           the server, to avoid timeout disconnect. The default value is 10
82           seconds.
83
84       -S slotname
85       --slot=slotname
86           Require pg_receivewal to use an existing replication slot (see
87           Section 26.2.6). When this option is used, pg_receivewal will
88           report a flush position to the server, indicating when each segment
89           has been synchronized to disk so that the server can remove that
90           segment if it is not otherwise needed.
91
92           When the replication client of pg_receivewal is configured on the
93           server as a synchronous standby, then using a replication slot will
94           report the flush position to the server, but only when a WAL file
95           is closed. Therefore, that configuration will cause transactions on
96           the primary to wait for a long time and effectively not work
97           satisfactorily. The option --synchronous (see below) must be
98           specified in addition to make this work correctly.
99
100       --synchronous
101           Flush the WAL data to disk immediately after it has been received.
102           Also send a status packet back to the server immediately after
103           flushing, regardless of --status-interval.
104
105           This option should be specified if the replication client of
106           pg_receivewal is configured on the server as a synchronous standby,
107           to ensure that timely feedback is sent to the server.
108
109       -v
110       --verbose
111           Enables verbose mode.
112
113       -Z level
114       --compress=level
115           Enables gzip compression of write-ahead logs, and specifies the
116           compression level (0 through 9, 0 being no compression and 9 being
117           best compression). The suffix .gz will automatically be added to
118           all filenames.
119
120       The following command-line options control the database connection
121       parameters.
122
123       -d connstr
124       --dbname=connstr
125           Specifies parameters used to connect to the server, as a connection
126           string. See Section 34.1.1 for more information.
127
128           The option is called --dbname for consistency with other client
129           applications, but because pg_receivewal doesn't connect to any
130           particular database in the cluster, database name in the connection
131           string will be ignored.
132
133       -h host
134       --host=host
135           Specifies the host name of the machine on which the server is
136           running. If the value begins with a slash, it is used as the
137           directory for the Unix domain socket. The default is taken from the
138           PGHOST environment variable, if set, else a Unix domain socket
139           connection is attempted.
140
141       -p port
142       --port=port
143           Specifies the TCP port or local Unix domain socket file extension
144           on which the server is listening for connections. Defaults to the
145           PGPORT environment variable, if set, or a compiled-in default.
146
147       -U username
148       --username=username
149           User name to connect as.
150
151       -w
152       --no-password
153           Never issue a password prompt. If the server requires password
154           authentication and a password is not available by other means such
155           as a .pgpass file, the connection attempt will fail. This option
156           can be useful in batch jobs and scripts where no user is present to
157           enter a password.
158
159       -W
160       --password
161           Force pg_receivewal to prompt for a password before connecting to a
162           database.
163
164           This option is never essential, since pg_receivewal will
165           automatically prompt for a password if the server demands password
166           authentication. However, pg_receivewal will waste a connection
167           attempt finding out that the server wants a password. In some cases
168           it is worth typing -W to avoid the extra connection attempt.
169
170       pg_receivewal can perform one of the two following actions in order to
171       control physical replication slots:
172
173       --create-slot
174           Create a new physical replication slot with the name specified in
175           --slot, then exit.
176
177       --drop-slot
178           Drop the replication slot with the name specified in --slot, then
179           exit.
180
181       Other options are also available:
182
183       -V
184       --version
185           Print the pg_receivewal version and exit.
186
187       -?
188       --help
189           Show help about pg_receivewal command line arguments, and exit.
190

EXIT STATUS

192       pg_receivewal will exit with status 0 when terminated by the SIGINT
193       signal. (That is the normal way to end it. Hence it is not an error.)
194       For fatal errors or other signals, the exit status will be nonzero.
195

ENVIRONMENT

197       This utility, like most other PostgreSQL utilities, uses the
198       environment variables supported by libpq (see Section 34.14).
199

NOTES

201       When using pg_receivewal instead of archive_command as the main WAL
202       backup method, it is strongly recommended to use replication slots.
203       Otherwise, the server is free to recycle or remove write-ahead log
204       files before they are backed up, because it does not have any
205       information, either from archive_command or the replication slots,
206       about how far the WAL stream has been archived. Note, however, that a
207       replication slot will fill up the server's disk space if the receiver
208       does not keep up with fetching the WAL data.
209
210       pg_receivewal will preserve group permissions on the received WAL files
211       if group permissions are enabled on the source cluster.
212

EXAMPLES

214       To stream the write-ahead log from the server at mydbserver and store
215       it in the local directory /usr/local/pgsql/archive:
216
217           $ pg_receivewal -h mydbserver -D /usr/local/pgsql/archive
218

SEE ALSO

220       pg_basebackup(1)
221
222
223
224PostgreSQL 11.3                      2019                     PG_RECEIVEWAL(1)
Impressum