Fixed patch attached.
Regards,
Tarvi Pillessaar
On 24.08.2013 17:58, Peter Eisentraut wrote:
On Tue, 2013-08-20 at 19:21 +0300, Tarvi Pillessaar wrote:
About patch:
Patch is tested against 9.2.4.
I was not sure that i should check if the lock holder's proclock was
found (as lock holder's proclock should be always there), check is there
to be on the safe side, but maybe it's unnecessary.
If it's not needed then fallback to old behavior (logging without
detail) is not needed as well.
And yes, i know that the lock holding time is not actually correct and
it actually shows milliseconds since transaction start.
Please fix this compiler warning:
proc.c: In function ‘ProcSleep’:
proc.c:1258:6: warning: ISO C90 forbids mixed declarations and code
[-Wdeclaration-after-statement]
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 3bfdd23..d75ca93 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -49,6 +49,7 @@
#include "storage/procsignal.h"
#include "storage/spin.h"
#include "utils/timestamp.h"
+#include "pgstat.h"
/* GUC variables */
@@ -1198,9 +1199,67 @@ ProcSleep(LOCALLOCK *locallock, LockMethod lockMethodTable)
}
if (myWaitStatus == STATUS_WAITING)
- ereport(LOG,
- (errmsg("process %d still waiting for %s on %s after %ld.%03d ms",
- MyProcPid, modename, buf.data, msecs, usecs)));
+ {
+ PROCLOCK *proclock2;
+ PGPROC *proc2;
+ PgBackendStatus *be;
+ bool found = false;
+
+ /* find lock holder */
+ proclock2 = (PROCLOCK *) SHMQueueNext(&(lock->procLocks), &(lock->procLocks),
+ offsetof(PROCLOCK, lockLink));
+ while (proclock2)
+ {
+ if (lockMethodTable->conflictTab[lockmode] & proclock2->holdMask)
+ break;
+
+ proclock2 = (PROCLOCK *) SHMQueueNext(&(lock->procLocks), &proclock2->lockLink,
+ offsetof(PROCLOCK, lockLink));
+ }
+
+ if (proclock2)
+ {
+ int numbackends;
+
+ /* get lock holder's beentry */
+ proc2 = proclock2->tag.myProc;
+ numbackends = pgstat_fetch_stat_numbackends();
+ for (i = 1; i <= numbackends; i++)
+ {
+ be = pgstat_fetch_stat_beentry(i);
+ if (be)
+ {
+ if (be->st_procpid == proc2->pid)
+ {
+ found = true;
+ break;
+ }
+ }
+ }
+ }
+
+ if (found)
+ {
+ long secs2;
+ int usecs2;
+ long msecs2;
+
+ /* calculate lock holder's tx duration */
+ TimestampDifference(be->st_xact_start_timestamp, GetCurrentTimestamp(), &secs2, &usecs2);
+ msecs2 = secs2 * 1000 + usecs2 / 1000;
+ usecs2 = usecs2 % 1000;
+
+ ereport(LOG,
+ (errmsg("process %d still waiting for %s on %s after %ld.%03d ms",
+ MyProcPid, modename, buf.data, msecs, usecs),
+ errdetail_log("process %d is holding lock for %ld.%03d ms, activity: %s",
+ proc2->pid, msecs2, usecs2, be->st_activity)));
+ }
+ else
+ ereport(LOG,
+ (errmsg("process %d still waiting for %s on %s after %ld.%03d ms",
+ MyProcPid, modename, buf.data, msecs, usecs)));
+ }
else if (myWaitStatus == STATUS_OK)
ereport(LOG,
(errmsg("process %d acquired %s on %s after %ld.%03d ms",
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers