mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Implement backup API functions for non-exclusive backups
Previously non-exclusive backups had to be done using the replication protocol and pg_basebackup. With this commit it's now possible to make them using pg_start_backup/pg_stop_backup as well, as long as the backup program can maintain a persistent connection to the database. Doing this, backup_label and tablespace_map are returned as results from pg_stop_backup() instead of being written to the data directory. This makes the server safe from a crash during an ongoing backup, which can be a problem with exclusive backups. The old syntax of the functions remain and work exactly as before, but since the new syntax is safer this should eventually be deprecated and removed. Only reference documentation is included. The main section on backup still needs to be rewritten to cover this, but since that is already scheduled for a separate large rewrite, it's not included in this patch. Reviewed by David Steele and Amit Kapila
This commit is contained in:
@ -17478,7 +17478,7 @@ SELECT set_config('log_statement_stats', 'off', false);
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<literal><function>pg_start_backup(<parameter>label</> <type>text</> <optional>, <parameter>fast</> <type>boolean</> </optional>)</function></literal>
|
||||
<literal><function>pg_start_backup(<parameter>label</> <type>text</> <optional>, <parameter>fast</> <type>boolean</> <optional>, <parameter>exclusive</> <type>boolean</> </optional></optional>)</function></literal>
|
||||
</entry>
|
||||
<entry><type>pg_lsn</type></entry>
|
||||
<entry>Prepare for performing on-line backup (restricted to superusers or replication roles)</entry>
|
||||
@ -17488,7 +17488,14 @@ SELECT set_config('log_statement_stats', 'off', false);
|
||||
<literal><function>pg_stop_backup()</function></literal>
|
||||
</entry>
|
||||
<entry><type>pg_lsn</type></entry>
|
||||
<entry>Finish performing on-line backup (restricted to superusers or replication roles)</entry>
|
||||
<entry>Finish performing exclusive on-line backup (restricted to superusers or replication roles)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
<literal><function>pg_stop_backup(<parameter>exclusive</> <type>boolean</>)</function></literal>
|
||||
</entry>
|
||||
<entry><type>setof record</type></entry>
|
||||
<entry>Finish performing exclusive or non-exclusive on-line backup (restricted to superusers or replication roles)</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>
|
||||
@ -17537,15 +17544,19 @@ SELECT set_config('log_statement_stats', 'off', false);
|
||||
</table>
|
||||
|
||||
<para>
|
||||
<function>pg_start_backup</> accepts an
|
||||
arbitrary user-defined label for the backup. (Typically this would be
|
||||
the name under which the backup dump file will be stored.) The function
|
||||
writes a backup label file (<filename>backup_label</>) and, if there
|
||||
are any links in the <filename>pg_tblspc/</> directory, a tablespace map
|
||||
file (<filename>tablespace_map</>) into the database cluster's data
|
||||
directory, performs a checkpoint, and then returns the backup's starting
|
||||
transaction log location as text. The user can ignore this result value,
|
||||
but it is provided in case it is useful.
|
||||
<function>pg_start_backup</> accepts an arbitrary user-defined label for
|
||||
the backup. (Typically this would be the name under which the backup dump
|
||||
file will be stored.) When used in exclusive mode, the function writes a
|
||||
backup label file (<filename>backup_label</>) and, if there are any links
|
||||
in the <filename>pg_tblspc/</> directory, a tablespace map file
|
||||
(<filename>tablespace_map</>) into the database cluster's data directory,
|
||||
performs a checkpoint, and then returns the backup's starting transaction
|
||||
log location as text. The user can ignore this result value, but it is
|
||||
provided in case it is useful. When used in non-exclusive mode, the
|
||||
contents of these files are instead returned by the
|
||||
<function>pg_stop_backup</> function, and should be written to the backup
|
||||
by the caller.
|
||||
|
||||
<programlisting>
|
||||
postgres=# select pg_start_backup('label_goes_here');
|
||||
pg_start_backup
|
||||
@ -17560,10 +17571,17 @@ postgres=# select pg_start_backup('label_goes_here');
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<function>pg_stop_backup</> removes the label file and, if it exists,
|
||||
the <filename>tablespace_map</> file created by
|
||||
<function>pg_start_backup</>, and creates a backup history file in
|
||||
the transaction log archive area. The history file includes the label given to
|
||||
In an exclusive backup, <function>pg_stop_backup</> removes the label file
|
||||
and, if it exists, the <filename>tablespace_map</> file created by
|
||||
<function>pg_start_backup</>. In a non-exclusive backup, the contents of
|
||||
the <filename>backup_label</> and <filename>tablespace_map</> are returned
|
||||
in the result of the function, and should be written to files in the
|
||||
backup (and not in the data directory).
|
||||
</para>
|
||||
|
||||
<para>
|
||||
The function also creates a backup history file in the transaction log
|
||||
archive area. The history file includes the label given to
|
||||
<function>pg_start_backup</>, the starting and ending transaction log locations for
|
||||
the backup, and the starting and ending times of the backup. The return
|
||||
value is the backup's ending transaction log location (which again
|
||||
|
Reference in New Issue
Block a user