FLASHBACK DATABASE dalla 11.2.0.1 (Guarantee Restore Point)

Flashback Database is much faster than point-in-time recovery because it does not require restoring datafiles from backup and requires applying fewer changes from the archived redo logs.

Creare un "guarantee restore point" del database così da potere effettuare un restore del db ad uno specifico valore SCN in un qualsiasi instante di tempo anche al di là del periodo definito dal paramatro di retention DB_FLASHBACK_RETENTION_TARGET.
Occorre abilitare la modalità Archivelog e la Flashback Database.

Dalla 11.2.0.1 non c'è bisogno di spegnere il db per metterlo in modalità Flashback ON ma il db deve essere in modalità archivelog.

 -- Verificare lo stato archive e flash recovery area

select log_mode,flashback_on from v$database;

-- Verificare il puntamento degli archievelog

 SQL> archive log list;

 Database log mode Archive Mode

 Automatic archival Enabled

 Archive destination /u05/oradata/CORE/

 Oldest online log sequence 2088

 Next log sequence to archive 2090

 Current log sequence 2090


-- Configurare la flashrecovery area che contiene il punto di restore

SQL> alter system set db_recovery_file_dest_size=20g scope=both;

SQL> alter system set db_recovery_file_dest='/u01/app/oracle/fra/' scope=both;

Viene creata sotto /u01/app/oracle/fra/

la directory  <nomeSID>/flashback

ATTENZIONE: mettere ad ON la flashback serve solo se oltre al punto di recovery iniziale si desiderano anche gli SCN successivi al primo punto di recovery. 

L'attivazione della Flashback non serve se basta solo tornare al primo restore point.

-- Attivare solo la flashback  se già abilitato archivelog mode

alter database flashback on;  <-- non si può fare finchè il db non è in archivelog mode

-- Se non abilitata la modalità archivelog occorre eseguire i seguenti passi

shutdown immediate;

startup mount;

alter database archivelog;

alter database open

alter database flashback on;


--Verificare la situazione:

select log_mode,flashback_on from v$database;

archive log list; 

-- Creare il resore point garantee GRP

SQL> create restore point BEFORE_SCHEMA_CHANGES guarantee flashback database;


-- Verificare la creazione

set pages 1000

set lines 1000

col name for a30

col TIME for a40

SELECT name,scn,database_incarnation#, guarantee_flashback_database, storage_size, time 

FROM gv$restore_point;

(gv se ambiente RAC)

Oppure

# rman target / 

RMAN>  LIST RESTORE POINT ALL;


-- Verificare gli oggetti presenti nella FRA

select * from v$flash_recovery_area_usage;


-- Verificare spazio disponibile e spazio occupato

select space_used/(1024*1024*1024) GB,space_limit/(1024*1024*1024) GB 

from v$recovery_file_dest;


IMPORTANTE: per avere un garantee restore point occorre conservare gli archive log.

Se dopo la creazione del restore point disabilito la flashback , posso restorare solo al punto di creazione del restore point.

When flashback database is enabled, old versions of blocks are written to the flashback logs if they are changed. During a flashback of the database, the old versions of blocks are copied back into the datafiles. The most recent version before the restore point is used and then made consistent using the archived logs.

Generally speaking, Flashback technology can only undo changes and redo logs can only redo changes or roll the database forward. As such, Flashback logs are pretty much like the opposite of archived redo logs.

Come individuare  determinare gli archivelog richiesti per effettuare guaranteed restore point ?
(Doc ID 1524217.1)

completion_time che indica la data della creazione del relativo archive.

 SELECT DISTINCT al.thread#, al.sequence#, al.resetlogs_change#, al.resetlogs_time,al.completion_time
    FROM v$archived_log al,
         (select grsp.rspfscn               from_scn,
                 grsp.rspscn                to_scn,
                 dbinc.resetlogs_change#    resetlogs_change#,
                 dbinc.resetlogs_time       resetlogs_time
            from x$kccrsp grsp,  v$database_incarnation dbinc
           where grsp.rspincarn = dbinc.incarnation#
             and bitand(grsp.rspflags, 2) != 0
             and bitand(grsp.rspflags, 1) = 1 -- guaranteed
             and grsp.rspfscn <= grsp.rspscn -- filter clean grp
             and grsp.rspfscn != 0
         ) grsp
      WHERE al.next_change#   >= grsp.from_scn
          AND al.first_change#    <= (grsp.to_scn + 1)
          AND al.resetlogs_change# = grsp.resetlogs_change#
          AND al.resetlogs_time       = grsp.resetlogs_time
          AND al.archived = 'YES';

Andare nella directory degli archivelog del sistema operativo e verificare che esistono.

-- Restorare ad un dato restore point

SQL> shutdown immediate;

SQL> startup mount;

SQL> flashback database to restore point BEFORE_SCHEMA_CHANGES;

SQL>  alter database open resetlogs;


--Eliminare un restore point:

-- ATTENZIONE: il restore point garantee deve essere eliminato a mano, se viene lasciato attivo e riempie la FRA si blocca il db

SQL> DROP RESTORE POINT BEFORE_SCHEMA_CHANGES;


Se siamo interessati solo al recupero di un solo un restore point e non vogliamo far crescere troppo gli archive log perché non abbiamo spazio (in genere in ambienti non di produzioni) allora possiamo salvare solo gli archive log del giorno in cui è stato creato il restore point e usare uno script a crontab per cancellare tutti gli altri.

crontab -l -u oracle

#5 15 * * * /home/oracle/SCRIPT/delete_archive.sh

# cat /home/oracle/SCRIPT/delete_archive.sh

#!/usr/bin/bash

export ORACLE_SID=TES01

export ORACLE_BASE=/u01/app/oracle

export ORACLE_HOSTNAME=<nomehost>

export ORACLE_HOME=/u01/app/oracle/product/11g/dbhom21

export PATH=$PATH:$ORACLE_HOME/bin

rman  target / @/home/oracle/SCRIPT/delete_archive.sql

# cat /home/oracle/SCRIPT/delete_archive.sql

run{

delete archivelog until time 'sysdate - 0';

}




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