Monday, August 3, 2009

Locked databases

SQL to get the session/thread holding a lock on a database.

dbaccess sysmaster;
set isolation to dirty read;

select b.name database_name, "HDR+"||a.type lock_type,
c.us_sid session_id, c.us_name owner,
d.th_id tid, d.th_name thread
from syslocks a, sysdatabases b, sysuserthreads c, systhreads d
where a.rowidlk=b.rowid
and a.owner=c.us_sid
and c.us_mttcb=d.th_addr
and b.name="<database name>";

For example:

select b.name database_name, "HDR+"||a.type lock_type,
c.us_sid session_id, c.us_name owner,
d.th_id tid, d.th_name thread
from syslocks a, sysdatabases b, sysuserthreads c, systhreads d
where a.rowidlk=b.rowid
and a.owner=c.us_sid
and c.us_mttcb=d.th_addr
and b.name="stores1"

-----

database_name stores1
lock_type HDR+S
session_id 97
owner informix
tid 140
thread sqlexec

No comments:

Post a Comment