oracle进行表数据恢复
oracle进行表数据恢复
NotFoundException 发表于3年前
oracle进行表数据恢复
  • 发表于 3年前
  • 阅读 9
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   


1、建表

-- Create table
create table DARCY
(
ID   NUMBER,
INFO NVARCHAR2(32)
)
tablespace DATA_SGPM
pctfree 10
initrans 1
maxtrans 255
storage
(
    initial 64K
    minextents 1
    maxextents unlimited
);

2、插入数据

insert into "SGPM"."DARCY"("ID","INFO") values ('1','aaa');

insert into "SGPM"."DARCY"("ID","INFO") values ('2','bbb');

insert into "SGPM"."DARCY"("ID","INFO") values ('3','ccc');

3、删除数据

SQL> select * from darcy;

        ID INFO
---------- --------------------------------------------------------------------------------
         1 aaa
         2 bbb
         3 ccc

SQL> delete from darcy where id = 1;

1 row deleted

SQL> commit;

Commit complete

SQL> select * from darcy;

        ID INFO
---------- --------------------------------------------------------------------------------
         2 bbb
         3 ccc

4、恢复数据

方法1:

查询最新的系统变更number

SQL> select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER
------------------------
                18144344

查看此次变更后的表记录

SQL> select * from darcy as of scn 18144344;

        ID INFO
---------- --------------------------------------------------------------------------------
         2 bbb
         3 ccc

说明这是删除数据后的表记录,我们只要找到某个scn,即删除表记录前的scn,

恢复到这个scn时的记录。

SQL> SELECT * FROM DARCY as of scn 18144252;

        ID INFO
---------- --------------------------------------------------------------------------------
         1 aaa
         2 bbb
         3 ccc

然后直接执行insert语句

方法2:

SQL> select * from flashback_transaction_query where table_name='DARCY';

XID               START_SCN START_TIMESTAMP COMMIT_SCN COMMIT_TIMESTAMP LOGON_USER                     UNDO_CHANGE# OPERATION                        TABLE_NAME                                                                       TABLE_OWNER                      ROW_ID              UNDO_SQL
---------------- ---------- --------------- ---------- ---------------- ------------------------------ ------------ -------------------------------- -------------------------------------------------------------------------------- -------------------------------- ------------------- --------------------------------------------------------------------------------
07001500AB280000   18144149 2010-9-9 10:14:   18144281 2010-9-9 10:17:1 SGPM                                      1 DELETE                           DARCY                                                                            SGPM                             AAAYQwAAcAAAKk2AAA insert into "SGPM"."DARCY"("ID","INFO") values ('1','aaa');
080018005F370000   18144244 2010-9-9 10:16:   18144252 2010-9-9 10:16:3 SGPM                                      1 INSERT                           DARCY                                                                            SGPM                             AAAYQwAAcAAAKk2AAC delete from "SGPM"."DARCY" where ROWID = 'AAAYQwAAcAAAKk2AAC';
080018005F370000   18144244 2010-9-9 10:16:   18144252 2010-9-9 10:16:3 SGPM                                      2 INSERT                           DARCY                                                                            SGPM                             AAAYQwAAcAAAKk2AAB delete from "SGPM"."DARCY" where ROWID = 'AAAYQwAAcAAAKk2AAB';
080018005F370000   18144244 2010-9-9 10:16:   18144252 2010-9-9 10:16:3 SGPM                                      3 INSERT                           DARCY                                                                            SGPM                             AAAYQwAAcAAAKk2AAA delete from "SGPM"."DARCY" where ROWID = 'AAAYQwAAcAAAKk2AAA';

执行UNDO_SQL,即:insert into "SGPM"."DARCY"("ID","INFO") values ('1','aaa');即可恢复数据。

或者直接运行:

SQL> flashback table DARCY to timestamp to_timestamp('2010-9-9 10:16:3','yyyy-mm-dd hh24:mi:ss');

flashback table DARCY to timestamp to_timestamp('2010-9-9 10:16:3','yyyy-mm-dd hh24:mi:ss')

ORA-08189: 因为未启用行移动功能, 不能闪回表

SQL> alter table DARCY enable row movement;

Table altered

SQL> flashback table DARCY to timestamp to_timestamp(2010-9-9 10:17:1,'yyyy-mm-dd hh24:mi:ss');

Done

SQL> SELECT * FROM DARCY;

        ID INFO
---------- --------------------------------------------------------------------------------
         1 aaa
         2 bbb
         3 ccc

5、drop表后的恢复

SQL> drop table darcy;

Table dropped

SQL> select * from darcy;

select * from darcy

ORA-00942: 表或视图不存在

SQL> select * from recyclebin;

OBJECT_NAME                    ORIGINAL_NAME                    OPERATION TYPE                      TS_NAME                        CREATETIME          DROPTIME               DROPSCN PARTITION_NAME                   CAN_UNDROP CAN_PURGE    RELATED BASE_OBJECT PURGE_OBJECT      SPACE
------------------------------ -------------------------------- --------- ------------------------- ------------------------------ ------------------- ------------------- ---------- -------------------------------- ---------- --------- ---------- ----------- ------------ ----------
BIN$CrbfFp0nRTWzETrAMvbD+A==$0 DARCY                            DROP      TABLE                     DATA_SGPM

SQL> SELECT * FROM USER_RECYCLEBIN;

OBJECT_NAME                    ORIGINAL_NAME                    OPERATION TYPE                      TS_NAME                        CREATETIME          DROPTIME               DROPSCN PARTITION_NAME                   CAN_UNDROP CAN_PURGE    RELATED BASE_OBJECT PURGE_OBJECT      SPACE
------------------------------ -------------------------------- --------- ------------------------- ------------------------------ ------------------- ------------------- ---------- -------------------------------- ---------- --------- ---------- ----------- ------------ ----------
BIN$CrbfFp0nRTWzETrAMvbD+A==$0 DARCY                            DROP      TABLE                     DATA_SGPM                      2010-09-09:10:15:50 2010-09-09:11:12:04   18154031                                  YES        YES            99376       99376        99376          8

SQL> flashback table darcy to before drop;

Done

SQL> select * from darcy;

        ID INFO
---------- --------------------------------------------------------------------------------
         1 aaa
         2 bbb
         3 ccc



共有 人打赏支持
粉丝 12
博文 88
码字总数 15044
×
NotFoundException
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: