diff --git a/doc/xml/reference.xml b/doc/xml/reference.xml index 4a10e64da..bfed3c2f5 100644 --- a/doc/xml/reference.xml +++ b/doc/xml/reference.xml @@ -719,7 +719,7 @@ Check the configuration. - The check command validates that and the archive_command setting are configured correctly for archiving and backups. It detects misconfigurations, particularly in archiving, that result in incomplete backups because required WAL segments did not reach the archive. The command can be run on the database or the backup host. + The check command validates that and the archive_command setting are configured correctly for archiving and backups. It detects misconfigurations, particularly in archiving, that result in incomplete backups because required WAL segments did not reach the archive. The command can be run on the database or the backup host. The command may also be run on the standby host, however, since pg_switch_xlog() cannot be performed on the standby, the command will only test the repository configuration. Note that pg_create_restore_point('pgBackRest Archive Check') and pg_switch_xlog() are called to force to archive a WAL segment. Restore points are only supported in >= 9.1 so for older versions the check command may fail if there has been no write activity since the last log rotation, therefore it is recommended that activity be generated by the user if there have been no writes since the last xlog switch before running the check command. diff --git a/doc/xml/release.xml b/doc/xml/release.xml index dbee4c7f9..7538e4e1a 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -159,6 +159,14 @@

Improved stanza-create command so that it can repair broken repositories in most cases and is robust enough to be made mandatory.

+ + + + + + +

Improved check command to run on a standby, though only basic checks are done because pg_switch_xlog() cannot be executed on a replica.

+
diff --git a/doc/xml/user-guide.xml b/doc/xml/user-guide.xml index ba0c40a41..994507e26 100644 --- a/doc/xml/user-guide.xml +++ b/doc/xml/user-guide.xml @@ -427,7 +427,7 @@ {[project-exe]} {[dash]}-stanza={[postgres-cluster-demo]} {[dash]}-log-level-console=info stanza-create - successfully created + completed successfully @@ -1617,12 +1617,13 @@

Replication allows multiple copies of a cluster (called standbys) to be created from a single master. The standbys are useful for balancing reads and to provide redundancy in case the master host fails.

+
Hot Standby

A hot standby performs replication using the WAL archive and allows read-only queries.

-

A new host named db-standby will be created to run the standby. Follow the instructions in Installation to install , Setup Demo Cluster to setup the demo cluster, and Create the Repository to create the repository on the db-standby host.

+

A new host named db-standby will be created to run the standby. Follow the instructions in Installation to install and Setup Demo Cluster to setup the demo cluster.

@@ -1659,17 +1660,6 @@ chown postgres:postgres /var/log/pgbackrest - - - mkdir {[backrest-repo-path]} - - - chmod 750 {[backrest-repo-path]} - - - chown postgres:postgres {[backrest-repo-path]} - - {[db-cluster-create]} @@ -1803,8 +1793,20 @@ {[test-table-data]} + +

Check the standby configuration for access to the repository.

