管理还原数据
练习undo表空间的管理操作Undo表空间毕竟是需要空间来存储数据的,既然如此,在存储undo数据的时候,只要能满足回滚就可以了。
- insert:undo中只记录了rowid,如果回退,只需要将改记录通过rowid删除即可;
- update:undo中只记录旧值,如果回退,通过旧值覆盖新值;
- delete:undo中记录整行记录,如果回退,通过反向操作恢复其值。
通过上述描述我们可以得出,delete操作是最占用undo空间的。
实验目标:
1) 创建一个新的 undo 表空间,表空间名称为 UNDOTBS2, 固定大小 100M;
2) 切换数据库的 undo 表空间为 UNDOTBS2;
3) 设置 undo 数据强制保留为 2 小时。
#查看undo相关参数
SYS@PROD> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO #自动管理回滚模式
undo_retention integer 900 #undo表空间数据保存时间,默认900秒
undo_tablespace string UNDOTBS1 #当前使用的undo表空间
#查看当前数据库undo表空间名称
SYS@PROD> show parameter undo_tablespace
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_tablespace string UNDOTBS1
SYS@PROD>
#创建一个新的表空间UNDOTBS2
SYS@PROD> create undo tablespace UNDOTBS2
2 datafile '/u01/app/oracle/oradata/PROD/undotbs2_01.dbf'
3 size 100M;
Tablespace created.
SYS@PROD>
#切换当前的undo表空间为UNDOTBS2
SYS@PROD> alter system set undo_tablespace=UNDOTBS2;
System altered.
SYS@PROD>
#验证
SYS@PROD> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS2
SYS@PROD>
注:创建undo表空间的时候,初始可以设置为自动扩展,当系统稳定的运行一段时间后,需要手工调整一下undo表空间,将自动扩展取消,为的是避免某用户忽略了提交事务而无意识的占用大量空间。
#更改undo保留时间为2小时
SYS@PROD> alter system set undo_retention=7200;
System altered.
#验证
SYS@PROD> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 7200 #单位为秒
undo_tablespace string UNDOTBS2
SYS@PROD>
#查看undo表空间保留数据模式
SYS@PROD> SELECT tablespace_name, retention FROM dba_tablespaces WHERE contents = 'UNDO';
TABLESPACE_NAME RETENTION
--------------- -----------
UNDOTBS1 NOGUARANTEE #默认为非强制保留
UNDOTBS2 NOGUARANTEE
SYS@PROD>
#更改undo表空间的保留模式
SYS@PROD> ALTER TABLESPACE UNDOTBS2 RETENTION GUARANTEE;
Tablespace altered.
#验证
SYS@PROD> SELECT tablespace_name, retention FROM dba_tablespaces WHERE contents = 'UNDO';
TABLESPACE_NAME RETENTION
--------------- -----------
UNDOTBS1 NOGUARANTEE
UNDOTBS2 GUARANTEE #修改后,确保7200秒内数据会保留在undo内
SYS@PROD>
注:确保保留期的开启与关闭,只适合undo表空间
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31399196/viewspace-2128156/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31399196/viewspace-2128156/