1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Support for non-exclusive backups in PostgreSQL 9.6.

This commit is contained in:
David Steele 2016-05-16 17:59:26 -04:00
parent 28c5e54b09
commit 0451d3afdd
9 changed files with 81 additions and 17 deletions

View File

@ -7,6 +7,8 @@ __No Release Date Set__
* Allow selective restore of databases from a cluster backup. This feature can result in major space and time savings when only specific databases are restored. Unrestored databases will not be accessible but must be manually dropped before they will be removed from the shared catalogue.
* Experimental support for non-exclusive backups in PostgreSQL 9.6 beta1. Changes to the control/catalog/WAL versions in subsequent betas may break compatibility but pgBackRest will be updated with each release to keep pace.
## v1.00: New Repository Format and Configuration Scheme, Link Support
__Released April 14, 2016__

View File

@ -14,6 +14,9 @@
<release-feature>
<text>Allow selective restore of databases from a cluster backup. This feature can result in major space and time savings when only specific databases are restored. Unrestored databases will not be accessible but must be manually dropped before they will be removed from the shared catalogue.</text>
</release-feature>
<release-feature>
<text>Experimental support for non-exclusive backups in <postgres/> 9.6 beta1. Changes to the control/catalog/WAL versions in subsequent betas may break compatibility but <backrest/> will be updated with each release to keep pace.</text>
</release-feature>
</release-feature-bullet-list>
</changelog-release>

View File

@ -57,6 +57,7 @@ my $oWalMagicHash =
hex('0xD075') => PG_VERSION_93,
hex('0xD07E') => PG_VERSION_94,
hex('0xD087') => PG_VERSION_95,
hex('0xD091') => PG_VERSION_96,
};
####################################################################################################################################

View File

@ -808,11 +808,40 @@ sub process
if (optionGet(OPTION_ONLINE))
{
($strArchiveStop) = $self->{oDb}->backupStop();
($strArchiveStop, my $strTimestampDbStop, my $oFileHash) = $self->{oDb}->backupStop();
$oBackupManifest->set(MANIFEST_SECTION_BACKUP, MANIFEST_KEY_ARCHIVE_STOP, undef, $strArchiveStop);
&log(INFO, 'archive stop: ' . $strArchiveStop);
# Write out files returned from stop backup
foreach my $strFile (sort(keys(%{$oFileHash})))
{
# Only save the file if it has content
if (defined($$oFileHash{$strFile}))
{
my $strFileName = $self->{oFile}->pathGet(PATH_BACKUP_TMP, $strFile);
# Write content out to a file
fileStringWrite($strFileName, $$oFileHash{$strFile});
# Compress if required
if ($bCompress)
{
$self->{oFile}->compress(PATH_BACKUP_ABSOLUTE, $strFileName);
$strFileName .= '.' . $self->{oFile}->{strCompressExtension};
}
# Add file to manifest
$oBackupManifest->fileAdd(
$strFile,
(fileStat($strFileName))->mtime,
length($$oFileHash{$strFile}),
$self->{oFile}->hash(PATH_BACKUP_ABSOLUTE, $strFileName, $bCompress));
&log(DETAIL, "wrote '${strFile}' file returned from pg_stop_backup()");
}
}
}
# If archive logs are required to complete the backup, then check them. This is the default, but can be overridden if the

View File

@ -68,6 +68,8 @@ use constant PG_VERSION_94 => '9.4';
push @EXPORT, qw(PG_VERSION_94);
use constant PG_VERSION_95 => '9.5';
push @EXPORT, qw(PG_VERSION_95);
use constant PG_VERSION_96 => '9.6';
push @EXPORT, qw(PG_VERSION_96);
####################################################################################################################################
# Map the control and catalog versions to PostgreSQL version.
@ -92,6 +94,7 @@ my $oPgControlVersionHash =
{
201409291 => PG_VERSION_94,
201510051 => PG_VERSION_95,
201605051 => PG_VERSION_96,
},
};
@ -171,7 +174,7 @@ sub versionSupport
);
my @strySupportVersion = (PG_VERSION_83, PG_VERSION_84, PG_VERSION_90, PG_VERSION_91, PG_VERSION_92, PG_VERSION_93,
PG_VERSION_94, PG_VERSION_95);
PG_VERSION_94, PG_VERSION_95, PG_VERSION_96);
# Return from function and log return values if any
return logDebugReturn
@ -668,8 +671,9 @@ sub backupStart
'HINT: is another backup already running on this cluster?', ERROR_LOCK_ACQUIRE);
}
# If stop-auto is enabled check for a running backup
if (optionGet(OPTION_STOP_AUTO))
# If stop-auto is enabled check for a running backup. This feature is not supported for PostgreSQL >= 9.6 since backups are
# run in non-exclusive mode.
if (optionGet(OPTION_STOP_AUTO) && $self->{strDbVersion} < PG_VERSION_96)
{
# Running backups can only be detected in PostgreSQL >= 9.3
if ($self->{strDbVersion} >= PG_VERSION_93)
@ -691,13 +695,16 @@ sub backupStart
}
# Start the backup
&log(INFO, "execute pg_start_backup() with label \"${strLabel}\": backup begins after " .
&log(INFO, 'execute ' . ($self->{strDbVersion} >= PG_VERSION_96 ? 'non-' : '') .
"exclusive pg_start_backup() with label \"${strLabel}\": backup begins after " .
($bStartFast ? "the requested immediate checkpoint" : "the next regular checkpoint") . " completes");
my ($strTimestampDbStart, $strArchiveStart) =
$self->executeSqlRow("select to_char(current_timestamp, 'YYYY-MM-DD HH24:MI:SS.US TZ'), " .
"pg_xlogfile_name(xlog) from pg_start_backup('${strLabel}'" .
($bStartFast ? ', true' : '') . ') as xlog');
"pg_xlogfile_name(lsn) from pg_start_backup('${strLabel}'" .
($bStartFast ? ', true' : '') .
($self->{strDbVersion} >= PG_VERSION_96 ? (!$bStartFast ? ', false' : '') . ', false' : '') .
') as lsn');
# Return from function and log return values if any
return logDebugReturn
@ -726,18 +733,30 @@ sub backupStop
);
# Stop the backup
&log(INFO, 'execute pg_stop_backup() and wait for all WAL segments to archive');
&log(INFO, 'execute ' . ($self->{strDbVersion} >= PG_VERSION_96 ? 'non-' : '') .
'exclusive pg_stop_backup() and wait for all WAL segments to archive');
my ($strTimestampDbStop, $strArchiveStop) =
$self->executeSqlRow("select to_char(clock_timestamp(), 'YYYY-MM-DD HH24:MI:SS.US TZ')," .
" pg_xlogfile_name(xlog) from pg_stop_backup() as xlog");
my ($strTimestampDbStop, $strArchiveStop, $strLabel, $strTablespaceMap) =
$self->executeSqlRow(
"select to_char(clock_timestamp(), 'YYYY-MM-DD HH24:MI:SS.US TZ'), pg_xlogfile_name(lsn), " .
($self->{strDbVersion} >= PG_VERSION_96 ? 'labelfile, spcmapfile' : "null as labelfile, null as spcmapfile") .
' from pg_stop_backup(' .
($self->{strDbVersion} >= PG_VERSION_96 ? 'false)' : ') as lsn'));
# Build a hash of the files that need to be written to the backup
my $oFileHash =
{
&MANIFEST_FILE_BACKUPLABEL => $strLabel,
&MANIFEST_FILE_TABLESPACEMAP => $strTablespaceMap
};
# Return from function and log return values if any
return logDebugReturn
(
$strOperation,
{name => 'strArchiveStop', value => $strArchiveStop},
{name => 'strTimestampDbStop', value => $strTimestampDbStop}
{name => 'strTimestampDbStop', value => $strTimestampDbStop},
{name => 'oFileHash', value => $oFileHash}
);
}

