14、管理 oracle undo
1、DML与undo
undo data:
原始的、修改之前的数据副本
用于支持:回退操作、读一致性查询、闪回查询、闪回事务处理及闪回表、从失败事务中进行恢复。
undo:旧数据
redo:改变的数据
SQL> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
undo_retention指定已经提交的还原信息要保留多长时间(秒)
undo表空间大小设置多大合适呢?
select name,BLOCK_SIZE/1024/1024 from v$datafile;
设置undo手动管理(需要重启数据库) ==不建议手动管理
alter system set undo_management=manual scope=spfile;
v$rollname
select * from v$rollname;
如何创建undo表空间?
SQL> select name from v$datafile;
NAME
--------------------------------------------------
+DATA/orcl/datafile/system.256.943301251
+DATA/orcl/datafile/sysaux.257.943301251
+DATA/orcl/datafile/undotbs1.258.943301251
+DATA/orcl/datafile/users.259.943301251
+DATA/orcl/datafile/example.265.943301433
+DATA/orcl/datafile/tbs.dbf
create undo tablespace untotbs2 datafile ‘+DATA/orcl/datafile/undotbs2.dbf‘ size 3m;
show parameter undo
alter system set undo_tablespace=untotbs2;//设置undo表空间为untotbs2
SQL> show parameter undo;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNTOTBS2
2、undo管理及使用
查看表空间是否自动扩展
SQL> select TABLESPACE_NAME,AUTOEXTENSIBLE from dba_data_files;
TABLESPACE_NAME AUT
------------------------------ ---
USERS YES
UNDOTBS1 YES
SYSAUX YES
SYSTEM YES
EXAMPLE YES
TBS_16K NO
UNTOTBS2 NO
undo快照过旧
SQL> select CURRENT_SCN from v$database;
CURRENT_SCN
-----------
2366951
################################################
例子:scn 闪回查询 15分钟。
SQL> create table t2 as select * from scott.emp;
Table created.
SQL> select CURRENT_SCN from v$database;
CURRENT_SCN
-----------
2367095
SQL> delete t2;
14 rows deleted.
SQL> commit;
Commit complete.
SQL> select count(*) from t2 as of scn 2367095;
COUNT(*)
----------
14
###################################################