Oracle 表和表数据恢复

阅读目录

  • 1. 表恢复
  • 2. 表数据恢复

1. 表恢复

   对误删的表,只要没有使用 purge 永久删除选项,那么基本上是能从 flashback table 区恢复回来的。

   数据表和其中的数据都是可以恢复回来的,记得 flashback table 是从 Oralce 10g 提供的,一般步骤有:

   a.从 flashback table 里查询被删除的数据表

select * from recyclebin order by droptime desc

   b.执行表的恢复

flashback table '需要恢复的表名' to before drop

2. 表数据恢复

   对误删的表记录,只要没有 truncate 语句,就可以根据事务的提交时间进行选择恢复。

   a. 先从 flashback_transaction_query 视图里查询,视图提供了供查询用的表名称、事务提交时间、undo_sql等字段。

select * from flashback_transaction_query where table_name='需要恢复数据的表名(大写)';

   b.查询删除的时间点

select to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss') time,
       to_char(dbms_flashback.get_system_change_number) scn
  from dual;

   或者你知道大概记得删除点,你也可以这样试试查询,找出删除前的时间点

select * from '需要恢复数据的表名' as of timestamp to_timestamp('时间点', 'yyyy-mm-dd hh24:mi:ss');

   c.进行数据恢复

   通过第二步找到数据丢失的时间点,恢复极为简单,语句为

flashback table '需要恢复数据的表名' to timestamp to_timestamp('数据丢失的前一时间点','yyyy-mm-dd hh24:mi:ss');

   注意:在执行上述操作的时候,需要允许 oracle 修改分配给行的 rowid,这时候 oracle 需要给恢复的数据分配新的物理地址。

alter table table_name enable row movement;

   其实找到数据丢失前的时间点后,恢复数据也可以将需要恢复的数据直接插入到目标表中

insert into '数据丢失的表' select * from t of timestamp to_timestamp('时间点', 'yyyy-mm-dd hh24:mi:ss') where .......;

猜你喜欢

转载自www.linuxidc.com/Linux/2016-08/134700.htm
今日推荐