1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-01-18 04:58:51 +02:00

Skip pg_internal.init temp file during backup.

If PostgreSQL crashes it can leave behind a pg_internal.init temp file with the pid as the extension, as discussed in https://www.postgresql.org/message-id/flat/20200131045352.GB2631%40paquier.xyz#7700b9481ef5b0dd5f09cc410b4750f6.  On restart this file is not cleaned up so it can persist for the lifetime of the cluster or until another process with the same id happens to write pg_internal.init.

This is arguably a bug in PostgreSQL, but in any case it makes sense not to backup this file.
This commit is contained in:
David Steele 2020-02-21 11:51:39 -05:00
parent 48d0f77fe3
commit cc743f2e04
3 changed files with 33 additions and 2 deletions

View File

@ -67,6 +67,16 @@
</release-feature-list>
<release-improvement-list>
<release-item>
<release-item-contributor-list>
<release-item-ideator id="michael.paquier"/>
<release-item-contributor id="david.steele"/>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>
<p>Skip <file>pg_internal.init</file> temp file during backup.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-contributor id="david.steele"/>
@ -8039,6 +8049,11 @@
<contributor-id type="github">mibiio</contributor-id>
</contributor>
<contributor id="michael.paquier">
<contributor-name-display>Michael Paquier</contributor-name-display>
<contributor-id type="github">michaelpq</contributor-id>
</contributor>
<contributor id="michael.renner">
<contributor-name-display>Michael Renner</contributor-name-display>
<contributor-id type="github">terrorobe</contributor-id>

View File

@ -579,8 +579,13 @@ manifestBuildCallback(void *data, const StorageInfo *info)
strPtr(manifestName));
}
// Skip pg_internal.init since it is recreated on startup
if (strEqZ(info->name, PG_FILE_PGINTERNALINIT))
// Skip pg_internal.init since it is recreated on startup. It's also possible, (though unlikely) that a temp file with
// the creating process id as the extension can exist so skip that as well. This seems to be a bug in PostgreSQL since
// the temp file should be removed on startup. Use regExpMatchOne() here instead of preparing a regexp in advance since
// the likelihood of needing the regexp should be very small.
if ((pgVersion <= PG_VERSION_84 || buildData.dbPath) && strBeginsWithZ(info->name, PG_FILE_PGINTERNALINIT) &&
(strSize(info->name) == sizeof(PG_FILE_PGINTERNALINIT) - 1 ||
regExpMatchOne(STRDEF("\\.[0-9]+"), strSub(info->name, sizeof(PG_FILE_PGINTERNALINIT) - 1))))
{
FUNCTION_TEST_RETURN_VOID();
return;

View File

@ -252,6 +252,10 @@ testRun(void)
// global directory
storagePathCreateP(storagePgWrite, STRDEF(PG_PATH_GLOBAL), .mode = 0700, .noParentCreate = true);
storagePutP(storageNewWriteP(storagePgWrite, STRDEF(PG_PATH_GLOBAL "/" PG_FILE_PGINTERNALINIT)), NULL);
storagePutP(storageNewWriteP(storagePgWrite, STRDEF(PG_PATH_GLOBAL "/" PG_FILE_PGINTERNALINIT ".1")), NULL);
storagePutP(
storageNewWriteP(storagePgWrite, STRDEF(PG_PATH_GLOBAL "/" PG_FILE_PGINTERNALINIT ".allow"), .modeFile = 0400,
.timeModified = 1565282114), NULL);
storagePutP(
storageNewWriteP(storagePgWrite, STRDEF(PG_PATH_GLOBAL "/t1_1"), .modeFile = 0400, .timeModified = 1565282114), NULL);
@ -282,6 +286,7 @@ testRun(void)
"\n"
"[target:file]\n"
"pg_data/PG_VERSION={\"size\":4,\"timestamp\":1565282100}\n"
"pg_data/global/pg_internal.init.allow={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/global/t1_1={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/pg_dynshmem/BOGUS={\"size\":0,\"timestamp\":1565282101}\n"
"pg_data/pg_notify/BOGUS={\"size\":0,\"timestamp\":1565282102}\n"
@ -419,6 +424,7 @@ testRun(void)
"pg_data/base/1/t1_1.1={\"size\":0,\"timestamp\":1565282113}\n"
"pg_data/base/1/t8888888_8888888_vm={\"size\":0,\"timestamp\":1565282113}\n"
"pg_data/base/1/t8888888_8888888_vm.999999={\"size\":0,\"timestamp\":1565282113}\n"
"pg_data/global/pg_internal.init.allow={\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/global/t1_1={\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/pg_dynshmem/BOGUS={\"master\":true,\"size\":0,\"timestamp\":1565282101}\n"
"pg_data/pg_hba.conf={\"master\":true,\"size\":9,\"timestamp\":1565282117}\n"
@ -537,6 +543,7 @@ testRun(void)
"pg_data/base/1/555_init.1={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/base/1/555_vm.1={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/base/1/555_vm.1_vm={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/global/pg_internal.init.allow={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/pg_dynshmem/BOGUS={\"size\":0,\"timestamp\":1565282101}\n"
"pg_data/pg_hba.conf={\"size\":9,\"timestamp\":1565282117}\n"
"pg_data/pg_replslot/BOGUS={\"size\":0,\"timestamp\":1565282103}\n"
@ -625,6 +632,7 @@ testRun(void)
"pg_data/base/1/555_init={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/base/1/555_init.1={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/base/1/555_vm.1_vm={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/global/pg_internal.init.allow={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/pg_dynshmem/BOGUS={\"size\":0,\"timestamp\":1565282101}\n"
"pg_data/pg_hba.conf={\"size\":9,\"timestamp\":1565282117}\n"
"pg_data/pg_replslot/BOGUS={\"size\":0,\"timestamp\":1565282103}\n"
@ -705,6 +713,7 @@ testRun(void)
"pg_data/base/1/555_init={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/base/1/555_init.1={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/base/1/555_vm.1_vm={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/global/pg_internal.init.allow={\"master\":false,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/pg_dynshmem/BOGUS={\"size\":0,\"timestamp\":1565282101}\n"
"pg_data/pg_hba.conf={\"size\":9,\"timestamp\":1565282117}\n"
"pg_data/pg_replslot/BOGUS={\"size\":0,\"timestamp\":1565282103}\n"
@ -852,6 +861,7 @@ testRun(void)
"pg_data/base/1/PG_VERSION={\"size\":0,\"timestamp\":1565282120}\n"
"pg_data/base/1/pg_filenode.map={\"size\":0,\"timestamp\":1565282120}\n"
"pg_data/global/pg_control={\"master\":true,\"size\":0,\"timestamp\":1565282101}\n"
"pg_data/global/pg_internal.init.allow={\"checksum-page\":true,\"size\":0,\"timestamp\":1565282114}\n"
"pg_data/pg_clog/BOGUS={\"size\":0,\"timestamp\":1565282121}\n"
"pg_data/pg_hba.conf={\"master\":true,\"size\":9,\"timestamp\":1565282117}\n"
"pg_data/pg_multixact/BOGUS={\"size\":0,\"timestamp\":1565282101}\n"
@ -903,6 +913,7 @@ testRun(void)
storageRemoveP(storageTest, STRDEF("pg/pg_tblspc/2"), .errorOnMissing = true);
storagePathRemoveP(storageTest, STRDEF("ts/2"), .recurse = true);
storageRemoveP(storagePgWrite, STRDEF(PG_PATH_GLOBAL "/" PG_FILE_PGINTERNALINIT ".allow"), .errorOnMissing = true);
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("manifest with all features - 12, online");