1. 查看数据储存的位置(FILE#,BLOCK#)
SELECT DBMS_ROWID.rowid_relative_fno (ROWID) "FILE#",
DBMS_ROWID.rowid_block_number (ROWID) "BLOCK#",
id,
name
FROM test.t2;
结果:
FILE# BLOCK# ID NAME
---------- ---------- ---------- --------------------
4 183 1 hello
4 183 2 world
表T2的对象ID。
SELECT object_id, data_object_id
FROM dba_objects
WHERE owner = 'TEST' AND object_name = 'T2';
结果:
OBJECT_ID DATA_OBJECT_ID
---------- --------------
76431 76431
2. 查看对应PCM锁信息
1)@instance1-session1, 查看当前会话的sid和spid, 以及查询一条记录
SQL> SELECT s.sid, p.spid
FROM v$process p, v$session s
WHERE p.addr = s.paddr AND s.sid = (SELECT DISTINCT sid FROM v$mystat);
SID SPID
---------- ------------------------
156 15837
SQL> SELECT *
FROM test.t2
WHERE id = 1;
ID NAME
---------- ------------------------------
1 hello
3. 在新会话查看锁和资源信息
@instance1-session2,查看会话的锁和资源信息。
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76 2 3 4 5 6 7 8 9 10 11 12 13 431;
no rows selected
@instance2-session2,查看会话的锁和资源信息。
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
KJBRRESP KJBRGRANT KJBRNCVL KJBRROLE KJBRNAME
---------------- --------- --------- ---------- ------------------------------
KJBRMASTER KJBRGRANTQ KJBRCVTQ KJBRWRITER KJBRSID
---------- ---------------- ---------------- ---------------- ----------
KJBRPKEY
----------
000000009E4C0FE0 KJUSERPR KJUSERNL 0 [0xb7][0x4],[BL][ext 0x0,0x0]
1 000000009ED98A68 00 00 0
76431
KJBRMASTER=1,说明这个数据快的master是实例2所在的节点上。这时在实例1节点上执行该语句是查不到记录的。
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 2 000000009ED98A68 KJUSERPR KJUSERNL 0 1
@instance1-session2,由于在实例1上进行的记录查询操作,所以在该实例上查询被访问的数据块处于shared current模式(status=scur)。
SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes,
g.mode_held,
g.block_count,
g.local,
g.flags
FROM v$bh b, v$gc_element g
WHERE b.lock_element_addr = g.gc_element_addr
AND b.file# = 4
AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES MODE_HELD BLOCK_COUNT LOCAL FLAGS
---------- ---------- ---------- ----------------- ------------ ------------- ---------- ----------- ---------- ----------
4 183 scur 183 0 0 1 1 1 32
4. 在实例2创建一个会话,查询另一条记录
@instance2-session1。(两行记录保存在同一个文件的同一个数据块中)
SQL> SELECT s.sid, p.spid
FROM v$process p, v$session s
WHERE p.addr = s.paddr AND s.sid = (SELECT DISTINCT sid FROM v$mystat);
SID SPID
---------- ------------------------
38 31796
SELECT *
FROM test.t2
WHERE id = 2;
ID NAME
---------- --------------------
2 world
5. 查看PCM锁及资源信息
@instance2-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes,
g.mode_held,
g.block_count,
g.local,
g.flags
FROM v$bh b, v$gc_element g
WHERE b.lock_element_addr = g.gc_element_addr
AND b.file# = 4
AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES MODE_HELD BLOCK_COUNT LOCAL FLAGS
---------- ---------- ---------- ----------------- ------------ ------------- ---------- ----------- ---------- ----------
4 183 scur 183 0 0 1 1 1 32
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
KJBRRESP KJBRGRANT KJBRNCVL KJBRROLE KJBRNAME KJBRMASTER KJBRGRANTQ KJBRCVTQ KJBRWRITER KJBRSID KJBRPKEY
---------------- --------- --------- ---------- ------------------------------ ---------- ---------------- ---------------- ---------------- ---------- ----------
000000009E4C0FE0 KJUSERPR KJUSERNL 0 [0xb7][0x4],[BL][ext 0x0,0x0] 1 000000009ED98A68 00 00 0 76431
SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 2 0000000069FC0A88 KJUSERPR KJUSERNL 0 1
[0xb7][0x4],[BL][ext 0x0,0x0] 2 000000009ED98A68 KJUSERPR KJUSERNL 0 1
@instance1-session2
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 1 0000000064FC5E78 KJUSERPR KJUSERNL 0 1
6. 修改第一条记录
@instance1-session1
update test.t2 set name='helloworld' where id=1;
1 row updated.
@instance1-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes,
g.mode_held,
g.block_count,
g.local,
g.flags
FROM v$bh b, v$gc_element g
WHERE b.lock_element_addr = g.gc_element_addr
AND b.file# = 4
AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES MODE_HELD BLOCK_COUNT LOCAL FLAGS
---------- ---------- ---------- ----------------- ------------ ------------- ---------- ----------- ---------- ----------
4 183 xcur 183 0 0 2 1 1 32
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 xcur 183 0 0
4 183 cr 0 0
@instance2-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 cr 0 0
@instance2-session2(master)
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
KJBRRESP KJBRGRANT KJBRNCVL KJBRROLE KJBRNAME KJBRMASTER KJBRGRANTQ KJBRCVTQ KJBRWRITER KJBRSID KJBRPKEY
---------------- --------- --------- ---------- ------------------------------ ---------- ---------------- ---------------- ---------------- ---------- ----------
000000009E4C0FE0 KJUSEREX KJUSERNL 0 [0xb7][0x4],[BL][ext 0x0,0x0] 1 000000009ED98A68 00 00 0 76431
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 2 000000009ED98A68 KJUSEREX KJUSERNL 0 1
@instance1-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
no rows selected
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 1 0000000064FC5E78 KJUSEREX KJUSERNL 0 1
7. 更新第二条记录
@instance2-session1
SQL> update test.t2 set name='worldhello' where id=2;
1 row updated.
@instance2-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes,
g.mode_held,
g.block_count,
g.local,
g.flags
FROM v$bh b, v$gc_element g
WHERE b.lock_element_addr = g.gc_element_addr
AND b.file# = 4
AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES MODE_HELD BLOCK_COUNT LOCAL FLAGS
---------- ---------- ---------- ----------------- ------------ ------------- ---------- ----------- ---------- ----------
4 183 xcur 183 0 0 2 1 0 32
@instance1-sesssion2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 pi 183 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
@instance2-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 xcur 183 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
@instance1-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
no rows selected
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 1 0000000064FC5E78 KJUSERNL KJUSERNL 192 1
@instance2-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
KJBRRESP KJBRGRANT KJBRNCVL KJBRROLE KJBRNAME KJBRMASTER KJBRGRANTQ KJBRCVTQ KJBRWRITER KJBRSID KJBRPKEY
---------------- --------- --------- ---------- ------------------------------ ---------- ---------------- ---------------- ---------------- ---------- ----------
000000009E4C0FE0 KJUSEREX KJUSERNL 64 [0xb7][0x4],[BL][ext 0x0,0x0] 1 000000009ED98A68 00 00 0 76431
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 2 0000000069FC0A88 KJUSEREX KJUSERNL 64 1
[0xb7][0x4],[BL][ext 0x0,0x0] 2 000000009ED98A68 KJUSERNL KJUSERNL 192 1
8. 更新提交
@instance2-session1
SQL> commit;
Commit complete.
@instance1-session1
SQL> commit;
Commit complete.
@instance1-session2
SQL> select * from test.t2;
ID NAME
---------- --------------------
1 helloworld
2 worldhello
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 pi 183 0 0
4 183 xcur 183 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
@instance2-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
@instance1-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
no rows selected
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 1 0000000064FC5E78 KJUSEREX KJUSERNL 0 1
@instance2-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
KJBRRESP KJBRGRANT KJBRNCVL KJBRROLE KJBRNAME KJBRMASTER KJBRGRANTQ KJBRCVTQ KJBRWRITER KJBRSID KJBRPKEY
---------------- --------- --------- ---------- ------------------------------ ---------- ---------------- ---------------- ---------------- ---------- ----------
000000009E4C0FE0 KJUSEREX KJUSERNL 0 [0xb7][0x4],[BL][ext 0x0,0x0] 1 000000009ED98A68 00 00 0 76431
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 2 000000009ED98A68 KJUSEREX KJUSERNL 0 1
9. 在实例2发起检查点操作
@instance2-session1
SQL> alter system checkpoint;
System altered.
@instance1-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 xcur 183 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
@instance2-session2
SQL> SELECT b.file#,
b.block#,
b.status,
b.lock_element_name,
b.forced_reads,
b.forced_writes
FROM v$bh b
WHERE b.file# = 4 AND b.block# = 183;
FILE# BLOCK# STATUS LOCK_ELEMENT_NAME FORCED_READS FORCED_WRITES
---------- ---------- ---------- ----------------- ------------ -------------
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
4 183 cr 0 0
@instance1-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
no rows selected
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 1 0000000064FC5E78 KJUSEREX KJUSERNL 0 1
@instance2-session2
SQL> SELECT kjbrresp,
kjbrgrant,
kjbrncvl,
kjbrrole,
kjbrname,
kjbrmaster,
kjbrgrantq,
kjbrcvtq,
kjbrwriter,
kjbrsid,
kjbrpkey
FROM x$kjbr
WHERE kjbrname LIKE '%b7%4%BL%' AND kjbrpkey = 76431;
KJBRRESP KJBRGRANT KJBRNCVL KJBRROLE KJBRNAME KJBRMASTER KJBRGRANTQ KJBRCVTQ KJBRWRITER KJBRSID KJBRPKEY
---------------- --------- --------- ---------- ------------------------------ ---------- ---------------- ---------------- ---------------- ---------- ----------
000000009E4C0FE0 KJUSEREX KJUSERNL 0 [0xb7][0x4],[BL][ext 0x0,0x0] 1 000000009ED98A68 00 00 0 76431
SQL> SELECT kjblname,
inst_id,
kjbllockp,
kjblgrant,
kjblrequest,
kjblrole,
kjblmaster
FROM x$kjbl
WHERE kjblname LIKE '%b7%4%BL%' AND kjblpkey = 76431;
KJBLNAME INST_ID KJBLLOCKP KJBLGRANT KJBLREQUE KJBLROLE KJBLMASTER
------------------------------ ---------- ---------------- --------- --------- ---------- ----------
[0xb7][0x4],[BL][ext 0x0,0x0] 2 000000009ED98A68 KJUSEREX KJUSERNL 0 1