From a8d1075f271458960da683e8ec28f5a656984159 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 18 Jun 2005 19:33:42 +0000 Subject: Add a time-of-preparation column to the pg_prepared_xacts view, per an old suggestion by Oliver Jowett. Also, add a transaction column to the pg_locks view to show the xid of each transaction holding or awaiting locks; this allows prepared transactions to be properly associated with the locks they own. There was already a column named 'transaction', and I chose to rename it to 'transactionid' --- since this column is new in the current devel cycle there should be no backwards compatibility issue to worry about. --- src/backend/utils/adt/lockfuncs.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/backend/utils/adt/lockfuncs.c') diff --git a/src/backend/utils/adt/lockfuncs.c b/src/backend/utils/adt/lockfuncs.c index e941ec2d3d8..0bdf918e475 100644 --- a/src/backend/utils/adt/lockfuncs.c +++ b/src/backend/utils/adt/lockfuncs.c @@ -6,7 +6,7 @@ * Copyright (c) 2002-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.18 2005/05/17 21:46:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/lockfuncs.c,v 1.19 2005/06/18 19:33:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -26,7 +26,7 @@ static const char * const LockTagTypeNames[] = { "extend", "page", "tuple", - "transaction", + "transactionid", "object", "userlock" }; @@ -64,7 +64,7 @@ pg_lock_status(PG_FUNCTION_ARGS) /* build tupdesc for result tuples */ /* this had better match pg_locks view in system_views.sql */ - tupdesc = CreateTemplateTupleDesc(12, false); + tupdesc = CreateTemplateTupleDesc(13, false); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "locktype", TEXTOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database", @@ -75,7 +75,7 @@ pg_lock_status(PG_FUNCTION_ARGS) INT4OID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 5, "tuple", INT2OID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 6, "transaction", + TupleDescInitEntry(tupdesc, (AttrNumber) 6, "transactionid", XIDOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 7, "classid", OIDOID, -1, 0); @@ -83,11 +83,13 @@ pg_lock_status(PG_FUNCTION_ARGS) OIDOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) 9, "objsubid", INT2OID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 10, "pid", + TupleDescInitEntry(tupdesc, (AttrNumber) 10, "transaction", + XIDOID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 11, "pid", INT4OID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 11, "mode", + TupleDescInitEntry(tupdesc, (AttrNumber) 12, "mode", TEXTOID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 12, "granted", + TupleDescInitEntry(tupdesc, (AttrNumber) 13, "granted", BOOLOID, -1, 0); funcctx->tuple_desc = BlessTupleDesc(tupdesc); @@ -118,8 +120,8 @@ pg_lock_status(PG_FUNCTION_ARGS) LOCKMODE mode = 0; const char *locktypename; char tnbuf[32]; - Datum values[12]; - char nulls[12]; + Datum values[13]; + char nulls[13]; HeapTuple tuple; Datum result; @@ -249,10 +251,14 @@ pg_lock_status(PG_FUNCTION_ARGS) break; } - values[9] = Int32GetDatum(proc->pid); - values[10] = DirectFunctionCall1(textin, + values[9] = TransactionIdGetDatum(proc->xid); + if (proc->pid != 0) + values[10] = Int32GetDatum(proc->pid); + else + nulls[10] = 'n'; + values[11] = DirectFunctionCall1(textin, CStringGetDatum(GetLockmodeName(mode))); - values[11] = BoolGetDatum(granted); + values[12] = BoolGetDatum(granted); tuple = heap_formtuple(funcctx->tuple_desc, values, nulls); result = HeapTupleGetDatum(tuple); -- cgit v1.2.3