aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pgstatfuncs.c
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2006-12-06 18:06:48 +0000
committerNeil Conway <neilc@samurai.com>2006-12-06 18:06:48 +0000
commit886a02d1cb19fe25859bd3c2d1f6a64b04cdc710 (patch)
treea0684de747e49ba23b5c7fead1052d378ecbb4dd /src/backend/utils/adt/pgstatfuncs.c
parentdd740e1fd066a5df628ba28dfdaee02d58dee0c5 (diff)
downloadpostgresql-886a02d1cb19fe25859bd3c2d1f6a64b04cdc710.tar.gz
postgresql-886a02d1cb19fe25859bd3c2d1f6a64b04cdc710.zip
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/utils/adt/pgstatfuncs.c')
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index e2d302b5a64..18709a981d4 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.34 2006/10/04 00:29:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.35 2006/12/06 18:06:47 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -44,6 +44,7 @@ extern Datum pg_stat_get_backend_userid(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_activity(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_waiting(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_backend_txn_start(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_start(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_client_addr(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_backend_client_port(PG_FUNCTION_ARGS);
@@ -422,6 +423,29 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(result);
}
+
+Datum
+pg_stat_get_backend_txn_start(PG_FUNCTION_ARGS)
+{
+ int32 beid = PG_GETARG_INT32(0);
+ TimestampTz result;
+ PgBackendStatus *beentry;
+
+ if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
+ PG_RETURN_NULL();
+
+ if (!superuser() && beentry->st_userid != GetUserId())
+ PG_RETURN_NULL();
+
+ result = beentry->st_txn_start_timestamp;
+
+ if (result == 0) /* not in a transaction */
+ PG_RETURN_NULL();
+
+ PG_RETURN_TIMESTAMPTZ(result);
+}
+
+
Datum
pg_stat_get_backend_start(PG_FUNCTION_ARGS)
{