undo信息的查询
1)v$session
查看用户建立的session
2)v$transaction
当前的事务
3)v$rollname
undo段的名称
4)v$rollstat
undo段的状态
5)dba_rollback_segs 数据字典里记录的undo段状态
一般来说,一个session只能对应一个事务,建立了session未必有事务,只有事务处于活动状态时(进行DML操作),vtransaction才能看到这个事务。换句话说,如果看到了事务(在‘v transaction里),那一定有个session和它对应,将两个视图连在一起,信息看得更为清楚。
查看当前有几个session连上来了
select username,sid,serial# from v$session where username is not null;
sys@ORCL>conn scott/tiger;
scott@ORCL>select username,sid,serial# from v$session where username is not null;
USERNAME SID SERIAL#
------------------------------ ---------- ----------
SCOTT 1 7
scott@ORCL>
---------------------
产生一个活动事务
两表联查,sid和serial#在v
transaction里,XIDUSN是undo segment的id,XIDSLOT是事务槽的id,UBABLK是undo块号
scott@ORCL>select * from TTT;
ID
----------
1
scott@ORCL>update TTT set id='2' where id='1';
scott@ORCL>select a.sid,a.serial#,a.username,b.xidusn,xidslot,b.ubablk,b.status from v$session a,v$transact
SID SERIAL# USERNAME XIDUSN XIDSLOT UBABLK STATUS
---------- ---------- ------------------------------ ---------- ---------- ---------- ----------------
1 7 SCOTT 16 22 222 ACTIVE
scott@ORCL>
对照上面看,线面语句显示出_SYSSMU18是一个活动段,与XIDUSN=8温和,说明这个段被读进buffer了
SQL> select a.usn,b.name,a.xacts from v$rollstat
a,v$rollname
b where a.usn=b.usn;
name:表空间下的10个段(10张大表)
xact:1表示激活,0表示未激活