diff options
author | Magnus Hagander <magnus@hagander.net> | 2019-03-09 10:45:17 -0800 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2019-03-09 10:47:30 -0800 |
commit | 6b9e875f7286d8535bff7955e5aa3602e188e436 (patch) | |
tree | bedeb8b9ba38b7aa151c329830589dc14bed292c /src/backend/replication/basebackup.c | |
parent | 3c5926301aea476025f118159688a6a88b2738bc (diff) |
Track block level checksum failures in pg_stat_database
This adds a column that counts how many checksum failures have occurred
on files belonging to a specific database. Both checksum failures
during normal backend processing and those created when a base backup
detects a checksum failure are counted.
Author: Magnus Hagander
Reviewed by: Julien Rouhaud
Diffstat (limited to 'src/backend/replication/basebackup.c')
-rw-r--r-- | src/backend/replication/basebackup.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index def6c03dd0c..6c324a6661d 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -58,7 +58,7 @@ typedef struct static int64 sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces, bool sendtblspclinks); static bool sendFile(const char *readfilename, const char *tarfilename, - struct stat *statbuf, bool missing_ok); + struct stat *statbuf, bool missing_ok, Oid dboid); static void sendFileWithContent(const char *filename, const char *content); static int64 _tarWriteHeader(const char *filename, const char *linktarget, struct stat *statbuf, bool sizeonly); @@ -342,7 +342,7 @@ perform_base_backup(basebackup_options *opt) (errcode_for_file_access(), errmsg("could not stat file \"%s\": %m", XLOG_CONTROL_FILE))); - sendFile(XLOG_CONTROL_FILE, XLOG_CONTROL_FILE, &statbuf, false); + sendFile(XLOG_CONTROL_FILE, XLOG_CONTROL_FILE, &statbuf, false, InvalidOid); } else sendTablespace(ti->path, false); @@ -592,7 +592,7 @@ perform_base_backup(basebackup_options *opt) (errcode_for_file_access(), errmsg("could not stat file \"%s\": %m", pathbuf))); - sendFile(pathbuf, pathbuf, &statbuf, false); + sendFile(pathbuf, pathbuf, &statbuf, false, InvalidOid); /* unconditionally mark file as archived */ StatusFilePath(pathbuf, fname, ".done"); @@ -1302,7 +1302,7 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces, if (!sizeonly) sent = sendFile(pathbuf, pathbuf + basepathlen + 1, &statbuf, - true); + true, isDbDir ? pg_atoi(lastDir + 1, sizeof(Oid), 0) : InvalidOid); if (sent || sizeonly) { @@ -1358,12 +1358,15 @@ is_checksummed_file(const char *fullpath, const char *filename) * * If 'missing_ok' is true, will not throw an error if the file is not found. * + * If dboid is anything other than InvalidOid then any checksum failures detected + * will get reported to the stats collector. + * * Returns true if the file was successfully sent, false if 'missing_ok', * and the file did not exist. */ static bool sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf, - bool missing_ok) + bool missing_ok, Oid dboid) { FILE *fp; BlockNumber blkno = 0; @@ -1580,6 +1583,9 @@ sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf ereport(WARNING, (errmsg("file \"%s\" has a total of %d checksum verification " "failures", readfilename, checksum_failures))); + + if (dboid != InvalidOid) + pgstat_report_checksum_failures_in_db(dboid, checksum_failures); } total_checksum_failures += checksum_failures; |