Chinaunix首页 | 论坛 | 博客
  • 博客访问: 84825
  • 博文数量: 37
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 386
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-11 11:33
文章分类

全部博文(37)

文章存档

2011年(1)

2010年(30)

2009年(6)

我的朋友

分类: LINUX

2010-03-08 22:11:50

前端时间开始了对《循序渐进ORACLE》这本书的学习研究
为了巩固学习知识,现每天日记于此
今天的话题:
ORACLE的闪回特性
ORACLE的这个闪回特性,真是让人倍感兴奋,因为他减轻了DBA的工作复杂度。
如果用户误操作,删除业务中原本不该删除的数据
这是就要利用到oracle 9i 版本中全新推出的——闪回特性
案例模仿:
假如hr用户在工作过程中将自己的表hr_test中的数据误删除
conn hr/hr
create table hr_test values(id number,name char(10));
commit;
插入数据以供模拟,(这里插入1000条记录以供测试)
begin
for i in 1 .. 1000
loop
insert into hr_test values(i,'Love');
end loop;
end;
/
commit;
现在删除20条记录
delete from hr_test where rownum < 21;
commit;(注意此处已经提交)
接下来怎么恢复呢?
这个就要利用闪回特性了:
以sys用户查看此时系统的scn
select dbms_flashback.get_system_change_number from dual;
结果为(我的测试库):2143983
在hr用户查看hr_test表的数据条数
select count(id) from hr_test ;
创建恢复数据表
create table hr_test_recov as select * from hr_test where 1=0;
(注意上句的1=0的意思是创建与hr_test表结构一样但为空的数据表hr_test_recov)
开始恢复操作:
当前scn为2143983
select count(*) from hr_test as of scn 2120000;
看看结果为多少,如果结果出现诸如如下信息:
ERROR at line 1:
ORA-08181: specified number is not a valid system change number
则说明scn提前过多
将scn往后推进,再试试
select count(*) from hr_test as of scn 2137799;
如出现:
count(*)
---------
1000
则说明,此时的scn就是你需要的scn
马上进行如下操作:
insert into hr_test_recov select * from hr_test as of scn 2137799;
并提交
commit;
看看hr_test_recov表中的数据条数
select count(id) from hr_test_recov;
绝对是1000条
然后将hr_test_recov的数据导入hr_test表中即可。
可见,闪回特性真的很好。
---THE END---
阅读(1039) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~