Re: pg_locks "at-a-glance" view

From: Decibel! <decibel(at)decibel(dot)org>
To: David Fetter <david(at)fetter(dot)org>
Cc: Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-general(at)postgresql(dot)org, Merlin Moncure <mmoncure(at)gmail(dot)com>
Subject: Re: pg_locks "at-a-glance" view
Date: 2008-06-19 16:02:32
Message-ID: F1FB17B1-AA42-45F1-82F2-347CB604FAA4@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jun 19, 2008, at 8:07 AM, David Fetter wrote:
> On Wed, Jun 18, 2008 at 05:39:59PM -0700, Jeff Davis wrote:
>> I was trying to create a more "at-a-glance" view of the pg_locks
>> table.
>> I included the SQL I came up with (after talking to Merlin) at the
>> bottom of this message.
>>
>> The idea is to show any queries that are waiting on a lock, and the
>> query that currently holds the lock on which those queries are
>> waiting.
>>
>> Is my logic correct?
>
> I'm not exactly sure, but it appears to match, at first blush, what's
> in src/backend/storage/lmgr/lock.c:
> static const LOCKMASK LockConflicts[] = {

Yeah, if you look at the code, locks are defined as numbers and I
believe there's a very simple patter of what conflicts; a higher lock
number conflicts with all those that are lower. So, it might be a lot
cleaner to have a function that defines numbers for all the lock
modes and just test to see if one lock is higher than another.

I think your logic in the view is correct. It might be helpful to
also list how long the queries have been running.

I really wish we had some kind of a site for listing useful queries
like this...
--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2008-06-19 16:11:43 Re: pg_locks "at-a-glance" view
Previous Message Garry Saddington 2008-06-19 15:55:41 Losing data