mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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.
This commit is contained in:
@ -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() -
|
||||
|
Reference in New Issue
Block a user