探索ORACLE之RMAN_07 参数文件丢失恢复
作者:吴伟龙 Name:Prodence Woo
QQ:286507175 msn:hapy-wuweilong@hotmail.com
Oracle数据库的参数文件有两种一种是pfile(初始化参数文件),还有一种是spfile(服务器初始化参数文件);实际上spfile是pfile衍生过来的一新参数文件,应用9i以后的版本,在9i之前的版本都不支持,只支持pfile;而且pfile是不能通过oracle命令来进行备份的,只有spfile才支持备份。
通过RMAN的备份来实现参数文件的恢复,仅适用于9i以后
1、通过rman备份参数文件:
RMAN> backupspfile;
Starting backupat 05-JUL-12
using channelORA_DISK_1
channelORA_DISK_1: starting full datafile backupset
channelORA_DISK_1: specifying datafile(s) in backupset
including currentSPFILE in backupset
channelORA_DISK_1: starting piece 1 at 05-JUL-12
channelORA_DISK_1: finished piece 1 at 05-JUL-12
piecehandle=/DBBak/bak_WWL_07_05_03nfbi5c_1_1 tag=TAG20120705T175348 comment=NONE
channelORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backupat 05-JUL-12
Starting ControlFile and SPFILE Autobackup at 05-JUL-12
piecehandle=/DBSoft/product/10.2.0/db_1/dbs/c-5520179-20120705-01 comment=NONE
Finished ControlFile and SPFILE Autobackup at 05-JUL-12
RMAN>
2、备份完之后,我们可以看到如下备份信息:
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- ------------ ----------- ------------ ---------------
3 Full 80.00K DISK 00:00:01 05-JUL-12
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20120705T175348
Piece Name:/DBBak/bak_WWL_07_05_03nfbi5c_1_1
SPFILE Included: Modification time: 05-JUL-12
3、模拟参数文件丢失:
SQL> showparameter spfile;
NAME TYPE VALUE
----------------------------------------------- ------------------------------
spfile string /DBSoft/product/10.2.0/db_1/db
s/spfileWWL.ora
SQL>
删除参数文件:
[oracle@wwldb ~]$ rm /DBSoft/product/10.2.0/db_1/dbs/spfileWWL.ora
[oracle@wwldb ~]$ ls /DBSoft/product/10.2.0/db_1/dbs/spfileWWL.ora
ls: /DBSoft/product/10.2.0/db_1/dbs/spfileWWL.ora: No such file ordirectory
[oracle@wwldb dbs]$ ll
total 7240
drwxr-xr-x 2 oracle oinstall 4096 Jul 5 18:25 bak
-rw-rw---- 1 oracle oinstall 1544 May 16 16:44 hc_WWL.dat
-rw-rw---- 1 oracle oinstall 24 May 23 15:52 lkDUMMY
-rw-rw---- 1 oracle oinstall 24 May 16 16:47 lkWWL
-rw-r----- 1 oracle oinstall 1536 May 21 15:05 orapwWWL
drwxr-xr-x 2 oracle oinstall 4096 Jul 5 18:25 pfilebak
-rw-r----- 1 oracle oinstall 7389184 Jul 5 17:53 snapcf_WWL.f
[oracle@wwldb dbs]$
我们可以看到这里面pfile和spfile都没有了,那么数据库肯定是起不来的,这个时候需要数据库起来肯定需要恢复spfile或手工写一个pfile来供数据库的启动。
4、重启数据库
SQL> startup
ORA-01078:failure in processing system parameters
LRM-00109: couldnot open parameter file '/DBSoft/product/10.2.0/db_1/dbs/initWWL.ora'
报错:没有找到参数文件,数据库无法启动,甚至无法到达nomount状态,这个时候我们是不能使用rman的,那么我们必须手工写一个非常简单的pfile,将数据库启动到nomount状态下,这个时候就可以通过rman来进行对数据库的spfile进行恢复了。
5、开始恢复参数文件:
编辑一个pfile文件在/DBSoft/product/10.2.0/db_1/dbs/目录下,执行添加如下一行内容即可,文件名称为initWWL.ora:
db_name=wwl
6、再次启动数据库,现在数据库已经能启动到nomount状态了:
SQL> conn / assysdba
Connected to anidle instance.
SQL> startup
ORACLE instancestarted.
Total SystemGlobal Area 117440512 bytes
Fixed Size 1218004 bytes
VariableSize 58722860 bytes
Database Buffers 50331648 bytes
Redo Buffers 7168000 bytes
ORA-00205: errorin identifying control file, check alert log for more info
SQL> selectinstance_name,status from v$instance;
INSTANCE_NAME STATUS
----------------------------
WWL STARTED
SQL>
7、这个时候我们就能通过rman来对spfile服务器参数文件进行恢复了。
RMAN> restore spfile;
Starting restore at 05-JUL-12
using target database control file insteadof recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK
RMAN-00571:===========================================================
RMAN-00569: =============== ERROR MESSAGESTACK FOLLOWS ===============
RMAN-00571:===========================================================
RMAN-03002: failure of restore command at07/05/2012 18:44:06
RMAN-06563: control file or SPFILE must berestored using FROM AUTOBACKUP
恢复的时候报错,说控制文件和spfile文件的恢复必须是来自于自动备份,但是我们没有做自动备份呀,怎么办,我们刚才是手工备份的参数文件。那么我们将用如下的指定备份路径来进行参数文件的恢复。
RMAN> restore spfile from'/DBBak/bak_WWL_07_05_03nfbi5c_1_1';
Starting restore at 05-JUL-12
using channel ORA_DISK_1
channel ORA_DISK_1: autobackup found:/DBBak/bak_WWL_07_05_03nfbi5c_1_1
channel ORA_DISK_1: SPFILE restore fromautobackup complete
Finished restore at 05-JUL-12
RMAN>
OK了,恢复成功。
8、查看spfile是否恢复成功;
[oracle@wwldb dbs]$ ll
total 7248
drwxr-xr-x 2 oracle oinstall 4096 Jul 5 18:25 bak
-rw-rw---- 1 oracle oinstall 1544 May 16 16:44 hc_WWL.dat
-rw-r--r-- 1 oracle oinstall 12 Jul 5 18:36 initWWL.ora
-rw-rw---- 1 oracle oinstall 24 May 23 15:52 lkDUMMY
-rw-rw---- 1 oracle oinstall 24 May 16 16:47 lkWWL
-rw-r----- 1 oracle oinstall 1536 May 21 15:05 orapwWWL
drwxr-xr-x 2 oracle oinstall 4096 Jul 5 18:25 pfilebak
-rw-r----- 1 oracle oinstall 7389184Jul 5 17:53 snapcf_WWL.f
-rw-r----- 1 oracleoinstall 2560 Jul 5 18:47 spfileWWL.ora
我们可以看到,现在spfile已经恢复成功了。
9、再次启动数据库:
SQL> startup
ORACLE instance started.
Total System Global Area 285212672 bytes
Fixed Size 1218968 bytes
Variable Size 79693416 bytes
Database Buffers 197132288 bytes
Redo Buffers 7168000 bytes
Database mounted.
Database opened.
SQL>
我们可以看到,数据库现在是已经起来了。
通过手工重建来实现参数文件的恢复,适用于所有版本
1、我们可以参考建库后生成的init.ora文件来进行修改,只需保留以下即可
[oracle@wwldb dbs]$ cat init.ora |grep -v ^# |grep -v ^$ >initWWL.ora
[oracle@wwldb dbs]$ ls
bak hc_WWL.dat init.ora initWWL.ora lkDUMMY lkWWL orapwWWL pfilebak snapcf_WWL.f
2、编辑initWWL.ora文件,修改db_name和control_files的值为实际值即可。
db_name=WWL
db_files = 80 # SMALL
db_file_multiblock_read_count = 8 # SMALL
db_block_buffers = 100 # SMALL
shared_pool_size = 62198988 #SMALL
log_checkpoint_interval = 10000
processes = 50 # SMALL
parallel_max_servers = 5 #SMALL
log_buffer = 32768 # SMALL
max_dump_file_size = 10240 # limit trace file size to 5 Meg each
global_names = TRUE
control_files ='/DBSoft/oradata/WWL/control01.ctl','/DBData/oradata/WWL/control02.ctl','/DBData/oradata/WWL/control03.ctl'
3、启动数据库:
SQL> startup
ORACLE instance started.
Total System Global Area 100663296 bytes
Fixed Size 1217884 bytes
Variable Size 88083108 bytes
Database Buffers 8388608 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL>
至此参数文件已经恢复成功。