aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/storage/ipc/standby.c9
-rw-r--r--src/backend/utils/activity/pgstat.c17
2 files changed, 23 insertions, 3 deletions
diff --git a/src/backend/storage/ipc/standby.c b/src/backend/storage/ipc/standby.c
index ffe5e1563f5..70b0da50fc1 100644
--- a/src/backend/storage/ipc/standby.c
+++ b/src/backend/storage/ipc/standby.c
@@ -1193,6 +1193,15 @@ standby_redo(XLogReaderState *record)
running.xids = xlrec->xids;
ProcArrayApplyRecoveryInfo(&running);
+
+ /*
+ * The startup process currently has no convenient way to schedule
+ * stats to be reported. XLOG_RUNNING_XACTS records issued at a
+ * regular cadence, making this a convenient location to report
+ * stats. While these records aren't generated with wal_level=minimal,
+ * stats also cannot be accessed during WAL replay.
+ */
+ pgstat_report_stat(true);
}
else if (info == XLOG_INVALIDATIONS)
{
diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c
index 0cdb552631e..d743fc0b289 100644
--- a/src/backend/utils/activity/pgstat.c
+++ b/src/backend/utils/activity/pgstat.c
@@ -615,10 +615,21 @@ pgstat_report_stat(bool force)
*/
Assert(!pgStatLocal.shmem->is_shutdown);
- now = GetCurrentTransactionStopTimestamp();
-
- if (!force)
+ if (force)
{
+ /*
+ * Stats reports are forced either when it's been too long since stats
+ * have been reported or in processes that force stats reporting to
+ * happen at specific points (including shutdown). In the former case
+ * the transaction stop time might be quite old, in the latter it
+ * would never get cleared.
+ */
+ now = GetCurrentTimestamp();
+ }
+ else
+ {
+ now = GetCurrentTransactionStopTimestamp();
+
if (pending_since > 0 &&
TimestampDifferenceExceeds(pending_since, now, PGSTAT_MAX_INTERVAL))
{