@@ -58,7 +58,7 @@ typedef struct
5858static int64 sendDir (const char * path ,int basepathlen ,bool sizeonly ,
5959List * tablespaces ,bool sendtblspclinks );
6060static bool sendFile (const char * readfilename ,const char * tarfilename ,
61- struct stat * statbuf ,bool missing_ok );
61+ struct stat * statbuf ,bool missing_ok , Oid dboid );
6262static void sendFileWithContent (const char * filename ,const char * content );
6363static int64 _tarWriteHeader (const char * filename ,const char * linktarget ,
6464struct stat * statbuf ,bool sizeonly );
@@ -342,7 +342,7 @@ perform_base_backup(basebackup_options *opt)
342342(errcode_for_file_access (),
343343errmsg ("could not stat file \"%s\": %m" ,
344344XLOG_CONTROL_FILE )));
345- sendFile (XLOG_CONTROL_FILE ,XLOG_CONTROL_FILE ,& statbuf , false);
345+ sendFile (XLOG_CONTROL_FILE ,XLOG_CONTROL_FILE ,& statbuf , false, InvalidOid );
346346}
347347else
348348sendTablespace (ti -> path , false);
@@ -592,7 +592,7 @@ perform_base_backup(basebackup_options *opt)
592592(errcode_for_file_access (),
593593errmsg ("could not stat file \"%s\": %m" ,pathbuf )));
594594
595- sendFile (pathbuf ,pathbuf ,& statbuf , false);
595+ sendFile (pathbuf ,pathbuf ,& statbuf , false, InvalidOid );
596596
597597/* unconditionally mark file as archived */
598598StatusFilePath (pathbuf ,fname ,".done" );
@@ -1302,7 +1302,7 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces,
13021302
13031303if (!sizeonly )
13041304sent = sendFile (pathbuf ,pathbuf + basepathlen + 1 ,& statbuf ,
1305- true);
1305+ true, isDbDir ? pg_atoi ( lastDir + 1 , sizeof ( Oid ), 0 ) : InvalidOid );
13061306
13071307if (sent || sizeonly )
13081308{
@@ -1358,12 +1358,15 @@ is_checksummed_file(const char *fullpath, const char *filename)
13581358 *
13591359 * If 'missing_ok' is true, will not throw an error if the file is not found.
13601360 *
1361+ * If dboid is anything other than InvalidOid then any checksum failures detected
1362+ * will get reported to the stats collector.
1363+ *
13611364 * Returns true if the file was successfully sent, false if 'missing_ok',
13621365 * and the file did not exist.
13631366 */
13641367static bool
13651368sendFile (const char * readfilename ,const char * tarfilename ,struct stat * statbuf ,
1366- bool missing_ok )
1369+ bool missing_ok , Oid dboid )
13671370{
13681371FILE * fp ;
13691372BlockNumber blkno = 0 ;
@@ -1580,6 +1583,9 @@ sendFile(const char *readfilename, const char *tarfilename, struct stat *statbuf
15801583ereport (WARNING ,
15811584(errmsg ("file \"%s\" has a total of %d checksum verification "
15821585"failures" ,readfilename ,checksum_failures )));
1586+
1587+ if (dboid != InvalidOid )
1588+ pgstat_report_checksum_failures_in_db (dboid ,checksum_failures );
15831589}
15841590total_checksum_failures += checksum_failures ;
15851591