首页 > 数据库 > Oracle > 基于时间戳闪回数据库
SQL> create table fbdb_time as select * from fbdb_scn where 1=2;
Table created.
第一条数据
SQL> insert into fbdb_time select 1 as
2 id,dbms_flashback.get_system_change_number as scn,
3 sysdate as dd from dual;
第二条数据
SQL> insert into fbdb_time select 2 as
2 id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
1 row created.
SQL> commit;
Commit complete.
第三条数据
SQL> insert into fbdb_time select 3 as
2 id,dbms_flashback.get_system_change_number as scn,sysdate as dd from dual;
1 row created.
SQL> commit;
Commit complete.
SQL> select * from fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
2 781618 2016-10-02 10:25:24
3 781629 2016-10-02 10:25:45
3、同样的,删除用户Scott模拟损坏数据库:
SQL> drop user scott cascade;
User dropped.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
4、打开数据库到mount状态,并逐步验证数据库的恢复状况:
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 587205712 bytes
Database Buffers 243269632 bytes
Redo Buffers 2371584 bytes
Database mounted.
SQL>flashback database to timestamp sysdate-15/1440 ;Flashback complete.
SQL> alter database open read only;
此时,查看数据是否闪回到预期的状态SQL> select * from fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
此时发现,还没有完全恢复SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 587205712 bytes
Database Buffers 243269632 bytes
Redo Buffers 2371584 bytes
Database mounted.
闪回数据库到时间点为2016-10-02 10:25:30,开启到只读状态,并查询数据:
SQL> flashback database to timestamp
2 to_date('2016-10-02 10:25:30','yyyy-mm-dd hh24:mi:ss');
Flashback complete.
SQL> alter database open read only;
SQL> select * from fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
2 781618 2016-10-02 10:25:24
这时候,比上一次的闪回,查询到多了一条数据,这样算尽量地恢复完整,降低数据的损失率alter database open RESETLOGS方式打开数据库
SQL> shutdown abort;
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 835104768 bytes
Fixed Size 2257840 bytes
Variable Size 587205712 bytes
Database Buffers 243269632 bytes
Redo Buffers 2371584 bytes
Database mounted.
SQL> alter database open RESETLOGS;
Database altered.
SQL> select * from scott.fbdb_time;
ID SCN DD
---------- ---------- -------------------
1 781596 2016-10-02 10:24:18
2 781618 2016-10-02 10:25:24
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31392094/viewspace-2125842/ ,如需转载,请注明出处,否则将追究法律责任。