13
13
*
14
14
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
15
15
*
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 $
17
17
* ----------
18
18
*/
19
19
#include "postgres.h"
@@ -1177,12 +1177,10 @@ pgstat_reset_shared_counters(const char *target)
1177
1177
if (strcmp (target , "bgwriter" ) == 0 )
1178
1178
msg .m_resettarget = RESET_BGWRITER ;
1179
1179
else
1180
- {
1181
1180
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\"." )));
1186
1184
1187
1185
pgstat_setheader (& msg .m_hdr , PGSTAT_MTYPE_RESETSHAREDCOUNTER );
1188
1186
pgstat_send (& msg , sizeof (msg ));
@@ -3292,11 +3290,15 @@ pgstat_write_statsfile(bool permanent)
3292
3290
/*
3293
3291
* It's not entirely clear whether there could be clock skew between
3294
3292
* backends and the collector; but just in case someone manages to
3295
- * send us a stats request time that's far in the future, reset it.
3293
+ * send us a stats request time that's in the future, reset it.
3296
3294
* This ensures that no inquiry message can cause more than one stats
3297
3295
* file write to occur.
3298
3296
*/
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
+ }
3300
3302
}
3301
3303
3302
3304
if (permanent )
@@ -3355,9 +3357,20 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3355
3357
* Try to open the status file. If it doesn't exist, the backends simply
3356
3358
* return zero for anything and the collector simply starts from scratch
3357
3359
* 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.
3358
3364
*/
3359
3365
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 )));
3360
3372
return dbhash ;
3373
+ }
3361
3374
3362
3375
/*
3363
3376
* Verify it's of the expected format.
@@ -3366,7 +3379,7 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3366
3379
|| format_id != PGSTAT_FILE_FORMAT_ID )
3367
3380
{
3368
3381
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3369
- (errmsg ("corrupted pgstat.stat file" )));
3382
+ (errmsg ("corrupted statistics file \"%s\"" , statfile )));
3370
3383
goto done ;
3371
3384
}
3372
3385
@@ -3376,7 +3389,7 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3376
3389
if (fread (& globalStats , 1 , sizeof (globalStats ), fpin ) != sizeof (globalStats ))
3377
3390
{
3378
3391
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3379
- (errmsg ("corrupted pgstat.stat file" )));
3392
+ (errmsg ("corrupted statistics file \"%s\"" , statfile )));
3380
3393
goto done ;
3381
3394
}
3382
3395
@@ -3398,7 +3411,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3398
3411
fpin ) != offsetof(PgStat_StatDBEntry , tables ))
3399
3412
{
3400
3413
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3401
- (errmsg ("corrupted pgstat.stat file" )));
3414
+ (errmsg ("corrupted statistics file \"%s\"" ,
3415
+ statfile )));
3402
3416
goto done ;
3403
3417
}
3404
3418
@@ -3412,7 +3426,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3412
3426
if (found )
3413
3427
{
3414
3428
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3415
- (errmsg ("corrupted pgstat.stat file" )));
3429
+ (errmsg ("corrupted statistics file \"%s\"" ,
3430
+ statfile )));
3416
3431
goto done ;
3417
3432
}
3418
3433
@@ -3474,7 +3489,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3474
3489
fpin ) != sizeof (PgStat_StatTabEntry ))
3475
3490
{
3476
3491
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3477
- (errmsg ("corrupted pgstat.stat file" )));
3492
+ (errmsg ("corrupted statistics file \"%s\"" ,
3493
+ statfile )));
3478
3494
goto done ;
3479
3495
}
3480
3496
@@ -3491,7 +3507,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3491
3507
if (found )
3492
3508
{
3493
3509
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3494
- (errmsg ("corrupted pgstat.stat file" )));
3510
+ (errmsg ("corrupted statistics file \"%s\"" ,
3511
+ statfile )));
3495
3512
goto done ;
3496
3513
}
3497
3514
@@ -3506,7 +3523,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3506
3523
fpin ) != sizeof (PgStat_StatFuncEntry ))
3507
3524
{
3508
3525
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3509
- (errmsg ("corrupted pgstat.stat file" )));
3526
+ (errmsg ("corrupted statistics file \"%s\"" ,
3527
+ statfile )));
3510
3528
goto done ;
3511
3529
}
3512
3530
@@ -3523,7 +3541,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3523
3541
if (found )
3524
3542
{
3525
3543
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3526
- (errmsg ("corrupted pgstat.stat file" )));
3544
+ (errmsg ("corrupted statistics file \"%s\"" ,
3545
+ statfile )));
3527
3546
goto done ;
3528
3547
}
3529
3548
@@ -3538,7 +3557,8 @@ pgstat_read_statsfile(Oid onlydb, bool permanent)
3538
3557
3539
3558
default :
3540
3559
ereport (pgStatRunningInCollector ? LOG : WARNING ,
3541
- (errmsg ("corrupted pgstat.stat file" )));
3560
+ (errmsg ("corrupted statistics file \"%s\"" ,
3561
+ statfile )));
3542
3562
goto done ;
3543
3563
}
3544
3564
}
@@ -3568,17 +3588,27 @@ pgstat_read_statsfile_timestamp(bool permanent, TimestampTz *ts)
3568
3588
const char * statfile = permanent ? PGSTAT_STAT_PERMANENT_FILENAME : pgstat_stat_filename ;
3569
3589
3570
3590
/*
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.
3572
3593
*/
3573
3594
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 )));
3574
3601
return false;
3602
+ }
3575
3603
3576
3604
/*
3577
3605
* Verify it's of the expected format.
3578
3606
*/
3579
3607
if (fread (& format_id , 1 , sizeof (format_id ), fpin ) != sizeof (format_id )
3580
3608
|| format_id != PGSTAT_FILE_FORMAT_ID )
3581
3609
{
3610
+ ereport (pgStatRunningInCollector ? LOG : WARNING ,
3611
+ (errmsg ("corrupted statistics file \"%s\"" , statfile )));
3582
3612
FreeFile (fpin );
3583
3613
return false;
3584
3614
}
@@ -3588,6 +3618,8 @@ pgstat_read_statsfile_timestamp(bool permanent, TimestampTz *ts)
3588
3618
*/
3589
3619
if (fread (& myGlobalStats , 1 , sizeof (myGlobalStats ), fpin ) != sizeof (myGlobalStats ))
3590
3620
{
3621
+ ereport (pgStatRunningInCollector ? LOG : WARNING ,
3622
+ (errmsg ("corrupted statistics file \"%s\"" , statfile )));
3591
3623
FreeFile (fpin );
3592
3624
return false;
3593
3625
}
0 commit comments