@@ -166,7 +166,7 @@ typedef struct PgStat_SnapshotEntry
166
166
static void pgstat_write_statsfile (void );
167
167
static void pgstat_read_statsfile (void );
168
168
169
- static void pgstat_reset_after_failure (TimestampTz ts );
169
+ static void pgstat_reset_after_failure (void );
170
170
171
171
static bool pgstat_flush_pending_entries (bool nowait );
172
172
@@ -427,6 +427,12 @@ pgstat_discard_stats(void)
427
427
errmsg ("unlinked permanent statistics file \"%s\"" ,
428
428
PGSTAT_STAT_PERMANENT_FILENAME )));
429
429
}
430
+
431
+ /*
432
+ * Reset stats contents. This will set reset timestamps of fixed-numbered
433
+ * stats to the current time (no variable stats exist).
434
+ */
435
+ pgstat_reset_after_failure ();
430
436
}
431
437
432
438
/*
@@ -1422,7 +1428,6 @@ pgstat_read_statsfile(void)
1422
1428
bool found ;
1423
1429
const char * statfile = PGSTAT_STAT_PERMANENT_FILENAME ;
1424
1430
PgStat_ShmemControl * shmem = pgStatLocal .shmem ;
1425
- TimestampTz ts = GetCurrentTimestamp ();
1426
1431
1427
1432
/* shouldn't be called from postmaster */
1428
1433
Assert (IsUnderPostmaster || !IsPostmasterEnvironment );
@@ -1445,7 +1450,7 @@ pgstat_read_statsfile(void)
1445
1450
(errcode_for_file_access (),
1446
1451
errmsg ("could not open statistics file \"%s\": %m" ,
1447
1452
statfile )));
1448
- pgstat_reset_after_failure (ts );
1453
+ pgstat_reset_after_failure ();
1449
1454
return ;
1450
1455
}
1451
1456
@@ -1597,19 +1602,20 @@ pgstat_read_statsfile(void)
1597
1602
ereport (LOG ,
1598
1603
(errmsg ("corrupted statistics file \"%s\"" , statfile )));
1599
1604
1600
- /* Set the current timestamp as reset timestamp */
1601
- pgstat_reset_after_failure (ts );
1605
+ pgstat_reset_after_failure ();
1602
1606
1603
1607
goto done ;
1604
1608
}
1605
1609
1606
1610
/*
1607
- * Helper to reset / drop stats after restoring stats from disk failed,
1608
- * potentially after already loading parts.
1611
+ * Helper to reset / drop stats after a crash or after restoring stats from
1612
+ * disk failed, potentially after already loading parts.
1609
1613
*/
1610
1614
static void
1611
- pgstat_reset_after_failure (TimestampTz ts )
1615
+ pgstat_reset_after_failure (void )
1612
1616
{
1617
+ TimestampTz ts = GetCurrentTimestamp ();
1618
+
1613
1619
/* reset fixed-numbered stats */
1614
1620
for (int kind = PGSTAT_KIND_FIRST_VALID ; kind <= PGSTAT_KIND_LAST ; kind ++ )
1615
1621
{
0 commit comments