O cenário que vamos simular neste artigo considera que todos os control files foram perdidos, e que:
- O banco está rodando em ARCHIVELOG mode;
- O backup do banco está disponível e com a opção AUTOBACKUP implementada;
- O formato do AUTOBACKUP está definido para a FRA;
- E os Online Redo Logs estão disponíveis.
Reconhecendo o nosso laboratório:
[oracle@oel8 ~]$ sqlplus / as sysdba
SQL*Plus: Release 18.0.0.0.0 - Production on Wed Aug 18 19:30:38 2021
Version 18.13.0.0.0
Copyright (c) 1982, 2018, Oracle. All rights reserved.
Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.13.0.0.0
SQL> SELECT NAME,OPEN_MODE,LOG_MODE FROM V$DATABASE;
NAME OPEN_MODE LOG_MODE
--------- -------------------- ------------
RMANDB READ WRITE ARCHIVELOG
SQL> SHO PARAMETER CONTROL_FILES;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_files string /oracle/fra/RMANDB/controlfile
/o1_mf_h8nytrty_.ctl, /oracle/
dados/RMANDB/o1_mf_h8nytrhd_.c
tl
Realizando o backup do banco de dados:
[oracle@oel8 ~]$ rman target /
Recovery Manager: Release 18.0.0.0.0 - Production on Wed Aug 18 19:31:21 2021
Version 18.13.0.0.0
Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
connected to target database: RMANDB (DBID=3825250984)
RMAN> BACKUP DATABASE;
Starting backup at 2021-08-18:19:31:26
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=61 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/dados/RMANDB/datafile/o1_mf_system_h8nynqfx_.dbf
input datafile file number=00003 name=/oracle/dados/RMANDB/datafile/o1_mf_sysaux_h8nyq35q_.dbf
input datafile file number=00004 name=/oracle/dados/RMANDB/datafile/o1_mf_undotbs1_h8nyrjdr_.dbf
input datafile file number=00005 name=/oracle/dados/RMANDB/datafile/ts_cortex_catalog.dbf
input datafile file number=00002 name=/oracle/dados/RMANDB/datafile/ts_hipo_catalog.dbf
input datafile file number=00007 name=/oracle/dados/RMANDB/datafile/o1_mf_users_h8nyrkn7_.dbf
channel ORA_DISK_1: starting piece 1 at 2021-08-18:19:31:27
channel ORA_DISK_1: finished piece 1 at 2021-08-18:19:32:32
piece handle=/oracle/fra/RMANDB/backupset/2021_08_18/o1_mf_nnndf_TAG20210818T193126_jkv2kzq7_.bkp tag=TAG20210818T193126 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
Finished backup at 2021-08-18:19:32:32
Starting Control File and SPFILE Autobackup at 2021-08-18:19:32:32
piece handle=/oracle/fra/RMANDB/autobackup/2021_08_18/o1_mf_s_1080934352_jkv2n19z_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2021-08-18:19:32:35
Deletando todos os control files:
RMAN> host 'rm /oracle/fra/RMANDB/controlfile/o1_mf_h8nytrty_.ctl /oracle/dados/RMANDB/o1_mf_h8nytrhd_.ctl';
host command complete
RMAN> host 'ls -lthr /oracle/fra/RMANDB/controlfile/o1_mf_h8nytrty_.ctl /oracle/dados/RMANDB/o1_mf_h8nytrhd_.ctl';
ls: cannot access '/oracle/fra/RMANDB/controlfile/o1_mf_h8nytrty_.ctl': No such file or directory
ls: cannot access '/oracle/dados/RMANDB/o1_mf_h8nytrhd_.ctl': No such file or directory
host command complete
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06135: error executing host command: Additional information: 512
Nessa etapa, nossa instância já identificou o problema:
SQL> SELECT NAME FROM V$DATABASE;
SELECT NAME FROM V$DATABASE
*
ERROR at line 1:
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/oracle/fra/RMANDB/controlfile/o1_mf_h8nytrty_.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
E ao tentar logar no RMAN devido a falta de control file:
[oracle@oel8 ~]$ rman target /
Recovery Manager: Release 18.0.0.0.0 - Production on Wed Aug 18 19:36:49 2021
Version 18.13.0.0.0
Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: initialization of internal recovery manager package failed
RMAN-06003: Oracle error from target database:
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/oracle/fra/RMANDB/controlfile/o1_mf_h8nytrty_.ctl'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Abortando a instância (não é possível realizar um shutdown \”limpo\” quando um contro file está indisponível):
SQL> SHU ABORT;
ORACLE instance shut down.
SQL>
Definindo o DBID do nosso banco e restaurando os control files:
RMAN> SET DBID 3825250984;
executing command: SET DBID
RMAN> STARTUP NOMOUNT;
Oracle instance started
Total System Global Area 1610612016 bytes
Fixed Size 8658224 bytes
Variable Size 520093696 bytes
Database Buffers 1073741824 bytes
Redo Buffers 8118272 bytes
RMAN> RESTORE CONTROLFILE FROM AUTOBACKUP;
Starting restore at 2021-08-18:19:42:06
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=38 device type=DISK
recovery area destination: /oracle/fra
database name (or database unique name) used for search: RMANDB
channel ORA_DISK_1: AUTOBACKUP /oracle/fra/RMANDB/autobackup/2021_08_18/o1_mf_s_1080934352_jkv2n19z_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210818
channel ORA_DISK_1: restoring control file from AUTOBACKUP /oracle/fra/RMANDB/autobackup/2021_08_18/o1_mf_s_1080934352_jkv2n19z_.bkp
channel ORA_DISK_1: control file restore from AUTOBACKUP complete
output file name=/oracle/fra/RMANDB/controlfile/o1_mf_h8nytrty_.ctl
output file name=/oracle/dados/RMANDB/o1_mf_h8nytrhd_.ctl
Finished restore at 2021-08-18:19:42:09
Após isso podemos fazer as etapas para o recover:
RMAN> SHUTDOWN IMMEDIATE;
Oracle instance shut down
RMAN> STARTUP MOUNT;
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 1610612016 bytes
Fixed Size 8658224 bytes
Variable Size 520093696 bytes
Database Buffers 1073741824 bytes
Redo Buffers 8118272 bytes
RMAN> RECOVER DATABASE;
Starting recover at 2021-08-18:19:44:49
Starting implicit crosscheck backup at 2021-08-18:19:44:49
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=44 device type=DISK
Crosschecked 1 objects
Finished implicit crosscheck backup at 2021-08-18:19:44:50
Starting implicit crosscheck copy at 2021-08-18:19:44:50
using channel ORA_DISK_1
Finished implicit crosscheck copy at 2021-08-18:19:44:50
searching for all files in the recovery area
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /oracle/fra/RMANDB/autobackup/2021_08_18/o1_mf_s_1080934352_jkv2n19z_.bkp
using channel ORA_DISK_1
starting media recovery
archived log for thread 1 with sequence 12 is already on disk as file /oracle/dados/RMANDB/onlinelog/o1_mf_3_jjml0g5l_.log
archived log file name=/oracle/dados/RMANDB/onlinelog/o1_mf_3_jjml0g5l_.log thread=1 sequence=12
media recovery complete, elapsed time: 00:00:00
Finished recover at 2021-08-18:19:44:51
Abrindo o banco em RESETLOGS:
RMAN> ALTER DATABASE OPEN RESETLOGS;
Statement processed
Validando ambiente:
RMAN> SELECT NAME,OPEN_MODE,LOG_MODE FROM V$DATABASE;
NAME OPEN_MODE LOG_MODE
--------- -------------------- ------------
RMANDB READ WRITE ARCHIVELOG
Apenas para constar, uma variação desse procedimento é caso o nosso banco esteja em NOARCHIVELOG mode. Neste caso, no momento do recover, executamos com a opção NOREDO, conforme exemplo abaixo:
RECOVER DATABASE NOREDO;
E outra variação: caso o AUTOBACKUP esteja configurado em uma área fora da FRA, devemos tratar como o exemplo abaixo:
RUN {
SET DBID XXXXX;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE disk TO '/oracle/controlfiles/autobackup_%F';
RESTORE CONTROLFILE FROM AUTOBACKUP;
}
Obs: Este procedimento foi criado pelo senhor Ahmed Baraka (www.ahmedbaraka.com) e foi apenas reproduzido por mim em um laboratório pessoal para fins de aprendizado.