控制文件(control file)是一个相当小的文件(最多能增长到64M左右),其中包含Oracle需要的其他文件的一个目录。参数文件告知实例控制文件的位置,控制文件则告知示例数据库和在线重做日志文件的位置。控制文件还告知了Oracle其他一些事情,如已发生检查点的有关信息、数据库名(必须和db_name参数匹配)、创建数据库的时间戳、归档重做日志的历史(有时这会让控制文件变大)、RMAN信息等。
控制文件应该通过硬件(RAID)多路保存,如果不支持镜像,则要通过Oracle多路保存。应该有不止一个副本,而且它们应该保存在不同的磁盘上,以防止万一出现磁盘故障而丢失控制文件。丢失控制文件并不是致命的,但是会使恢复变得困难很多。
如果丢失了所有的控制文件并且没有任何的备份,我们可以通过重建控制文件来打开数据库。其中,重建控制文件至少需要以下信息:
1.数据库名
2.字符集
4.初始化参数,包括MAXLOGFILES、MAXLOGMEMBERS、MAXDATAFILES、MAXINSTANCES、MAXLOGHISTORY等;
1.环境准备
数据库版本
我们在Oracle11g中进行测试。
sql>select*fromv$version; BANNER -------------------------------------------------------------------------------- OracleDatabase11gEnterpriseEditionRelease11.2.0.3.0-Production PL/sqlRelease11.2.0.3.0-Production CORE11.2.0.3.0Production TNSforLinux:Version11.2.0.3.0-Production NLSRTLVersion11.2.0.3.0-Production sql>
1.通过查询control_files初始化参数,获取控制文件路径;
sql>showparametercontrol_files NAMETYPEVALUE ----------------------------------------------------------------------------- control_filesstring/u01/app/oracle/oradata/HOEGH/ control01.ctl,/u01/app/oracle /oradata/HOEGH/control02.ctl sql>
[oracle@HOEGH~]$rm/u01/app/oracle/oradata/HOEGH/control01.ctl [oracle@HOEGH~]$rm/u01/app/oracle/oradata/HOEGH/control02.ctl [oracle@HOEGH~]$
3.此时,强制关闭数据库,然后重启数据库,报ORA-00205错误。需要注意的是,此时执行shutdown immediate命令,数据库无法正常关闭,只能关闭到mounted状态;需要使用shutdown abort命令强制关闭数据库。
sql>shutdownimmediate Databaseclosed. ORA-00210:cannotopenthespecifiedcontrolfile ORA-00202:controlfile:\'/u01/app/oracle/oradata/HOEGH/control01.ctl\' ORA-27041:unabletoopenfile LinuxError:2:Nosuchfileordirectory Additionalinformation:3 sql>selectstatusfromv$instance; STATUS ------------ MOUNTED sql> sql>shutdownabort ORACLEinstanceshutdown. sql> sql>startup ORACLEinstancestarted. TotalSystemGlobalArea941600768bytes FixedSize1348860bytes VariableSize515902212bytes DatabaseBuffers419430400bytes RedoBuffers4919296bytes ORA-00205:errorinidentifyingcontrolfile,checkalertlogformoreinfo sql>
sql>createpfilefromspfile; Filecreated. sql>
[oracle@hoeghdbs]$catinitHOEGH.ora HOEGH.__db_cache_size=419430400 HOEGH.__java_pool_size=4194304 HOEGH.__large_pool_size=4194304 HOEGH.__oracle_base=\'/u01/app/oracle\'#ORACLE_BASEsetfromenvironment HOEGH.__pga_aggregate_target=377487360 HOEGH.__sga_target=566231040 HOEGH.__shared_io_pool_size=0 HOEGH.__shared_pool_size=130023424 HOEGH.__streams_pool_size=0 *.audit_file_dest=\'/u01/app/oracle/admin/HOEGH/adump\' *.audit_trail=\'db\' *.compatible=\'11.2.0.0.0\' *.control_files=\'/u01/app/oracle/oradata/HOEGH/control01.ctl\',\'/u01/app/oracle/oradata/HOEGH/control02.ctl\' *.db_block_size=8192 *.db_domain=\'\' *.db_name=\'HOEGH\' *.diagnostic_dest=\'/u01/app/oracle\' *.dispatchers=\'(PROTOCOL=TCP)(SERVICE=HOEGHXDB)\' *.memory_max_target=943718400 *.memory_target=943718400 *.open_cursors=300 *.processes=150 *.remote_login_passwordfile=\'EXCLUSIVE\' *.undo_tablespace=\'UNDOTBS1\' [oracle@hoeghdbs]$
3.启动到nomount状态,获取字符集
由于需要执行查询语句select userenv('language') from dual;来获取字符集,因此需要将数据库启动到nomount状态。
sql>startupnomount ORACLEinstancestarted. TotalSystemGlobalArea941600768bytes FixedSize1348860bytes VariableSize515902212bytes DatabaseBuffers419430400bytes RedoBuffers4919296bytes sql> sql>selectuserenv(\'language\')fromdual; USERENV(\'LANGUAGE\') ---------------------------------------------------- AMERICAN_AMERICA.US7ASCII sql>
[oracle@hoeghHOEGH]$ls-lh total1.8G -rw-r-----1oracleoinstall314MMay3011:07example01.dbf -rw-r-----1oracleoinstall51MMay3011:07redo01.log -rw-r-----1oracleoinstall51MMay3011:07redo02.log -rw-r-----1oracleoinstall51MMay3011:07redo03.log -rw-r-----1oracleoinstall541MMay3011:07sysaux01.dbf -rw-r-----1oracleoinstall721MMay3011:07system01.dbf -rw-r-----1oracleoinstall30MOct132014temp01.dbf -rw-r-----1oracleoinstall96MMay3011:07undotbs01.dbf -rw-r-----1oracleoinstall5.1MMay3011:07users01.dbf [oracle@hoeghHOEGH]$
这样,创建控制文件所需的基本信息都已经有了,我们来生成创建控制文件脚本。
STARTUPNOMOUNT CREATECONTROLFILEREUSEDATABASE\"HOEGH\"NORESETLOGSARCHIVELOG MAXLOGFILES5 MAXLOGMEMBERS3 MAXDATAFILES100 MAXINSTANCES1 MAXLOGHISTORY226 LOGFILE GROUP1\'/u01/app/oracle/oradata/HOEGH/redo01.log\'SIZE50M,GROUP2\'/u01/app/oracle/oradata/HOEGH/redo02.log\'SIZE50M,GROUP3\'/u01/app/oracle/oradata/HOEGH/redo03.log\'SIZE50M DATAFILE \'/u01/app/oracle/oradata/HOEGH/system01.dbf\',\'/u01/app/oracle/oradata/HOEGH/sysaux01.dbf\',\'/u01/app/oracle/oradata/HOEGH/undotbs01.dbf\',\'/u01/app/oracle/oradata/HOEGH/users01.dbf\',\'/u01/app/oracle/oradata/HOEGH/example01.dbf\',\'/u01/app/oracle/oradata/HOEGH/temp01.dbf\' CHARACTERSETUS7ASCII ;
6.重建控制文件
需要注意的是,在执行上述创建脚本时会报错,系统提示临时文件不属于数据文件,如下所示:
sql>@/u01/app/oracle/oradata/HOEGH/CreateControlFile.sql ORA-01081:cannotstartalready-runningORACLE-shutitdownfirst CREATECONTROLFILEREUSEDATABASE\"HOEGH\"NORESETLOGSARCHIVELOG * ERRORatline1: ORA-01503:CREATECONTROLFILEFailed ORA-01160:fileisnotadatafile ORA-01110:datafile:\'/u01/app/oracle/oradata/HOEGH/temp01.dbf\' sql>
修改脚本并重新执行,重建控制文件后,数据库会打开到mount状态。
sql>@/u01/app/oracle/oradata/HOEGH/CreateControlFile.sql ORACLEinstancestarted. TotalSystemGlobalArea941600768bytes FixedSize1348860bytes VariableSize515902212bytes DatabaseBuffers419430400bytes RedoBuffers4919296bytes Controlfilecreated. sql> sql>selectstatusfromv$instance; STATUS ------------ MOUNTED sql>
7.打开数据库
在打开数据库时,会报错,提示system01数据文件需要执行介质恢复,我们执行recover database即可。
sql>alaterdatabaSEOpen; SP2-0734:unknowncommandbeginning\"alaterdat...\"-restoflineignored. sql> sql>alterdatabaSEOpen; alterdatabaSEOpen * ERRORatline1: ORA-01113:file1needsmediarecovery ORA-01110:datafile1:\'/u01/app/oracle/oradata/HOEGH/system01.dbf\' sql>recoverdatabase; Mediarecoverycomplete. sql> sql>alterdatabaSEOpen; Databasealtered. sql> sql>select*fromv$version; BANNER -------------------------------------------------------------------------------- OracleDatabase11gEnterpriseEditionRelease11.2.0.3.0-Production PL/sqlRelease11.2.0.3.0-Production CORE11.2.0.3.0Production TNSforLinux:Version11.2.0.3.0-Production NLSRTLVersion11.2.0.3.0-Production sql> sql>selecttablespace_namefromdba_tablespaces; TABLESPACE_NAME ------------------------------ SYSTEM SYSAUX UNDOTBS1 TEMP USERS EXAMPLE 6rowsselected. sql>
8.总结
下面总结一下重建控制文件的步骤:
2.获取字符集名;
4.重建控制文件;
5.执行介质恢复;
6.打开数据库。
原文来自:http://blog.itpub.net/30162081/viewspace-1677995/