diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-30 03:23:49 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-04-30 03:23:49 +0000 |
commit | 957d08c81f9cc277725c83b9381c5154b6318a5e (patch) | |
tree | 1c665d6e63c2cb02156df44a3519d2a0bebcaea3 /src/backend/access/transam | |
parent | 57b82bf324285464783796e5614d5f9aadd0817f (diff) | |
download | postgresql-957d08c81f9cc277725c83b9381c5154b6318a5e.tar.gz postgresql-957d08c81f9cc277725c83b9381c5154b6318a5e.zip |
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.
Diffstat (limited to 'src/backend/access/transam')
-rw-r--r-- | src/backend/access/transam/xact.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d705d7a5c1e..e3f16d38a5b 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.240 2007/04/26 23:24:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.241 2007/04/30 03:23:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -160,11 +160,13 @@ static CommandId currentCommandId; /* * xactStartTimestamp is the value of transaction_timestamp(). * stmtStartTimestamp is the value of statement_timestamp(). + * xactStopTimestamp is the time at which we log a commit or abort WAL record. * These do not change as we enter and exit subtransactions, so we don't * keep them inside the TransactionState stack. */ static TimestampTz xactStartTimestamp; static TimestampTz stmtStartTimestamp; +static TimestampTz xactStopTimestamp; /* * GID to be used for preparing the current transaction. This is also @@ -436,6 +438,20 @@ GetCurrentStatementStartTimestamp(void) } /* + * GetCurrentTransactionStopTimestamp + * + * We return current time if the transaction stop time hasn't been set + * (which can happen if we decide we don't need to log an XLOG record). + */ +TimestampTz +GetCurrentTransactionStopTimestamp(void) +{ + if (xactStopTimestamp != 0) + return xactStopTimestamp; + return GetCurrentTimestamp(); +} + +/* * SetCurrentStatementStartTimestamp */ void @@ -445,6 +461,15 @@ SetCurrentStatementStartTimestamp(void) } /* + * SetCurrentTransactionStopTimestamp + */ +static inline void +SetCurrentTransactionStopTimestamp(void) +{ + xactStopTimestamp = GetCurrentTimestamp(); +} + +/* * GetCurrentTransactionNestLevel * * Note: this will return zero when not inside any transaction, one when @@ -747,7 +772,8 @@ RecordTransactionCommit(void) */ MyProc->inCommit = true; - xlrec.xtime = time(NULL); + SetCurrentTransactionStopTimestamp(); + xlrec.xtime = timestamptz_to_time_t(xactStopTimestamp); xlrec.nrels = nrels; xlrec.nsubxacts = nchildren; rdata[0].data = (char *) (&xlrec); @@ -1042,7 +1068,8 @@ RecordTransactionAbort(void) xl_xact_abort xlrec; XLogRecPtr recptr; - xlrec.xtime = time(NULL); + SetCurrentTransactionStopTimestamp(); + xlrec.xtime = timestamptz_to_time_t(xactStopTimestamp); xlrec.nrels = nrels; xlrec.nsubxacts = nchildren; rdata[0].data = (char *) (&xlrec); @@ -1415,9 +1442,11 @@ StartTransaction(void) /* * set transaction_timestamp() (a/k/a now()). We want this to be the same * as the first command's statement_timestamp(), so don't do a fresh - * GetCurrentTimestamp() call (which'd be expensive anyway). + * GetCurrentTimestamp() call (which'd be expensive anyway). Also, + * mark xactStopTimestamp as unset. */ xactStartTimestamp = stmtStartTimestamp; + xactStopTimestamp = 0; pgstat_report_txn_timestamp(xactStartTimestamp); /* |