ITPub博客

首页 > 数据库 > Oracle > 010.笔记:恢复用户错误

010.笔记:恢复用户错误

原创 Oracle 作者:limintjhn 时间:2012-10-02 09:45:12 0 删除 编辑

1.FLASHBACK DROP
(1)为了尽量避免 连接错误模式或登录错误实例删除正确的表,可以编辑$ORACLE_HOME/sqlplus/admin,增加一条设置
set sqlprompt "_user'@'_connect_identifier> "
(2)FLASHBACKUP DROP方法只应用于表,但是除了外键约束之外的所有关联对象也将被恢复
(3)ORACLE10G删除表,实际是重命名
(4)DROP后的表在回收站能查到,实际上这些表使用的还是他们原来占用的表空间。RENAME不会改变对象的物理位置。
(5)使用Flashback Drop
drop table purge;
flashback table to before drop rename to ;
flashback table tb_test to before drop;
flashback table "BIN$SKSDKFSKKLSDFKSKDFSKDKSFSLDSFL" to before drop;--回收站里的表名要使用双引号
如果用户被删除,所对应模式的表就不能用Flashback Drop恢复了。

2.练习:通过SQL*plus使用Flashback Drop
(1)创建一个用户
create user dropper identified by dropper;
grant connect,resource to dropper;
connect dropper/dropper;
(2)创建一个有索引和约束的新表
create table names (name varchar2(10));
create index name_idx on names(name);
alter table names add (constraint name_u unique(name));
insert into names values('John');
commit;
(3)
select * from user_objects;
select * from user_constraints;
drop table names;
select * from user_objects;
select * from user_constraints;
select * from "BIN$...";
SELECT * from user_recyclebin;

(4)
flashback table names to before drop;
alter index "BIN$..." rename to name_idx;
alter TABLE names rename constraint "BIN$.." to name_u;

(5)drop user dropper cascade;
select * from dba_recyclebin where owner='DROPPER';


3.管理回收站
(1)管理回收站
使用一个隐藏的参数可以禁用回收站
在SYSTEM表空间中存储的表无法启用FLASHBACK DROP,因为这些表会被立即彻底地清除
(2)收回回收站的空间
如果为数据文件启用了自动扩展的属性,那么只有在已删除对象占用的所有空间都被重新指派之后,ORACLE才会真正地自动扩展文件。
drop table purge
purge table
purge tablespace
purge tablespace user
purge user_recyclebin
purge dba_recyclebin

4.FLASHBACK QUERY
(1)基本的FLASHBACK QUERY
Flashback Query的所有形式都依赖撤销
select * from countries as of timestamp (systimestamp - 5/1440);--查询5分钟之前的状态
select * from regions as of timestamp to_timestamp('2012-09-28 10:02:00','yyyy-mm-dd hh24:mi:ss');
select * from regions as of timestamp to_timestamp('2012-09-28 10:02:00','yyyy-mm-dd hh24:mi:ss')
minus
select * from regions;
--通过dbms_flashback程序包,我们可以将整个会话返回至早先的时间点:
execute dbms_flashback.enable_at_time(to_timestamp('2012-09-28 10:02:00','yyyy-mm-dd hh24:mi:ss'));
execute dbms_flashback.disable;
--FLASHBACK QUERY可以接受一个时间标记或者一个SCN,如果使用指定一个时间点,那么这个时间点将会映射为一个精度为3秒钟的SCN。

(2)Flashback Table Query
对于表闪回操作来说,表上的触发器在默认情况下是禁用的。
为了解决主外键关系的问题,表闪回语法允许使用一条命令闪回多个表。
启用表闪回的第一个步骤是启用表上的记录转移
alter table dept enable row movement;
alter table emp enable row movement;
flashback table dept to timestamp to_timestamp('2012-09-28 10:02:00','yyyy-mm-dd hh24:mi:ss');--单表闪回
flashback table dept,emp to timestamp to_timestamp('2012-09-28 10:02:00','yyyy-mm-dd hh24:mi:ss');--多表闪回
flashback table dept,emp to scn 65232832 enable triggers;--引发DML触发器

select * from TEST_REC as of scn 1241842;--经测试,为scn=1241842生效后的结果集
flashback table TEST_REC to scn 1245345;--经测试,闪回至scn=1245345之后

(5)Flashback Versions Query
--user_id为56的相应记录的所有版本
select username,user_id ,
versions_startscn,
versions_starttime,
versions_endscn,
versions_endtime,
versions_xid, --独特标识符
versions_operation --操作:INSERT UPDATE DELETE
from test_rec
versions between scn minvalue and maxvalue
where user_id=56;

(6)Flashback Transaction Query
--查询可以闪回的事务
select *
from flashback_transaction_query t
where t.logon_user='SYSTEM' and t.table_name='TEST_REC' order by t.commit_timestamp;


(7)闪回与撤销数据
撤销表空间应足够大。设置撤销表空间的retention_guarantee属性,设置undo_retention实例参数。
通过监视V$UNDOSTAT来计算必需的撤销表空间大小。


















[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7901922/viewspace-1059528/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-02-03

  • 博文量
    53
  • 访问量
    36585