查看undo表空间管理方式:show parameter undo_management
查看undo表空间名称:show parameter undo_tablespace
查看数据文件:select name from v$datafile;
创建undo表空间:create undo tablespace undotbs2 datafile '/u01/app/oracle/oradata/myorcl/undotbs02.dbf' size 10m;
切换undo表空间:alter system set undo_tablespace=undotbs2 scope=both;
切换undo表空间管理方式:alter system set umdo_management=manual scope=spfile;--切换到手动模式
修改表所属的表空间:alter table t_user move tablespace system;
用户没有可用的segment时,无法创建表,oracle11g及其之后的版本新加了参数deferred_segment_creation,为true时可以创建不带数据的表
创建rollback的segment:create rollback segment rbs1 tablespace undotbs1;
修改状态:alter rollbask segment rbs1 online;
查看参数rollback:show parameter rollback
oracle推荐一个segment中存放5个事务,segment数量足够使用时,oracle会自动分配
默认数据库重启后手动创建的segment状态会是offline,需要修改参数:alter system set rollback_segments='RBS1' scope=spfile;--多个参数以逗号间隔,rollback_segments=‘’,'',...
重启后查看segment状态:select segment_name,tablespace_name,status from dba_rollback_segs;
切换undo表空间管理方式:alter system set umdo_management=auto scope=spfile;--切换到自动模式,重启后生效
闪回查询(查询commit之前的数据):
select * from t_user as of timestamp(sysdate-5/1440);
select * from t_user as of scn 1704047;
启动行移动:alter table t_user enable row movement;
将表中数据回退到5分钟之前:
flashback table t_user to timestamp(sysdate-5/1440);--最大支持900秒
flashback table t_user to scn 1704047;
查看参数undo:show parameter undo
闪回版本查询:
select versions_startscn,versions_endscn,versions_operation,versions_xid,apple from t_user versions between scn minvalue and maxvalue where user_id=3;
select versions_starttime,versions_endtime,versions_operation,versions_xid,apple from t_user versions between scn minvalue and maxvalue where user_id=3;
追加日志数据模式:alter database add supplemental log data;
闪回事务查询(sys用户):select undo_sql from flashback_transaction_query where xid='0F00170006000000';--xid通过闪回版本查询获取