1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-07 12:02:30 +03:00

Implement rate-limiting logic on how often backends will attempt to send

messages to the stats collector.  This avoids the problem that enabling
stats_row_level for autovacuum has a significant overhead for short
read-only transactions, as noted by Arjen van der Meijden.  We can avoid
an extra gettimeofday call by piggybacking on the one done for WAL-logging
xact commit or abort (although that doesn't help read-only transactions,
since they don't WAL-log anything).

In my proposal for this, I noted that we could change the WAL log entries
for commit/abort to record full TimestampTz precision, instead of only
time_t as at present.  That's not done in this patch, but will be committed
separately.
This commit is contained in:
Tom Lane
2007-04-30 03:23:49 +00:00
parent 57b82bf324
commit 957d08c81f
9 changed files with 104 additions and 47 deletions

View File

@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2007, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.153 2007/04/21 04:10:53 tgl Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.154 2007/04/30 03:23:49 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -608,15 +608,34 @@ void allow_immediate_pgstat_restart(void)
/* ----------
* pgstat_report_tabstat() -
*
* Called from tcop/postgres.c to send the so far collected
* per table access statistics to the collector.
* Called from tcop/postgres.c to send the so far collected per-table
* access statistics to the collector. Note that this is called only
* when not within a transaction, so it is fair to use transaction stop
* time as an approximation of current time.
* ----------
*/
void
pgstat_report_tabstat(void)
{
static TimestampTz last_report = 0;
TimestampTz now;
/* Don't expend a clock check if nothing to do */
if (RegularTabStat.tsa_used == 0 &&
SharedTabStat.tsa_used == 0)
return;
/*
* For each message buffer used during the last query set the header
* Don't send a message unless it's been at least PGSTAT_STAT_INTERVAL
* msec since we last sent one.
*/
now = GetCurrentTransactionStopTimestamp();
if (!TimestampDifferenceExceeds(last_report, now, PGSTAT_STAT_INTERVAL))
return;
last_report = now;
/*
* For each message buffer used during the last queries, set the header
* fields and send it out; then mark the entries unused.
*/
pgstat_report_one_tabstat(&RegularTabStat, MyDatabaseId);