View File

@ -182,6 +182,8 @@ use constant DB_FILE_TABLESPACEMAP => 'tablespa
####################################################################################################################################
# Manifest locations for important files/paths
####################################################################################################################################
use constant MANIFEST_FILE_BACKUPLABEL => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_BACKUPLABEL;
push @EXPORT, qw(MANIFEST_FILE_BACKUPLABEL);
use constant MANIFEST_FILE_PGCONTROL => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_PGCONTROL;
push @EXPORT, qw(MANIFEST_FILE_PGCONTROL);
use constant MANIFEST_FILE_TABLESPACEMAP => MANIFEST_TARGET_PGDATA . '/' . DB_FILE_TABLESPACEMAP;

View File

@ -1854,8 +1854,9 @@ sub BackRestTestBackup_Test
BackRestTestBackup_PgExecute("update test set message = '$strDefaultMessage'", false);
BackRestTestBackup_PgSwitchXlog();
# Start a backup so the next backup has to restart it
if (BackRestTestCommon_DbVersion() >= PG_VERSION_93)
# Start a backup so the next backup has to restart it. This test is not required for PostgreSQL >= 9.6 since backups
# are run in non-exlusive mode.
if (BackRestTestCommon_DbVersion() >= PG_VERSION_93 && BackRestTestCommon_DbVersion() < PG_VERSION_96)
{
BackRestTestBackup_PgSelectOne("select pg_start_backup('test backup that will be cancelled', true)");
}

View File

@ -43,6 +43,7 @@ my $oyVm =
PG_VERSION_93,
PG_VERSION_94,
PG_VERSION_95,
PG_VERSION_96,
],
db_minimal =>
@ -60,12 +61,14 @@ my $oyVm =
PG_VERSION_93,
PG_VERSION_94,
PG_VERSION_95,
PG_VERSION_96,
],
db_minimal =>
[
PG_VERSION_93,
PG_VERSION_95,
PG_VERSION_96,
],
},
@ -82,6 +85,7 @@ my $oyVm =
PG_VERSION_93,
PG_VERSION_94,
PG_VERSION_95,
PG_VERSION_96,
],
db_minimal =>
@ -102,6 +106,7 @@ my $oyVm =
PG_VERSION_93,
PG_VERSION_94,
PG_VERSION_95,
PG_VERSION_96,
],
db_minimal =>

View File

@ -293,14 +293,16 @@ sub containerBuild
"RUN rpm -ivh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-1.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-2.noarch.rpm";
"RUN rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-2.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.6/redhat/rhel-6-x86_64/pgdg-centos96-9.6-1.noarch.rpm";
}
elsif ($strOS eq OS_CO7)
{
$strImage .=
"RUN rpm -ivh http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-1.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-1.noarch.rpm";
"RUN rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-1.noarch.rpm\n" .
"RUN rpm -ivh http://yum.postgresql.org/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-1.noarch.rpm";
}
elsif ($strOS eq OS_U12 || $strOS eq OS_U14)
{
@ -313,7 +315,7 @@ sub containerBuild
$strImage .=
"RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ " .
($strOS eq OS_U12 ? 'precise' : 'trusty') .
"-pgdg main' >> /etc/apt/sources.list.d/pgdg.list\n" .
"-pgdg main 9.6' >> /etc/apt/sources.list.d/pgdg.list\n" .
"RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -\n" .
"RUN apt-get update";
}