控制文件(Control File)是Oracle的物理文件之一,它记录了数据库的名字、数据文件的位置等信息。控制文件的重要性在于,一旦控制文件损坏,数据库将会宕机。控制文件是一个很小的二进制文件,用户不能编辑控制文件,控制文件的修改由Oracle自动完成。那么,我们能够查看控制文件里面的具体信息吗?答案是可以的,我们可以通过转储文件来获得控制文件的详细信息。
1.生成控制文件的转储文件
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
PL/SQL Release 11.2.0.3.0 - Production
CORE 11.2.0.3.0 Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
SQL> alter database backup controlfile to trace ;
Database altered.
SQL>
2.查找生成的转储文件
我们知道,用户生成的TRACE文件存储在udump目录下。在Oracle10g中,udump路径是$ORACLE_HOME/admin/SID/udump,而Oracle11g则大不一样。我们可以通过查看user_dump_dest参数来定位udump目录的具体位置。
SQL> show parameter user_dump_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
user_dump_dest string /u01/app/oracle/diag/rdbms/linuxidc/HOEGH/trace
SQL>
然后,我们使用ls命令找到最近生成的TRACE文件,就是图示的linuxidc_ora_304.trc文件。
[oracle@linuxidc trace]$ ls -ltr
total 1332
此处省略三百字
-rw-r----- 1 oracle oinstall 932 May 9 21:26 linuxidc_mmon_4805.trm
-rw-r----- 1 oracle oinstall 9750 May 9 21:26 linuxidc_mmon_4805.trc
-rw-r----- 1 oracle oinstall 4562 May 9 21:28 linuxidc_dbrm_4789.trm
-rw-r----- 1 oracle oinstall 80534 May 9 21:28 linuxidc_dbrm_4789.trc
-rw-r----- 1 oracle oinstall 97 May 9 21:29 linuxidc_ora_304.trm
-rw-r----- 1 oracle oinstall 12786 May 9 21:29 linuxidc_ora_304.trc
3.查看控制文件具体信息
现在,我们就可以通过more命令来查看控制文件的具体信息了。
[oracle@linuxidc trace]$ more linuxidc_ora_304.trc
Trace file /u01/app/oracle/diag/rdbms/linuxidc/HOEGH/trace/linuxidc_ora_304.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
System name: Linux
Node name: linuxidc.example.com
Release: 2.6.18-164.el5PAE
Version: #1 SMP Thu Sep 3 02:28:20 EDT 2009
Machine: i686
VM name: VMWare Version: 6
Instance name: linuxidc
Redo thread mounted by this instance: 1
Oracle process number: 26
Unix process pid: 304, image: oracle@linuxidc.example.com (TNS V1-V3)
*** 2016-05-09 21:29:07.246
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initialization file.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="linuxidc"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE, NODG_CONFIG'
-- LOG_ARCHIVE_MAX_PROCESSES=4
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/u01/app/oracle/product/11.2.0/dbhome_1/dbs/arch
'
-- LOG_ARCHIVE_DEST_1='MANDATORY NOREOPEN NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM EXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='NOREGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_1='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_1=ENABLE
--
-- Below are two sets of SQL statements, each of which creates a new
-- control file and uses it to open the database. The first set opens
-- the database with the NORESETLOGS option and should be used only if
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should be used
-- if online logs are unavailable.
-- The appropriate set of statements can be copied from the trace into
-- a script file, edited as necessary, and executed when there is a
-- need to re-create the control file.
--
-- Set #1. NORESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- Additional logs may be required for media recovery of offline
-- Use this only if the current versions of all online logs are
-- available.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "linuxidc" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/linuxidc/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/linuxidc/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/linuxidc/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/linuxidc/system01.dbf',
'/u01/app/oracle/oradata/linuxidc/sysaux01.dbf',
'/u01/app/oracle/oradata/linuxidc/undotbs01.dbf',
'/u01/app/oracle/oradata/linuxidc/users01.dbf',
'/u01/app/oracle/oradata/linuxidc/example01.dbf',
'/u01/app/oracle/oradata/linuxidc/test01.dbf'
CHARACTER SET AL32UTF8
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
arch1_1_762197622.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
arch1_1_860888149.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- Database can now be opened normally.
ALTER DATABASE OPEN;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/linuxidc/temp01.dbf'
SIZE 30408704 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
--
-- Set #2. RESETLOGS case
--
-- The following commands will create a new control file and use it
-- to open the database.
-- Data used by Recovery Manager will be lost.
-- The contents of online logs will be lost and all backups will
-- be invalidated. Use this only if online logs are damaged.
-- After mounting the created controlfile, the following SQL
-- statement will place the database in the appropriate
-- protection mode:
-- ALTER DATABASE SET STANDBY DATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "linuxidc" RESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/linuxidc/redo01.log' SIZE 50M BLOCKSIZE 512,
GROUP 2 '/u01/app/oracle/oradata/linuxidc/redo02.log' SIZE 50M BLOCKSIZE 512,
GROUP 3 '/u01/app/oracle/oradata/linuxidc/redo03.log' SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/linuxidc/system01.dbf',
'/u01/app/oracle/oradata/linuxidc/sysaux01.dbf',
'/u01/app/oracle/oradata/linuxidc/undotbs01.dbf',
'/u01/app/oracle/oradata/linuxidc/users01.dbf',
'/u01/app/oracle/oradata/linuxidc/example01.dbf',
'/u01/app/oracle/oradata/linuxidc/test01.dbf'
CHARACTER SET AL32UTF8
;
-- Commands to re-create incarnation table
-- Below log names MUST be changed to existing filenames on
-- disk. Any one log file from each branch can be used to
-- re-create incarnation records.
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
arch1_1_762197622.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u01/app/oracle/product/11.2.0/dbhome_1/dbs/
arch1_1_860888149.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE USING BACKUP CONTROLFILE
-- Database can now be opened zeroing the online logs.
ALTER DATABASE OPEN RESETLOGS;
-- Commands to add tempfiles to temporary tablespaces.
-- Online tempfiles have complete space information.
-- Other tempfiles may require adjustment.
ALTER TABLESPACE TEMP ADD TEMPFILE '/u01/app/oracle/oradata/linuxidc/temp01.dbf
我们可以看到转储文件里包含了数据库的名字、数据文件的位置等信息,并且按照是否需要resetlogs分别给出了创建控制文件的sql语句。控制文件非常重要,我们可以把它备份下来以防万一。