list blocking queries

From: Scot Kreienkamp <SKreien(at)la-z-boy(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: list blocking queries
Date: 2012-01-30 17:48:56
Message-ID: 17082AAFC33A934082836458CB53494311D904@MONEXCH01.na.lzb.hq
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hey everyone,

My apologies for the slightly novice post on this, but I'm a bit stumped. I have this query that I found on the net and adapted a little to find the queries that were blocking:

"select bl.pid as \"Blocked PID\", a.usename as \"Blocked User\", kl.pid as \"Blocking PID\", ka.usename as \"Blocking User\", to_char(age(now(), a.query_start),'HH24h:MIm:SSs') as \"Age\" from pg_catalog.pg_locks bl join pg_catalog.pg_stat_activity a on bl.pid = a.procpid join pg_catalog.pg_locks kl join pg_catalog.pg_stat_activity ka on kl.pid = ka.procpid on bl.transactionid = kl.transactionid and bl.pid != kl.pid where not bl.granted;"

To test it I ran this twice simultaneously:
begin work;
lock table traffic in EXCLUSIVE mode;
select pg_sleep(300);
commit work;

PG_stat_activity does show the second lock table query as waiting, but the query I pasted above returns zero results. I have not run this same test on 8.3 as pg_sleep didn't exist then, but I know the query works because I've used it in my 8.3 production environment. Bottom line is I'm not sure if the query to list blocked/blocking PID's doesn't work on 9.1 or if it's the way I'm testing it.

That query is a bit above my head for now as I'm only a part time DBA at my job. Thank you for any insights you can give me.

BTW, the streaming replication and hot standby on 9.1 rocks!!! Thanks to everyone involved for that!!

Scot Kreienkamp
skreien(at)la-z-boy(dot)com

This message is intended only for the individual or entity to which it is addressed. It may contain privileged, confidential information which is exempt from disclosure under applicable laws. If you are not the intended recipient, please note that you are strictly prohibited from disseminating or distributing this information (other than to the intended recipient) or copying this information. If you have received this communication in error, please notify us immediately by e-mail or by telephone at the above number. Thank you.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2012-01-30 17:51:58 Re: pg_dump -s dumps data?!
Previous Message hubert depesz lubaczewski 2012-01-30 17:45:09 Re: pg_dump -s dumps data?!