SPFILE损坏或丢失不是大问题,可通过PFILE重建,如果PFILE也丢失就从alert log中复制一份。但如果RMAN备份了SPFILE,就可以通过RMAN来恢复
恢复SPFILE分以下情况
Note the following considerations when restoring the server parameter file:
- 如果数据库已使用SPFILE启动
If the instance is already started with the server parameter file, then you cannot overwrite the existing server parameter file.
- 如果数据库已使用PFILE启动
When the instance is started with a client-side initialization parameter file, RMAN restores the server parameter file to the default location if the TO clause is not used in the restore command. The default location is platform-specific, for example, ?/dbs/spfile.ora on Linux.
- 如果使用了catalog
A recovery catalog simplifies the recovery procedure because you can avoid recording and remembering the DBID. This procedure assumes that you are not using a recovery catalog.
To restore the server parameter file from autobackup:
- Start RMAN and do one of the following:
如果SPFILE丢失时数据库启动中可直接连接;如果未启动则需要连接后并指定DBID
If the database instance is started at the time of the loss of the server parameter file, then connect to the target database.
If the database instance is not started when the server parameter file is lost, and if you are not using a recovery catalog, then run the SET DBID command to set the DBID of the target database:
SET DBID 320066378;
- Shut down the database instance and restart it without mounting the database.
这时数据库会用一个假的parameter file启动到nomount
When the server parameter file is not available, RMAN starts the instance with a dummy parameter file. For example, enter the following command:
STARTUP FORCE NOMOUNT;
- Execute a RUN command to restore the server parameter file.
Depending on the situation, you may need to execute multiple commands in the RUN command. Note the following considerations:
- If restoring from tape, then use ALLOCATE CHANNEL to allocate an SBT channel manually. If restoring from disk, then RMAN uses the default disk channel.
- If the autobackups were not produced with the default format (%F), then use the SET CONTROLFILE AUTOBACKUP FOR DEVICE TYPE command to specify the format in effect when the autobackup was performed.
- If the most recent autobackup was not created today, then use SET UNTIL to specify the date from which to start the search.
- If RMAN is not connected to a recovery catalog, then use SET DBID to set the DBID for the target database.
- To restore the server parameter file to a nondefault location, specify the TO clause or TO PFILE clause on the RESTORE SPFILE command.
- If you know that RMAN never produces more than n autobackups each day, then you can set the RESTORE SPFILE FROM AUTOBACKUP ... MAXSEQ parameter to n to reduce the search time. MAXSEQ is set to 255 by default, and RESTORE counts backward from MAXSEQ to find the last backup of the day. To terminate the restore operation if you do not find the autobackup in the current day (or specified day), set MAXDAYS 1 on the RESTORE command.
示例
RUN {
ALLOCATE CHANNEL c1 DEVICE TYPE sbt PARMS ...;
SET UNTIL TIME 'SYSDATE-7';
SET CONTROLFILE AUTOBACKUP FORMAT
FOR DEVICE TYPE sbt TO '/disk1/control_files/autobackup_%F';
SET DBID 123456789;
RESTORE SPFILE TO '/tmp/spfileTEMP.ora' FROM AUTOBACKUP MAXDAYS 10; }
注如果使用指定备份没必要指定DBID来恢复,如
RMAN> restore spfile from '/autobackup/2018_09_18/o1_mf_s_987197833_ft3b29ff_.bkp';
- Restart the database instance with the restored file.
如果SPFILE不在默位置可以手动创建一个PFILE文件,在PFILE文件中指定SPFILE选项
If you are restarting RMAN with a server parameter file in a nondefault location, then create an initialization parameter file with the line SPFILE=new_location, where new_location is the path name of the restored server parameter file. Then, restart the instance with the client-side initialization parameter file.
For example, create a file /tmp/init.ora which contains the single line:
SPFILE=/tmp/spfileTEMP.ora
You can use the following RMAN command to restart the instance with the restored server parameter file:
STARTUP FORCE PFILE=/tmp/init.ora;
示例:
- RMAN配置
RMAN> configure controlfile autobackup on;
- 全备
RMAN> BACKUP DATABASE ARCHIVELOG ALL;
- 查看DBID
SQL> select dbid from v$database; --1514939295
- 查看是否有SPFILE备份
RMAN> list backup of spfile;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
15 Full 9.36M DISK 00:00:00 2018-09-18 21:37:13
BP Key: 15 Status: AVAILABLE Compressed: NO Tag: TAG20180918T213713
Piece Name:
/oracle/fast_recovery_area/ORCL/autobackup/2018_09_18/o1_mf_s_987197833_ft3b29ff_.bkp
SPFILE Included: Modification time: 2018-09-18 21:34:42
SPFILE db_unique_name: ORCL
- 关闭数据库模拟SPFILE丢失
SQL> shutdown immediate
$ mv spfileorcl.ora spfileorcl.old
$ mv initorcl.ora initorcl.old
- RMAN启动到NOMOUNT
$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Sep 18 21:13:42 2018
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database (not started)
RMAN> startup nomount;
注:没有参数文件SQL*PLUS是无法启动到NOMOUNT,但RMAN可以
- 恢复SPFIEL
方式一:使用自动备份的spfile,但需要指定dbid
RMAN> set dbid=1514939295;
RMAN> restore spfile from autobackup;
方式二:直接指定备份集,不需要指定dbid
RMAN> restore spfile from '/oracle/fast_recovery_area/ORCL/autobackup/2018_09_18/o1_mf_s_987197833_ft3b29ff_.bkp';
- 关闭数据库重启启动
RMAN> SHUTDOWN IMMEDIATE;
RMAN> STARTUP;