1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-15 01:04:37 +02:00

Set application_name to "pgBackRest [command]" for database connections.

Suggested by Jens Wilke.
This commit is contained in:
David Steele
2016-10-05 21:15:10 -04:00
parent 0a4099fff8
commit 16d0e767ef
4 changed files with 38 additions and 0 deletions

View File

@ -172,6 +172,14 @@
<p>Added the <br-option>log-level-stderr</br-option> option to control whether console log messages are sent to <id>stderr</id> or <id>stdout</id>. By default this is set to <setting>warn</setting> which represents a change in behavior from previous versions, even though it may be more intuitive. Setting <br-option>log-level-stderr=off</br-option> will preserve the old behavior.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="wilke.jens"/>
</release-item-contributor-list>
<p>Set <id>application_name</id> to <id>"pgBackRest [command]"</id> for database connections.</p>
</release-item>
<release-item>
<p>Check that archive_mode is enabled when <br-option>archive-check</br-option> option enabled.</p>
</release-item>

View File

@ -207,6 +207,18 @@ sub connect
$bResult = false;
undef($self->{hDb});
}
else
{
my ($fDbVersion) = $self->versionGet();
if ($fDbVersion >= PG_VERSION_APPLICATION_NAME)
{
$self->{hDb}->do(
"set application_name = '" . BACKREST_NAME . ' [' .
(optionValid(OPTION_COMMAND) ? optionGet(OPTION_COMMAND) : commandGet()) . "]'")
or confess &log(ERROR, $self->{hDb}->errstr, ERROR_DB_QUERY);
}
}
}
}

View File

@ -34,6 +34,8 @@ use constant PG_VERSION_95 => '9.5';
use constant PG_VERSION_96 => '9.6';
push @EXPORT, qw(PG_VERSION_96);
use constant PG_VERSION_APPLICATION_NAME => PG_VERSION_90;
push @EXPORT, qw(PG_VERSION_APPLICATION_NAME);
use constant PG_VERSION_HOT_STANDBY => PG_VERSION_91;
push @EXPORT, qw(PG_VERSION_HOT_STANDBY);
use constant PG_VERSION_BACKUP_STANDBY => PG_VERSION_92;

View File

@ -2100,10 +2100,26 @@ sub backupTestRun
{strTest => TEST_MANIFEST_BUILD, fTestDelay => $fTestDelay,
strOptionalParam => '--' . OPTION_STOP_AUTO . ' --no-' . OPTION_BACKUP_ARCHIVE_CHECK});
# Drop a table
$oHostDbMaster->sqlExecute('drop table test_remove');
$oHostDbMaster->sqlXlogRotate();
$oHostDbMaster->sqlExecute("update test set message = '$strIncrMessage'", {bCommit => true});
# Check that application name is set
if ($oHostDbMaster->dbVersion() >= PG_VERSION_APPLICATION_NAME)
{
my $strApplicationNameExpected = BACKREST_NAME . ' [' . CMD_BACKUP . ']';
my $strApplicationName = $oHostDbMaster->sqlSelectOne(
"select application_name from pg_stat_activity where application_name like '" . BACKREST_NAME . "%'");
if (!defined($strApplicationName) || $strApplicationName ne $strApplicationNameExpected)
{
confess &log(ERROR,
"application name '" . (defined($strApplicationName) ? $strApplicationName : '[null]') .
"' does not match '" . $strApplicationNameExpected . "'");
}
}
my $strIncrBackup = $oHostBackup->backupEnd($strType, $oExecuteBackup);
# Setup the xid target