oracle数据库undo分析的实验
1、查找当前的undo表空间
SQL> show parameter undo_tablespace;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
2、创建undo表空间undotbs2
CREATE UNDO TABLESPACE undotbs2 DATAFILE '/u01/app/oracle/oradata/ORCL/datafile/undotbs2.dbf' SIZE 100M;
3、创建表空间 test_undo
CREATE TABLESPACE test_undo DATAFILE '/u01/app/oracle/oradata/ORCL/datafile/test_undo.dbf' SIZE 128K;
4、创建测试表 test_undo_tab
create table test_undo_tab(txt char(1000)) tablespace test_undo;
5、插入数据
insert into test_undo_tab values ('teststring1');
insert into test_undo_tab values ('teststring2');
6、执行手工检查点,将以上改变写入数据文件:
SQL> alter system checkpoint;
System altered
7、将undo_tablespace 设置为undotbs2
SQL> ALTER SYSTEM SET undo_tablespace=undotbs2;
System altered
SQL> show parameter undo_tablespace;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS2
8、进行日志切换使当前日志不包含字符串teststring
SQL> alter system switch logfile;
System altered
9、查看这时候的redo log应该包含redo 和 undo (提交的和未提交的数据信息)
strings /u01/app/oracle/oradata/ORCL/onlinelog/o1_mf_2_9slwncdn_.log | grep teststring
teststring_uncommitted
teststring1
teststring_committed
10、检查当前数据文件应该是不包含更新后的数值(只有更新前数据)因为还未触发检查点
strings /u01/app/oracle/oradata/ORCL/datafile/test_undo.dbf | grep teststring
teststring2
teststring1
eg:
11、此时触发检查点
alter system checkpoint;
System altered
12、再次检查数据文件发现数据已为最新值(提交的和未提交的值)
strings /u01/app/oracle/oradata/ORCL/datafile/test_undo.dbf | grep teststring
teststring_committed ,
teststring_uncommitted
13、最后检查Undotbs2表空间发现包含更新前的数值
strings /u01/app/oracle/oradata/ORCL/datafile/undotbs2.dbf | grep teststring
teststring2
teststring1
14、清理创建的对象
drop tablespace test_undo including contents and datafiles;
alter system set undo_tablespace=undotbs1;
drop tablespace undotbs2 including contents and datafiles;