How to find what Java program has a transaction open?

From: Paul Tomblin <ptomblin(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: How to find what Java program has a transaction open?
Date: 2008-02-20 01:34:05
Message-ID: 47BB838D.5070903@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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(at)xcski(dot)com> http://blog.xcski.com/
Compared to system administration, being cursed forever is a step up.
-- Paul Tomko

Browse pgsql-jdbc by date

  From Date Subject
Next Message Gustav Trede 2008-02-20 09:21:09 Re: extra rowcopy in ResultSet allways needed ?.
Previous Message Michael Paesold 2008-02-19 16:22:33 Re: Implementing setQueryTimeout() - round 2