1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-06-25 00:16:54 +02:00

Disable query parallelism in PostgreSQL sessions used for backup control.

There is no need to have parallelism enabled in a backup control session. In particular, 9.6 marks pg_stop_backup() as parallel-safe but an error will be thrown if pg_stop_backup() is run in a worker.
This commit is contained in:
David Steele
2020-06-25 08:02:48 -04:00
parent c5a507b9a6
commit ea04ec7b3f
7 changed files with 45 additions and 7 deletions

View File

@ -19,6 +19,10 @@
<p>Asynchronous S3 multipart upload.</p>
</release-item>
<release-item>
<p>Disable query parallelism in <postgres/> sessions used for backup control.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/>

View File

@ -236,6 +236,11 @@ dbOpen(Db *this)
// Set application name to help identify the backup session
if (this->pgVersion >= PG_VERSION_APPLICATION_NAME)
dbExec(this, strNewFmt("set application_name = '%s'", strPtr(this->applicationName)));
// There is no need to have parallelism enabled in a backup session. In particular, 9.6 marks pg_stop_backup() as
// parallel-safe but an error will be thrown if pg_stop_backup() is run in a worker.
if (this->pgVersion >= PG_VERSION_PARALLEL_QUERY)
dbExec(this, STRDEF("set max_parallel_workers_per_gather = 0"));
}
MEM_CONTEXT_TEMP_END();

View File

@ -52,6 +52,9 @@ Version where various PostgreSQL capabilities were introduced
// recovery target action supported
#define PG_VERSION_RECOVERY_TARGET_ACTION PG_VERSION_95
// parallel query supported
#define PG_VERSION_PARALLEL_QUERY PG_VERSION_96
// xlog was renamed to wal
#define PG_VERSION_WAL_RENAME PG_VERSION_10

View File

@ -433,6 +433,13 @@ sub clusterStart
$strCommand .= ' -c wal_level=hot_standby -c hot_standby=' . ($bHotStandby ? 'on' : 'off');
}
# Force parallel mode on to make sure we are disabling it and there are no issues. This is important for testing that 9.6
# works since pg_stop_backup() is marked parallel safe and will error if run in a worker.
if ($self->pgVersion() >= PG_VERSION_96)
{
$strCommand .= " -c force_parallel_mode='on' -c max_parallel_workers_per_gather=2";
}
$strCommand .=
($self->pgVersion() >= PG_VERSION_HOT_STANDBY ? ' -c max_wal_senders=3' : '') .
' -c listen_addresses=\'*\'' .

View File

@ -100,6 +100,16 @@ Macros for defining groups of functions that implement various queries and comma
{.session = sessionParam, .function = HRNPQ_CLEAR}, \
{.session = sessionParam, .function = HRNPQ_GETRESULT, .resultNull = true}
#define HRNPQ_MACRO_SET_MAX_PARALLEL_WORKERS_PER_GATHER(sessionParam) \
{.session = sessionParam, .function = HRNPQ_SENDQUERY, .param = "[\"set max_parallel_workers_per_gather = 0\"]", \
.resultInt = 1}, \
{.session = sessionParam, .function = HRNPQ_CONSUMEINPUT}, \
{.session = sessionParam, .function = HRNPQ_ISBUSY}, \
{.session = sessionParam, .function = HRNPQ_GETRESULT}, \
{.session = sessionParam, .function = HRNPQ_RESULTSTATUS, .resultInt = PGRES_COMMAND_OK}, \
{.session = sessionParam, .function = HRNPQ_CLEAR}, \
{.session = sessionParam, .function = HRNPQ_GETRESULT, .resultNull = true}
#define HRNPQ_MACRO_IS_STANDBY_QUERY(sessionParam, standbyParam) \
{.session = sessionParam, .function = HRNPQ_SENDQUERY, .param = "[\"select pg_catalog.pg_is_in_recovery()\"]", .resultInt = 1},\
{.session = sessionParam, .function = HRNPQ_CONSUMEINPUT}, \
@ -506,6 +516,15 @@ Macros to simplify dbOpen() for specific database versions
HRNPQ_MACRO_SET_APPLICATION_NAME(sessionParam), \
HRNPQ_MACRO_IS_STANDBY_QUERY(sessionParam, standbyParam)
#define HRNPQ_MACRO_OPEN_GE_96(sessionParam, connectParam, pgVersion, pgPathParam, standbyParam, archiveMode, archiveCommand) \
HRNPQ_MACRO_OPEN(sessionParam, connectParam), \
HRNPQ_MACRO_SET_SEARCH_PATH(sessionParam), \
HRNPQ_MACRO_SET_CLIENT_ENCODING(sessionParam), \
HRNPQ_MACRO_VALIDATE_QUERY(sessionParam, pgVersion, pgPathParam, archiveMode, archiveCommand), \
HRNPQ_MACRO_SET_APPLICATION_NAME(sessionParam), \
HRNPQ_MACRO_SET_MAX_PARALLEL_WORKERS_PER_GATHER(sessionParam), \
HRNPQ_MACRO_IS_STANDBY_QUERY(sessionParam, standbyParam)
/***********************************************************************************************************************************
Data type constants
***********************************************************************************************************************************/

View File

@ -353,10 +353,10 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
harnessPqScriptSet((HarnessPq [])
{
// Connect to primary
HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_96, pg1Path, false, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_96, pg1Path, false, NULL, NULL),
// Connect to standby
HRNPQ_MACRO_OPEN_GE_92(2, "dbname='postgres' port=5433", PG_VERSION_96, pg2Path, true, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(2, "dbname='postgres' port=5433", PG_VERSION_96, pg2Path, true, NULL, NULL),
// Get start time
HRNPQ_MACRO_TIME_QUERY(1, (int64_t)backupTimeStart * 1000),
@ -393,7 +393,7 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
harnessPqScriptSet((HarnessPq [])
{
// Connect to primary
HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_11, pg1Path, false, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_11, pg1Path, false, NULL, NULL),
// Get start time
HRNPQ_MACRO_TIME_QUERY(1, (int64_t)backupTimeStart * 1000),
@ -416,7 +416,7 @@ testBackupPqScript(unsigned int pgVersion, time_t backupTimeStart, TestBackupPqS
harnessPqScriptSet((HarnessPq [])
{
// Connect to primary
HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_11, pg1Path, false, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_11, pg1Path, false, NULL, NULL),
// Get start time
HRNPQ_MACRO_TIME_QUERY(1, (int64_t)backupTimeStart * 1000),

View File

@ -273,7 +273,7 @@ testRun(void)
harnessPqScriptSet((HarnessPq [])
{
// Connect to primary
HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_96, "/pg1", false, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_96, "/pg1", false, NULL, NULL),
// Start backup
HRNPQ_MACRO_ADVISORY_LOCK(1, true),
@ -351,10 +351,10 @@ testRun(void)
harnessPqScriptSet((HarnessPq [])
{
// Connect to primary
HRNPQ_MACRO_OPEN_GE_92(1, "dbname='postgres' port=5432", PG_VERSION_10, "/pg1", false, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(1, "dbname='postgres' port=5432", PG_VERSION_10, "/pg1", false, NULL, NULL),
// Connect to standby
HRNPQ_MACRO_OPEN_GE_92(2, "dbname='postgres' port=5433", PG_VERSION_10, "/pg2", true, NULL, NULL),
HRNPQ_MACRO_OPEN_GE_96(2, "dbname='postgres' port=5433", PG_VERSION_10, "/pg2", true, NULL, NULL),
// Start backup
HRNPQ_MACRO_ADVISORY_LOCK(1, true),