From 7117685461af50f50c03f43e6a622284c8d54694 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Tue, 5 Apr 2016 20:03:49 +0200 Subject: 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 --- doc/src/sgml/func.sgml | 48 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 1bc9fbc4f51..c6017e61aee 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -17478,7 +17478,7 @@ SELECT set_config('log_statement_stats', 'off', false); - pg_start_backup(label text , fast boolean ) + pg_start_backup(label text , fast boolean , exclusive boolean ) pg_lsn Prepare for performing on-line backup (restricted to superusers or replication roles) @@ -17488,7 +17488,14 @@ SELECT set_config('log_statement_stats', 'off', false); pg_stop_backup() pg_lsn - Finish performing on-line backup (restricted to superusers or replication roles) + Finish performing exclusive on-line backup (restricted to superusers or replication roles) + + + + pg_stop_backup(exclusive boolean) + + setof record + Finish performing exclusive or non-exclusive on-line backup (restricted to superusers or replication roles) @@ -17537,15 +17544,19 @@ SELECT set_config('log_statement_stats', 'off', false); - 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 (backup_label) and, if there - are any links in the pg_tblspc/ directory, a tablespace map - file (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. + 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 (backup_label) and, if there are any links + in the pg_tblspc/ directory, a tablespace map file + (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 + pg_stop_backup function, and should be written to the backup + by the caller. + postgres=# select pg_start_backup('label_goes_here'); pg_start_backup @@ -17560,10 +17571,17 @@ postgres=# select pg_start_backup('label_goes_here'); - pg_stop_backup removes the label file and, if it exists, - the tablespace_map file created by - 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, pg_stop_backup removes the label file + and, if it exists, the tablespace_map file created by + pg_start_backup. In a non-exclusive backup, the contents of + the backup_label and 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). + + + + The function also creates a backup history file in the transaction log + archive area. The history file includes the label given to 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 -- cgit v1.2.3