Skip to content

Commit e3cb1a5

Browse files
committed
Report stats when replaying XLOG_RUNNING_XACTS
Previously stats in the startup process would only get reported during shutdown of the startup process. It has been that way for a long time, but became a lot more noticeable with the new pg_stat_io view, which separates out IO done by different backend types... While replaying after every XLOG_RUNNING_XACTS isn't the prettiest approach, it has the advantage of being quite easy. Given that we're well past feature freeze... It's not a problem that we don't report stats more frequently with wal_level=minimal, in that case stats can't be read before the stats process has shut down. Besides the above, this commit also changes pgstat_report_stat() to acquire the timestamp with GetCurrentTimestamp() instead of GetCurrentTransactionStopTimestamp(). Thanks to Melih Mutlu, Kyotaro Horiguchi for prototypes of other approaches to solving this issue. Reported-by: Fujii Masao <masao.fujii@oss.nttdata.com> Discussion: https://postgr.es/m/5315aedc-fbca-1556-c5de-dc2e00b23a14@oss.nttdata.com
1 parent 7398e27 commit e3cb1a5

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/backend/storage/ipc/standby.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,15 @@ standby_redo(XLogReaderState *record)
11931193
running.xids = xlrec->xids;
11941194

11951195
ProcArrayApplyRecoveryInfo(&running);
1196+
1197+
/*
1198+
* The startup process currently has no convenient way to schedule
1199+
* stats to be reported. XLOG_RUNNING_XACTS records issued at a
1200+
* regular cadence, making this a convenient location to report
1201+
* stats. While these records aren't generated with wal_level=minimal,
1202+
* stats also cannot be accessed during WAL replay.
1203+
*/
1204+
pgstat_report_stat(true);
11961205
}
11971206
else if (info == XLOG_INVALIDATIONS)
11981207
{

src/backend/utils/activity/pgstat.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,10 +615,21 @@ pgstat_report_stat(bool force)
615615
*/
616616
Assert(!pgStatLocal.shmem->is_shutdown);
617617

618-
now = GetCurrentTransactionStopTimestamp();
619-
620-
if (!force)
618+
if (force)
621619
{
620+
/*
621+
* Stats reports are forced either when it's been too long since stats
622+
* have been reported or in processes that force stats reporting to
623+
* happen at specific points (including shutdown). In the former case
624+
* the transaction stop time might be quite old, in the latter it
625+
* would never get cleared.
626+
*/
627+
now = GetCurrentTimestamp();
628+
}
629+
else
630+
{
631+
now = GetCurrentTransactionStopTimestamp();
632+
622633
if (pending_since > 0 &&
623634
TimestampDifferenceExceeds(pending_since, now, PGSTAT_MAX_INTERVAL))
624635
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy