Restoring the SPFILE from AUTOBACKUP

Neste artigo, vamos simular a recuperação de um SPFILE perdido, onde o banco de dados está indisponível no momento da recuperação. Assumimos que a base esteja rodando em ARCHIVELOG mode, e que o recurso de AUTOBACKUP esteja configurado.

Reconhecendo nosso ambiente de laboratório:

[oracle@oel8 ~]$ rman target /
 
Recovery Manager: Release 18.0.0.0.0 - Production on Mon Aug 16 20:28:31 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> SELECT NAME,OPEN_MODE,LOG_MODE FROM V$DATABASE;
 
using target database control file instead of recovery catalog
NAME      OPEN_MODE            LOG_MODE
--------- -------------------- ------------
RMANDB    READ WRITE           ARCHIVELOG

Realizando um backup full do banco de dados:

RMAN> BACKUP DATABASE;
 
Starting backup at 2021-08-16:20:31:41
using channel ORA_DISK_1
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-16:20:31:42
channel ORA_DISK_1: finished piece 1 at 2021-08-16:20:33:37
piece handle=/oracle/fra/RMANDB/backupset/2021_08_16/o1_mf_nnndf_TAG20210816T203141_jkoxbyqr_.bkp tag=TAG20210816T203141 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
Finished backup at 2021-08-16:20:33:37
 
Starting Control File and SPFILE Autobackup at 2021-08-16:20:33:37
piece handle=/oracle/fra/RMANDB/autobackup/2021_08_16/o1_mf_s_1080765217_jkoxgl0s_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 2021-08-16:20:33:40

Para esse cenário de recuperação, usaremos 2 informações que vamos coletar agora: o DBID (pois não estamos usando um catálogo de backup) e o diretório onde reside a nossa FRA:

SQL> SELECT DBID FROM V$DATABASE;
 
      DBID
----------
3825250984
 
SQL> SHOW PARAMETER DB_RECOVERY_FILE_DEST;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string      /oracle/fra
db_recovery_file_dest_size           big integer 5G

Deletando o SPFILE:

SQL> SHO PARAMETER SPFILE;
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /oracle/18.0.0/product/dbs/spf
                                                 ileRMANDB.ora
SQL> ! rm /oracle/18.0.0/product/dbs/spfileRMANDB.ora

Baixando a nossa instância:

SQL> SHU IMMEDIATE;
Database closed.
Database dismounted.
ORACLE instance shut down.

Ao tentar levantar o ambiente, o SPFILE não é identificado e a operação falha:

SQL> STARTUP;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/oracle/18.0.0/product/dbs/initRMANDB.ora'

O processo de recuperação é simples. Primeiro iniciamos uma instância com o comando abaixo, onde a cláusula FORCE utiliza um “dummy parameter file”, para que possamos dar início ao restore que acontecerá em seguida (esse detalhe podemos ver na documentação, conforme este LINK):

[oracle@oel8 RMANDB]$ rman target /
 
Recovery Manager: Release 18.0.0.0.0 - Production on Mon Aug 16 20:43:39 2021
Version 18.13.0.0.0
 
Copyright (c) 1982, 2018, Oracle and/or its affiliates.  All rights reserved.
 
connected to target database (not started)
 
RMAN> STARTUP FORCE NOMOUNT;
 
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/oracle/18.0.0/product/dbs/initRMANDB.ora'
 
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
 
Total System Global Area    1073740616 bytes
 
Fixed Size                     8665928 bytes
Variable Size                281018368 bytes
Database Buffers             780140544 bytes
Redo Buffers                   3915776 bytes

Conforme já citado, como não estamos usando um catálogo de backup, precisaremos definir o DBID do nosso banco, além de passar o diretório da nossa FRA, conforme exemplo abaixo:

RUN{
    SET DBID 3825250984; 
    RESTORE SPFILE FROM AUTOBACKUP DB_RECOVERY_FILE_DEST='/oracle/fra' DB_NAME='RMANDB'; 
   }

Log de execução:

RMAN> RUN{
        SET DBID 3825250984;
        RESTORE SPFILE FROM AUTOBACKUP DB_RECOVERY_FILE_DEST='/oracle/fra' DB_NAME='RMANDB';
   }2> 3> 4>
 
executing command: SET DBID
 
Starting restore at 2021-08-16:20:46:49
using channel ORA_DISK_1
 
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_16/o1_mf_s_1080765217_jkoxgl0s_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210816
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /oracle/fra/RMANDB/autobackup/2021_08_16/o1_mf_s_1080765217_jkoxgl0s_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2021-08-16:20:46:50

Agora basta baixarmos a instância e subir o ambiente:

SQL> SHU IMMEDIATE;
ORA-01507: database not mounted
 
 
ORACLE instance shut down.
SQL> STARTUP;
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
Database mounted.
Database opened.
SQL> ! ls -lthr /oracle/18.0.0/product/dbs/spfileRMANDB.ora
-rw-r-----. 1 oracle oinstall 9.5K Aug 16 20:48 /oracle/18.0.0/product/dbs/spfileRMANDB.ora

Apenas para termos conhecimento, caso nosso ambiente utilize catálogo de backup, a recuperação do SPFILE é feita apenas com o comando abaixo:

RMAN> STARTUP FORCE NOMOUNT;
RMAN> RESTORE SPFILE FROM AUTOBACKUP;

Além disso, caso precisemos restaurar o SPFILE para um nome ou diretório específico, podemos fazer conforme exemplo abaixo:

[oracle@oel8 RMANDB]$ rman target /
 
Recovery Manager: Release 18.0.0.0.0 - Production on Mon Aug 16 20:51:51 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> RESTORE SPFILE TO '/tmp/BSS.ora' FROM AUTOBACKUP;
 
Starting restore at 2021-08-16:20:52:04
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=68 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_16/o1_mf_s_1080765217_jkoxgl0s_.bkp found in the recovery area
channel ORA_DISK_1: looking for AUTOBACKUP on day: 20210816
channel ORA_DISK_1: restoring spfile from AUTOBACKUP /oracle/fra/RMANDB/autobackup/2021_08_16/o1_mf_s_1080765217_jkoxgl0s_.bkp
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2021-08-16:20:52:06
 
RMAN> host 'ls -lthr /tmp/BSS.ora';
 
-rw-r-----. 1 oracle oinstall 9.5K Aug 16 20:52 /tmp/BSS.ora
host command complete

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.

2 thoughts on “Restoring the SPFILE from AUTOBACKUP”

  1. Pingback: Restoring the SPFILE from the alert.log file – Bruno Santos da Silva

  2. Pingback: Restoring the SPFILE from the alert.log file – SWIV

Leave a Comment

Your email address will not be published.