Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca1ba50

Browse files
committed
Add more debugging information when failing to read pgstats files
This is useful to know which part of a stats file is corrupted whenreading it, adding to the server logs a WARNING with details about whatcould not be read before giving up with the remaining data in the file.Author: Michael PaquierReviewed-by: Bertrand DrouvotDiscussion:https://postgr.es/m/Zp8o6_cl0KSgsnvS@paquier.xyz
1 parent7f56eaf commitca1ba50

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

‎src/backend/utils/activity/pgstat.c

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,9 +1537,18 @@ pgstat_read_statsfile(void)
15371537
/*
15381538
* Verify it's of the expected format.
15391539
*/
1540-
if (!read_chunk_s(fpin,&format_id)||
1541-
format_id!=PGSTAT_FILE_FORMAT_ID)
1540+
if (!read_chunk_s(fpin,&format_id))
1541+
{
1542+
elog(WARNING,"could not read format ID");
1543+
gotoerror;
1544+
}
1545+
1546+
if (format_id!=PGSTAT_FILE_FORMAT_ID)
1547+
{
1548+
elog(WARNING,"found incorrect format ID %d (expected %d)",
1549+
format_id,PGSTAT_FILE_FORMAT_ID);
15421550
gotoerror;
1551+
}
15431552

15441553
/*
15451554
* We found an existing statistics file. Read it and put all the stats
@@ -1559,22 +1568,37 @@ pgstat_read_statsfile(void)
15591568

15601569
/* entry for fixed-numbered stats */
15611570
if (!read_chunk_s(fpin,&kind))
1571+
{
1572+
elog(WARNING,"could not read stats kind for entry of type %c",t);
15621573
gotoerror;
1574+
}
15631575

15641576
if (!pgstat_is_kind_valid(kind))
1577+
{
1578+
elog(WARNING,"invalid stats kind %d for entry of type %c",
1579+
kind,t);
15651580
gotoerror;
1581+
}
15661582

15671583
info=pgstat_get_kind_info(kind);
15681584

15691585
if (!info->fixed_amount)
1586+
{
1587+
elog(WARNING,"invalid fixed_amount in stats kind %d for entry of type %c",
1588+
kind,t);
15701589
gotoerror;
1590+
}
15711591

15721592
/* Load back stats into shared memory */
15731593
ptr= ((char*)shmem)+info->shared_ctl_off+
15741594
info->shared_data_off;
15751595

15761596
if (!read_chunk(fpin,ptr,info->shared_data_len))
1597+
{
1598+
elog(WARNING,"could not read data of stats kind %d for entry of type %c with size %u",
1599+
kind,t,info->shared_data_len);
15771600
gotoerror;
1601+
}
15781602

15791603
break;
15801604
}
@@ -1591,10 +1615,17 @@ pgstat_read_statsfile(void)
15911615
{
15921616
/* normal stats entry, identified by PgStat_HashKey */
15931617
if (!read_chunk_s(fpin,&key))
1618+
{
1619+
elog(WARNING,"could not read key for entry of type %c",t);
15941620
gotoerror;
1621+
}
15951622

15961623
if (!pgstat_is_kind_valid(key.kind))
1624+
{
1625+
elog(WARNING,"invalid stats kind for entry %d/%u/%u of type %c",
1626+
key.kind,key.dboid,key.objoid,t);
15971627
gotoerror;
1628+
}
15981629
}
15991630
else
16001631
{
@@ -1604,22 +1635,41 @@ pgstat_read_statsfile(void)
16041635
NameDataname;
16051636

16061637
if (!read_chunk_s(fpin,&kind))
1638+
{
1639+
elog(WARNING,"could not read stats kind for entry of type %c",t);
16071640
gotoerror;
1641+
}
16081642
if (!read_chunk_s(fpin,&name))
1643+
{
1644+
elog(WARNING,"could not read name of stats kind %d for entry of type %c",
1645+
kind,t);
16091646
gotoerror;
1647+
}
16101648
if (!pgstat_is_kind_valid(kind))
1649+
{
1650+
elog(WARNING,"invalid stats kind %d for entry of type %c",
1651+
kind,t);
16111652
gotoerror;
1653+
}
16121654

16131655
kind_info=pgstat_get_kind_info(kind);
16141656

16151657
if (!kind_info->from_serialized_name)
1658+
{
1659+
elog(WARNING,"invalid from_serialized_name in stats kind %d for entry of type %c",
1660+
kind,t);
16161661
gotoerror;
1662+
}
16171663

16181664
if (!kind_info->from_serialized_name(&name,&key))
16191665
{
16201666
/* skip over data for entry we don't care about */
16211667
if (fseek(fpin,pgstat_get_entry_len(kind),SEEK_CUR)!=0)
1668+
{
1669+
elog(WARNING,"could not seek \"%s\" of stats kind %d for entry of type %c",
1670+
NameStr(name),kind,t);
16221671
gotoerror;
1672+
}
16231673

16241674
continue;
16251675
}
@@ -1638,8 +1688,8 @@ pgstat_read_statsfile(void)
16381688
if (found)
16391689
{
16401690
dshash_release_lock(pgStatLocal.shared_hash,p);
1641-
elog(WARNING,"found duplicate stats entry %d/%u/%u",
1642-
key.kind,key.dboid,key.objoid);
1691+
elog(WARNING,"found duplicate stats entry %d/%u/%u of type %c",
1692+
key.kind,key.dboid,key.objoid,t);
16431693
gotoerror;
16441694
}
16451695

@@ -1649,7 +1699,11 @@ pgstat_read_statsfile(void)
16491699
if (!read_chunk(fpin,
16501700
pgstat_get_entry_data(key.kind,header),
16511701
pgstat_get_entry_len(key.kind)))
1702+
{
1703+
elog(WARNING,"could not read data for entry %d/%u/%u of type %c",
1704+
key.kind,key.dboid,key.objoid,t);
16521705
gotoerror;
1706+
}
16531707

16541708
break;
16551709
}
@@ -1660,11 +1714,15 @@ pgstat_read_statsfile(void)
16601714
* file
16611715
*/
16621716
if (fgetc(fpin)!=EOF)
1717+
{
1718+
elog(WARNING,"could not read end-of-file");
16631719
gotoerror;
1720+
}
16641721

16651722
gotodone;
16661723

16671724
default:
1725+
elog(WARNING,"could not read entry of type %c",t);
16681726
gotoerror;
16691727
}
16701728
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp