Skip to content

Commit 19516af

Browse files
committed
Fix various checksum check problems for pg_verify_checksums and base backups
Three issues are fixed in this patch: - Base backups forgot to ignore files specific to EXEC_BACKEND, leading to spurious warnings when checksums are enabled, per analysis from me. - pg_verify_checksums forgot about files specific to EXEC_BACKEND, leading to failures of the tool on any such build, particularly Windows. This error was originally found by newly-introduced TAP tests in various buildfarm members using EXEC_BACKEND. - pg_verify_checksums forgot to count for temporary files and temporary paths, which could be valid relation files, without checksums, per report from Andres Freund. More tests are added to cover this case. A new test case which emulates corruption for a file in a different tablespace is added, coming from from Michael Banck, while I have coded the main code and refactored the test code. Author: Michael Banck, Michael Paquier Reviewed-by: Stephen Frost, David Steele Discussion: https://postgr.es/m/20181021134206.GA14282@paquier.xyz
1 parent 8503630 commit 19516af

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/backend/replication/basebackup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,19 @@ static const char *excludeFiles[] =
189189

190190
/*
191191
* List of files excluded from checksum validation.
192+
*
193+
* Note: this list should be kept in sync with what pg_verify_checksums.c
194+
* includes.
192195
*/
193196
static const char *noChecksumFiles[] = {
194197
"pg_control",
195198
"pg_filenode.map",
196199
"pg_internal.init",
197200
"PG_VERSION",
201+
#ifdef EXEC_BACKEND
202+
"config_exec_params",
203+
"config_exec_params.new",
204+
#endif
198205
NULL,
199206
};
200207

src/bin/pg_verify_checksums/pg_verify_checksums.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "storage/bufpage.h"
2121
#include "storage/checksum.h"
2222
#include "storage/checksum_impl.h"
23+
#include "storage/fd.h"
2324

2425

2526
static int64 files = 0;
@@ -49,11 +50,20 @@ usage(void)
4950
printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));
5051
}
5152

53+
/*
54+
* List of files excluded from checksum validation.
55+
*
56+
* Note: this list should be kept in sync with what basebackup.c includes.
57+
*/
5258
static const char *const skip[] = {
5359
"pg_control",
5460
"pg_filenode.map",
5561
"pg_internal.init",
5662
"PG_VERSION",
63+
#ifdef EXEC_BACKEND
64+
"config_exec_params",
65+
"config_exec_params.new",
66+
#endif
5767
NULL,
5868
};
5969

@@ -62,13 +72,10 @@ skipfile(const char *fn)
6272
{
6373
const char *const *f;
6474

65-
if (strcmp(fn, ".") == 0 ||
66-
strcmp(fn, "..") == 0)
67-
return true;
68-
6975
for (f = skip; *f; f++)
7076
if (strcmp(*f, fn) == 0)
7177
return true;
78+
7279
return false;
7380
}
7481

@@ -146,9 +153,22 @@ scan_directory(const char *basedir, const char *subdir)
146153
char fn[MAXPGPATH];
147154
struct stat st;
148155

149-
if (skipfile(de->d_name))
156+
if (strcmp(de->d_name, ".") == 0 ||
157+
strcmp(de->d_name, "..") == 0)
150158
continue;
151159

160+
/* Skip temporary files */
161+
if (strncmp(de->d_name,
162+
PG_TEMP_FILE_PREFIX,
163+
strlen(PG_TEMP_FILE_PREFIX)) == 0)
164+
continue;
165+
166+
/* Skip temporary folders */
167+
if (strncmp(de->d_name,
168+
PG_TEMP_FILES_DIR,
169+
strlen(PG_TEMP_FILES_DIR)) == 0)
170+
return;
171+
152172
snprintf(fn, sizeof(fn), "%s/%s", path, de->d_name);
153173
if (lstat(fn, &st) < 0)
154174
{
@@ -163,6 +183,9 @@ scan_directory(const char *basedir, const char *subdir)
163183
*segmentpath;
164184
BlockNumber segmentno = 0;
165185

186+
if (skipfile(de->d_name))
187+
continue;
188+
166189
/*
167190
* Cut off at the segment boundary (".") to get the segment number
168191
* in order to mix it into the checksum. Then also cut off at the

0 commit comments

Comments
 (0)