Unix Technical Forum

lock query

This is a discussion on lock query within the Pgsql General forums, part of the PostgreSQL category; --> I wonder if anyone might help me generate a SQL query that peers into pg_locks, pg_stat_activity, etc and tells ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-09-2008, 02:25 PM
Ed L.
 
Posts: n/a
Default lock query


I wonder if anyone might help me generate a SQL query that peers
into pg_locks, pg_stat_activity, etc and tells in plain language
exactly *who* each backend is blocked *on* while awaiting
lock(s).

Here's what I'm looking at now:

SELECT date_trunc('second', now()) as now, a.client_addr as ip,
l.pid, l.locktype, l.mode, l.granted,
r.relname, l.page, l.tuple, l.transactionid,
a.query_start, a.current_query as sql
FROM pg_locks l LEFT OUTER JOIN pg_class r ON r.oid = l.relation
LEFT OUTER JOIN pg_stat_activity a ON l.pid =
a.procpid
ORDER BY a.query_start ASC;

For busy systems with hundreds of backends and hundreds of
queries per second, I find the output of this query very
difficult to quickly who is holding the key lock(s) on which
blocked backends wait. What would be really helpful is a query
that generated output along the lines of:

"Backend pid 123 is blocked awaiting pid 456 lock on 'sessions'
relation."

Perhaps this function already exists? If not, what is needed to
get there?

TIA,
Ed

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:12 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com