闪回数据库的简单介绍

闪回数据库方法可以用sqlplus,也可以用RMAN执行:

创新互联公司主营和县网站建设的网络公司,主营网站建设方案,成都App制作,和县h5微信小程序搭建,和县网站营销推广欢迎和县等地区企业咨询

SQL> FLASHBACK DATABASE TO TIMESTAMP(''); --(基于时间点)

SQL> FLASHBACK DATABASE TO SCN ; --(基于SCN)

SQL> FLASHBACK DATABASE TO RESTORE POINT ; --(基于sestore point ,创建命令create restore point 名称)

RMAN> FLASHBACK DATABASE TO TIME =  "TO_DATE('2009-05-27 16:00:00',  'YYYY-MM-DD HH24:MI:SS')";--(基于时间点)

RMAN> FLASHBACK DATABASE TO SCN=23565; --(基于SCN)

RMAN> FLASHBACK DATABASE TO SEQUENCE=223 THREAD=1; --(序列号,可用list incarnation of database 查看当前sequence)

上述两种方法都可以实现flashback database需要注意的是操作完成后使用命令打开数据库alter database open resetlogs

下面来演示下基于时间点的闪回数据库实验:

1.查看当前归档

SQL> archive log list

Database log mode       Archive Mode

Automatic archival       Enabled

Archive destination       USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     25

Next log sequence to archive   27

Current log sequence       27

2.查看下闪回数据库打开没,如果没打开使用alter database flashback on命令打开

SQL> select flashback_on from v_$database;

FLASHBACK_ON

------------------

YES

3.先查询当前时间

SQL> select to_char(sysdate,'yyyy-mm-dd:hh34:mi:ss') from dual;

TO_CHAR(SYSDATE,'YY

-------------------

2017-07-17:16:16:45

4.切换HR用 ,用HR建个表TMP717并 插入一行数据,接着把表删除(加上PURGE),用DBA用户切换日志

SQL> conn hr/123456

Connected.

SQL> create table tmp717 (cons_no varchar2(10));

Table created.

                               

SQL> insert into tmp717 values('1');

1 row created.

SQL> commit;

Commit complete.

SQL> select to_char(sysdate,'yyyy-mm-dd:hh34:mi:ss') from dual;

TO_CHAR(SYSDATE,'YY

-------------------

2017-07-17:16:20:47

SQL> drop table tmp717 purge 

  2  ;

Table dropped.

SQL> conn / as sysdba

Connected.

SQL> alter system switch logfile;

System altered.

SQL> archive log list

Database log mode       Archive Mode

Automatic archival       Enabled

Archive destination       USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence     26

Next log sequence to archive   28

Current log sequence       28

(当前日志变成28)

5.关闭数据库,启动到MOUNT状态(闪回数据库必须的操作)

SQL> shutdown immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

SQL> startup mount

ORACLE instance started.

Total System Global Area  820236288 bytes

Fixed Size    1339628 bytes

Variable Size  549457684 bytes

Database Buffers  264241152 bytes

Redo Buffers    5197824 bytes

Database mounted.

SQL> exit

6.打开RMAN进行闪回操作

[oracle@station4 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jul 17 16:31:13 2017

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1359978017, not open)

RMAN> list incarnation of database ;--(先查看下当前化身)

List of Database Incarnations

DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1       1       ORCL     1359978017       PARENT  1          13-AUG-09

2       2       ORCL     1359978017       CURRENT 754488     22-NOV-13

RMAN> run {

2> sql "alter session set nls_date_format=''YYYY-MM-DD:HH24:MI:SS''";

3> set until time '2017-07-17:16:20:47';

4> restore database;

5> recover database;}

7.用RESETLOGS打开数据库,并查询表还原成功

SQL> alter database open resetlogs;

Database altered.

SQL> select * from hr.tmp717;

CONS_NO

----------

1

8.重新查看化身

RMAN> list incarnation of database;

List of Database Incarnations

DB Key  Inc Key DB Name  DB ID            STATUS  Reset SCN  Reset Time

------- ------- -------- ---------------- --- ---------- ----------

1       1       ORCL     1359978017       PARENT  1          13-AUG-09

2       2       ORCL     1359978017       PARENT  754488     22-NOV-13

3       3       ORCL     1359978017       CURRENT 1083685    17-JUL-17

上述实验也可以用SQL> FLASHBACK DATABASE TO TIMESTAMP('2017-07-17:16:20:47'); 操作结果是一样的

实验中看出化身了一个,当前化身号是1083685,并且删除的表还原回来了,表示成功执行。


文章题目:闪回数据库的简单介绍
链接地址:http://pwwzsj.com/article/ijceij.html