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

Commit52e2b33

Browse files
committed
Add some logging code for unexpected cases in pgstat.c, particularly being
unable to read a stats file for reasons other than ENOENT, and having to resetlast_statrequest because it's later than current time in the collector.Not clear if this will shed any light on the "pgstat wait timeout" business,but it seems like a good idea in general.In passing, do some message-style-police work on recently-addedpgstat_reset_shared_counters code.
1 parentd75f7a0 commit52e2b33

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

‎src/backend/postmaster/pgstat.c

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2010, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.201 2010/02/26 02:00:55 momjian Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.202 2010/03/12 22:19:19 tgl Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -1177,12 +1177,10 @@ pgstat_reset_shared_counters(const char *target)
11771177
if (strcmp(target,"bgwriter")==0)
11781178
msg.m_resettarget=RESET_BGWRITER;
11791179
else
1180-
{
11811180
ereport(ERROR,
1182-
(errcode(ERRCODE_SYNTAX_ERROR),
1183-
errmsg("unrecognized reset target: '%s'",target),
1184-
errhint("allowed targets are 'bgwriter'.")));
1185-
}
1181+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1182+
errmsg("unrecognized reset target: \"%s\"",target),
1183+
errhint("Target must be \"bgwriter\".")));
11861184

11871185
pgstat_setheader(&msg.m_hdr,PGSTAT_MTYPE_RESETSHAREDCOUNTER);
11881186
pgstat_send(&msg,sizeof(msg));
@@ -3292,11 +3290,15 @@ pgstat_write_statsfile(bool permanent)
32923290
/*
32933291
* It's not entirely clear whether there could be clock skew between
32943292
* backends and the collector; but just in case someone manages to
3295-
* send us a stats request time that'sfarin the future, reset it.
3293+
* send us a stats request time that's in the future, reset it.
32963294
* This ensures that no inquiry message can cause more than one stats
32973295
* file write to occur.
32983296
*/
3299-
last_statrequest=last_statwrite;
3297+
if (last_statrequest>last_statwrite)
3298+
{
3299+
elog(LOG,"last_statrequest is in the future, resetting");
3300+
last_statrequest=last_statwrite;
3301+
}
33003302
}
33013303

33023304
if (permanent)
@@ -3355,9 +3357,20 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
33553357
* Try to open the status file. If it doesn't exist, the backends simply
33563358
* return zero for anything and the collector simply starts from scratch
33573359
* with empty counters.
3360+
*
3361+
* ENOENT is a possibility if the stats collector is not running or has
3362+
* not yet written the stats file the first time. Any other failure
3363+
* condition is suspicious.
33583364
*/
33593365
if ((fpin=AllocateFile(statfile,PG_BINARY_R))==NULL)
3366+
{
3367+
if (errno!=ENOENT)
3368+
ereport(pgStatRunningInCollector ?LOG :WARNING,
3369+
(errcode_for_file_access(),
3370+
errmsg("could not open statistics file \"%s\": %m",
3371+
statfile)));
33603372
returndbhash;
3373+
}
33613374

33623375
/*
33633376
* Verify it's of the expected format.
@@ -3366,7 +3379,7 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
33663379
||format_id!=PGSTAT_FILE_FORMAT_ID)
33673380
{
33683381
ereport(pgStatRunningInCollector ?LOG :WARNING,
3369-
(errmsg("corruptedpgstat.stat file")));
3382+
(errmsg("corruptedstatistics file \"%s\"",statfile)));
33703383
gotodone;
33713384
}
33723385

@@ -3376,7 +3389,7 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
33763389
if (fread(&globalStats,1,sizeof(globalStats),fpin)!=sizeof(globalStats))
33773390
{
33783391
ereport(pgStatRunningInCollector ?LOG :WARNING,
3379-
(errmsg("corruptedpgstat.stat file")));
3392+
(errmsg("corruptedstatistics file \"%s\"",statfile)));
33803393
gotodone;
33813394
}
33823395

@@ -3398,7 +3411,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
33983411
fpin)!= offsetof(PgStat_StatDBEntry,tables))
33993412
{
34003413
ereport(pgStatRunningInCollector ?LOG :WARNING,
3401-
(errmsg("corrupted pgstat.stat file")));
3414+
(errmsg("corrupted statistics file \"%s\"",
3415+
statfile)));
34023416
gotodone;
34033417
}
34043418

@@ -3412,7 +3426,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
34123426
if (found)
34133427
{
34143428
ereport(pgStatRunningInCollector ?LOG :WARNING,
3415-
(errmsg("corrupted pgstat.stat file")));
3429+
(errmsg("corrupted statistics file \"%s\"",
3430+
statfile)));
34163431
gotodone;
34173432
}
34183433

@@ -3474,7 +3489,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
34743489
fpin)!=sizeof(PgStat_StatTabEntry))
34753490
{
34763491
ereport(pgStatRunningInCollector ?LOG :WARNING,
3477-
(errmsg("corrupted pgstat.stat file")));
3492+
(errmsg("corrupted statistics file \"%s\"",
3493+
statfile)));
34783494
gotodone;
34793495
}
34803496

@@ -3491,7 +3507,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
34913507
if (found)
34923508
{
34933509
ereport(pgStatRunningInCollector ?LOG :WARNING,
3494-
(errmsg("corrupted pgstat.stat file")));
3510+
(errmsg("corrupted statistics file \"%s\"",
3511+
statfile)));
34953512
gotodone;
34963513
}
34973514

@@ -3506,7 +3523,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
35063523
fpin)!=sizeof(PgStat_StatFuncEntry))
35073524
{
35083525
ereport(pgStatRunningInCollector ?LOG :WARNING,
3509-
(errmsg("corrupted pgstat.stat file")));
3526+
(errmsg("corrupted statistics file \"%s\"",
3527+
statfile)));
35103528
gotodone;
35113529
}
35123530

@@ -3523,7 +3541,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
35233541
if (found)
35243542
{
35253543
ereport(pgStatRunningInCollector ?LOG :WARNING,
3526-
(errmsg("corrupted pgstat.stat file")));
3544+
(errmsg("corrupted statistics file \"%s\"",
3545+
statfile)));
35273546
gotodone;
35283547
}
35293548

@@ -3538,7 +3557,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
35383557

35393558
default:
35403559
ereport(pgStatRunningInCollector ?LOG :WARNING,
3541-
(errmsg("corrupted pgstat.stat file")));
3560+
(errmsg("corrupted statistics file \"%s\"",
3561+
statfile)));
35423562
gotodone;
35433563
}
35443564
}
@@ -3568,17 +3588,27 @@ pgstat_read_statsfile_timestamp(bool permanent, TimestampTz *ts)
35683588
constchar*statfile=permanent ?PGSTAT_STAT_PERMANENT_FILENAME :pgstat_stat_filename;
35693589

35703590
/*
3571-
* Try to open the status file.
3591+
* Try to open the status file. As above, anything but ENOENT is worthy
3592+
* of complaining about.
35723593
*/
35733594
if ((fpin=AllocateFile(statfile,PG_BINARY_R))==NULL)
3595+
{
3596+
if (errno!=ENOENT)
3597+
ereport(pgStatRunningInCollector ?LOG :WARNING,
3598+
(errcode_for_file_access(),
3599+
errmsg("could not open statistics file \"%s\": %m",
3600+
statfile)));
35743601
return false;
3602+
}
35753603

35763604
/*
35773605
* Verify it's of the expected format.
35783606
*/
35793607
if (fread(&format_id,1,sizeof(format_id),fpin)!=sizeof(format_id)
35803608
||format_id!=PGSTAT_FILE_FORMAT_ID)
35813609
{
3610+
ereport(pgStatRunningInCollector ?LOG :WARNING,
3611+
(errmsg("corrupted statistics file \"%s\"",statfile)));
35823612
FreeFile(fpin);
35833613
return false;
35843614
}
@@ -3588,6 +3618,8 @@ pgstat_read_statsfile_timestamp(bool permanent, TimestampTz *ts)
35883618
*/
35893619
if (fread(&myGlobalStats,1,sizeof(myGlobalStats),fpin)!=sizeof(myGlobalStats))
35903620
{
3621+
ereport(pgStatRunningInCollector ?LOG :WARNING,
3622+
(errmsg("corrupted statistics file \"%s\"",statfile)));
35913623
FreeFile(fpin);
35923624
return false;
35933625
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp