每一个oracle块的头部都有事务槽,oracle块里有一个PCT_free的概念,即oracle会预留块大小的10%作为缓冲,当修改oracle的事务增加时,事务槽向下增长,当更新oracle块的数据时,数据向上增长,PCT_free的空间被压缩。当PCT_free被用完时,oracle就彻底填满了,如果还有事务要修改Oracle块,就需要在事务队列中等待这叫做事务槽的争用。
假如一张表占有8个oracle块,insert操作可以均匀的分布到八个oracle块里,但是delete和update操作时针对具体数据的,也就是针对具体oracle块的。Insert操作不容易发生事务槽的争用,但是delete和update容易发生事务槽的争用。
事务槽的演示实验:
1. 新建一张t10表:
SQL> create table t10(id number(5), namechar (2000)); Table created.
2. 向表中插入数据:
Insert into t10 values(1,’a’); Insert into t10 values(2,’b’); Insert into t10 values(3,’c’); Insert into t10 values(4,’d’); Insert into t10 values(5,’e’); Commit;
3. 查询t10表数据的文件编号和块编号:
SQL> selectdbms_rowid.rowid_relative_fno(rowid) file_number,dbms_rowid.rowid_block_number(rowid) block_number, id from t10; FILE_NUMBER BLOCK_NUMBER ID ----------- ------------ ---------- 1 61210 1 1 61210 2 1 61210 3 1 61211 4 1 61211 5
5条数据都在文件1中,占了两个oracle块(61210、61211)。
4. 更新一条数据:
SQL> update t10 set name='abcd' where id=1; 1 row updated.
5.
SQL> selectubafil,ubablk,xidusn,xidslot,xidsqn,start_scnb from v$transaction; UBAFIL UBABLK XIDUSN XIDSLOT XIDSQN START_SCNB ---------- ---------- ---------- -------------------- ---------- 2 125 8 21 469 884821
UBAFIL和UBABLK代表回滚块,XIDUSN是回滚段的编号,XIDSLOT事务表的编号,XIDSQN事务槽被覆盖的次数,START_SCNB是SCN号(不用关注)。
前五个参数是事务表中的
XIDUSN、XIDSLOT、XIDSQN就是从XID分解出来的信息;UBAFIL、UBABLK合起来指向UBA的地址。
6. 步骤5知道了回滚段的编号(XIDUSN)为8,我们就可以找出段的名字:
SQL> select * from v$rollname; USN NAME ---------- ------------------------------ 0 SYSTEM 1_SYSSMU1$ 2_SYSSMU2$ 3 _SYSSMU3$ 4_SYSSMU4$ 5_SYSSMU5$ 6_SYSSMU6$ 7_SYSSMU7$ 8_SYSSMU8$ 9_SYSSMU9$ 10_SYSSMU10$ 11 rows selected.
8号回滚段的名字是_SYSSMU8$
7. 新开一个会话,把_SYSSMU8$回滚段dump出来;
SQL> alter system dump undo header '_SYSSMU8$'; System altered.
8. 在新开会话中查询当前会话的编号:
SQL> select spid from v$process where addr in (selectpaddr from v$session where sid=(select sid from v$mystat where rownum=1)); SPID ------------ 12710
9. 根据第三步中的文件号和oracle块号把ID等于1的数据的oracle块dump出来:
SQL> alter system dump datafile 1 block 61210; System altered.
查会话ID:
SQL> select spid from v$process where addr in (selectpaddr from v$session where sid=(select sid from v$mystat where rownum=1)); SPID ------------ 9974
退出会话并转到udump目录:
SQL>exit Disconnectedfrom Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bitProduction Withthe Partitioning, OLAP and Data Mining options [oracle@redhat4~]$ cd $ORACLE_BASE [oracle@redhat4oracle]$ cd admin/jiagulun/udump/
查看会话ID所对应的文件:
[oracle@redhat4 udump]$ ls *9974* jiagulun_ora_9974.trc
用vim打开该文件:
[oracle@redhat4 udump]$ vi jiagulun_ora_9974.trc /u01/app/oracle/admin/jiagulun/udump/jiagulun_ora_9974.trc Oracle Database 10g Enterprise Edition Release 10.2.0.1.0- 64bit Production With the Partitioning, OLAP and Data Mining options ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1 System name: Linux Node name: redhat4 Release: 2.6.9-78.ELsmp Version: #1SMP Wed Jul 9 15:46:26 EDT 2008 Machine: x86_64 Instance name: jiagulun Redo thread mounted by this instance: 1 Oracle process number: 15 Unix process pid: 9974, image: oracle@redhat4 (TNS V1-V3) *** 2015-12-09 09:41:45.286 *** SERVICE NAME:(SYS$USERS) 2015-12-09 09:41:45.285 *** SESSION ID:(159.3) 2015-12-09 09:41:45.285 Start dump data blocks tsn: 0 file#: 1 minblk 61210maxblk 61210 buffer tsn: 0 rdba: 0x0040ef1a (1/61210) scn: 0x0000.000d824c seq: 0x01 flg: 0x04 tail: 0x824c0601 frmt: 0x02 chkval: 0x7343 type: 0x06=trans data Hex dump of block: st=0, typ_found=1 Dump of memory from 0x00000000064E1E00 to0x00000000064E3E00 0064E1E00 0000A206 0040EF1A 000D824C 04010000 [[email protected].......] 0064E1E10 00007343 00000001 0000CDEC 000D820E [Cs..............] 0064E1E20 00000000 00020002 00000000 002E0008 [................] 0064E1E30 000001D4 0080007B 000601BA 00008000 [....{...........] 0064E1E40 000D8055 00150008 000001D5 0080007D [U...........}...] 0064E1E50 000201BA 00000001 00000000 00030100 [................] 0064E1E60 0018FFFF 07FD0815 000007FD 17C70003 [................] 0064E1E70 08150FEE 00000000 00000000 00000000 [................] 0064E1E80 00000000 00000000 00000000 00000000 [................] Repeat 126times 0064E2670 02002C00 FE04C102 206307D0 20202020 [.,........c ] 0064E2680 20202020 20202020 20202020 20202020 [ ] Repeat 123times 0064E2E40 20202020 20202020 002C2020 03C10202 [ ,.....] 0064E2E50 6207D0FE 20202020 20202020 20202020 [...b ] 0064E2E60 20202020 20202020 20202020 20202020 [ ] Repeat 123times 0064E3620 2C202020 C1020202 07D0FE02 64636261 [ ,........abcd] 0064E3630 20202020 20202020 20202020 20202020 [ ] Repeat 123times 0064E3DF0 20202020 20202020 20202020 824C0601 [ ..L.] Block header dump: 0x0040ef1a Object id onBlock? Y seg/obj:0xcdec csc: 0x00.d820e itc: 2 flg: - typ: 1 - DATA fsl: 0 fnx: 0x0 ver: 0x01 Itl Xid Uba Flag Lck Scn/Fsc 0x01 0x0008.02e.000001d4 0x0080007b.01ba.06 C--- 0 scn 0x0000.000d8055 0x02 0x0008.015.000001d5 0x0080007d.01ba.02 ---- 1 fsc 0x0000.00000000 data_block_dump,data header at 0x64e1e5c =============== tsiz: 0x1fa0 hsiz: 0x18 pbl: 0x064e1e5c bdba: 0x0040ef1a 76543210 flag=-------- ntab=1 Type :quit<Enter> to exit Vim
101-105部分就是事务槽