]> begriffs open source - ai-pg/blob - full-docs/man1/pg_basebackup.1
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man1 / pg_basebackup.1
1 '\" t
2 .\"     Title: pg_basebackup
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_BASEBACKUP" "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_basebackup \- take a base backup of a PostgreSQL cluster
32 .SH "SYNOPSIS"
33 .HP \w'\fBpg_basebackup\fR\ 'u
34 \fBpg_basebackup\fR [\fIoption\fR...]
35 .SH "DESCRIPTION"
36 .PP
37 pg_basebackup
38 is used to take a base backup of a running
39 PostgreSQL
40 database cluster\&. The backup is taken without affecting other clients of the database, and can be used both for point\-in\-time recovery (see
41 Section\ \&25.3) and as the starting point for a log\-shipping or streaming\-replication standby server (see
42 Section\ \&26.2)\&.
43 .PP
44 pg_basebackup
45 can take a full or incremental base backup of the database\&. When used to take a full backup, it makes an exact copy of the database cluster\*(Aqs files\&. When used to take an incremental backup, some files that would have been part of a full backup may be replaced with incremental versions of the same files, containing only those blocks that have been modified since the reference backup\&. An incremental backup cannot be used directly; instead,
46 \fBpg_combinebackup\fR(1)
47 must first be used to combine it with the previous backups upon which it depends\&. See
48 Section\ \&25.3.3
49 for more information about incremental backups, and
50 Section\ \&25.3.5
51 for steps to recover from a backup\&.
52 .PP
53 In any mode,
54 pg_basebackup
55 makes sure the server is put into and out of backup mode automatically\&. Backups are always taken of the entire database cluster; it is not possible to back up individual databases or database objects\&. For selective backups, another tool such as
56 \fBpg_dump\fR(1)
57 must be used\&.
58 .PP
59 The backup is made over a regular
60 PostgreSQL
61 connection that uses the replication protocol\&. The connection must be made with a user ID that has
62 REPLICATION
63 permissions (see
64 Section\ \&21.2) or is a superuser, and
65 pg_hba\&.conf
66 must permit the replication connection\&. The server must also be configured with
67 max_wal_senders
68 set high enough to provide at least one walsender for the backup plus one for WAL streaming (if used)\&.
69 .PP
70 There can be multiple
71 \fBpg_basebackup\fRs running at the same time, but it is usually better from a performance point of view to take only one backup, and copy the result\&.
72 .PP
73 pg_basebackup
74 can make a base backup from not only a primary server but also a standby\&. To take a backup from a standby, set up the standby so that it can accept replication connections (that is, set
75 \fImax_wal_senders\fR
76 and
77 hot_standby, and configure its
78 pg_hba\&.conf
79 appropriately)\&. You will also need to enable
80 full_page_writes
81 on the primary\&.
82 .PP
83 Note that there are some limitations in taking a backup from a standby:
84 .sp
85 .RS 4
86 .ie n \{\
87 \h'-04'\(bu\h'+03'\c
88 .\}
89 .el \{\
90 .sp -1
91 .IP \(bu 2.3
92 .\}
93 The backup history file is not created in the database cluster backed up\&.
94 .RE
95 .sp
96 .RS 4
97 .ie n \{\
98 \h'-04'\(bu\h'+03'\c
99 .\}
100 .el \{\
101 .sp -1
102 .IP \(bu 2.3
103 .\}
104 pg_basebackup
105 cannot force the standby to switch to a new WAL file at the end of backup\&. When you are using
106 \-X none, if write activity on the primary is low,
107 pg_basebackup
108 may need to wait a long time for the last WAL file required for the backup to be switched and archived\&. In this case, it may be useful to run
109 \fBpg_switch_wal\fR
110 on the primary in order to trigger an immediate WAL file switch\&.
111 .RE
112 .sp
113 .RS 4
114 .ie n \{\
115 \h'-04'\(bu\h'+03'\c
116 .\}
117 .el \{\
118 .sp -1
119 .IP \(bu 2.3
120 .\}
121 If the standby is promoted to be primary during backup, the backup fails\&.
122 .RE
123 .sp
124 .RS 4
125 .ie n \{\
126 \h'-04'\(bu\h'+03'\c
127 .\}
128 .el \{\
129 .sp -1
130 .IP \(bu 2.3
131 .\}
132 All WAL records required for the backup must contain sufficient full\-page writes, which requires you to enable
133 \fIfull_page_writes\fR
134 on the primary\&.
135 .RE
136 .PP
137 Whenever
138 pg_basebackup
139 is taking a base backup, the server\*(Aqs
140 pg_stat_progress_basebackup
141 view will report the progress of the backup\&. See
142 Section\ \&27.4.6
143 for details\&.
144 .SH "OPTIONS"
145 .PP
146 The following command\-line options control the location and format of the output:
147 .PP
148 \fB\-D \fR\fB\fIdirectory\fR\fR
149 .br
150 \fB\-\-pgdata=\fR\fB\fIdirectory\fR\fR
151 .RS 4
152 Sets the target directory to write the output to\&.
153 pg_basebackup
154 will create this directory (and any missing parent directories) if it does not exist\&. If it already exists, it must be empty\&.
155 .sp
156 When the backup is in tar format, the target directory may be specified as
157 \-
158 (dash), causing the tar file to be written to
159 stdout\&.
160 .sp
161 This option is required\&.
162 .RE
163 .PP
164 \fB\-F \fR\fB\fIformat\fR\fR
165 .br
166 \fB\-\-format=\fR\fB\fIformat\fR\fR
167 .RS 4
168 Selects the format for the output\&.
169 \fIformat\fR
170 can be one of the following:
171 .PP
172 p
173 .br
174 plain
175 .RS 4
176 Write the output as plain files, with the same layout as the source server\*(Aqs data directory and tablespaces\&. When the cluster has no additional tablespaces, the whole database will be placed in the target directory\&. If the cluster contains additional tablespaces, the main data directory will be placed in the target directory, but all other tablespaces will be placed in the same absolute path as they have on the source server\&. (See
177 \fB\-\-tablespace\-mapping\fR
178 to change that\&.)
179 .sp
180 This is the default format\&.
181 .RE
182 .PP
183 t
184 .br
185 tar
186 .RS 4
187 Write the output as tar files in the target directory\&. The main data directory\*(Aqs contents will be written to a file named
188 base\&.tar, and each other tablespace will be written to a separate tar file named after that tablespace\*(Aqs OID\&.
189 .sp
190 If the target directory is specified as
191 \-
192 (dash), the tar contents will be written to standard output, suitable for piping to (for example)
193 gzip\&. This is only allowed if the cluster has no additional tablespaces and WAL streaming is not used\&.
194 .RE
195 .RE
196 .PP
197 \fB\-i \fR\fB\fIold_manifest_file\fR\fR
198 .br
199 \fB\-\-incremental=\fR\fB\fIold_manifest_file\fR\fR
200 .RS 4
201 Performs an
202 incremental backup\&. The backup manifest for the reference backup must be provided, and will be uploaded to the server, which will respond by sending the requested incremental backup\&.
203 .RE
204 .PP
205 \fB\-R\fR
206 .br
207 \fB\-\-write\-recovery\-conf\fR
208 .RS 4
209 Creates a
210 standby\&.signal
211
212 file and appends connection settings to the
213 postgresql\&.auto\&.conf
214 file in the target directory (or within the base archive file when using tar format)\&. This eases setting up a standby server using the results of the backup\&.
215 .sp
216 The
217 postgresql\&.auto\&.conf
218 file will record the connection settings and, if specified, the replication slot that
219 pg_basebackup
220 is using, so that streaming replication and
221 logical replication slot synchronization
222 will use the same settings later on\&. The dbname will be recorded only if the dbname was specified explicitly in the connection string or
223 environment variable\&.
224 .RE
225 .PP
226 \fB\-t \fR\fB\fItarget\fR\fR
227 .br
228 \fB\-\-target=\fR\fB\fItarget\fR\fR
229 .RS 4
230 Instructs the server where to place the base backup\&. The default target is
231 client, which specifies that the backup should be sent to the machine where
232 pg_basebackup
233 is running\&. If the target is instead set to
234 server:/some/path, the backup will be stored on the machine where the server is running in the
235 /some/path
236 directory\&. Storing a backup on the server requires superuser privileges or having privileges of the
237 pg_write_server_files
238 role\&. If the target is set to
239 blackhole, the contents are discarded and not stored anywhere\&. This should only be used for testing purposes, as you will not end up with an actual backup\&.
240 .sp
241 Since WAL streaming is implemented by
242 pg_basebackup
243 rather than by the server, this option cannot be used together with
244 \-Xstream\&. Since that is the default, when this option is specified, you must also specify either
245 \-Xfetch
246 or
247 \-Xnone\&.
248 .RE
249 .PP
250 \fB\-T \fR\fB\fIolddir\fR\fR\fB=\fR\fB\fInewdir\fR\fR
251 .br
252 \fB\-\-tablespace\-mapping=\fR\fB\fIolddir\fR\fR\fB=\fR\fB\fInewdir\fR\fR
253 .RS 4
254 Relocates the tablespace in directory
255 \fIolddir\fR
256 to
257 \fInewdir\fR
258 during the backup\&. To be effective,
259 \fIolddir\fR
260 must exactly match the path specification of the tablespace as it is defined on the source server\&. (But it is not an error if there is no tablespace in
261 \fIolddir\fR
262 on the source server\&.) Meanwhile
263 \fInewdir\fR
264 is a directory in the receiving host\*(Aqs filesystem\&. As with the main target directory,
265 \fInewdir\fR
266 need not exist already, but if it does exist it must be empty\&. Both
267 \fIolddir\fR
268 and
269 \fInewdir\fR
270 must be absolute paths\&. If either path needs to contain an equal sign (=), precede that with a backslash\&. This option can be specified multiple times for multiple tablespaces\&.
271 .sp
272 If a tablespace is relocated in this way, the symbolic links inside the main data directory are updated to point to the new location\&. So the new data directory is ready to be used for a new server instance with all tablespaces in the updated locations\&.
273 .sp
274 Currently, this option only works with plain output format; it is ignored if tar format is selected\&.
275 .RE
276 .PP
277 \fB\-\-waldir=\fR\fB\fIwaldir\fR\fR
278 .RS 4
279 Sets the directory to write WAL (write\-ahead log) files to\&. By default WAL files will be placed in the
280 pg_wal
281 subdirectory of the target directory, but this option can be used to place them elsewhere\&.
282 \fIwaldir\fR
283 must be an absolute path\&. As with the main target directory,
284 \fIwaldir\fR
285 need not exist already, but if it does exist it must be empty\&. This option can only be specified when the backup is in plain format\&.
286 .RE
287 .PP
288 \fB\-X \fR\fB\fImethod\fR\fR
289 .br
290 \fB\-\-wal\-method=\fR\fB\fImethod\fR\fR
291 .RS 4
292 Includes the required WAL (write\-ahead log) files in the backup\&. This will include all write\-ahead logs generated during the backup\&. Unless the method
293 none
294 is specified, it is possible to start a postmaster in the target directory without the need to consult the WAL archive, thus making the output a completely standalone backup\&.
295 .sp
296 The following
297 \fImethod\fRs for collecting the write\-ahead logs are supported:
298 .PP
299 n
300 .br
301 none
302 .RS 4
303 Don\*(Aqt include write\-ahead logs in the backup\&.
304 .RE
305 .PP
306 f
307 .br
308 fetch
309 .RS 4
310 The write\-ahead log files are collected at the end of the backup\&. Therefore, it is necessary for the source server\*(Aqs
311 wal_keep_size
312 parameter to be set high enough that the required log data is not removed before the end of the backup\&. If the required log data has been recycled before it\*(Aqs time to transfer it, the backup will fail and be unusable\&.
313 .sp
314 When tar format is used, the write\-ahead log files will be included in the
315 base\&.tar
316 file\&.
317 .RE
318 .PP
319 s
320 .br
321 stream
322 .RS 4
323 Stream write\-ahead log data while the backup is being taken\&. This method will open a second connection to the server and start streaming the write\-ahead log in parallel while running the backup\&. Therefore, it will require two replication connections not just one\&. As long as the client can keep up with the write\-ahead log data, using this method requires no extra write\-ahead logs to be saved on the source server\&.
324 .sp
325 When tar format is used, the write\-ahead log files will be written to a separate file named
326 pg_wal\&.tar
327 (if the server is a version earlier than 10, the file will be named
328 pg_xlog\&.tar)\&.
329 .sp
330 This value is the default\&.
331 .RE
332 .RE
333 .PP
334 \fB\-z\fR
335 .br
336 \fB\-\-gzip\fR
337 .RS 4
338 Enables gzip compression of tar file output, with the default compression level\&. Compression is only available when using the tar format, and the suffix
339 \&.gz
340 will automatically be added to all tar filenames\&.
341 .RE
342 .PP
343 \fB\-Z \fR\fB\fIlevel\fR\fR
344 .br
345 \fB\-Z [{client|server}\-]\fR\fB\fImethod\fR\fR\fB[:\fR\fB\fIdetail\fR\fR\fB]\fR
346 .br
347 \fB\-\-compress=\fR\fB\fIlevel\fR\fR
348 .br
349 \fB\-\-compress=[{client|server}\-]\fR\fB\fImethod\fR\fR\fB[:\fR\fB\fIdetail\fR\fR\fB]\fR
350 .RS 4
351 Requests compression of the backup\&. If
352 client
353 or
354 server
355 is included, it specifies where the compression is to be performed\&. Compressing on the server will reduce transfer bandwidth but will increase server CPU consumption\&. The default is
356 client
357 except when
358 \-\-target
359 is used\&. In that case, the backup is not being sent to the client, so only server compression is sensible\&. When
360 \-Xstream, which is the default, is used, server\-side compression will not be applied to the WAL\&. To compress the WAL, use client\-side compression, or specify
361 \-Xfetch\&.
362 .sp
363 The compression method can be set to
364 gzip,
365 lz4,
366 zstd,
367 none
368 for no compression or an integer (no compression if 0,
369 gzip
370 if greater than 0)\&. 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
371 \fIkeyword\fR
372 or
373 \fIkeyword=value\fR\&. Currently, the supported keywords are
374 level,
375 long, and
376 workers\&. The detail string cannot be used when the compression method is specified as a plain integer\&.
377 .sp
378 If no compression level is specified, the default compression level will be used\&. If only a level is specified without mentioning an algorithm,
379 gzip
380 compression will be used if the level is greater than 0, and no compression will be used if the level is 0\&.
381 .sp
382 When the tar format is used with
383 gzip,
384 lz4, or
385 zstd, the suffix
386 \&.gz,
387 \&.lz4, or
388 \&.zst, respectively, will be automatically added to all tar filenames\&. When the plain format is used, client\-side compression may not be specified, but it is still possible to request server\-side compression\&. If this is done, the server will compress the backup for transmission, and the client will decompress and extract it\&.
389 .sp
390 When this option is used in combination with
391 \-Xstream,
392 pg_wal\&.tar
393 will be compressed using
394 gzip
395 if client\-side gzip compression is selected, but will not be compressed if any other compression algorithm is selected, or if server\-side compression is selected\&.
396 .RE
397 .PP
398 The following command\-line options control the generation of the backup and the invocation of the program:
399 .PP
400 \fB\-c {fast|spread}\fR
401 .br
402 \fB\-\-checkpoint={fast|spread}\fR
403 .RS 4
404 Sets checkpoint mode to fast (immediate) or spread (the default) (see
405 Section\ \&25.3.4)\&.
406 .RE
407 .PP
408 \fB\-C\fR
409 .br
410 \fB\-\-create\-slot\fR
411 .RS 4
412 Specifies that the replication slot named by the
413 \-\-slot
414 option should be created before starting the backup\&. An error is raised if the slot already exists\&.
415 .RE
416 .PP
417 \fB\-l \fR\fB\fIlabel\fR\fR
418 .br
419 \fB\-\-label=\fR\fB\fIlabel\fR\fR
420 .RS 4
421 Sets the label for the backup\&. If none is specified, a default value of
422 \(lqpg_basebackup base backup\(rq
423 will be used\&.
424 .RE
425 .PP
426 \fB\-n\fR
427 .br
428 \fB\-\-no\-clean\fR
429 .RS 4
430 By default, when
431 \fBpg_basebackup\fR
432 aborts with an error, it removes any directories it might have created before discovering that it cannot finish the job (for example, the target directory and write\-ahead log directory)\&. This option inhibits tidying\-up and is thus useful for debugging\&.
433 .sp
434 Note that tablespace directories are not cleaned up either way\&.
435 .RE
436 .PP
437 \fB\-N\fR
438 .br
439 \fB\-\-no\-sync\fR
440 .RS 4
441 By default,
442 \fBpg_basebackup\fR
443 will wait for all files to be written safely to disk\&. This option causes
444 \fBpg_basebackup\fR
445 to return without waiting, which is faster, but means that a subsequent operating system crash can leave the base backup corrupt\&. Generally, this option is useful for testing but should not be used when creating a production installation\&.
446 .RE
447 .PP
448 \fB\-P\fR
449 .br
450 \fB\-\-progress\fR
451 .RS 4
452 Enables progress reporting\&. Turning this on will deliver an approximate progress report during the backup\&. Since the database may change during the backup, this is only an approximation and may not end at exactly
453 100%\&. In particular, when WAL log is included in the backup, the total amount of data cannot be estimated in advance, and in this case the estimated target size will increase once it passes the total estimate without WAL\&.
454 .RE
455 .PP
456 \fB\-r \fR\fB\fIrate\fR\fR
457 .br
458 \fB\-\-max\-rate=\fR\fB\fIrate\fR\fR
459 .RS 4
460 Sets the maximum transfer rate at which data is collected from the source server\&. This can be useful to limit the impact of
461 pg_basebackup
462 on the server\&. Values are in kilobytes per second\&. Use a suffix of
463 M
464 to indicate megabytes per second\&. A suffix of
465 k
466 is also accepted, and has no effect\&. Valid values are between 32 kilobytes per second and 1024 megabytes per second\&.
467 .sp
468 This option always affects transfer of the data directory\&. Transfer of WAL files is only affected if the collection method is
469 fetch\&.
470 .RE
471 .PP
472 \fB\-S \fR\fB\fIslotname\fR\fR
473 .br
474 \fB\-\-slot=\fR\fB\fIslotname\fR\fR
475 .RS 4
476 This option can only be used together with
477 \-X stream\&. It causes WAL streaming to use the specified replication slot\&. If the base backup is intended to be used as a streaming\-replication standby using a replication slot, the standby should then use the same replication slot name as
478 primary_slot_name\&. This ensures that the primary server does not remove any necessary WAL data in the time between the end of the base backup and the start of streaming replication on the new standby\&.
479 .sp
480 The specified replication slot has to exist unless the option
481 \fB\-C\fR
482 is also used\&.
483 .sp
484 If this option is not specified and the server supports temporary replication slots (version 10 and later), then a temporary replication slot is automatically used for WAL streaming\&.
485 .RE
486 .PP
487 \fB\-\-sync\-method=\fR\fB\fImethod\fR\fR
488 .RS 4
489 When set to
490 fsync, which is the default,
491 \fBpg_basebackup\fR
492 will recursively open and synchronize all files in the backup directory\&. When the plain format is used, the search for files will follow symbolic links for the WAL directory and each configured tablespace\&.
493 .sp
494 On Linux,
495 syncfs
496 may be used instead to ask the operating system to synchronize the whole file system that contains the backup directory\&. When the plain format is used,
497 \fBpg_basebackup\fR
498 will also synchronize the file systems that contain the WAL files and each tablespace\&. See
499 recovery_init_sync_method
500 for information about the caveats to be aware of when using
501 syncfs\&.
502 .sp
503 This option has no effect when
504 \fB\-\-no\-sync\fR
505 is used\&.
506 .RE
507 .PP
508 \fB\-v\fR
509 .br
510 \fB\-\-verbose\fR
511 .RS 4
512 Enables verbose mode\&. Will output some extra steps during startup and shutdown, as well as show the exact file name that is currently being processed if progress reporting is also enabled\&.
513 .RE
514 .PP
515 \fB\-\-manifest\-checksums=\fR\fB\fIalgorithm\fR\fR
516 .RS 4
517 Specifies the checksum algorithm that should be applied to each file included in the backup manifest\&. Currently, the available algorithms are
518 NONE,
519 CRC32C,
520 SHA224,
521 SHA256,
522 SHA384, and
523 SHA512\&. The default is
524 CRC32C\&.
525 .sp
526 If
527 NONE
528 is selected, the backup manifest will not contain any checksums\&. Otherwise, it will contain a checksum of each file in the backup using the specified algorithm\&. In addition, the manifest will always contain a
529 SHA256
530 checksum of its own contents\&. The
531 SHA
532 algorithms are significantly more CPU\-intensive than
533 CRC32C, so selecting one of them may increase the time required to complete the backup\&.
534 .sp
535 Using a SHA hash function provides a cryptographically secure digest of each file for users who wish to verify that the backup has not been tampered with, while the CRC\-32C algorithm provides a checksum that is much faster to calculate; it is good at catching errors due to accidental changes but is not resistant to malicious modifications\&. Note that, to be useful against an adversary who has access to the backup, the backup manifest would need to be stored securely elsewhere or otherwise verified not to have been modified since the backup was taken\&.
536 .sp
537 \fBpg_verifybackup\fR(1)
538 can be used to check the integrity of a backup against the backup manifest\&.
539 .RE
540 .PP
541 \fB\-\-manifest\-force\-encode\fR
542 .RS 4
543 Forces all filenames in the backup manifest to be hex\-encoded\&. If this option is not specified, only non\-UTF8 filenames are hex\-encoded\&. This option is mostly intended to test that tools which read a backup manifest file properly handle this case\&.
544 .RE
545 .PP
546 \fB\-\-no\-estimate\-size\fR
547 .RS 4
548 Prevents the server from estimating the total amount of backup data that will be streamed, resulting in the
549 backup_total
550 column in the
551 pg_stat_progress_basebackup
552 view always being
553 NULL\&.
554 .sp
555 Without this option, the backup will start by enumerating the size of the entire database, and then go back and send the actual contents\&. This may make the backup take slightly longer, and in particular it will take longer before the first data is sent\&. This option is useful to avoid such estimation time if it\*(Aqs too long\&.
556 .sp
557 This option is not allowed when using
558 \fB\-\-progress\fR\&.
559 .RE
560 .PP
561 \fB\-\-no\-manifest\fR
562 .RS 4
563 Disables generation of a backup manifest\&. If this option is not specified, the server will generate and send a backup manifest which can be verified using
564 \fBpg_verifybackup\fR(1)\&. The manifest is a list of every file present in the backup with the exception of any WAL files that may be included\&. It also stores the size, last modification time, and an optional checksum for each file\&.
565 .RE
566 .PP
567 \fB\-\-no\-slot\fR
568 .RS 4
569 Prevents the creation of a temporary replication slot for the backup\&.
570 .sp
571 By default, if log streaming is selected but no slot name is given with the
572 \fB\-S\fR
573 option, then a temporary replication slot is created (if supported by the source server)\&.
574 .sp
575 The main purpose of this option is to allow taking a base backup when the server has no free replication slots\&. Using a replication slot is almost always preferred, because it prevents needed WAL from being removed by the server during the backup\&.
576 .RE
577 .PP
578 \fB\-\-no\-verify\-checksums\fR
579 .RS 4
580 Disables verification of checksums, if they are enabled on the server the base backup is taken from\&.
581 .sp
582 By default, checksums are verified and checksum failures will result in a non\-zero exit status\&. However, the base backup will not be removed in such a case, as if the
583 \fB\-\-no\-clean\fR
584 option had been used\&. Checksum verification failures will also be reported in the
585 pg_stat_database
586 view\&.
587 .RE
588 .PP
589 The following command\-line options control the connection to the source server:
590 .PP
591 \fB\-d \fR\fB\fIconnstr\fR\fR
592 .br
593 \fB\-\-dbname=\fR\fB\fIconnstr\fR\fR
594 .RS 4
595 Specifies parameters used to connect to the server, as a
596 connection string; these will override any conflicting command line options\&.
597 .sp
598 This option is called
599 \-\-dbname
600 for consistency with other client applications, but because
601 pg_basebackup
602 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
603 ~/\&.pgpass\&. Similarly, middleware or proxies used in connecting to
604 PostgreSQL
605 might utilize the name for purposes such as connection routing\&. The database name can also be used by
606 logical replication slot synchronization\&.
607 .RE
608 .PP
609 \fB\-h \fR\fB\fIhost\fR\fR
610 .br
611 \fB\-\-host=\fR\fB\fIhost\fR\fR
612 .RS 4
613 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 a Unix domain socket\&. The default is taken from the
614 \fBPGHOST\fR
615 environment variable, if set, else a Unix domain socket connection is attempted\&.
616 .RE
617 .PP
618 \fB\-p \fR\fB\fIport\fR\fR
619 .br
620 \fB\-\-port=\fR\fB\fIport\fR\fR
621 .RS 4
622 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&. Defaults to the
623 \fBPGPORT\fR
624 environment variable, if set, or a compiled\-in default\&.
625 .RE
626 .PP
627 \fB\-s \fR\fB\fIinterval\fR\fR
628 .br
629 \fB\-\-status\-interval=\fR\fB\fIinterval\fR\fR
630 .RS 4
631 Specifies the number of seconds between status packets sent back to the source server\&. Smaller values allow more accurate monitoring of backup progress from the server\&. A value of zero disables periodic status updates completely, although an update will still be sent when requested by the server, to avoid timeout\-based disconnects\&. The default value is 10 seconds\&.
632 .RE
633 .PP
634 \fB\-U \fR\fB\fIusername\fR\fR
635 .br
636 \fB\-\-username=\fR\fB\fIusername\fR\fR
637 .RS 4
638 Specifies the user name to connect as\&.
639 .RE
640 .PP
641 \fB\-w\fR
642 .br
643 \fB\-\-no\-password\fR
644 .RS 4
645 Prevents issuing a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
646 \&.pgpass
647 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\&.
648 .RE
649 .PP
650 \fB\-W\fR
651 .br
652 \fB\-\-password\fR
653 .RS 4
654 Forces
655 pg_basebackup
656 to prompt for a password before connecting to the source server\&.
657 .sp
658 This option is never essential, since
659 pg_basebackup
660 will automatically prompt for a password if the server demands password authentication\&. However,
661 pg_basebackup
662 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
663 \fB\-W\fR
664 to avoid the extra connection attempt\&.
665 .RE
666 .PP
667 Other options are also available:
668 .PP
669 \fB\-V\fR
670 .br
671 \fB\-\-version\fR
672 .RS 4
673 Prints the
674 pg_basebackup
675 version and exits\&.
676 .RE
677 .PP
678 \fB\-?\fR
679 .br
680 \fB\-\-help\fR
681 .RS 4
682 Shows help about
683 pg_basebackup
684 command line arguments, and exits\&.
685 .RE
686 .SH "ENVIRONMENT"
687 .PP
688 This utility, like most other
689 PostgreSQL
690 utilities, uses the environment variables supported by
691 libpq
692 (see
693 Section\ \&32.15)\&.
694 .PP
695 The environment variable
696 \fBPG_COLOR\fR
697 specifies whether to use color in diagnostic messages\&. Possible values are
698 always,
699 auto
700 and
701 never\&.
702 .SH "NOTES"
703 .PP
704 At the beginning of the backup, a checkpoint needs to be performed on the source server\&. This can take some time (especially if the option
705 \-\-checkpoint=fast
706 is not used), during which
707 pg_basebackup
708 will appear to be idle\&.
709 .PP
710 The backup will include all files in the data directory and tablespaces, including the configuration files and any additional files placed in the directory by third parties, except certain temporary files managed by PostgreSQL and operating system files\&. But only regular files and directories are copied, except that symbolic links used for tablespaces are preserved\&. Symbolic links pointing to certain directories known to PostgreSQL are copied as empty directories\&. Other symbolic links and special device files are skipped\&. See
711 Section\ \&54.4
712 for the precise details\&.
713 .PP
714 In plain format, tablespaces will be backed up to the same path they have on the source server, unless the option
715 \-\-tablespace\-mapping
716 is used\&. Without this option, running a plain format base backup on the same host as the server will not work if tablespaces are in use, because the backup would have to be written to the same directory locations as the original tablespaces\&.
717 .PP
718 When tar format is used, it is the user\*(Aqs responsibility to unpack each tar file before starting a PostgreSQL server that uses the data\&. If there are additional tablespaces, the tar files for them need to be unpacked in the correct locations\&. In this case the symbolic links for those tablespaces will be created by the server according to the contents of the
719 tablespace_map
720 file that is included in the
721 base\&.tar
722 file\&.
723 .PP
724 pg_basebackup
725 works with servers of the same or older major version, down to 9\&.1\&. However, WAL streaming mode (\-X stream) only works with server version 9\&.3 and later, the tar format (\-\-format=tar) only works with server version 9\&.5 and later, and incremental backup (\-\-incremental) only works with server version 17 and later\&.
726 .PP
727 pg_basebackup
728 will preserve group permissions for data files if group permissions are enabled on the source cluster\&.
729 .SH "EXAMPLES"
730 .PP
731 To create a base backup of the server at
732 mydbserver
733 and store it in the local directory
734 /usr/local/pgsql/data:
735 .sp
736 .if n \{\
737 .RS 4
738 .\}
739 .nf
740 $ \fBpg_basebackup \-h mydbserver \-D /usr/local/pgsql/data\fR
741 .fi
742 .if n \{\
743 .RE
744 .\}
745 .PP
746 To create a backup of the local server with one compressed tar file for each tablespace, and store it in the directory
747 backup, showing a progress report while running:
748 .sp
749 .if n \{\
750 .RS 4
751 .\}
752 .nf
753 $ \fBpg_basebackup \-D backup \-Ft \-z \-P\fR
754 .fi
755 .if n \{\
756 .RE
757 .\}
758 .PP
759 To create a backup of a single\-tablespace local database and compress this with
760 bzip2:
761 .sp
762 .if n \{\
763 .RS 4
764 .\}
765 .nf
766 $ \fBpg_basebackup \-D \- \-Ft \-X fetch | bzip2 > backup\&.tar\&.bz2\fR
767 .fi
768 .if n \{\
769 .RE
770 .\}
771 .sp
772 (This command will fail if there are multiple tablespaces in the database\&.)
773 .PP
774 To create a backup of a local database where the tablespace in
775 /opt/ts
776 is relocated to
777 \&./backup/ts:
778 .sp
779 .if n \{\
780 .RS 4
781 .\}
782 .nf
783 $ \fBpg_basebackup \-D backup/data \-T /opt/ts=$(pwd)/backup/ts\fR
784 .fi
785 .if n \{\
786 .RE
787 .\}
788 .PP
789 To create a backup of the local server with one tar file for each tablespace compressed with
790 gzip
791 at level 9, stored in the directory
792 backup:
793 .sp
794 .if n \{\
795 .RS 4
796 .\}
797 .nf
798 $ \fBpg_basebackup \-D backup \-Ft \-\-compress=gzip:9\fR
799 .fi
800 .if n \{\
801 .RE
802 .\}
803 .SH "SEE ALSO"
804 \fBpg_dump\fR(1), Section\ \&27.4.6