FLASHBACK DATABASE ante 11.2.0.1 (Restore Point)

Post testato su Oracle 11gR2.

Per verificare che sia abilitato eseguire la query seguente.

SQL> select FLASHBACK_ON from V$DATABASE;

A cosa serve?
Serve  per effettuare il restore del db in un certo istante di tempo.

Se abilitato, viene attivato un processo di background RVWR e il db genera in automatico nuovi files flashback logs che sono una immagine dei blocchi fisici del database.
Il processo RVWR copia questi files nella flash recovery area in una directory chiamata flashback.
Ad esempio sotto la directory
/home/oracle/rm_flashrecoveryarea/TEST 
avremo le seguenti direcorty

drwxr-x--- 11 oracle oinstall 4096 Jan 22 00:07 archivelog
drwxr-x---  5 oracle oinstall 4096 Jan 20 00:01 autobackup
drwxr-x---  5 oracle oinstall 4096 Jan 22 08:20 backupset
drwxr-x---  2 oracle oinstall 4096 Jun 10  2013 datafile
drwxr-x---  2 oracle oinstall 4096 Jan 22 03:04 flashback


Comi si abilita?
Il database deve essere  in modalità Archivelog (vedi post ARCHIVE LOG) e
deve essere settata la flash recovery area.

1) Chiudere il database
SQL> shutdown immediate;

2) Impostare il db in stato mount
SQL> startup nomount;
SQL> alter database mount;

3) Impostare lunghezza in minuti della finestra di flashback (di default è 1440 minuti cioè un giorno).
SQL>alter system set db_flashback_retention_target=2880 scope=both;

esempio 2 giorni

Di seguito la query di verifica dei parametri di sistema.

select * from v$parameter 
where upper(name) ='DB_FLASHBACK_RETENTION_TARGET';

4) Eseguire da Rman o Sqlplus il comando
SQL> alter database flashback on;

5) Restar del database
SQL> alter database open;


A questo punto viene creato sotto la flash recovery area una nuova directory
drwxr-x--- 3 oracle oinstall 4096 Jan 17 12:38 autobackup
drwxr-x--- 5 oracle oinstall 4096 Jan 21 16:10 backupset
drwxr-x--- 2 oracle oinstall 4096 Jan  9 11:17 control
drwxr-x--- 2 oracle oinstall 4096 Jan 21 13:23 datafile
drwxr-x--- 2 oracle oinstall 4096 Jan 22 12:00 flashback


Come si effettua il restore? 
Quando si effettua il flashback database il database deve in stato mount da RMAN o SQLPLUS:

RMAN> shutdown immediate;
RMAN> startup mount;

Successivamente si possono effettuare queste istruzioni

RMAN> FLASHBACK DATABASE TO TIME="TO_DATE('2018-10-01 17:00:00','YYYY-MM-DD HH24:MI:SS')";
RMAN> FLASHBACK DATABASE TO SCN=283738;
RMAN> FLASHBACK DATABASE TO SEQUENCE=223 THREAD=1;
RMAN> FLASHBACK DATABASE TO RESTORE POINT 'restore_point';

E' consigliato aprire prima il database in modalità sola lettura e controllare che il valore SCN o il tempo di restore del database sia quello desiderato

RMAN> sql 'alter database open read only';

Controllare lo stato desiderato ed infine riaprire il db in modalità resetslogs.
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN>  alter database open RESETLOGS;

Se il valore non è quello atteso,  eseguire il recovery del database per portarlo ai valori attesi ed infine aprire il database in modalità resetlogs.

Per risalire all'ultimo SCN e TIME_STAMP a cui è possibile effettuare il recovery del db tramite la flashback, usare la vista seguente.
select oldest_flashback_scn ,oldest_flashback_time
from V$FLASHBACK_DATABASE_LOG

SCN, System Change Number, è un progressivo numerico assegnato automaticamente e in tempo reale dal database ad ogni transazione committata.
Per risalire all'ultimo SCN utilizzare la seguente funzione.
select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER from dual;
oppure la vista del dizionario dati
select CURRENT_SCN from V$DATABASE ;


Come si disabilita?

SQL> startup mount;
SQL> alter database flashback off;
SQL> alter database open;


La vista V$FLASHBACK_DATABASE_LOG serve per monitorare lo spazio della FRA.
flashback_size    indica la dimensione dei flashback data
estimated_flashback_size    fornisce una stima della dimensione dei flashback logs che soddisfano la retention del database (colonna retention_target).

L'istruzione Flashback Database non può essere utilizzata se è stato cancellato un datafile o un tablespace o se è stata ridotta la dimensione di un datafile. Occorre usare in questo caso RMAN.



Post popolari in questo blog

ORA-12154: TNS: il listener non è attualmente a conoscenza del servizio richiesto nel descrittore di connessione

Create e Drop Pluggable Database