Re: understanding pg_locks

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Ben Chobot <bench(at)silentmedia(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: understanding pg_locks
Date: 2011-05-21 15:53:17
Message-ID: 1869.1305993197@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ben Chobot <bench(at)silentmedia(dot)com> writes:
> We recently had an issue where a misbehaving application was running a long transaction that modified a bunch of rows, and this was holding up other transactions that wanted to do similar modifications. No surprising there. But what I'm unclear of is how this was showing up in pg_locks. The blocked transactions were all waiting on the transactionid of the long-running transaction, not any particular relation or tuple. Why doesn't pg_locks show the actual blockage?

We don't try to record individual tuple locks in pg_locks (or more
accurately, in the shared-memory data structure that pg_locks presents a
view of), because it wouldn't be hard at all for applications to blow
out the limited amount of space in shared memory if we did. Instead,
this type of case is represented as you see, with the waiter(s) blocked
on the XID of the transaction that's modified and not yet committed the
row. The actual holder of the row lock is indicated in the tuple's
on-disk state.

In recent PG versions you can find out which tuple is at stake. I don't
remember the exact details offhand, but there should be at least one
waiting transaction (*not* the successful updater) that is holding a
pg_locks tuple lock on the tuple in question. This will be released as
soon as it's successfully locked the tuple on-disk.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dan S 2011-05-21 16:08:29 Re: counterintuitive behaviour in pl/pgsql
Previous Message Michael Glaesemann 2011-05-21 15:39:51 Re: counterintuitive behaviour in pl/pgsql