+ + + Check the configuration + + + {[project-exe]} {[dash]}-stanza={[postgres-cluster-demo]} {[dash]}-log-level-console=info check + all other checks passed + +
+
Streaming Replication diff --git a/lib/pgBackRest/Archive.pm b/lib/pgBackRest/Archive.pm index 9c6ebb18e..b3a26e748 100644 --- a/lib/pgBackRest/Archive.pm +++ b/lib/pgBackRest/Archive.pm @@ -1110,9 +1110,6 @@ sub check # Validate the database configuration $oDb->configValidate(); - # Force archiving - my $strWalSegment = $oDb->xlogSwitch(); - # Get the timeout and error message to display - if it is 0 we are testing my $iArchiveTimeout = optionGet(OPTION_ARCHIVE_TIMEOUT); @@ -1125,6 +1122,7 @@ sub check my $strArchiveId = undef; my $strArchiveFile = undef; + my $strWalSegment = undef; # Turn off console logging to control when to display the error logLevelSet(undef, OFF); @@ -1167,9 +1165,11 @@ sub check }; } - # If able to get the archive id then check the archived WAL file with the time specified - if ($iResult == 0) + # If able to get the archive id then force archiving and check the arrival of the archived WAL file with the time specified + if ($iResult == 0 && !$oDb->isStandby()) { + $strWalSegment = $oDb->xlogSwitch(); + eval { $strArchiveFile = $self->walFileName($oFile, $strArchiveId, $strWalSegment, false, $iArchiveTimeout); @@ -1195,17 +1195,29 @@ sub check # Else, log the error. if ($iResult == 0) { - &log(INFO, - "WAL segment ${strWalSegment} successfully stored in the archive at '" . - $oFile->pathGet(PATH_BACKUP_ARCHIVE, "$strArchiveId/${strArchiveFile}") . "'"); + if (!$oDb->isStandby()) + { + &log(INFO, + "WAL segment ${strWalSegment} successfully stored in the archive at '" . + $oFile->pathGet(PATH_BACKUP_ARCHIVE, "$strArchiveId/${strArchiveFile}") . "'"); + } + else + { + &log(INFO, "switch xlog cannot be performed on the standby, all other checks passed successfully"); + } } else { &log(ERROR, $strResultMessage, $iResult); - &log(WARN, - "WAL segment ${strWalSegment} did not reach the archive:" . (defined($strArchiveId) ? $strArchiveId : '') . "\n" . - "HINT: Check the archive_command to ensure that all options are correct (especialy --stanza).\n" . - "HINT: Check the PostreSQL server log for errors."); + + # If a switch xlog was attempted, then alert the user to the WAL that did not reach the archive + if (defined($strWalSegment)) + { + &log(WARN, + "WAL segment ${strWalSegment} did not reach the archive:" . (defined($strArchiveId) ? $strArchiveId : '') . "\n" . + "HINT: Check the archive_command to ensure that all options are correct (especialy --stanza).\n" . + "HINT: Check the PostreSQL server log for errors."); + } } # Return from function and log return values if any diff --git a/lib/pgBackRest/Config/ConfigHelpData.pm b/lib/pgBackRest/Config/ConfigHelpData.pm index 81cc7814f..82ea335f7 100644 --- a/lib/pgBackRest/Config/ConfigHelpData.pm +++ b/lib/pgBackRest/Config/ConfigHelpData.pm @@ -983,7 +983,8 @@ my $oConfigHelpData = "The check command validates that pgBackRest and the archive_command setting are configured correctly for " . "archiving and backups. It detects misconfigurations, particularly in archiving, that result in incomplete " . "backups because required WAL segments did not reach the archive. The command can be run on the database or " . - "the backup host.\n" . + "the backup host. The command may also be run on the standby host, however, since pg_switch_xlog() cannot " . + "be performed on the standby, the command will only test the repository configuration.\n" . "\n" . "Note that pg_create_restore_point('pgBackRest Archive Check') and pg_switch_xlog() are called to force " . "PostgreSQL to archive a WAL segment. Restore points are only supported in PostgreSQL >= 9.1 so for older " . diff --git a/test/expect/backup-full-005.log b/test/expect/backup-full-005.log index 19251c2f5..fbba05004 100644 --- a/test/expect/backup-full-005.log +++ b/test/expect/backup-full-005.log @@ -115,6 +115,10 @@ log-level-stderr=off log-path=[TEST_PATH]/db-standby/spool/log repo-path=[TEST_PATH]/db-master/repo +check db - verify check command on standby (db-standby host) +> [CONTAINER-EXEC] db-standby [BACKREST-BIN] --config=[TEST_PATH]/db-standby/pgbackrest.conf --log-level-console=detail --stanza=db check +------------------------------------------------------------------------------------------------------------------------------------ + incr backup - update during backup (db-master host) > [CONTAINER-EXEC] db-master [BACKREST-BIN] --config=[TEST_PATH]/db-master/pgbackrest.conf --stop-auto --no-archive-check --buffer-size=24576 --stanza=db backup --test --test-delay=1 --test-point=manifest-build=y ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/test/expect/backup-full-006.log b/test/expect/backup-full-006.log index ec17da39b..464f5585a 100644 --- a/test/expect/backup-full-006.log +++ b/test/expect/backup-full-006.log @@ -115,6 +115,10 @@ repo-path=[TEST_PATH]/db-standby/repo archive-copy=y start-fast=y +check db - verify check command on standby (db-standby host) +> [CONTAINER-EXEC] db-standby [BACKREST-BIN] --config=[TEST_PATH]/db-standby/pgbackrest.conf --log-level-console=detail --stanza=db check +------------------------------------------------------------------------------------------------------------------------------------ + incr backup - update during backup (db-standby host) > [CONTAINER-EXEC] db-standby [BACKREST-BIN] --config=[TEST_PATH]/db-standby/pgbackrest.conf --stop-auto --no-archive-check --buffer-size=24576 --stanza=db backup --test --test-delay=1 --test-point=manifest-build=y ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/test/expect/backup-full-011.log b/test/expect/backup-full-011.log index 44373008a..4d425bb51 100644 --- a/test/expect/backup-full-011.log +++ b/test/expect/backup-full-011.log @@ -163,6 +163,10 @@ repo-path=[TEST_PATH]/backup/repo archive-copy=y start-fast=y +check db - verify check command on standby (db-standby host) +> [CONTAINER-EXEC] db-standby [BACKREST-BIN] --config=[TEST_PATH]/db-standby/pgbackrest.conf --log-level-console=detail --stanza=db check +------------------------------------------------------------------------------------------------------------------------------------ + incr backup - update during backup (backup host) > [CONTAINER-EXEC] backup [BACKREST-BIN] --config=[TEST_PATH]/backup/pgbackrest.conf --stop-auto --no-archive-check --buffer-size=24576 --stanza=db backup --test --test-delay=1 --test-point=manifest-build=y ------------------------------------------------------------------------------------------------------------------------------------ diff --git a/test/lib/pgBackRestTest/Backup/BackupTest.pm b/test/lib/pgBackRestTest/Backup/BackupTest.pm index f267649bb..f4c510bb2 100755 --- a/test/lib/pgBackRestTest/Backup/BackupTest.pm +++ b/test/lib/pgBackRestTest/Backup/BackupTest.pm @@ -2349,6 +2349,9 @@ sub backupTestRun { $strFullBackup = $strStandbyBackup; } + + # Confirm the check command runs without error on a standby + $oHostDbStandby->check('verify check command on standby'); } # Execute stop and make sure the backup fails diff --git a/test/lib/pgBackRestTest/Backup/Common/HostBackupTest.pm b/test/lib/pgBackRestTest/Backup/Common/HostBackupTest.pm index bf4cd4f3a..eed9333aa 100644 --- a/test/lib/pgBackRestTest/Backup/Common/HostBackupTest.pm +++ b/test/lib/pgBackRestTest/Backup/Common/HostBackupTest.pm @@ -783,14 +783,17 @@ sub stanzaCreate bLogOutput => $self->synthetic()}); # If the info file was created, then add it to the expect log - if ($self->synthetic() && fileExists($self->repoPath() . '/backup/' . $self->stanza() . '/backup.info')) + if (defined($self->{oLogTest}) && $self->synthetic()) { - $self->{oLogTest}->supplementalAdd($self->repoPath() . '/backup/' . $self->stanza() . '/backup.info'); - } + if (fileExists($self->repoPath() . '/backup/' . $self->stanza() . '/backup.info')) + { + $self->{oLogTest}->supplementalAdd($self->repoPath() . '/backup/' . $self->stanza() . '/backup.info'); + } - if ($self->synthetic() && fileExists($self->repoPath() . '/archive/' . $self->stanza() . '/archive.info')) - { - $self->{oLogTest}->supplementalAdd($self->repoPath() . '/archive/' . $self->stanza() . '/archive.info'); + if (fileExists($self->repoPath() . '/archive/' . $self->stanza() . '/archive.info')) + { + $self->{oLogTest}->supplementalAdd($self->repoPath() . '/archive/' . $self->stanza() . '/archive.info'); + } } # Return from function and log return values if any