We use Sybase ASE (15.5) server as our DB and are having strange, intermittent SPID blocking issues that I am trying to detect and mitigate programmatically at the application-layer.
Sybase allows you to schedule so-called "reorgs" which from what I can tell are periodic re-indexes/table compactions, cleanups, etc. Scheduled DB maintenance, basically.
Every once in a while, we get all the planets coming into alignment with each other, where:
widgets
table; thenwidgets
table. The reorg places an exclusive lock request on widgets
, but can't obtain the lock because widgets
is already locked and blocked by the hanging SPID/query; thenwidgets
; such thatwidgets
, but widgets
is tied up in a blocking shared lock by a hung SPID. And because the reorg has placed an exclusive lock on widgets
, all other queries wanting shared locks on widgets
have to wait until the reorg is complete (because a newly requested exclusive lock trumps a newly requested shared lock).I think my ideal strategy here would be to:
Thanks in advance!
You can get the commands that are running in the database with the following query:
select cmd from sysprocesses
To find locking information you can join master..syslocks
and your_db..sysobjects
to find out what locks exist on the object you are trying to access. syslocks.type
indicates the kind of lock that is in place, and those possible values can be found here:
select object_name(id), db_name(dbid), type from master..syslocks
where dbid = db_id("your_db")
Hopefully that helps.
To find if the lock is tied to a reorg, I think you should be able to join syslocks.spid to sysprocesses.spid where cmd = "REORG" or something like:
select p.cmd, p.spid, l.type from master..sysprocesses p, master..syslocks l where CMD = "REORG"