1PG_BASEBACKUP(1)        PostgreSQL 9.2.24 Documentation       PG_BASEBACKUP(1)
2
3
4

NAME

6       pg_basebackup - take a base backup of a PostgreSQL cluster
7

SYNOPSIS

9       pg_basebackup [option...]
10

DESCRIPTION

12       pg_basebackup is used to take base backups of a running PostgreSQL
13       database cluster. These are taken without affecting other clients to
14       the database, and can be used both for point-in-time recovery (see
15       Section 24.3, “Continuous Archiving and Point-in-Time Recovery (PITR)”,
16       in the documentation) and as the starting point for a log shipping or
17       streaming replication standby servers (see Section 25.2, “Log-Shipping
18       Standby Servers”, in the documentation).
19
20       pg_basebackup makes a binary copy of the database cluster files, while
21       making sure the system is put in and out of backup mode automatically.
22       Backups are always taken of the entire database cluster; it is not
23       possible to back up individual databases or database objects. For
24       individual database backups, a tool such as pg_dump(1) must be used.
25
26       The backup is made over a regular PostgreSQL connection, and uses the
27       replication protocol. The connection must be made with a superuser or a
28       user having REPLICATION permissions (see Section 20.2, “Role
29       Attributes”, in the documentation), and pg_hba.conf must explicitly
30       permit the replication connection. The server must also be configured
31       with max_wal_senders set high enough to leave at least one session
32       available for the backup.
33
34       There can be multiple pg_basebackups running at the same time, but it
35       is better from a performance point of view to take only one backup, and
36       copy the result.
37
38       pg_basebackup can make a base backup from not only the master but also
39       the standby. To take a backup from the standby, set up the standby so
40       that it can accept replication connections (that is, set
41       max_wal_senders and hot_standby, and configure host-based
42       authentication). You will also need to enable full_page_writes on the
43       master.
44
45       Note that there are some limitations in an online backup from the
46       standby:
47
48       ·   The backup history file is not created in the database cluster
49           backed up.
50
51       ·   There is no guarantee that all WAL files required for the backup
52           are archived at the end of backup. If you are planning to use the
53           backup for an archive recovery and want to ensure that all required
54           files are available at that moment, you need to include them into
55           the backup by using the -x option.
56
57       ·   If the standby is promoted to the master during online backup, the
58           backup fails.
59
60       ·   All WAL records required for the backup must contain sufficient
61           full-page writes, which requires you to enable full_page_writes on
62           the master and not to use a tool like pg_compresslog as
63           archive_command to remove full-page writes from WAL files.
64
65

OPTIONS

