2011-01-23 12:21:23 +01:00
|
|
|
<!--
|
|
|
|
doc/src/sgml/ref/pg_basebackup.sgml
|
|
|
|
PostgreSQL documentation
|
|
|
|
-->
|
|
|
|
|
|
|
|
<refentry id="app-pgbasebackup">
|
2014-02-24 03:25:35 +01:00
|
|
|
<indexterm zone="app-pgbasebackup">
|
|
|
|
<primary>pg_basebackup</primary>
|
|
|
|
</indexterm>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<refmeta>
|
2020-07-10 16:51:29 +02:00
|
|
|
<refentrytitle><application>pg_basebackup</application></refentrytitle>
|
2011-01-23 12:21:23 +01:00
|
|
|
<manvolnum>1</manvolnum>
|
|
|
|
<refmiscinfo>Application</refmiscinfo>
|
|
|
|
</refmeta>
|
|
|
|
|
|
|
|
<refnamediv>
|
|
|
|
<refname>pg_basebackup</refname>
|
|
|
|
<refpurpose>take a base backup of a <productname>PostgreSQL</productname> cluster</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
|
|
|
|
<refsynopsisdiv>
|
|
|
|
<cmdsynopsis>
|
|
|
|
<command>pg_basebackup</command>
|
2017-10-09 03:44:17 +02:00
|
|
|
<arg rep="repeat"><replaceable>option</replaceable></arg>
|
2011-01-23 12:21:23 +01:00
|
|
|
</cmdsynopsis>
|
|
|
|
</refsynopsisdiv>
|
|
|
|
|
|
|
|
<refsect1>
|
2020-06-07 13:10:18 +02:00
|
|
|
<title>Description</title>
|
2011-01-23 12:21:23 +01:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
<application>pg_basebackup</application> is used to take a base backup of
|
|
|
|
a running <productname>PostgreSQL</productname> database cluster. The backup
|
|
|
|
is taken without affecting other clients of the database, and can be used
|
2017-11-23 15:39:47 +01:00
|
|
|
both for point-in-time recovery (see <xref linkend="continuous-archiving"/>)
|
2020-08-15 21:43:34 +02:00
|
|
|
and as the starting point for a log-shipping or streaming-replication standby
|
|
|
|
server (see <xref linkend="warm-standby"/>).
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2023-12-20 15:49:12 +01:00
|
|
|
<application>pg_basebackup</application> 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's 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,
|
|
|
|
<xref linkend="app-pgcombinebackup"/> must first
|
|
|
|
be used to combine it with the previous backups upon which it depends.
|
|
|
|
See <xref linkend="backup-incremental-backup" /> for more information
|
|
|
|
about incremental backups, and <xref linkend="backup-pitr-recovery" />
|
|
|
|
for steps to recover from a backup.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
In any mode, <application>pg_basebackup</application> 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
|
2017-11-23 15:39:47 +01:00
|
|
|
<xref linkend="app-pgdump"/> must be used.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The backup is made over a regular <productname>PostgreSQL</productname>
|
2020-08-15 21:43:34 +02:00
|
|
|
connection that uses the replication protocol. The connection must be made
|
|
|
|
with a user ID that has <literal>REPLICATION</literal> permissions
|
|
|
|
(see <xref linkend="role-attributes"/>) or is a superuser,
|
|
|
|
and <link linkend="auth-pg-hba-conf"><filename>pg_hba.conf</filename></link>
|
|
|
|
must permit the replication connection. The server must also be configured
|
|
|
|
with <xref linkend="guc-max-wal-senders"/> set high enough to provide at
|
|
|
|
least one walsender for the backup plus one for WAL streaming (if used).
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
There can be multiple <command>pg_basebackup</command>s running at the same time, but it is usually
|
2011-01-31 17:13:01 +01:00
|
|
|
better from a performance point of view to take only one backup, and copy
|
2011-01-31 21:51:51 +01:00
|
|
|
the result.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
2012-01-25 19:02:04 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
<application>pg_basebackup</application> can make a base backup from
|
2020-08-15 21:43:34 +02:00
|
|
|
not only a primary server but also a standby. To take a backup from a standby,
|
2012-01-25 19:02:04 +01:00
|
|
|
set up the standby so that it can accept replication connections (that is, set
|
2017-11-23 15:39:47 +01:00
|
|
|
<varname>max_wal_senders</varname> and <xref linkend="guc-hot-standby"/>,
|
2020-08-15 21:43:34 +02:00
|
|
|
and configure its <filename>pg_hba.conf</filename> appropriately).
|
2020-06-15 19:12:58 +02:00
|
|
|
You will also need to enable <xref linkend="guc-full-page-writes"/> on the primary.
|
2012-01-25 19:02:04 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Note that there are some limitations in taking a backup from a standby:
|
2012-01-25 19:02:04 +01:00
|
|
|
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The backup history file is not created in the database cluster backed up.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2021-04-23 08:45:46 +02:00
|
|
|
<application>pg_basebackup</application> cannot force the standby
|
|
|
|
to switch to a new WAL file at the end of backup.
|
|
|
|
When you are using <literal>-X none</literal>, if write activity on
|
|
|
|
the primary is low, <application>pg_basebackup</application> 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
|
|
|
|
<function>pg_switch_wal</function> on the primary in order to
|
|
|
|
trigger an immediate WAL file switch.
|
2012-01-25 19:02:04 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
If the standby is promoted to be primary during backup, the backup fails.
|
2012-01-25 19:02:04 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
All WAL records required for the backup must contain sufficient full-page writes,
|
2022-08-19 03:00:12 +02:00
|
|
|
which requires you to enable <varname>full_page_writes</varname> on the primary.
|
2012-01-25 19:02:04 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
2020-03-03 04:03:43 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
Whenever <application>pg_basebackup</application> is taking a base
|
2020-08-15 21:43:34 +02:00
|
|
|
backup, the server's <structname>pg_stat_progress_basebackup</structname>
|
2020-03-03 04:03:43 +01:00
|
|
|
view will report the progress of the backup.
|
|
|
|
See <xref linkend="basebackup-progress-reporting"/> for details.
|
|
|
|
</para>
|
2011-01-23 12:21:23 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Options</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
The following command-line options control the location and format of the
|
2020-08-15 21:43:34 +02:00
|
|
|
output:
|
2011-01-23 12:21:23 +01:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>-D <replaceable class="parameter">directory</replaceable></option></term>
|
|
|
|
<term><option>--pgdata=<replaceable class="parameter">directory</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Sets the target directory to write the output to.
|
|
|
|
<application>pg_basebackup</application> will create this directory
|
|
|
|
(and any missing parent directories) if it does not exist. If it
|
|
|
|
already exists, it must be empty.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
When the backup is in tar format, the target directory may be
|
|
|
|
specified as <literal>-</literal> (dash), causing the tar file to be
|
|
|
|
written to <literal>stdout</literal>.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2012-05-20 00:15:55 +02:00
|
|
|
This option is required.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>-F <replaceable class="parameter">format</replaceable></option></term>
|
|
|
|
<term><option>--format=<replaceable class="parameter">format</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Selects the format for the output. <replaceable>format</replaceable>
|
|
|
|
can be one of the following:
|
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>p</literal></term>
|
|
|
|
<term><literal>plain</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Write the output as plain files, with the same layout as the
|
2020-08-15 21:43:34 +02:00
|
|
|
source server's data directory and tablespaces. When the cluster has
|
2011-01-23 12:21:23 +01:00
|
|
|
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
|
2020-08-15 21:43:34 +02:00
|
|
|
in the same absolute path as they have on the source server.
|
2021-03-17 21:10:37 +01:00
|
|
|
(See <option>--tablespace-mapping</option> to change that.)
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
This is the default format.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>t</literal></term>
|
|
|
|
<term><literal>tar</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Write the output as tar files in the target directory. The main
|
2020-08-15 21:43:34 +02:00
|
|
|
data directory's contents will be written to a file named
|
|
|
|
<filename>base.tar</filename>, and each other tablespace will be
|
|
|
|
written to a separate tar file named after that tablespace's OID.
|
|
|
|
</para>
|
2011-01-23 12:21:23 +01:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
If the target directory is specified as <literal>-</literal>
|
|
|
|
(dash), the tar contents will be written to
|
|
|
|
standard output, suitable for piping to (for example)
|
|
|
|
<productname>gzip</productname>. This is only allowed if
|
2017-05-12 17:49:56 +02:00
|
|
|
the cluster has no additional tablespaces and WAL
|
|
|
|
streaming is not used.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2011-08-07 09:49:45 +02:00
|
|
|
</variablelist></para>
|
2011-01-23 12:21:23 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2023-12-20 15:49:12 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-i <replaceable class="parameter">old_manifest_file</replaceable></option></term>
|
2023-12-21 21:36:17 +01:00
|
|
|
<term><option>--incremental=<replaceable class="parameter">old_manifest_file</replaceable></option></term>
|
2023-12-20 15:49:12 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Performs an <link linkend="backup-incremental-backup">incremental
|
|
|
|
backup</link>. 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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2013-01-05 16:54:06 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-R</option></term>
|
|
|
|
<term><option>--write-recovery-conf</option></term>
|
|
|
|
<listitem>
|
|
|
|
|
|
|
|
<para>
|
2021-03-31 22:23:25 +02:00
|
|
|
Creates a
|
|
|
|
<link linkend="file-standby-signal"><filename>standby.signal</filename></link>
|
|
|
|
<indexterm><primary><filename>standby.signal</filename></primary><secondary>pg_basebackup --write-recovery-conf</secondary></indexterm>
|
|
|
|
file and appends
|
2020-08-15 21:43:34 +02:00
|
|
|
connection settings to the <filename>postgresql.auto.conf</filename>
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
<para>
|
2018-11-25 16:31:16 +01:00
|
|
|
The <filename>postgresql.auto.conf</filename> file will record the connection
|
2015-07-22 03:06:45 +02:00
|
|
|
settings and, if specified, the replication slot
|
2020-08-15 21:43:34 +02:00
|
|
|
that <application>pg_basebackup</application> is using, so that
|
2024-03-21 06:18:59 +01:00
|
|
|
streaming replication and <link linkend="logicaldecoding-replication-slots-synchronization">
|
|
|
|
logical replication slot synchronization</link> will use the same
|
|
|
|
settings later on. The dbname will be recorded only if the dbname was
|
|
|
|
specified explicitly in the connection string or <link linkend="libpq-envars">
|
|
|
|
environment variable</link>.
|
2013-01-05 16:54:06 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
Support base backup targets.
pg_basebackup now has a --target=TARGET[:DETAIL] option. If specfied,
it is sent to the server as the value of the TARGET option to the
BASE_BACKUP command. If DETAIL is included, it is sent as the value of
the new TARGET_DETAIL option to the BASE_BACKUP command. If the
target is anything other than 'client', pg_basebackup assumes that it
will now be the server's job to write the backup in a location somehow
defined by the target, and that it therefore needs to write nothing
locally. However, the server will still send messages to the client
for progress reporting purposes.
On the server side, we now support two additional types of backup
targets. There is a 'blackhole' target, which just throws away the
backup data without doing anything at all with it. Naturally, this
should only be used for testing and debugging purposes, since you will
not actually have a backup when it finishes running. More usefully,
there is also a 'server' target, so you can now use something like
'pg_basebackup -Xnone -t server:/SOME/PATH' to write a backup to some
location on the server. We can extend this to more types of targets
in the future, and might even want to create an extensibility
mechanism for adding new target types.
Since WAL fetching is handled with separate client-side logic, it's
not part of this mechanism; thus, backups with non-default targets
must use -Xnone or -Xfetch.
Patch by me, with a bug fix by Jeevan Ladhe. The patch set of which
this is a part has also had review and/or testing from Tushar Ahuja,
Suraj Kharage, Dipesh Pandit, and Mark Dilger.
Discussion: http://postgr.es/m/CA+TgmoaYZbz0=Yk797aOJwkGJC-LK3iXn+wzzMx7KdwNpZhS5g@mail.gmail.com
2021-11-16 21:20:50 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-t <replaceable class="parameter">target</replaceable></option></term>
|
|
|
|
<term><option>--target=<replaceable class="parameter">target</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Instructs the server where to place the base backup. The default target
|
|
|
|
is <literal>client</literal>, which specifies that the backup should
|
|
|
|
be sent to the machine where <application>pg_basebackup</application>
|
|
|
|
is running. If the target is instead set to
|
|
|
|
<literal>server:/some/path</literal>, the backup will be stored on
|
|
|
|
the machine where the server is running in the
|
|
|
|
<literal>/some/path</literal> directory. Storing a backup on the
|
2022-04-02 19:24:38 +02:00
|
|
|
server requires superuser privileges or having privileges of the
|
2022-01-28 18:26:33 +01:00
|
|
|
<literal>pg_write_server_files</literal> role. If the target is set to
|
Support base backup targets.
pg_basebackup now has a --target=TARGET[:DETAIL] option. If specfied,
it is sent to the server as the value of the TARGET option to the
BASE_BACKUP command. If DETAIL is included, it is sent as the value of
the new TARGET_DETAIL option to the BASE_BACKUP command. If the
target is anything other than 'client', pg_basebackup assumes that it
will now be the server's job to write the backup in a location somehow
defined by the target, and that it therefore needs to write nothing
locally. However, the server will still send messages to the client
for progress reporting purposes.
On the server side, we now support two additional types of backup
targets. There is a 'blackhole' target, which just throws away the
backup data without doing anything at all with it. Naturally, this
should only be used for testing and debugging purposes, since you will
not actually have a backup when it finishes running. More usefully,
there is also a 'server' target, so you can now use something like
'pg_basebackup -Xnone -t server:/SOME/PATH' to write a backup to some
location on the server. We can extend this to more types of targets
in the future, and might even want to create an extensibility
mechanism for adding new target types.
Since WAL fetching is handled with separate client-side logic, it's
not part of this mechanism; thus, backups with non-default targets
must use -Xnone or -Xfetch.
Patch by me, with a bug fix by Jeevan Ladhe. The patch set of which
this is a part has also had review and/or testing from Tushar Ahuja,
Suraj Kharage, Dipesh Pandit, and Mark Dilger.
Discussion: http://postgr.es/m/CA+TgmoaYZbz0=Yk797aOJwkGJC-LK3iXn+wzzMx7KdwNpZhS5g@mail.gmail.com
2021-11-16 21:20:50 +01:00
|
|
|
<literal>blackhole</literal>, 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.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Since WAL streaming is implemented by
|
|
|
|
<application>pg_basebackup</application> rather than by the server,
|
|
|
|
this option cannot be used together with <literal>-Xstream</literal>.
|
|
|
|
Since that is the default, when this option is specified, you must also
|
|
|
|
specify either <literal>-Xfetch</literal> or <literal>-Xnone</literal>.
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2014-02-22 19:38:06 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-T <replaceable class="parameter">olddir</replaceable>=<replaceable class="parameter">newdir</replaceable></option></term>
|
|
|
|
<term><option>--tablespace-mapping=<replaceable class="parameter">olddir</replaceable>=<replaceable class="parameter">newdir</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Relocates the tablespace in directory <replaceable>olddir</replaceable>
|
2014-02-22 19:38:06 +01:00
|
|
|
to <replaceable>newdir</replaceable> during the backup. To be
|
|
|
|
effective, <replaceable>olddir</replaceable> must exactly match the
|
2020-08-15 21:43:34 +02:00
|
|
|
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 <replaceable>olddir</replaceable> on the source server.)
|
|
|
|
Meanwhile <replaceable>newdir</replaceable> is a directory in the
|
|
|
|
receiving host's filesystem. As with the main target directory,
|
|
|
|
<replaceable>newdir</replaceable> need not exist already, but if
|
|
|
|
it does exist it must be empty.
|
2014-02-22 19:38:06 +01:00
|
|
|
Both <replaceable>olddir</replaceable>
|
2020-08-15 21:43:34 +02:00
|
|
|
and <replaceable>newdir</replaceable> must be absolute paths. If
|
|
|
|
either path needs to contain an equal sign (<literal>=</literal>),
|
|
|
|
precede that with a backslash. This option can be specified multiple
|
|
|
|
times for multiple tablespaces.
|
2014-02-22 19:38:06 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
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.
|
2021-03-17 21:10:37 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Currently, this option only works with plain output format; it is
|
|
|
|
ignored if tar format is selected.
|
|
|
|
</para>
|
2014-02-22 19:38:06 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2013-11-27 06:00:16 +01:00
|
|
|
<varlistentry>
|
2017-02-09 22:42:51 +01:00
|
|
|
<term><option>--waldir=<replaceable class="parameter">waldir</replaceable></option></term>
|
2013-11-27 06:00:16 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Sets the directory to write WAL (write-ahead log) files to.
|
|
|
|
By default WAL files will be placed in
|
|
|
|
the <filename>pg_wal</filename> subdirectory of the target
|
|
|
|
directory, but this option can be used to place them elsewhere.
|
2017-02-09 22:42:51 +01:00
|
|
|
<replaceable>waldir</replaceable> must be an absolute path.
|
2020-08-15 21:43:34 +02:00
|
|
|
As with the main target directory,
|
|
|
|
<replaceable>waldir</replaceable> 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.
|
2013-11-27 06:00:16 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-30 21:30:09 +01:00
|
|
|
<varlistentry>
|
2012-06-10 13:43:51 +02:00
|
|
|
<term><option>-X <replaceable class="parameter">method</replaceable></option></term>
|
2017-02-09 22:42:51 +01:00
|
|
|
<term><option>--wal-method=<replaceable class="parameter">method</replaceable></option></term>
|
2011-01-30 21:30:09 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Includes the required WAL (write-ahead log) files in the
|
2017-05-12 17:49:56 +02:00
|
|
|
backup. This will include all write-ahead logs generated during
|
2017-01-04 10:40:38 +01:00
|
|
|
the backup. Unless the method <literal>none</literal> is specified,
|
2020-08-15 21:43:34 +02:00
|
|
|
it is possible to start a postmaster in the target
|
2022-09-15 00:40:58 +02:00
|
|
|
directory without the need to consult the WAL archive, thus
|
2020-08-15 21:43:34 +02:00
|
|
|
making the output a completely standalone backup.
|
2011-01-30 21:30:09 +01:00
|
|
|
</para>
|
2011-10-26 20:13:33 +02:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
The following <replaceable>method</replaceable>s for collecting the
|
|
|
|
write-ahead logs are supported:
|
2011-10-26 20:13:33 +02:00
|
|
|
|
|
|
|
<variablelist>
|
2017-01-04 10:40:38 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>n</literal></term>
|
|
|
|
<term><literal>none</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Don't include write-ahead logs in the backup.
|
2017-01-04 10:40:38 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-10-26 20:13:33 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><literal>f</literal></term>
|
|
|
|
<term><literal>fetch</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-05-12 17:49:56 +02:00
|
|
|
The write-ahead log files are collected at the end of the backup.
|
2020-08-15 21:43:34 +02:00
|
|
|
Therefore, it is necessary for the source server's
|
2020-07-20 06:30:18 +02:00
|
|
|
<xref linkend="guc-wal-keep-size"/> parameter to be set high
|
2020-08-15 21:43:34 +02:00
|
|
|
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's time to transfer it, the backup will fail and be
|
|
|
|
unusable.
|
2011-10-26 20:13:33 +02:00
|
|
|
</para>
|
2016-10-23 15:16:31 +02:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
When tar format is used, the write-ahead log files will be
|
|
|
|
included in the <filename>base.tar</filename> file.
|
2016-10-23 15:16:31 +02:00
|
|
|
</para>
|
2011-10-26 20:13:33 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><literal>s</literal></term>
|
|
|
|
<term><literal>stream</literal></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
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.
|
2011-10-26 20:13:33 +02:00
|
|
|
</para>
|
2016-10-23 15:16:31 +02:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
When tar format is used, the write-ahead log files will be
|
2019-04-08 22:27:35 +02:00
|
|
|
written to a separate file named <filename>pg_wal.tar</filename>
|
2019-01-29 10:42:41 +01:00
|
|
|
(if the server is a version earlier than 10, the file will be named
|
|
|
|
<filename>pg_xlog.tar</filename>).
|
2016-10-23 15:16:31 +02:00
|
|
|
</para>
|
2017-01-04 10:40:38 +01:00
|
|
|
<para>
|
|
|
|
This value is the default.
|
|
|
|
</para>
|
2011-10-26 20:13:33 +02:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2020-06-07 14:54:28 +02:00
|
|
|
</variablelist></para>
|
2011-01-30 21:30:09 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-05-30 00:02:02 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-z</option></term>
|
|
|
|
<term><option>--gzip</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Enables gzip compression of tar file output, with the default
|
|
|
|
compression level. Compression is only available when using
|
2016-10-23 15:16:31 +02:00
|
|
|
the tar format, and the suffix <filename>.gz</filename> will
|
|
|
|
automatically be added to all tar filenames.
|
2011-05-30 00:02:02 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-Z <replaceable class="parameter">level</replaceable></option></term>
|
2022-03-23 14:19:14 +01:00
|
|
|
<term><option>-Z [{client|server}-]<replaceable class="parameter">method</replaceable>[:<replaceable>detail</replaceable>]</option></term>
|
2011-01-23 12:21:23 +01:00
|
|
|
<term><option>--compress=<replaceable class="parameter">level</replaceable></option></term>
|
2022-03-23 14:19:14 +01:00
|
|
|
<term><option>--compress=[{client|server}-]<replaceable class="parameter">method</replaceable>[:<replaceable>detail</replaceable>]</option></term>
|
2011-01-23 12:21:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
Server-side gzip compression.
pg_basebackup's --compression option now lets you write either
"client-gzip" or "server-gzip" instead of just "gzip" to specify
where the compression should be performed. If you write simply
"gzip" it's taken to mean "client-gzip" unless you also use
--target, in which case it is interpreted to mean "server-gzip",
because that's the only thing that makes any sense in that case.
To make this work, the BASE_BACKUP command now takes new
COMPRESSION and COMPRESSION_LEVEL options.
At present, pg_basebackup cannot decompress .gz files, so
server-side compression will cause a failure if (1) -Ft is not
used or (2) -R is used or (3) -D- is used without --no-manifest.
Along the way, I removed the information message added by commit
5c649fe153367cdab278738ee4aebbfd158e0546 which occurred if you
specified no compression level and told you that the default level
had been used instead. That seemed like more output than most
people would want.
Also along the way, this adds a check to the server for
unrecognized base backup options. This repairs a bug introduced
by commit 0ba281cb4bf9f5f65529dfa4c8282abb734dd454.
This commit also adds some new test cases for pg_verifybackup.
They take a server-side backup with and without compression, and
then extract the backup if we have the OS facilities available
to do so, and then run pg_verifybackup on the extracted
directory. That is a good test of the functionality added by
this commit and also improves test coverage for the backup target
patch (commit 3500ccc39b0dadd1068a03938e4b8ff562587ccc) and for
pg_verifybackup itself.
Patch by me, with a bug fix by Jeevan Ladhe. The patch set of which
this is a part has also had review and/or testing from Tushar Ahuja,
Suraj Kharage, Dipesh Pandit, and Mark Dilger.
Discussion: http://postgr.es/m/CA+Tgmoa-ST7fMLsVJduOB7Eub=2WjfpHS+QxHVEpUoinf4bOSg@mail.gmail.com
2022-01-24 21:13:18 +01:00
|
|
|
Requests compression of the backup. If <literal>client</literal> or
|
|
|
|
<literal>server</literal> 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 <literal>client</literal> except when
|
|
|
|
<literal>--target</literal> is used. In that case, the backup is not
|
|
|
|
being sent to the client, so only server compression is sensible.
|
|
|
|
When <literal>-Xstream</literal>, 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 <literal>-Xfetch</literal>.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
2022-01-21 03:08:43 +01:00
|
|
|
<para>
|
2022-03-07 21:08:45 +01:00
|
|
|
The compression method can be set to <literal>gzip</literal>,
|
Refactor code parsing compression option values (-Z/--compress)
This commit moves the code in charge of deparsing the method and detail
strings fed later to parse_compress_specification() to a common routine,
where the backward-compatible case of only an integer being found (N
= 0 => "none", N > 1 => gzip at level N) is handled.
Note that this has a side-effect for pg_basebackup, as we now attempt to
detect "server-" and "client-" before checking for the integer-only
pre-14 grammar, where values like server-N and client-N (without the
follow-up detail string) are now valid rather than failing because of an
unsupported method name. Past grammars are still handled the same way,
but these flavors are now authorized, and would now switch to consider N
= 0 as no compression and N > 1 as gzip with the compression level used
as N, with the caller still controlling if the compression method should
be done server-side, client-side or is unspecified. The documentation
of pg_basebackup is updated to reflect that.
This benefits other code paths that would like to rely on the same logic
as pg_basebackup and pg_receivewal with option values used for
compression specifications, one area discussed lately being pg_dump.
Author: Georgios Kokolatos, Michael Paquier
Discussion: https://postgr.es/m/O4mutIrCES8ZhlXJiMvzsivT7ztAMja2lkdL1LJx6O5f22I2W8PBIeLKz7mDLwxHoibcnRAYJXm1pH4tyUNC4a8eDzLn22a6Pb1S74Niexg=@pm.me
2022-11-30 01:34:32 +01:00
|
|
|
<literal>lz4</literal>, <literal>zstd</literal>,
|
|
|
|
<literal>none</literal> for no compression or an integer (no
|
|
|
|
compression if 0, <literal>gzip</literal> 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,
|
2023-10-27 23:23:09 +02:00
|
|
|
each of the form
|
|
|
|
<replaceable>keyword</replaceable> or
|
|
|
|
<replaceable>keyword=value</replaceable>.
|
2023-04-06 17:18:38 +02:00
|
|
|
Currently, the supported keywords are <literal>level</literal>,
|
|
|
|
<literal>long</literal>, and <literal>workers</literal>.
|
Refactor code parsing compression option values (-Z/--compress)
This commit moves the code in charge of deparsing the method and detail
strings fed later to parse_compress_specification() to a common routine,
where the backward-compatible case of only an integer being found (N
= 0 => "none", N > 1 => gzip at level N) is handled.
Note that this has a side-effect for pg_basebackup, as we now attempt to
detect "server-" and "client-" before checking for the integer-only
pre-14 grammar, where values like server-N and client-N (without the
follow-up detail string) are now valid rather than failing because of an
unsupported method name. Past grammars are still handled the same way,
but these flavors are now authorized, and would now switch to consider N
= 0 as no compression and N > 1 as gzip with the compression level used
as N, with the caller still controlling if the compression method should
be done server-side, client-side or is unspecified. The documentation
of pg_basebackup is updated to reflect that.
This benefits other code paths that would like to rely on the same logic
as pg_basebackup and pg_receivewal with option values used for
compression specifications, one area discussed lately being pg_dump.
Author: Georgios Kokolatos, Michael Paquier
Discussion: https://postgr.es/m/O4mutIrCES8ZhlXJiMvzsivT7ztAMja2lkdL1LJx6O5f22I2W8PBIeLKz7mDLwxHoibcnRAYJXm1pH4tyUNC4a8eDzLn22a6Pb1S74Niexg=@pm.me
2022-11-30 01:34:32 +01:00
|
|
|
The detail string cannot be used when the compression method
|
|
|
|
is specified as a plain integer.
|
2022-03-23 14:19:14 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If no compression level is specified, the default compression level
|
|
|
|
will be used. If only a level is specified without mentioning an
|
|
|
|
algorithm, <literal>gzip</literal> compression will be used if the
|
|
|
|
level is greater than 0, and no compression will be used if the level
|
|
|
|
is 0.
|
Server-side gzip compression.
pg_basebackup's --compression option now lets you write either
"client-gzip" or "server-gzip" instead of just "gzip" to specify
where the compression should be performed. If you write simply
"gzip" it's taken to mean "client-gzip" unless you also use
--target, in which case it is interpreted to mean "server-gzip",
because that's the only thing that makes any sense in that case.
To make this work, the BASE_BACKUP command now takes new
COMPRESSION and COMPRESSION_LEVEL options.
At present, pg_basebackup cannot decompress .gz files, so
server-side compression will cause a failure if (1) -Ft is not
used or (2) -R is used or (3) -D- is used without --no-manifest.
Along the way, I removed the information message added by commit
5c649fe153367cdab278738ee4aebbfd158e0546 which occurred if you
specified no compression level and told you that the default level
had been used instead. That seemed like more output than most
people would want.
Also along the way, this adds a check to the server for
unrecognized base backup options. This repairs a bug introduced
by commit 0ba281cb4bf9f5f65529dfa4c8282abb734dd454.
This commit also adds some new test cases for pg_verifybackup.
They take a server-side backup with and without compression, and
then extract the backup if we have the OS facilities available
to do so, and then run pg_verifybackup on the extracted
directory. That is a good test of the functionality added by
this commit and also improves test coverage for the backup target
patch (commit 3500ccc39b0dadd1068a03938e4b8ff562587ccc) and for
pg_verifybackup itself.
Patch by me, with a bug fix by Jeevan Ladhe. The patch set of which
this is a part has also had review and/or testing from Tushar Ahuja,
Suraj Kharage, Dipesh Pandit, and Mark Dilger.
Discussion: http://postgr.es/m/CA+Tgmoa-ST7fMLsVJduOB7Eub=2WjfpHS+QxHVEpUoinf4bOSg@mail.gmail.com
2022-01-24 21:13:18 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2022-03-07 21:08:45 +01:00
|
|
|
When the tar format is used with <literal>gzip</literal>,
|
|
|
|
<literal>lz4</literal>, or <literal>zstd</literal>, the suffix
|
|
|
|
<filename>.gz</filename>, <filename>.lz4</filename>, or
|
|
|
|
<filename>.zst</filename>, 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.
|
2022-01-21 03:08:43 +01:00
|
|
|
</para>
|
2022-02-11 15:41:42 +01:00
|
|
|
<para>
|
|
|
|
When this option is used in combination with
|
|
|
|
<literal>-Xstream</literal>, <literal>pg_wal.tar</literal> will
|
|
|
|
be compressed using <literal>gzip</literal> if client-side gzip
|
2022-03-07 21:08:45 +01:00
|
|
|
compression is selected, but will not be compressed if any other
|
|
|
|
compression algorithm is selected, or if server-side compression
|
|
|
|
is selected.
|
2022-02-11 15:41:42 +01:00
|
|
|
</para>
|
2011-01-23 12:21:23 +01:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The following command-line options control the generation of the
|
2020-09-21 18:43:42 +02:00
|
|
|
backup and the invocation of the program:
|
2011-01-23 12:21:23 +01:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2022-01-25 20:54:35 +01:00
|
|
|
<term><option>-c {fast|spread}</option></term>
|
|
|
|
<term><option>--checkpoint={fast|spread}</option></term>
|
2011-01-23 12:21:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Sets checkpoint mode to fast (immediate) or spread (the default)
|
|
|
|
(see <xref linkend="backup-lowlevel-base-backup"/>).
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-09-26 22:07:52 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-C</option></term>
|
|
|
|
<term><option>--create-slot</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Specifies that the replication slot named by the
|
|
|
|
<literal>--slot</literal> option should be created before starting
|
|
|
|
the backup. An error is raised if the slot already exists.
|
2017-09-26 22:07:52 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-l <replaceable class="parameter">label</replaceable></option></term>
|
|
|
|
<term><option>--label=<replaceable class="parameter">label</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the label for the backup. If none is specified, a default value of
|
2012-03-01 20:16:24 +01:00
|
|
|
<quote><literal>pg_basebackup base backup</literal></quote> will be used.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2016-09-12 18:00:00 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-n</option></term>
|
2016-10-19 18:00:00 +02:00
|
|
|
<term><option>--no-clean</option></term>
|
2016-09-12 18:00:00 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
By default, when <command>pg_basebackup</command> aborts with an
|
|
|
|
error, it removes any directories it might have created before
|
2020-08-15 21:43:34 +02:00
|
|
|
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.
|
2016-09-12 18:00:00 +02:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
Note that tablespace directories are not cleaned up either way.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-09-26 17:58:22 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-N</option></term>
|
|
|
|
<term><option>--no-sync</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
By default, <command>pg_basebackup</command> will wait for all files
|
|
|
|
to be written safely to disk. This option causes
|
|
|
|
<command>pg_basebackup</command> 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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-P</option></term>
|
|
|
|
<term><option>--progress</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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
|
2011-01-30 21:30:09 +01:00
|
|
|
<literal>100%</literal>. In particular, when WAL log is included in the
|
|
|
|
backup, the total amount of data cannot be estimated in advance, and
|
2011-08-17 11:01:06 +02:00
|
|
|
in this case the estimated target size will increase once it passes the
|
|
|
|
total estimate without WAL.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2020-08-15 21:43:34 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-r <replaceable class="parameter">rate</replaceable></option></term>
|
|
|
|
<term><option>--max-rate=<replaceable class="parameter">rate</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Sets the maximum transfer rate at which data is collected from the
|
|
|
|
source server. This can be useful to limit the impact
|
|
|
|
of <application>pg_basebackup</application> on the server. Values
|
|
|
|
are in kilobytes per second. Use a suffix of <literal>M</literal>
|
|
|
|
to indicate megabytes per second. A suffix of <literal>k</literal>
|
|
|
|
is also accepted, and has no effect. Valid values are between 32
|
|
|
|
kilobytes per second and 1024 megabytes per second.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
This option always affects transfer of the data directory. Transfer of
|
|
|
|
WAL files is only affected if the collection method
|
|
|
|
is <literal>fetch</literal>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2016-09-29 18:00:00 +02:00
|
|
|
<varlistentry>
|
2017-09-26 17:58:22 +02:00
|
|
|
<term><option>-S <replaceable>slotname</replaceable></option></term>
|
|
|
|
<term><option>--slot=<replaceable class="parameter">slotname</replaceable></option></term>
|
2016-09-29 18:00:00 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2017-09-26 17:58:22 +02:00
|
|
|
This option can only be used together with <literal>-X
|
2020-08-15 21:43:34 +02:00
|
|
|
stream</literal>. It causes WAL streaming to use the specified
|
2017-09-26 17:58:22 +02:00
|
|
|
replication slot. If the base backup is intended to be used as a
|
2020-08-15 21:43:34 +02:00
|
|
|
streaming-replication standby using a replication slot, the standby
|
|
|
|
should then use the same replication slot name as
|
|
|
|
<xref linkend="guc-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.
|
2017-09-26 17:58:22 +02:00
|
|
|
</para>
|
2017-09-26 22:07:52 +02:00
|
|
|
<para>
|
|
|
|
The specified replication slot has to exist unless the
|
|
|
|
option <option>-C</option> is also used.
|
|
|
|
</para>
|
2017-09-26 17:58:22 +02:00
|
|
|
<para>
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
Allow using syncfs() in frontend utilities.
This commit allows specifying a --sync-method in several frontend
utilities that must synchronize many files to disk (initdb,
pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade).
On Linux, users can specify "syncfs" to synchronize the relevant
file systems instead of calling fsync() for every single file. In
many cases, using syncfs() is much faster.
As with recovery_init_sync_method, this new option comes with some
caveats. The descriptions of these caveats have been moved to a
new appendix section in the documentation.
Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier, Thomas Munro, Robert Haas, Justin Pryzby
Discussion: https://postgr.es/m/20210930004340.GM831%40telsasoft.com
2023-09-07 01:27:16 +02:00
|
|
|
<varlistentry>
|
2023-10-04 21:40:50 +02:00
|
|
|
<term><option>--sync-method=<replaceable class="parameter">method</replaceable></option></term>
|
Allow using syncfs() in frontend utilities.
This commit allows specifying a --sync-method in several frontend
utilities that must synchronize many files to disk (initdb,
pg_basebackup, pg_checksums, pg_dump, pg_rewind, and pg_upgrade).
On Linux, users can specify "syncfs" to synchronize the relevant
file systems instead of calling fsync() for every single file. In
many cases, using syncfs() is much faster.
As with recovery_init_sync_method, this new option comes with some
caveats. The descriptions of these caveats have been moved to a
new appendix section in the documentation.
Co-authored-by: Justin Pryzby
Reviewed-by: Michael Paquier, Thomas Munro, Robert Haas, Justin Pryzby
Discussion: https://postgr.es/m/20210930004340.GM831%40telsasoft.com
2023-09-07 01:27:16 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
When set to <literal>fsync</literal>, which is the default,
|
|
|
|
<command>pg_basebackup</command> 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.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
On Linux, <literal>syncfs</literal> 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,
|
|
|
|
<command>pg_basebackup</command> will also synchronize the file systems
|
|
|
|
that contain the WAL files and each tablespace. See
|
|
|
|
<xref linkend="syncfs"/> for more information about using
|
|
|
|
<function>syncfs()</function>.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
This option has no effect when <option>--no-sync</option> is used.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2018-05-21 16:01:49 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-v</option></term>
|
|
|
|
<term><option>--verbose</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2017-09-26 17:58:22 +02:00
|
|
|
<varlistentry>
|
2020-06-07 14:07:33 +02:00
|
|
|
<term><option>--manifest-checksums=<replaceable class="parameter">algorithm</replaceable></option></term>
|
2017-09-26 17:58:22 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-06-07 14:07:33 +02:00
|
|
|
Specifies the checksum algorithm that should be applied to each file
|
|
|
|
included in the backup manifest. Currently, the available
|
|
|
|
algorithms are <literal>NONE</literal>, <literal>CRC32C</literal>,
|
|
|
|
<literal>SHA224</literal>, <literal>SHA256</literal>,
|
|
|
|
<literal>SHA384</literal>, and <literal>SHA512</literal>.
|
|
|
|
The default is <literal>CRC32C</literal>.
|
2017-09-26 17:58:22 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2020-06-07 14:07:33 +02:00
|
|
|
If <literal>NONE</literal> 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 <literal>SHA256</literal>
|
|
|
|
checksum of its own contents. The <literal>SHA</literal> algorithms
|
|
|
|
are significantly more CPU-intensive than <literal>CRC32C</literal>,
|
|
|
|
so selecting one of them may increase the time required to complete
|
|
|
|
the backup.
|
2017-09-26 17:58:22 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2020-06-07 14:07:33 +02:00
|
|
|
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
|
2020-08-15 21:43:34 +02:00
|
|
|
tampered with, while the CRC32C algorithm provides a checksum that is
|
|
|
|
much faster to calculate; it is good at catching errors due to accidental
|
2020-09-21 18:43:42 +02:00
|
|
|
changes but is not resistant to malicious modifications. Note that, to
|
2020-06-07 14:07:33 +02:00
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
<xref linkend="app-pgverifybackup"/> can be used to check the
|
2020-06-07 14:07:33 +02:00
|
|
|
integrity of a backup against the backup manifest.
|
2016-09-29 18:00:00 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2018-04-03 13:47:16 +02:00
|
|
|
<varlistentry>
|
2020-06-07 14:07:33 +02:00
|
|
|
<term><option>--manifest-force-encode</option></term>
|
2018-04-03 13:47:16 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-06-07 14:07:33 +02:00
|
|
|
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.
|
2018-04-03 13:47:16 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2020-03-19 09:09:00 +01:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>--no-estimate-size</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Prevents the server from estimating the total
|
2020-03-19 09:09:00 +01:00
|
|
|
amount of backup data that will be streamed, resulting in the
|
2020-08-15 21:43:34 +02:00
|
|
|
<structfield>backup_total</structfield> column in the
|
|
|
|
<structname>pg_stat_progress_basebackup</structname> view
|
|
|
|
always being <literal>NULL</literal>.
|
2020-03-19 09:09:00 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
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's too long.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
This option is not allowed when using <option>--progress</option>.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>--no-manifest</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Disables generation of a backup manifest. If this option is not
|
|
|
|
specified, the server will generate and send a backup manifest
|
2020-08-15 21:43:34 +02:00
|
|
|
which can be verified using <xref linkend="app-pgverifybackup"/>.
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2020-06-07 14:07:33 +02:00
|
|
|
<term><option>--no-slot</option></term>
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Prevents the creation of a temporary replication slot
|
|
|
|
for the backup.
|
2020-06-07 14:07:33 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
By default, if log streaming is selected but no slot name is given
|
|
|
|
with the <option>-S</option> option, then a temporary replication
|
|
|
|
slot is created (if supported by the source server).
|
2020-06-07 14:07:33 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
The main purpose of this option is to allow taking a base backup when
|
2020-08-15 21:43:34 +02:00
|
|
|
the server has no free replication slots. Using a replication slot
|
2020-06-07 14:07:33 +02:00
|
|
|
is almost always preferred, because it prevents needed WAL from being
|
|
|
|
removed by the server during the backup.
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2020-06-07 14:07:33 +02:00
|
|
|
<term><option>--no-verify-checksums</option></term>
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-06-07 14:07:33 +02:00
|
|
|
Disables verification of checksums, if they are enabled on the server
|
|
|
|
the base backup is taken from.
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
</para>
|
|
|
|
<para>
|
2020-06-07 14:07:33 +02:00
|
|
|
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 <option>--no-clean</option> option
|
2020-08-15 21:43:34 +02:00
|
|
|
had been used. Checksum verification failures will also be reported
|
2020-06-07 14:07:33 +02:00
|
|
|
in the <link linkend="monitoring-pg-stat-database-view">
|
|
|
|
<structname>pg_stat_database</structname></link> view.
|
Generate backup manifests for base backups, and validate them.
A manifest is a JSON document which includes (1) the file name, size,
last modification time, and an optional checksum for each file backed
up, (2) timelines and LSNs for whatever WAL will need to be replayed
to make the backup consistent, and (3) a checksum for the manifest
itself. By default, we use CRC-32C when checksumming data files,
because we are trying to detect corruption and user error, not foil an
adversary. However, pg_basebackup and the server-side BASE_BACKUP
command now have options to select a different algorithm, so users
wanting a cryptographic hash function can select SHA-224, SHA-256,
SHA-384, or SHA-512. Users not wanting file checksums at all can
disable them, or disable generating of the backup manifest altogether.
Using a cryptographic hash function in place of CRC-32C consumes
significantly more CPU cycles, which may slow down backups in some
cases.
A new tool called pg_validatebackup can validate a backup against the
manifest. If no checksums are present, it can still check that the
right files exist and that they have the expected sizes. If checksums
are present, it can also verify that each file has the expected
checksum. Additionally, it calls pg_waldump to verify that the
expected WAL files are present and parseable. Only plain format
backups can be validated directly, but tar format backups can be
validated after extracting them.
Robert Haas, with help, ideas, review, and testing from David Steele,
Stephen Frost, Andrew Dunstan, Rushabh Lathia, Suraj Kharage, Tushar
Ahuja, Rajkumar Raghuwanshi, Mark Dilger, Davinder Singh, Jeevan
Chalke, Amit Kapila, Andres Freund, and Noah Misch.
Discussion: http://postgr.es/m/CA+TgmoZV8dw1H2bzZ9xkKwdrk8+XYa+DC9H=F7heO2zna5T6qg@mail.gmail.com
2020-04-03 20:59:47 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
2011-01-23 12:21:23 +01:00
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
The following command-line options control the connection to the source
|
|
|
|
server:
|
2011-01-23 12:21:23 +01:00
|
|
|
|
|
|
|
<variablelist>
|
2013-02-25 13:48:27 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-d <replaceable class="parameter">connstr</replaceable></option></term>
|
|
|
|
<term><option>--dbname=<replaceable class="parameter">connstr</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-10-03 04:19:31 +02:00
|
|
|
Specifies parameters used to connect to the server, as a <link
|
2020-11-11 01:18:35 +01:00
|
|
|
linkend="libpq-connstring">connection string</link>; these
|
2020-10-03 04:19:31 +02:00
|
|
|
will override any conflicting command line options.
|
2013-02-25 13:48:27 +01:00
|
|
|
</para>
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
The option is called <literal>--dbname</literal> for consistency with other
|
2013-02-25 13:48:27 +01:00
|
|
|
client applications, but because <application>pg_basebackup</application>
|
2020-08-15 21:43:34 +02:00
|
|
|
doesn't connect to any particular database in the cluster, any database
|
2023-09-21 13:53:07 +02:00
|
|
|
name in the connection string will be ignored
|
|
|
|
by <productname>PostgreSQL</productname>. Middleware, or proxies, used in
|
|
|
|
connecting to <productname>PostgreSQL</productname> might however
|
2024-03-21 06:18:59 +01:00
|
|
|
utilize the value. The database name specified in connection string can
|
|
|
|
also be used by <link linkend="logicaldecoding-replication-slots-synchronization">
|
|
|
|
logical replication slot synchronization</link>.
|
2013-02-25 13:48:27 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-h <replaceable class="parameter">host</replaceable></option></term>
|
|
|
|
<term><option>--host=<replaceable class="parameter">host</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
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
|
2020-08-15 21:43:34 +02:00
|
|
|
directory for a Unix domain socket. The default is taken
|
2011-01-23 12:21:23 +01:00
|
|
|
from the <envar>PGHOST</envar> environment variable, if set,
|
|
|
|
else a Unix domain socket connection is attempted.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>-p <replaceable class="parameter">port</replaceable></option></term>
|
|
|
|
<term><option>--port=<replaceable class="parameter">port</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Specifies the TCP port or local Unix domain socket file
|
|
|
|
extension on which the server is listening for connections.
|
|
|
|
Defaults to the <envar>PGPORT</envar> environment variable, if
|
|
|
|
set, or a compiled-in default.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2012-08-24 06:06:59 +02:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-s <replaceable class="parameter">interval</replaceable></option></term>
|
|
|
|
<term><option>--status-interval=<replaceable class="parameter">interval</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
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,
|
2012-11-08 09:25:58 +01:00
|
|
|
although an update will still be sent when requested by the server, to
|
2020-08-15 21:43:34 +02:00
|
|
|
avoid timeout-based disconnects. The default value is 10 seconds.
|
2012-08-24 06:06:59 +02:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<varlistentry>
|
|
|
|
<term><option>-U <replaceable>username</replaceable></option></term>
|
|
|
|
<term><option>--username=<replaceable class="parameter">username</replaceable></option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Specifies the user name to connect as.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-w</option></term>
|
|
|
|
<term><option>--no-password</option></term>
|
2011-01-23 12:21:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Prevents issuing a password prompt. If the server requires
|
2011-01-23 12:21:23 +01:00
|
|
|
password authentication and a password is not available by
|
|
|
|
other means such as a <filename>.pgpass</filename> 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.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
|
|
|
<term><option>-W</option></term>
|
|
|
|
<term><option>--password</option></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Forces <application>pg_basebackup</application> to prompt for a
|
|
|
|
password before connecting to the source server.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
This option is never essential, since
|
2011-10-25 22:46:14 +02:00
|
|
|
<application>pg_basebackup</application> will automatically prompt
|
2011-01-23 12:21:23 +01:00
|
|
|
for a password if the server demands password authentication.
|
|
|
|
However, <application>pg_basebackup</application> will waste a
|
|
|
|
connection attempt finding out that the server wants a password.
|
2017-10-09 03:44:17 +02:00
|
|
|
In some cases it is worth typing <option>-W</option> to avoid the extra
|
2011-01-23 12:21:23 +01:00
|
|
|
connection attempt.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2012-06-18 01:44:00 +02:00
|
|
|
Other options are also available:
|
2011-01-23 12:21:23 +01:00
|
|
|
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-V</option></term>
|
|
|
|
<term><option>--version</option></term>
|
2011-01-23 12:21:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Prints the <application>pg_basebackup</application> version and exits.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
<varlistentry>
|
2017-10-09 03:44:17 +02:00
|
|
|
<term><option>-?</option></term>
|
|
|
|
<term><option>--help</option></term>
|
2011-01-23 12:21:23 +01:00
|
|
|
<listitem>
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
Shows help about <application>pg_basebackup</application> command line
|
|
|
|
arguments, and exits.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Environment</title>
|
|
|
|
|
|
|
|
<para>
|
2017-10-09 03:44:17 +02:00
|
|
|
This utility, like most other <productname>PostgreSQL</productname> utilities,
|
|
|
|
uses the environment variables supported by <application>libpq</application>
|
2017-11-23 15:39:47 +01:00
|
|
|
(see <xref linkend="libpq-envars"/>).
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
<para>
|
|
|
|
The environment variable <envar>PG_COLOR</envar> specifies whether to use
|
2020-03-09 02:53:22 +01:00
|
|
|
color in diagnostic messages. Possible values are
|
|
|
|
<literal>always</literal>, <literal>auto</literal> and
|
Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.
Features:
- Program name is automatically prefixed.
- Message string does not end with newline. This removes a common
source of inconsistencies and omissions.
- Additionally, a final newline is automatically stripped, simplifying
use of PQerrorMessage() etc., another common source of mistakes.
- I converted error message strings to use %m where possible.
- As a result of the above several points, more translatable message
strings can be shared between different components and between
frontends and backend, without gratuitous punctuation or whitespace
differences.
- There is support for setting a "log level". This is not meant to be
user-facing, but can be used internally to implement debug or
verbose modes.
- Lazy argument evaluation, so no significant overhead if logging at
some level is disabled.
- Some color in the messages, similar to gcc and clang. Set
PG_COLOR=auto to try it out. Some colors are predefined, but can be
customized by setting PG_COLORS.
- Common files (common/, fe_utils/, etc.) can handle logging much more
simply by just using one API without worrying too much about the
context of the calling program, requiring callbacks, or having to
pass "progname" around everywhere.
- Some programs called setvbuf() to make sure that stderr is
unbuffered, even on Windows. But not all programs did that. This
is now done centrally.
Soft goals:
- Reduces vertical space use and visual complexity of error reporting
in the source code.
- Encourages more deliberate classification of messages. For example,
in some cases it wasn't clear without analyzing the surrounding code
whether a message was meant as an error or just an info.
- Concepts and terms are vaguely aligned with popular logging
frameworks such as log4j and Python logging.
This is all just about printing stuff out. Nothing affects program
flow (e.g., fatal exits). The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.
I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded. One significant change is that
pg_rewind used to write all error messages to stdout. That is now
changed to stderr.
Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 14:24:37 +02:00
|
|
|
<literal>never</literal>.
|
|
|
|
</para>
|
2011-01-23 12:21:23 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Notes</title>
|
|
|
|
|
2017-02-26 21:27:51 +01:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
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
|
|
|
|
<literal>--checkpoint=fast</literal> is not used), during
|
|
|
|
which <application>pg_basebackup</application> will appear to be idle.
|
2017-02-26 21:27:51 +01:00
|
|
|
</para>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
<para>
|
|
|
|
The backup will include all files in the data directory and tablespaces,
|
|
|
|
including the configuration files and any additional files placed in the
|
2016-09-28 18:00:00 +02:00
|
|
|
directory by third parties, except certain temporary files managed by
|
2024-02-13 13:47:12 +01:00
|
|
|
PostgreSQL and operating system files. But only regular files and
|
|
|
|
directories are copied, except that
|
2016-09-28 18:00:00 +02:00
|
|
|
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.
|
2017-11-23 15:39:47 +01:00
|
|
|
See <xref linkend="protocol-replication"/> for the precise details.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
In plain format, tablespaces will be backed up to the same path
|
|
|
|
they have on the source server, unless the
|
2015-09-11 03:22:21 +02:00
|
|
|
option <literal>--tablespace-mapping</literal> is used. Without
|
2014-02-22 19:38:06 +01:00
|
|
|
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.
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
Make pg_basebackup work with pre-9.3 servers, and add server version check.
A new 'starttli' field was added to the response of BASE_BACKUP command.
Make pg_basebackup tolerate the case that it's missing, so that it still
works with older servers.
Add an explicit check for the server version, so that you get a nicer error
message if you try to use it with a pre-9.1 server.
The streaming protocol message format changed in 9.3, so -X stream still won't
work with pre-9.3 servers. I added a version check to ReceiveXLogStream()
earlier, but write that slightly differently, so that in 9.4, it will still
work with a 9.3 server. (In 9.4, the error message needs to be adjusted to
"9.3 or above", though). Also, if the version check fails, don't retry.
2013-03-22 12:02:59 +01:00
|
|
|
|
2015-05-12 15:29:10 +02:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
When tar format is used, it is the user's responsibility to unpack each
|
|
|
|
tar file before starting a PostgreSQL server that uses the data. If there
|
|
|
|
are additional tablespaces, the
|
2015-05-12 15:29:10 +02:00
|
|
|
tar files for them need to be unpacked in the correct locations. In this
|
2015-09-11 03:22:21 +02:00
|
|
|
case the symbolic links for those tablespaces will be created by the server
|
2017-10-09 03:44:17 +02:00
|
|
|
according to the contents of the <filename>tablespace_map</filename> file that is
|
|
|
|
included in the <filename>base.tar</filename> file.
|
2015-05-12 15:29:10 +02:00
|
|
|
</para>
|
|
|
|
|
Make pg_basebackup work with pre-9.3 servers, and add server version check.
A new 'starttli' field was added to the response of BASE_BACKUP command.
Make pg_basebackup tolerate the case that it's missing, so that it still
works with older servers.
Add an explicit check for the server version, so that you get a nicer error
message if you try to use it with a pre-9.1 server.
The streaming protocol message format changed in 9.3, so -X stream still won't
work with pre-9.3 servers. I added a version check to ReceiveXLogStream()
earlier, but write that slightly differently, so that in 9.4, it will still
work with a 9.3 server. (In 9.4, the error message needs to be adjusted to
"9.3 or above", though). Also, if the version check fails, don't retry.
2013-03-22 12:02:59 +01:00
|
|
|
<para>
|
|
|
|
<application>pg_basebackup</application> works with servers of the same
|
2015-09-11 03:22:21 +02:00
|
|
|
or an older major version, down to 9.1. However, WAL streaming mode (<literal>-X
|
2020-08-15 21:43:34 +02:00
|
|
|
stream</literal>) only works with server version 9.3 and later, and tar format
|
|
|
|
(<literal>--format=tar</literal>) only works with server version 9.5
|
|
|
|
and later.
|
Make pg_basebackup work with pre-9.3 servers, and add server version check.
A new 'starttli' field was added to the response of BASE_BACKUP command.
Make pg_basebackup tolerate the case that it's missing, so that it still
works with older servers.
Add an explicit check for the server version, so that you get a nicer error
message if you try to use it with a pre-9.1 server.
The streaming protocol message format changed in 9.3, so -X stream still won't
work with pre-9.3 servers. I added a version check to ReceiveXLogStream()
earlier, but write that slightly differently, so that in 9.4, it will still
work with a 9.3 server. (In 9.4, the error message needs to be adjusted to
"9.3 or above", though). Also, if the version check fails, don't retry.
2013-03-22 12:02:59 +01:00
|
|
|
</para>
|
2015-05-12 15:29:10 +02:00
|
|
|
|
2018-04-07 23:45:39 +02:00
|
|
|
<para>
|
2020-08-15 21:43:34 +02:00
|
|
|
<application>pg_basebackup</application> will preserve group permissions
|
|
|
|
for data files if group permissions are enabled on the source cluster.
|
2018-04-07 23:45:39 +02:00
|
|
|
</para>
|
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>Examples</title>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To create a base backup of the server at <literal>mydbserver</literal>
|
|
|
|
and store it in the local directory
|
|
|
|
<filename>/usr/local/pgsql/data</filename>:
|
2011-05-02 18:19:48 +02:00
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>pg_basebackup -h mydbserver -D /usr/local/pgsql/data</userinput>
|
|
|
|
</screen>
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
2011-05-30 00:02:02 +02:00
|
|
|
To create a backup of the local server with one compressed
|
2011-01-23 12:21:23 +01:00
|
|
|
tar file for each tablespace, and store it in the directory
|
|
|
|
<filename>backup</filename>, showing a progress report while running:
|
2011-05-02 18:19:48 +02:00
|
|
|
<screen>
|
2011-05-30 00:02:02 +02:00
|
|
|
<prompt>$</prompt> <userinput>pg_basebackup -D backup -Ft -z -P</userinput>
|
2011-05-02 18:19:48 +02:00
|
|
|
</screen>
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
|
|
|
|
|
|
|
<para>
|
|
|
|
To create a backup of a single-tablespace local database and compress
|
|
|
|
this with <productname>bzip2</productname>:
|
2011-05-02 18:19:48 +02:00
|
|
|
<screen>
|
2017-01-04 10:40:38 +01:00
|
|
|
<prompt>$</prompt> <userinput>pg_basebackup -D - -Ft -X fetch | bzip2 > backup.tar.bz2</userinput>
|
2011-05-02 18:19:48 +02:00
|
|
|
</screen>
|
2011-05-10 21:37:50 +02:00
|
|
|
(This command will fail if there are multiple tablespaces in the
|
|
|
|
database.)
|
2011-01-23 12:21:23 +01:00
|
|
|
</para>
|
2014-02-22 19:38:06 +01:00
|
|
|
|
|
|
|
<para>
|
|
|
|
To create a backup of a local database where the tablespace in
|
|
|
|
<filename>/opt/ts</filename> is relocated
|
|
|
|
to <filename>./backup/ts</filename>:
|
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>pg_basebackup -D backup/data -T /opt/ts=$(pwd)/backup/ts</userinput>
|
2020-06-07 14:54:28 +02:00
|
|
|
</screen></para>
|
2022-01-21 03:08:43 +01:00
|
|
|
|
|
|
|
<para>
|
2023-10-27 23:23:09 +02:00
|
|
|
To create a backup of the local server with one tar file for each tablespace
|
2022-01-21 03:08:43 +01:00
|
|
|
compressed with <application>gzip</application> at level 9, stored in the
|
|
|
|
directory <filename>backup</filename>:
|
|
|
|
<screen>
|
|
|
|
<prompt>$</prompt> <userinput>pg_basebackup -D backup -Ft --compress=gzip:9</userinput>
|
2022-04-07 18:23:28 +02:00
|
|
|
</screen></para>
|
2022-01-21 03:08:43 +01:00
|
|
|
|
2011-01-23 12:21:23 +01:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1>
|
|
|
|
<title>See Also</title>
|
|
|
|
|
|
|
|
<simplelist type="inline">
|
2017-11-23 15:39:47 +01:00
|
|
|
<member><xref linkend="app-pgdump"/></member>
|
2021-03-05 06:58:16 +01:00
|
|
|
<member><xref linkend="basebackup-progress-reporting"/></member>
|
2011-01-23 12:21:23 +01:00
|
|
|
</simplelist>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
</refentry>
|