07 November, 2016

Flashback Database -- 1 : Introduction to Operations

Continuing on my previous post,  ....

In 11gR2,  ALTER DATABASE FLASHBACK ON   and OFF can be executed when the database is OPEN.  Setting FLASHBACK OFF results in deletion of all Flashback Files.

Here is some information that I have pulled from my test database environment :

SQL> alter session set nls_date_format='DD-MON-RR HH24:MI:SS';

Session altered.

SQL> 
SQL> select oldest_flashback_scn, oldest_flashback_time,
  2  retention_target, flashback_size
  3  from v$flashback_database_log;

OLDEST_FLASHBACK_SCN OLDEST_FLASHBACK_T RETENTION_TARGET FLASHBACK_SIZE
-------------------- ------------------ ---------------- --------------
             7140652 07-NOV-16 10:53:30              180      314572800

SQL> select sysdate from dual;

SYSDATE
------------------
07-NOV-16 17:46:54

SQL> 
SQL> select begin_time, end_time, flashback_data, estimated_flashback_size
  2  from v$flashback_database_stat
  3  order by begin_time;

BEGIN_TIME         END_TIME           FLASHBACK_DATA ESTIMATED_FLASHBACK_SIZE
------------------ ------------------ -------------- ------------------------
06-NOV-16 18:56:28 06-NOV-16 21:20:55      202129408                251873280
06-NOV-16 21:20:55 07-NOV-16 09:53:26      107102208                 62054400
07-NOV-16 09:53:26 07-NOV-16 10:53:30       51609600                 67866624
07-NOV-16 10:53:30 07-NOV-16 13:14:45       10682368                 60887040
07-NOV-16 13:14:45 07-NOV-16 14:14:51       66002944                 67986432
07-NOV-16 14:14:51 07-NOV-16 15:14:57       10018816                 66112512
07-NOV-16 15:14:57 07-NOV-16 16:15:01       10190848                 64441344
07-NOV-16 16:15:01 07-NOV-16 17:15:05       53559296                 68751360
07-NOV-16 17:15:05 07-NOV-16 17:47:57       52862976                        0

9 rows selected.

SQL> 
SQL> select log#, sequence#, bytes/1048576 Size_MB, first_time
  2  from v$flashback_database_logfile
  3  order by sequence#;

      LOG#  SEQUENCE#    SIZE_MB FIRST_TIME
---------- ---------- ---------- ------------------
         6          6         50 07-NOV-16 09:00:46
         1          7         50 07-NOV-16 10:36:01
         2          8         50 07-NOV-16 13:13:22
         3          9         50 07-NOV-16 13:43:28
         4         10         50 07-NOV-16 16:43:49
         5         11         50 07-NOV-16 17:44:42

6 rows selected.

SQL> 


Firstly, we note (as in my previous blog post), that the available flashback that is from 10:53am to 5:46pm (almost 7hours) exceeds the Flashback Target of 3hours (180minutes).  Apparently, Flashback Logfiles 1 to 5 have already been purged (but I find no entries for the deletions in the alert log).

Note how the "earliest time" does not match in all three views.  The OLDEST_FLASHBACK_TIME is 10:53am although V$FLASHBACK_DATABASE_STAT reports statistics from the previous day (I had enabled Flashback in the database at 18:56:27 of 06-Nov) while V$FLASHBACK_DATABASE_LOGILE shows an existing logfile from 09:00am to 10:36am.

Let me do a Flashback.  I must rely on the V$FLASHBACK_DATABASE_LOG view to know that I  cannot flashback beyond 10:53am.

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             750781320 bytes
Database Buffers          310378496 bytes
Redo Buffers                5517312 bytes
Database mounted.
SQL> 
SQL> flashback database to timestamp trunc(sysdate)+11/24;

Flashback complete.

SQL> 
SQL> alter database open read only;  --- to verify data if necessary

Database altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup;     
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size                  2260088 bytes
Variable Size             750781320 bytes
Database Buffers          310378496 bytes
Redo Buffers                5517312 bytes
Database mounted.
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open


SQL> alter database open resetlogs;

Database altered.

SQL> 


A FLASHBACK DATABASE requires an OPEN RESETLOGS to open READ WRITE.

Let's look at the alert log for messages about the Flashback operation itself :

Mon Nov 07 17:56:36 2016
flashback database to timestamp trunc(sysdate)+11/24
Flashback Restore Start
Flashback Restore Complete
Flashback Media Recovery Start
 started logmerger process
Parallel Media Recovery started with 2 slaves
Flashback Media Recovery Log /u02/FRA/ORCL/archivelog/2016_11_07/o1_mf_1_81_d2052ofj_.arc
Mon Nov 07 17:56:43 2016
Incomplete Recovery applied until change 7141255 time 11/07/2016 11:00:01
Flashback Media Recovery Complete
Completed: flashback database to timestamp trunc(sysdate)+11/24
Mon Nov 07 17:57:08 2016
alter database open read only


What happens if I disable and re-enable Flashback ?

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

SQL> alter database flashback off;

Database altered.

SQL> 

From the alert log :
Mon Nov 07 18:03:02 2016
alter database flashback off
Stopping background process RVWR
Deleted Oracle managed file /u02/FRA/ORCL/flashback/o1_mf_d1y32vjv_.flb
Deleted Oracle managed file /u02/FRA/ORCL/flashback/o1_mf_d1y32xq0_.flb
Deleted Oracle managed file /u02/FRA/ORCL/flashback/o1_mf_d1y3bhkx_.flb
Deleted Oracle managed file /u02/FRA/ORCL/flashback/o1_mf_d1y3dd8r_.flb
Deleted Oracle managed file /u02/FRA/ORCL/flashback/o1_mf_d1y6r6bf_.flb
Deleted Oracle managed file /u02/FRA/ORCL/flashback/o1_mf_d1ycky3v_.flb
Flashback Database Disabled
Completed: alter database flashback off

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

SQL> alter database flashback on;

Database altered.

SQL> 

From the alert log :
Mon Nov 07 18:04:21 2016
alter database flashback on
Starting background process RVWR
Mon Nov 07 18:04:21 2016
RVWR started with pid=30, OS id=12621
Flashback Database Enabled at SCN 7142426
Completed: alter database flashback on

From the FRA :
[oracle@ora11204 flashback]$ pwd
/u02/FRA/ORCL/flashback
[oracle@ora11204 flashback]$ ls -ltr
total 102416
-rw-rw----. 1 oracle oracle 52436992 Nov  7 18:04 o1_mf_d20nf7wc_.flb
-rw-rw----. 1 oracle oracle 52436992 Nov  7 18:05 o1_mf_d20nf5nz_.flb
[oracle@ora11204 flashback]$ 

SQL> alter session set nls_date_Format='DD-MON-RR HH24:MI:SS';

Session altered.

SQL> select log#, sequence#, bytes/1048576 Size_MB, first_time
  2  from v$flashback_database_logfile
  3  order by sequence#;

      LOG#  SEQUENCE#    SIZE_MB FIRST_TIME
---------- ---------- ---------- ------------------
         2          1         50
         1          1         50 07-NOV-16 18:04:22

SQL> 
 


So, I can set FLASHBACK OFF and ON when the database is OPEN.  (But I can't execute a FLASHBACK TO .... with the database OPEN).
.
.
.

No comments: