sp_lock [<spid1>[, <spid2>]] | [@verbose = <int>]
<spid1>
是来自 master.dbo.sysprocesses 表的 SAP ASE 进程 ID 号。运行 sp_who 以获取锁定进程的 <spid>。
<spid2>
是要用于检查锁的另一个 SAP ASE 进程 ID 号。
@verbose = <int>
显示表名而非 <spid> 的并置名称,例如 test..testa,后跟 <spid>。
> 注意
> <int> 可以是任意数据,因为 sp_lock 只检查 @verbose 是否为空值。
显示串行进程的锁状态,该串行进程的 spid 为 7、18 和 23 并具有两个进程系列。fid 为 1 的系列具有 spid 为 1 的协调进程以及 spid 为 8、9 和 10 的工作进程。fid 为 11 的系列具有 spid 为 11 的协调进程以及 spid 为 12、13 和 14 的工作进程。
sp_lock
The class column will display the cursor name for locks associated with a
cursor for the current user and the cursor id for other users.
fid spid locktype table_id page dbname class context
--- ---- ------------- ---------- ----- ------- -------------- -------
0 7 Sh_intent 480004741 0 master Non Cursor Lock NULL
0 18 Ex_intent 16003088 0 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 587 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 590 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 1114 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 1140 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 1283 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 1362 pubtune Non Cursor Lock NULL
0 18 Ex_page 16003088 1398 pubtune Non Cursor Lock NULL
0 18 Ex_page-blk 16003088 634 pubtune Non Cursor Lock NULL
0 18 Update_page 16003088 1114 pubtune Non Cursor Lock NULL
0 18 Update_page-blk 16003088 634 pubtune Non Cursor Lock NULL
0 23 Sh_intent 16003088 0 pubtune Non Cursor Lock NULL
0 23 Sh_intent 176003658 0 pubtune Non Cursor Lock NULL
0 23 Ex_intent 208003772 0 pubtune Non Cursor Lock NULL
1 1 Sh_intent 176003658 0 tpcd Non Cursor Lock Sync-pt duration request
1 1 Sh_intent-blk 208003772 0 tpcd Non Cursor Lock Sync-pt duration request
1 8 Sh_page 176003658 41571 tpcd Non Cursor Lock NULL
1 9 Sh_page 176003658 41571 tpcd Non Cursor Lock NULL
1 10 Sh_page 176003658 41571 tpcd Non Cursor Lock NULL
11 11 Sh_intent 176003658 0 tpcd Non Cursor Lock Sync-pt duration request
11 12 Sh_page 176003658 41571 tpcd Non Cursor Lock NULL
11 13 Sh_page 176003658 41571 tpcd Non Cursor Lock NULL
11 14 Sh_page 176003658 41571 tpcd Non Cursor Lock NULL
显示有关 spid 7 当前持有的锁的信息:
sp_lock 7
The class column will display the cursor name for locks associated with a
cursor for the current user and the cursor id for other users.
fid spid locktype table_id page dbname class context
--- ---- --------- --------- ---- ------ ---------------- ----------
0 7 Sh_intent 480004741 0 master Non Cursor Lock NULL
首先在 pubs2 数据库中查询其当前持有锁的正在运行的进程的 ID(1056003762),然后使用 @verbose 选项查询 pubs2 数据库,这会返回对象名(master..spt_values)和进程 ID:
1> use pubs2
2> go
1> sp_lock
2> go
The class column will display the cursor name for locks associated with a cursor for the current user and the cursor id for other users.
fid spid loid locktype table_id page row dbname class context
--- ---- ---- -------- -------- ---- --- ------ ------ ----------
0 15 30 Sh_intent 1056003762 0 0 master Non Cursor Lock
(1 row affected)
(return status = 0)
1> sp_lock @verbose=0
2> go
The class column will display the cursor name for locks associated with a cursor for the current user and the cursor id for other users.
fid spid loid locktype page row objectName id class context
--- ---- ---- -------- ---- --- ------------------ -------- ------ -------
0 15 30 Sh_intent 0 0 master..spt_values 1056003762 Non Cursor Lock
(1 row affected)
(return status = 0)
此示例显示当前由 SAP ASE 持有的全部锁,包括分区锁。
sp_lock
go
fid spid loid locktype table_id partitionid page row dbname class context
--- ---- ---- -------- ---------- ----------- ---- --- ------ ------ -------
0 13 26 Ex_intent 420193516 0 0 0 master Non Cursor Lock
0 13 26 Ex_intent_partition 420193516 452193630 0 0 master Non Cursor Lock
0 13 26 Ex_page 420193516 452193630 4993 0 master Non Cursor Lock
0 14 28 Ex_intent 420193516 0 0 0 master Non Cursor Lock
0 14 28 Ex_intent_partition 420193516 468193687 0 0 master Non Cursor Lock
0 14 28 Ex_page 420193516 468193687 5001 0 master Non Cursor Lock
0 16 32 Sh_intent 1006623598 0 0 0 master Non Cursor Lock
partitionid 的表锁值和精细锁值为 0。仅为分区级锁填充 partitionid。
使用 sp_lock 时,还存在一些其它注意事项:
- “Sh_row”指示共享行锁
- “Update_row”指示更新行锁
- “Ex_row”指示排它行锁
sp_lock 列有:
loid
列标识阻塞事务的唯一锁所有者 ID。偶数 loid 值表示本地事务拥有该锁。如果 loid 值为奇数,则表示外部事务拥有该锁。
locktype
列指示锁是共享锁(前缀为“Sh”)、排它锁(前缀为“Ex”)还是更新锁,并且指定该锁是在表上(“table”或“intent”)持有还是在页上(“page”)持有。
“locktype”列中的“blk”后缀表明此进程正在阻塞需要获取锁的另一个进程。在此进程结束后,其它进程将继续执行。“locktype”列中的“demand”后缀表明该进程正尝试获取排它锁。
class
列表示锁是否与游标关联。它显示下列内容之一:
- “Non Cursor Lock”表示锁没有与游标关联。
- “Cursor Id <>关联。
游标名表示锁与游标 <cursor_name> 相关联,该游标属于执行 sp_lock 的当前用户。
fid
列标识锁所属的系列(包括协调进程及其工作进程)。fid 的值为:
- 值零表明 spid 表示的任务被串行执行。它不参与并行执行。
- 非零值表明持有锁的任务 (spid) 是并行执行语句的进程系列的成员(由 fid 标识)。如果值等于 spid, 则表明该任务是并行执行查询的进程系列中的协调进程。
context
列标识锁的环境。同一系列中的工作进程具有相同的环境值。“context”的合法值如下所示:
- “NULL”– 持有该锁的任务或者是串行执行的查询,或者是事务隔离级别 1 中并行执行的查询。
- “Syncpt duration request”– 持有该锁的任务在完成查询前将一直持有该锁。
在以下情况下锁的上下文可以是“Sync-pt duration request”:锁是作为并行查询的一部分持有的表锁,或者锁被事务隔离级别 3 上的工作进程持有,或者锁被并行查询中的工作进程持有且在事务的持续时间内必须被持有。
- “Ind pg”– 表示索引页锁(仅适用于全页锁定表)
- “Inf key”– 指示无限键锁(对于仅数据锁定表上事务隔离级别 3 的某些范围查询)
- “Range”– 指示范围锁(对于仅数据锁定表上事务隔离级别 3 的范围查询)
这些新值可以与“Fam dur”(代替“Sync pt duration”)一起出现以及彼此一起出现(如果适用)。
row
列显示行级锁的行号。