diff options
| author | Neil Conway <neilc@samurai.com> | 2006-12-06 18:06:48 +0000 |
|---|---|---|
| committer | Neil Conway <neilc@samurai.com> | 2006-12-06 18:06:48 +0000 |
| commit | 886a02d1cb19fe25859bd3c2d1f6a64b04cdc710 (patch) | |
| tree | a0684de747e49ba23b5c7fead1052d378ecbb4dd /src/backend/postmaster/pgstat.c | |
| parent | dd740e1fd066a5df628ba28dfdaee02d58dee0c5 (diff) | |
Add a txn_start column to pg_stat_activity. This makes it easier to
identify long-running transactions. Since we already need to record
the transaction-start time (e.g. for now()), we don't need any
additional system calls to report this information.
Catversion bumped, initdb required.
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
| -rw-r--r-- | src/backend/postmaster/pgstat.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 19a694caf30..ef9487ade03 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -13,7 +13,7 @@ * * Copyright (c) 2001-2006, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.140 2006/11/21 20:59:52 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.141 2006/12/06 18:06:47 neilc Exp $ * ---------- */ #include "postgres.h" @@ -1355,6 +1355,7 @@ pgstat_bestart(void) beentry->st_procpid = MyProcPid; beentry->st_proc_start_timestamp = proc_start_timestamp; beentry->st_activity_start_timestamp = 0; + beentry->st_txn_start_timestamp = 0; beentry->st_databaseid = MyDatabaseId; beentry->st_userid = userid; beentry->st_clientaddr = clientaddr; @@ -1443,6 +1444,29 @@ pgstat_report_activity(const char *cmd_str) Assert((beentry->st_changecount & 1) == 0); } +/* + * Set the current transaction start timestamp to the specified + * value. If there is no current active transaction, this is signified + * by 0. + */ +void +pgstat_report_txn_timestamp(TimestampTz tstamp) +{ + volatile PgBackendStatus *beentry = MyBEEntry; + + if (!pgstat_collect_querystring || !beentry) + return; + + /* + * Update my status entry, following the protocol of bumping + * st_changecount before and after. We use a volatile pointer + * here to ensure the compiler doesn't try to get cute. + */ + beentry->st_changecount++; + beentry->st_txn_start_timestamp = tstamp; + beentry->st_changecount++; + Assert((beentry->st_changecount & 1) == 0); +} /* ---------- * pgstat_report_waiting() - |