67       The following command-line options control the location and format of
68       the output.
69
70       -D directory, --pgdata=directory
71           Directory to write the output to.  pg_basebackup will create the
72           directory and any parent directories if necessary. The directory
73           may already exist, but it is an error if the directory already
74           exists and is not empty.
75
76           When the backup is in tar mode, and the directory is specified as -
77           (dash), the tar file will be written to stdout.
78
79           This option is required.
80
81       -F format, --format=format
82           Selects the format for the output.  format can be one of the
83           following:
84
85           p, plain
86               Write the output as plain files, with the same layout as the
87               current data directory and tablespaces. When the cluster has no
88               additional tablespaces, the whole database will be placed in
89               the target directory. If the cluster contains additional
90               tablespaces, the main data directory will be placed in the
91               target directory, but all other tablespaces will be placed in
92               the same absolute path as they have on the server.
93
94               This is the default format.
95
96           t, tar
97               Write the output as tar files in the target directory. The main
98               data directory will be written to a file named base.tar, and
99               all other tablespaces will be named after the tablespace OID.
100
101               If the value - (dash) is specified as target directory, the tar
102               contents will be written to standard output, suitable for
103               piping to for example gzip. This is only possible if the
104               cluster has no additional tablespaces.
105
106       -x, --xlog
107           Using this option is equivalent of using -X with method fetch.
108
109       -X method, --xlog-method=method
110           Includes the required transaction log files (WAL files) in the
111           backup. This will include all transaction logs generated during the
112           backup. If this option is specified, it is possible to start a
113           postmaster directly in the extracted directory without the need to
114           consult the log archive, thus making this a completely standalone
115           backup.
116
117           The following methods for collecting the transaction logs are
118           supported:
119
120           f, fetch
121               The transaction log files are collected at the end of the
122               backup. Therefore, it is necessary for the wal_keep_segments
123               parameter to be set high enough that the log is not removed
124               before the end of the backup. If the log has been rotated when
125               it's time to transfer it, the backup will fail and be unusable.
126
127           s, stream
128               Stream the transaction log while the backup is created. This
129               will open a second connection to the server and start streaming
130               the transaction log in parallel while running the backup.
131               Therefore, it will use up two slots configured by the
132               max_wal_senders parameter. As long as the client can keep up
133               with transaction log received, using this mode requires no
134               extra transaction logs to be saved on the master.
135
136
137       -z, --gzip
138           Enables gzip compression of tar file output, with the default
139           compression level. Compression is only available when using the tar
140           format.
141
142       -Z level, --compress=level
143           Enables gzip compression of tar file output, and specifies the
144           compression level (0 through 9, 0 being no compression and 9 being
145           best compression). Compression is only available when using the tar
146           format.
147
148       The following command-line options control the generation of the backup
149       and the running of the program.
150
151       -c fast|spread, --checkpoint=fast|spread
152           Sets checkpoint mode to fast or spread (default).
153
154       -l label, --label=label
155           Sets the label for the backup. If none is specified, a default
156           value of “pg_basebackup base backup” will be used.
157
158       -P, --progress
159           Enables progress reporting. Turning this on will deliver an
160           approximate progress report during the backup. Since the database
161           may change during the backup, this is only an approximation and may
162           not end at exactly 100%. In particular, when WAL log is included in
163           the backup, the total amount of data cannot be estimated in
164           advance, and in this case the estimated target size will increase
165           once it passes the total estimate without WAL.
166
167           When this is enabled, the backup will start by enumerating the size
168           of the entire database, and then go back and send the actual
169           contents. This may make the backup take slightly longer, and in
170           particular it will take longer before the first data is sent.
171
172       -v, --verbose
173           Enables verbose mode. Will output some extra steps during startup
174           and shutdown, as well as show the exact file name that is currently
175           being processed if progress reporting is also enabled.
176
177       The following command-line options control the database connection
178       parameters.
179
180       -h host, --host=host
181           Specifies the host name of the machine on which the server is
182           running. If the value begins with a slash, it is used as the
183           directory for the Unix domain socket. The default is taken from the
184           PGHOST environment variable, if set, else a Unix domain socket
185           connection is attempted.
186
187       -p port, --port=port
188           Specifies the TCP port or local Unix domain socket file extension
189           on which the server is listening for connections. Defaults to the
190           PGPORT environment variable, if set, or a compiled-in default.
191
192       -s interval, --status-interval=interval
193           Specifies the number of seconds between status packets sent back to
194           the server. This is required when streaming the transaction log
195           (using --xlog=stream) if replication timeout is configured on the
196           server, and allows for easier monitoring. A value of zero disables
197           the status updates completely. The default value is 10 seconds.
198
199       -U username, --username=username
200           User name to connect as.
201
202       -w, --no-password
203           Never issue a password prompt. If the server requires password
204           authentication and a password is not available by other means such
205           as a .pgpass file, the connection attempt will fail. This option
206           can be useful in batch jobs and scripts where no user is present to
207           enter a password.
208
209       -W, --password
210           Force pg_basebackup to prompt for a password before connecting to a
211           database.
212
213           This option is never essential, since pg_basebackup will
214           automatically prompt for a password if the server demands password
215           authentication. However, pg_basebackup will waste a connection
216           attempt finding out that the server wants a password. In some cases
217           it is worth typing -W to avoid the extra connection attempt.
218
219       Other options are also available:
220
221       -V, --version
222           Print the pg_basebackup version and exit.
223
224       -?, --help
225           Show help about pg_basebackup command line arguments, and exit.
226

ENVIRONMENT

228       This utility, like most other PostgreSQL utilities, uses the
229       environment variables supported by libpq (see Section 31.14,
230       “Environment Variables”, in the documentation).
231

NOTES

233       The backup will include all files in the data directory and
234       tablespaces, including the configuration files and any additional files
235       placed in the directory by third parties. Only regular files and
236       directories are allowed in the data directory, no symbolic links or
237       special device files.
238
239       The way PostgreSQL manages tablespaces, the path for all additional
240       tablespaces must be identical whenever a backup is restored. The main
241       data directory, however, is relocatable to any location.
242

EXAMPLES

244       To create a base backup of the server at mydbserver and store it in the
245       local directory /usr/local/pgsql/data:
246
247           $ pg_basebackup -h mydbserver -D /usr/local/pgsql/data
248
249       To create a backup of the local server with one compressed tar file for
250       each tablespace, and store it in the directory backup, showing a
251       progress report while running:
252
253           $ pg_basebackup -D backup -Ft -z -P
254
255       To create a backup of a single-tablespace local database and compress
256       this with bzip2:
257
258           $ pg_basebackup -D - -Ft | bzip2 > backup.tar.bz2
259
260       (This command will fail if there are multiple tablespaces in the
261       database.)
262

SEE ALSO

264       pg_dump(1)
265
266
267
268PostgreSQL 9.2.24                 2017-11-06                  PG_BASEBACKUP(1)
Impressum