FLASHBACK DATABASE dalla 11.2.0.1 (Guarantee Restore Point)
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 /
-- 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.-- 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';
}