All technological notes.
Server Parameter File & Control FileServer Parameter File \& Control File
Server Parameter FileFROM MEMORYFROM MEMORY clause:
text initialization parameter file (PFILE) or server parameter file (SPFILE) by using the current system wide parameter settings.In a RAC environment, the created file contains the parameter settings from each instance. 包含每个实例的参数
During instance startup, all parameter settings are logged in to the alert.log file.
alert.log parameter dump text is written in valid parameter syntax.
PFILE for a subsequent instance. 原理: 实例启动时, 参数以合规的语法记录在 log, 所以可以剪切和复制到新文件.PFILE or SPFILE is written to alert.log at instance startup time.
PFILE is used, the alert log indicates this as well.也会记录参数文件名, 所以可以在命令中加入文件名Syntax:
-------- 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';
Scenario:
server parameter file and cannot use the FROM MEMORY clauseSolution:

-- 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;
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;

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

fast recovery area and DB_NAME options to specify where the autobackups can be found.rman target /
restore spfile from autobackup
recovery area '/u01/app/oracle/fast_recovery_area'
db_name 'orcl';

-- rman
shutdown
-- startup instance using the restored spfile
startup

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;
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;
Control Filecontrol files and on whether at least one control file remains or all have been lost. 总体而言, 基于存储设置和 cf 损失程度control file copyASM storageNOMOUNT mode.RESTORE CONTROLFILE command to restore the control file from an existing control filerestore controlfile
from '+DATA/orcl/controlfile/current.260.695209463"';
control files are stored as regular file system filesonline log files and the data files:| 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 |
ALTER DATABASE BACKUP CONTROLFILE TO TRACE command
The commands used for restoring your control file are the same, whether or not you are using a fast recovery area.
If you are using a fast recovery area, RMAN implicitly cross-checks backups and image copies listed in the control file and catalogs any files in the fast recovery area that are not recorded in the restored control file, thereby improving the usefulness of the restored control file in the restoration of the rest of your database. 恢复的 CF 与 FRA 的备份可能有差异, 所以恢复 CF 时会交叉检查.
Tape backups are not automatically cross-checked after the restoration of a control file.
Example:
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;
Recovery CatalogPrerequisites:
NOMOUNT staterecovery catalogNo need to set the DBID or use the control file autobackup to restore the control file. 使用备份时, 需要表明 dbid; 使用 catalog 时, 不需要.
The restored control file is written to all locations listed in the CONTROL_FILES initialization parameter. 恢复的 CF 会写到 target db 的这个参数指定的路径.
-- restore control file using catalog
RESTORE CONTROLFILE
-- restore the control file to a non-default location.
RESTORE CONTROLFILE... TO <destination>
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

adrci to view the alert logadrci
show home
set home home_str
# set home diag/rdbms/orcl/orcl
show alert -tail 20
exit

Data Recovery Advisor for a solution.rman target "'/ as sysbackup'"
LIST FAILURE;
ADVISE FAILURE;
-- preview rman command line
REPAIR FAILURE PREVIEW;
REPAIR FAILURE;
-- confirm failure has been repaired
LIST FAILURE;



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
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;
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

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

adrci to view the alert logadrci
show home
set home home_str
# set home diag/rdbms/orcl/orcl
show alert -tail 30
exit

rdarman target "'/ as sysbackup'"
LIST FAILURE;
ADVISE FAILURE;
REPAIR FAILURE PREVIEW;



Option 1:
REPAIR FAILURE.LIST FAILURE;
ADVISE FAILURE;
REPAIR FAILURE PREVIEW;
REPAIR FAILURE;
Option 2: Manually recover
RESTORE CONTROLFILE FROM AUTOBACKUP;
ALTER DATABASE MOUNT;

RESETLOGS option.
control file is older than the SCN in the data files and the data files have not been restored with the UNTIL cause.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'

Solution:
RECOVER DATABASE;
ALTER DATABASE OPEN RESETLOGS;
-- confirm issue gets fixed
LIST FAILURE;

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

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

-- rman
BACKUP DATABASE PLUS ARCHIVELOG DELETE INPUT;
delete noprompt obsolete;
exit
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;
SPFILE and Control FileDBID or use recovery catalog.SPFILE from the autobackup.SPFILE.control file from the autobackup.control file.RESETLOGS option.