aboutsummaryrefslogtreecommitdiff
path: root/src/backend/tcop/postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/tcop/postgres.c')
-rw-r--r--src/backend/tcop/postgres.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 260b650f15f..95dc2e2c835 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3372,6 +3372,14 @@ ProcessInterrupts(void)
IdleSessionTimeoutPending = false;
}
+ if (IdleStatsUpdateTimeoutPending)
+ {
+ /* timer should have been disarmed */
+ Assert(!IsTransactionBlock());
+ IdleStatsUpdateTimeoutPending = false;
+ pgstat_report_stat(true);
+ }
+
if (ProcSignalBarrierPending)
ProcessProcSignalBarrier();
@@ -4044,6 +4052,7 @@ PostgresMain(const char *dbname, const char *username)
volatile bool send_ready_for_query = true;
bool idle_in_transaction_timeout_enabled = false;
bool idle_session_timeout_enabled = false;
+ bool idle_stats_update_timeout_enabled = false;
AssertArg(dbname != NULL);
AssertArg(username != NULL);
@@ -4407,6 +4416,8 @@ PostgresMain(const char *dbname, const char *username)
}
else
{
+ long stats_timeout;
+
/*
* Process incoming notifies (including self-notifies), if
* any, and send relevant messages to the client. Doing it
@@ -4417,7 +4428,14 @@ PostgresMain(const char *dbname, const char *username)
if (notifyInterruptPending)
ProcessNotifyInterrupt(false);
- pgstat_report_stat(false);
+ /* Start the idle-stats-update timer */
+ stats_timeout = pgstat_report_stat(false);
+ if (stats_timeout > 0)
+ {
+ idle_stats_update_timeout_enabled = true;
+ enable_timeout_after(IDLE_STATS_UPDATE_TIMEOUT,
+ stats_timeout);
+ }
set_ps_display("idle");
pgstat_report_activity(STATE_IDLE, NULL);
@@ -4452,9 +4470,9 @@ PostgresMain(const char *dbname, const char *username)
firstchar = ReadCommand(&input_message);
/*
- * (4) turn off the idle-in-transaction and idle-session timeouts, if
- * active. We do this before step (5) so that any last-moment timeout
- * is certain to be detected in step (5).
+ * (4) turn off the idle-in-transaction, idle-session and
+ * idle-stats-update timeouts if active. We do this before step (5) so
+ * that any last-moment timeout is certain to be detected in step (5).
*
* At most one of these timeouts will be active, so there's no need to
* worry about combining the timeout.c calls into one.
@@ -4469,6 +4487,11 @@ PostgresMain(const char *dbname, const char *username)
disable_timeout(IDLE_SESSION_TIMEOUT, false);
idle_session_timeout_enabled = false;
}
+ if (idle_stats_update_timeout_enabled)
+ {
+ disable_timeout(IDLE_STATS_UPDATE_TIMEOUT, false);
+ idle_stats_update_timeout_enabled = false;
+ }
/*
* (5) disable async signal conditions again.