http://www-01.ibm.com/support/docview.wss?uid=swg21503717
Internal Plan Lock(P lock) (Package Cache/ Plan Lock): Any execution of SQL, whether static or dynamic, must be done while holding a 'package lock'. This ensures that no-one can drop the package that is being executed.
1. 创建存储过程PROCEDURE01,并找到对应的package name和状态,可以看到 PKGNAME为P917055792,状态有效
inst97@db2a:~$ cat create.pro
CREATE OR REPLACE PROCEDURE PROCEDURE01 ()
DYNAMIC RESULT SETS 2
P1: BEGIN
-- Declare cursor
DECLARE cursor1 CURSOR WITH RETURN for
SELECT ID FROM INST97.T1 with RR;
DECLARE cursor2 CURSOR WITH RETURN for
SELECT ID FROM INST97.T2 with RR;
-- Cursor left open for client application
OPEN cursor1;
OPEN cursor2;
END P1
@
inst97@db2a:~$ db2 -td@ -f create.pro
DB20000I The SQL command completed successfully.
inst97@db2a:~$ db2 "select trim (substr (r.routineschema, 1, 10)) as routineschema,trim (substr (r.routinename, 1, 30)) as routinename, r.valid, trim (substr (p.pkgschema, 1, 15)) as pkgschema, trim (substr (p.pkgname, 1, 15)) as pkgname, p.valid from syscat.routines r, syscat.packages p, syscat.procedures a,syscat.routinedep b where b.specificname=r.specificname and r.specificname=a.specificname and r.routinetype = 'P' and b.bname=p.pkgname and a.procname='PROCEDURE01' order by p.create_time desc fetch first 5 rows only"
ROUTINESCHEMA ROUTINENAME VALID PKGSCHEMA PKGNAME VALID
------------- ------------------------------ ----- --------------- --------------- -----
INST97 PROCEDURE01 Y INST97 P917055792 Y
1 record(s) selected.
inst97@db2a:~$ db2 +c "ALTER TABLE t2 alter column name set data type char(21)"
DB20000I The SQL command completed successfully.
inst97@db2a:~$ db2pd -db sample -locks
Database Partition 0 -- Database SAMPLE -- Active -- Up 0 days 00:01:33 -- Date 2017-11-03-01.59.52.615142
Locks:
Address TranHdl Lockname Type Mode Sts Owner Dur HoldCount Att ReleaseFlg rrIID
0x00007FC65BE05A00 2 00000E0001002E000000000052 Row ..S G 2 2 0 0x00000010 0x40000000 1
0x00007FC65BE01F00 2 00000705040000000000000052 Row ..X G 2 1 0 0x00000008 0x40000000 0
0x00007FC65BE02E80 2 00000C0106002F000000000052 Row .NS G 2 2 0 0x00000000 0x40000000 0
0x00007FC65BE02280 2 41414141414242636F724AC241 Internal P ..S G 2 1 0 0x00000000 0x40000000 0
0x00007FC65BE06200 2 00000500063600006018076543 CatCache ..X G 2 255 0 0x00000000 0x40000000 0
0x00007FC65BE02580 2 0000000103820000E01D076543 CatCache ..X G 2 255 0 0x00000000 0x40000000 0
0x00007FC65BE05E80 2 00000A00150005000000000052 Row ..X G 2 1 0 0x00000010 0x40000000 5
0x00007FC65BE05C00 2 00000D0002002C000000000052 Row ..X G 2 1 0 0x00000000 0x40000000 0
0x00007FC65BE02780 2 02000000C67F0000E01D076543 CatCache ..X G 2 255 0 0x00000000 0x40000000 0
0x00007FC65BE04C80 2 00000500060036000000000052 Row ..X G 2 12 0 0x00000000 0x40000000 0
0x00007FC65BE02A80 2 00000001030082000000000052 Row ..X G 2 4 0 0x00000000 0x40000000 0
0x00007FC65BE02C00 2 6A41483542444C68F77CF90A41 Internal P ..X G 2 1 0 0x00000000 0x40000000 0
0x00007FC65BE05F80 2 01000000C67F00006018076543 CatCache ..X G 2 255 0 0x00000000 0x40000000 0
0x00007FC65BE01900 2 000006000C0038010000000052 Row ..X G 2 1 0 0x00000010 0x40000000 1
0x00007FC65BE00100 2 00000E0008002D000000000052 Row ..S G 2 1 0 0x00000010 0x40000000 1
0x00007FC65BE02180 2 00000E0000002E000000000052 Row ..S G 2 2 0 0x00000010 0x40000000 1
0x00007FC65BE02380 2 00000E00000000000000000054 Table .IS G 2 2 0 0x00002010 0x40000000 0
0x00007FC65BE06300 2 00000C01000000000000000054 Table .IS G 2 7 0 0x00002000 0x40000000 0
0x00007FC65BE02080 2 00000705000000000000000054 Table .IX G 2 1 0 0x00002000 0x40000000 0
0x00007FC65BE02D80 2 03000400000000000000000054 Table ..Z G 2 4 0 0x00002000 0x40000000 0
0x00007FC65BE02880 2 00000C00000000000000000054 Table .IS G 2 2 0 0x00002000 0x40000000 0
0x00007FC65BE05B00 2 00000500000000000000000054 Table .IX G 2 12 0 0x00002000 0x40000000 0
0x00007FC65BE02C80 2 00000001000000000000000054 Table .IX G 2 4 0 0x00002000 0x40000000 0
0x00007FC65BE05D00 2 00000D00000000000000000054 Table .IX G 2 1 0 0x00002000 0x40000000 0
0x00007FC65BE01C00 2 00000600000000000000000054 Table .IX G 2 1 0 0x00002010 0x40000000 0
0x00007FC65BE02480 2 00000A00000000000000000054 Table .IX G 2 1 0 0x00002010 0x40000000 0
inst97@db2a:~$ db2pd -db sample -static | grep -i 6A41483542444C68F77CF90A41
0x00007FC6651FFBC0 INST97 P917055792 jAH5BDLh 2 0 3 CS 5 U 6A41483542444C68F77CF90A41
inst97@db2a:~$ db2 commit
DB20000I The SQL command completed successfully.
inst97@db2a:~$ db2 "select trim (substr (r.routineschema, 1, 10)) as routineschema,trim (substr (r.routinename, 1, 30)) as routinename, r.valid, trim (substr (p.pkgschema, 1, 15)) as pkgschema, trim (substr (p.pkgname, 1, 15)) as pkgname, p.valid from syscat.routines r, syscat.packages p, syscat.procedures a,syscat.routinedep b where b.specificname=r.specificname and r.specificname=a.specificname and r.routinetype = 'P' and b.bname=p.pkgname and a.procname='PROCEDURE01' order by p.create_time desc fetch first 5 rows only"
ROUTINESCHEMA ROUTINENAME VALID PKGSCHEMA PKGNAME VALID
------------- ------------------------------ ----- --------------- --------------- -----
INST97 PROCEDURE01 N INST97 P917055792 N
1 record(s) selected.