1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Error with hints when backup user cannot read pg_settings.

This condition used to give a not-very-clear error which we have been intending to improve. But in the meantime the changes in fbff299 resulted in a segfault for this condition instead because the data_directory was assumed to be non-NULL.

Fix this by explicitly throwing an error with hints when any row in pg_settings cannot be selected.
This commit is contained in:
David Steele 2020-09-17 10:35:27 -04:00 committed by GitHub
parent c71609879b
commit 9db3143973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 79 additions and 0 deletions

View File

@ -14,6 +14,19 @@
<release-list>
<release date="XXXX-XX-XX" version="2.30dev" title="UNDER DEVELOPMENT">
<release-core-list>
<release-bug-list>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="mohamed.insaf.k"/>
<release-item-contributor id="david.steele"/>
<release-item-reviewer id="stefan.fercot"/>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>
<p>Error with hints when backup user cannot read <id>pg_settings</id>.</p>
</release-item>
</release-bug-list>
<release-improvement-list>
<release-item>
<release-item-contributor-list>
@ -9044,6 +9057,11 @@
<contributor-id type="github">Yuxael</contributor-id>
</contributor>
<contributor id="mohamed.insaf.k">
<contributor-name-display>Mohamed Insaf K</contributor-name-display>
<contributor-id type="github">insafk</contributor-id>
</contributor>
<contributor id="mohamad.el.rifai">
<contributor-name-display>Mohamad El-Rifai</contributor-name-display>
<contributor-id type="github">melrifa1</contributor-id>

View File

@ -219,6 +219,19 @@ dbOpen(Db *this)
" (select setting from pg_catalog.pg_settings where name = 'archive_mode')::text,"
" (select setting from pg_catalog.pg_settings where name = 'archive_command')::text"));
// Check that none of the return values are null, which indicates the user cannot select some rows in pg_settings
for (unsigned int columnIdx = 0; columnIdx < varLstSize(row); columnIdx++)
{
if (varLstGet(row, columnIdx) == NULL)
{
THROW(
DbQueryError,
"unable to select some rows from pg_settings\n"
"HINT: is the backup running as the postgres user?\n"
"HINT: is the pg_read_all_settings role assigned for " PG_NAME " >= " PG_VERSION_10_STR "?");
}
}
// Strip the minor version off since we don't need it. In the future it might be a good idea to warn users when they are
// running an old minor version.
this->pgVersion = varUIntForce(varLstGet(row, 0)) / 100 * 100;

View File

@ -145,6 +145,54 @@ testRun(void)
strLstAddZ(argList, "--pg1-path=/pg1");
harnessCfgLoad(cfgCmdBackup, argList);
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("error when unable to select any pg_settings");
harnessPqScriptSet((HarnessPq [])
{
// Connect to primary
HRNPQ_MACRO_OPEN(1, "dbname='postgres' port=5432"),
HRNPQ_MACRO_SET_SEARCH_PATH(1),
HRNPQ_MACRO_SET_CLIENT_ENCODING(1),
// Return NULL for a row in pg_settings
{.session = 1, .function = HRNPQ_SENDQUERY, .param =
"[\"select (select setting from pg_catalog.pg_settings where name = 'server_version_num')::int4,"
" (select setting from pg_catalog.pg_settings where name = 'data_directory')::text,"
" (select setting from pg_catalog.pg_settings where name = 'archive_mode')::text,"
" (select setting from pg_catalog.pg_settings where name = 'archive_command')::text\"]",
.resultInt = 1},
{.session = 1, .function = HRNPQ_CONSUMEINPUT},
{.session = 1, .function = HRNPQ_ISBUSY},
{.session = 1, .function = HRNPQ_GETRESULT},
{.session = 1, .function = HRNPQ_RESULTSTATUS, .resultInt = PGRES_TUPLES_OK},
{.session = 1, .function = HRNPQ_NTUPLES, .resultInt = 1},
{.session = 1, .function = HRNPQ_NFIELDS, .resultInt = 4},
{.session = 1, .function = HRNPQ_FTYPE, .param = "[0]", .resultInt = HRNPQ_TYPE_INT},
{.session = 1, .function = HRNPQ_FTYPE, .param = "[1]", .resultInt = HRNPQ_TYPE_TEXT},
{.session = 1, .function = HRNPQ_FTYPE, .param = "[2]", .resultInt = HRNPQ_TYPE_TEXT},
{.session = 1, .function = HRNPQ_FTYPE, .param = "[3]", .resultInt = HRNPQ_TYPE_TEXT},
{.session = 1, .function = HRNPQ_GETVALUE, .param = "[0,0]", .resultZ = "0"},
{.session = 1, .function = HRNPQ_GETVALUE, .param = "[0,1]", .resultZ = "value"},
{.session = 1, .function = HRNPQ_GETVALUE, .param = "[0,2]", .resultZ = "value"},
{.session = 1, .function = HRNPQ_GETVALUE, .param = "[0,3]", .resultZ = ""},
{.session = 1, .function = HRNPQ_GETISNULL, .param = "[0,3]", .resultInt = 1},
{.session = 1, .function = HRNPQ_CLEAR},
{.session = 1, .function = HRNPQ_GETRESULT, .resultNull = true},
// Close primary
HRNPQ_MACRO_CLOSE(1),
HRNPQ_MACRO_DONE()
});
TEST_ERROR(dbGet(true, true, false), DbConnectError, "unable to find primary cluster - cannot proceed");
TEST_RESULT_LOG(
"P00 WARN: unable to check pg-1: [DbQueryError] unable to select some rows from pg_settings\n"
" HINT: is the backup running as the postgres user?\n"
" HINT: is the pg_read_all_settings role assigned for PostgreSQL >= 10?");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("PostgreSQL 8.3 start backup with no start fast");