Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Recovery - Server Parameter File & Control File

Back


Recovery from Loss of Server Parameter File

Recover from current system: FROM MEMORY

-------- Create PFILE --------

-- creates a PFILE from the default SPFILE used by the current instance
CREATE PFILE
FROM SPFILE;

-- creates a PFILE with a specified name from the default SPFILE:
CREATE PFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initORCL_custom.ora'
FROM SPFILE;

-- creates a PFILE(for current instance) from a specified SPFILE
CREATE PFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initORCL.ora'
FROM SPFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileORCL.ora';

-- specifies both the input SPFILE and the output PFILE explicitly
CREATE PFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initORCL_custom.ora'
FROM SPFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileORCL.ora';

-- creates a PFILE based on the current parameter values in memory (the running instance's settings):
CREATE PFILE FROM MEMORY;


-------- Create SPFILE --------

-- Create SPFILE from default PFILE
CREATE SPFILE
FROM PFILE;

-- Create SPFILE from specified PFILE
CREATE SPFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileORCL.ora'
FROM PFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initORCL.ora';

-- Create SPFILE from memory
CREATE SPFILE
FROM MEMORY;

-- Create SPFILE with specified name from default PFILE
CREATE SPFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileORCL_custom.ora'
FROM PFILE;

-- Create SPFILE with specified input PFILE and output SPFILE
CREATE SPFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileORCL_custom.ora'
FROM PFILE='/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initORCL.ora';

Restore from Autobackup

diagram_spf

-- Restore the SPFILE from auto backup
RESTORE SPFILE
FROM AUTOBACKUP

-- Restore the SPFILE from auto backup to a nondefault location
RESTORE SPFILE TO <file name>
FROM AUTOBACKUP

-- Restore the SPFILE from the fast recovery area
run {
    restore spfile from autobackup
    recovery area = '<flash recovery area destination>'
    db_name = '<db_name>';
}
STARTUP FORCE NOMOUNT;
RESTORE SPFILE FROM AUTOBACKUP;
STARTUP FORCE;

Lab: Restore the parameter file

Setup Environment

rman target /

-- clear configuration for the control file autobackup location on disk.
-- RMAN creates control file autobackups in the fast recovery area when no other destination is configured.
-- /u01/app/oracle/fast_recovery_area/ORCL/autobackup
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;
CONFIGURE CONTROLFILE AUTOBACKUP CLEAR;

-- confirm
show all;

BACKUP DATABASE;

lab_sp

sqlplus / as sysdba

ALTER SESSION SET container=orclpdb;
show con_name

-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;

-- Create tablespace
CREATE TABLESPACE bartbs
DATAFILE '/u01/app/oracle/oradata/ORCL/orclpdb/bartbs.dbf' SIZE 10M
SEGMENT SPACE MANAGEMENT MANUAL;

-- Create user
CREATE USER BAR IDENTIFIED BY pass4BAR
DEFAULT TABLESPACE bartbs
QUOTA UNLIMITED ON bartbs;

GRANT CREATE SESSION TO BAR;

-- create table and populate
-- be sure table is at least 2 blocks long
CREATE TABLE BAR.barcopy
TABLESPACE bartbs
AS SELECT * FROM HR.EMPLOYEES;

INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;

INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;
-- Create backup of the bartbs tablespace
rman target "'sys@orclpdb as sysdba'"

BACKUP AS COPY TABLESPACE bartbs;
-- update the table
sqlplus / as sysdba

ALTER SESSION SET container=orclpdb;
UPDATE BAR.BARCOPY SET salary = salary+1;
COMMIT;
sqlplus / as sysdba

shutdown abort
exit
# copy the existing spfile
cp /u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileorcl.ora /home/oracle/backup/spfileorcl.ora

# remove spfile
rm -f /u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileorcl.ora

# remove pfile
if [ -e /u01/app/oracle/product/19.0.0/dbhome_1/dbs/initorcl.ora ]
then
	cp /u01/app/oracle/product/19.0.0/dbhome_1/dbs/initorcl.ora /home/oracle/backup/initorcl.ora
	rm -f /u01/app/oracle/product/19.0.0/dbhome_1/dbs/initorcl.ora
fi

# copy file back to oracle db
# cp /home/oracle/backup/initorcl.ora /u01/app/oracle/product/19.0.0/dbhome_1/dbs/initorcl.ora
# cp /home/oracle/backup/spfileorcl.ora /u01/app/oracle/product/19.0.0/dbhome_1/dbs/spfileorcl.ora
rman target "'/ as sysbackup'"
startup

lab_sp


Restore SPFile

rman target /

restore spfile from autobackup
recovery area '/u01/app/oracle/fast_recovery_area'
db_name 'orcl';

lab_sp

-- rman
shutdown

-- startup instance using the restored spfile
startup

lab_sp

sqlplus / as sysdba
alter session set container=orclpdb;
alter pluggable database open;

select * from BAR.BARCOPY;
-- rman
-- confirm no failure
list failure;

BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;
delete noprompt obsolete;

Clean up

rman target "'sys@orclpdb as sysdba'"
delete NOPROMPT copy of tablespace bartbs;
exit;

sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;

-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;

EXIT;

Recovery from Loss of Control File


Remain at least one control file copy

restore controlfile
from '+DATA/orcl/controlfile/current.260.695209463"';


Loss of All Control File Copies

Online log status Data file status:Current Data file status:Backup
Available Restore backup cf, complete recovery,OPEN RESETLOGS Restore backup cf, complete recovery, OPEN RESETLOGS
Unavailable Re-create cf,, OPEN RESETLOGS Restore backup cf, pitr, OPEN RESETLOGS


Restore from Autobackup

diagram_cf

STARTUP NOMOUNT;
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;
-- must recover the database, because now have a backup control file that contains information about an older version of the database.
RECOVER DATABASE;
-- must specify RESETLOGS because the new control file represents a different instantiation of the database.
ALTER DATABASE OPEN RESETLOGS;

Using Recovery Catalog

-- restore control file using catalog
RESTORE CONTROLFILE

-- restore the control file to a non-default location.
RESTORE CONTROLFILE... TO <destination>

Lab: Restore single loss of control file

Setup Environment

rman target /

BACKUP DATABASE;
sqlplus / as sysdba

ALTER SESSION SET container=orclpdb;
show con_name

-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;

-- Create tablespace
CREATE TABLESPACE bartbs
DATAFILE '/u01/app/oracle/oradata/ORCL/orclpdb/bartbs.dbf' SIZE 10M
SEGMENT SPACE MANAGEMENT MANUAL;

-- Create user
CREATE USER BAR IDENTIFIED BY pass4BAR
DEFAULT TABLESPACE bartbs
QUOTA UNLIMITED ON bartbs;

GRANT CREATE SESSION TO BAR;

-- create table and populate
-- be sure table is at least 2 blocks long
CREATE TABLE BAR.barcopy
TABLESPACE bartbs
AS SELECT * FROM HR.EMPLOYEES;

INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;

INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;
-- Create backup of the bartbs tablespace
rman target "'sys@orclpdb as sysdba'"

BACKUP AS COPY TABLESPACE bartbs;
-- update the table
sqlplus / as sysdba

ALTER SESSION SET container=orclpdb;
UPDATE BAR.BARCOPY SET salary = salary+1;
COMMIT;
sqlplus / as sysdba

shutdown abort
exit
if [ -e /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl ]
then
  rm -f /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl
fi

sqlplus / as sysdba
startup

lab_cf


Restore Control File

adrci

show home
set home home_str
# set home diag/rdbms/orcl/orcl

show alert -tail 20

exit

lab_cf lab_cf

rman target "'/ as sysbackup'"

LIST FAILURE;
ADVISE FAILURE;
-- preview rman command line
REPAIR FAILURE PREVIEW;
REPAIR FAILURE;

-- confirm failure has been repaired
LIST FAILURE;

lab_cf

lab_cf

lab_cf

ALTER SESSION SET container=orclpdb;
alter pluggable database open;
select * from BAR.BARCOPY;
-- rman
-- confirm no failure
list failure;

BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;
delete noprompt obsolete;
exit

Clean up

rman target "'sys@orclpdb as sysdba'"
delete NOPROMPT copy of tablespace bartbs;
exit;

sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;

-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;

EXIT;

Lab: Restore loss of all control files

Setup Environment

rman target /

BACKUP DATABASE;
sqlplus / as sysdba

ALTER SESSION SET container=orclpdb;
show con_name

-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;

-- Create tablespace
CREATE TABLESPACE bartbs
DATAFILE '/u01/app/oracle/oradata/ORCL/orclpdb/bartbs.dbf' SIZE 10M
SEGMENT SPACE MANAGEMENT MANUAL;

-- Create user
CREATE USER BAR IDENTIFIED BY pass4BAR
DEFAULT TABLESPACE bartbs
QUOTA UNLIMITED ON bartbs;

GRANT CREATE SESSION TO BAR;

-- create table and populate
-- be sure table is at least 2 blocks long
CREATE TABLE BAR.barcopy
TABLESPACE bartbs
AS SELECT * FROM HR.EMPLOYEES;

INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;

INSERT INTO BAR.BARCOPY
SELECT * FROM BAR.BARCOPY;
-- Create backup of the bartbs tablespace
rman target "'/ as sysdba'"

BACKUP AS COPY TABLESPACE orclpdb:bartbs;
-- update the table
sqlplus / as sysdba

ALTER SESSION SET container=orclpdb;
UPDATE BAR.BARCOPY SET salary = salary+1;
COMMIT;
sqlplus / as sysdba

shutdown abort
exit
# copy control01
cp /u01/app/oracle/oradata/ORCL/control01.ctl /home/oracle/backup
# remove control01
rm -f /u01/app/oracle/oradata/ORCL/control01.ctl

if [ -e /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl ]
then
  # copy control02
	cp /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl /home/oracle/backup
  # remove control02
	rm -f /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl
fi

# confirm all control files are removed
ls /u01/app/oracle/oradata/ORCL/control01.ctl
ls /u01/app/oracle/fast_recovery_area/ORCL/control02.ctl

lab_allcf

sqlplus / as sysdba
startup
-- ORA-00205: error in identifying control file, check alert log for more info

lab_allcf


Restore Control File

adrci

show home
set home home_str
# set home diag/rdbms/orcl/orcl

show alert -tail 30

exit

lab_allcf

rman target "'/ as sysbackup'"

LIST FAILURE;
ADVISE FAILURE;
REPAIR FAILURE PREVIEW;

lab_allcf

lab_allcf

lab_allcf


Option 1:

LIST FAILURE;
ADVISE FAILURE;
REPAIR FAILURE PREVIEW;
REPAIR FAILURE;

Option 2: Manually recover

RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;

lab_allcf


ALTER DATABASE OPEN;
-- ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
ALTER DATABASE OPEN RESETLOGS;
-- ORA-01194: file 1 needs more recovery to be consistent
-- ORA-01110: data file 1: '/u01/app/oracle/oradata/ORCL/system01.dbf'

lab_allcf lab_allcf


Solution:

RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;

-- confirm issue gets fixed
LIST FAILURE;

lab_allcf lab_allcf

ALTER SESSION SET container=orclpdb;
alter pluggable database open;
select * from BAR.BARCOPY;
SELECT *
FROM V$DATABASE_INCARNATION;

lab_allcf

SELECT NAME, DBID, CURRENT_SCN, LOG_MODE, OPEN_MODE
FROM V$DATABASE ;

lab_allcf

-- rman
BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;
delete noprompt obsolete;
exit

Clean up

rman target "'/ as sysdba'"
delete NOPROMPT copy of tablespace orclpdb:bartbs;
exit;

sqlplus / as sysdba
ALTER SESSION SET container=orclpdb;

-- CLEANUP from previous run
DROP USER bar CASCADE;
DROP TABLESPACE bartbs INCLUDING CONTENTS AND DATAFILES;

EXIT;

Recover from loss of both SPFILE and Control File

  1. Set the DBID or use recovery catalog.
  2. Restore the SPFILE from the autobackup.
  3. Start the instance with the restored SPFILE.
  4. Restore the control file from the autobackup.
  5. Mount the database with the restored control file.
  6. Restore and recover the database.
  7. Open the database with the RESETLOGS option.