pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Paul Tomblin <ptomblin@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: How to find what Java program has a transaction open?
Date: Tue, 19 Feb 2008 20:34:05 -0500
Message-ID: <47BB838D.5070903@gmail.com> (raw)

I got the following query from a comment on the PostgreSQL site:

select pg_stat_activity.datname,pg_class.relname,pg_locks.transaction, 
pg_locks.mode,pg_locks.granted,pg_stat_activity.usename,substr(pg_stat_activity.current_query,1,30), 
pg_stat_activity.query_start, age(now(),pg_stat_activity.query_start) as 
"age", pg_stat_activity.procpid from pg_stat_activity,pg_locks left outer join 
pg_class on (pg_locks.relation = pg_class.oid)  where 
pg_locks.pid=pg_stat_activity.procpid and pg_class.relname not like 'pg_%' 
order by query_start;

and it's great, in that it shows me what Postgres PID is holding the lock, and 
on what table.  But what I don't know is how to figure out what Java program 
it is that's got the lock.  If I do a "ps auwwx | grep [pid]", the socket 
number will be part of the command line for that process, and then I can use 
"lsof -i :[socketnumber]" which shows me two tasks that have that socket open, 
the PostgreSQL task and the Java task, and then I can use "ps auwwx | grep 
[pid]" to find the arguments to the Java task, including the main class.

Is there a more direct way?

-- 
Paul Tomblin <ptomblin@xcski.com> http://blog.xcski.com/
Compared to system administration, being cursed forever is a step up.
               -- Paul Tomko



Message-ID: <47BB838D.5070903@gmail.com>
Permalink:  ../47BB838D.5070903@gmail.com/
Also on:    postgresql.org/message-id/47BB838D.5070903@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: ptomblin@gmail.com
  Subject: Re: How to find what Java program has a transaction open?
  In-Reply-To: <47BB838D.5070903@gmail.com>
  References: <47BB838D.5070903@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox