一. Oracle 控制文件内容
我们可以通过v$controlfile_record_section 视图查看控制文件里包含的内容。
SQL> select type from v$controlfile_record_section;
TYPE
--------------------------------------------------------
DATABASE
CKPT PROGRESS
REDO THREAD
REDO LOG
DATAFILE
FILENAME
TABLESPACE
TEMPORARY FILENAME
RMAN CONFIGURATION
LOG HISTORY
OFFLINE RANGE
ARCHIVED LOG
BACKUP SET
BACKUP PIECE
BACKUP DATAFILE
BACKUP REDOLOG
DATAFILE COPY
BACKUP CORRUPTION
COPY CORRUPTION
DELETED OBJECT
PROXY COPY
BACKUP SPFILE
DATABASE INCARNATION
FLASHBACK LOG
RECOVERY DESTINATION
INSTANCE SPACE RESERVATION
REMOVABLE RECOVERY FILES
RMAN STATUS
THREAD INSTANCE NAME MAPPING
MTTR
DATAFILE HISTORY
STANDBY DATABASE MATRIX
GUARANTEED RESTORE POINT
RESTORE POINT
DATABASE BLOCK CORRUPTION
ACM OPERATION
FOREIGN ARCHIVED LOG
37 rows selected.
二. 可以通过dump看到控制文件内
2.1 直接dump controlfile
alter system set events'immediate trace name controlf level 10'
2.2. 使用alter database backup controlfile to filename
以上两种方法生成的dump文件是不可读的即乱码。 只有生成trace后,才是可读的。
2.2. 使用alter database backup controlfile to trace
生成的trace 文件在udump目录下,可以通过日期来判断。
SQL>show parameteruser_dump_dest
也可以使用如下SQL 查询对应的trace 文件:
SELECT a.VALUE ||b.symbol|| c.instance_name|| '_ora_' ||d.spid|| '.trc'
trace_file
FROM (SELECT VALUE
FROMv$parameter
WHERE name = 'user_dump_dest') a,
(SELECT SUBSTR (VALUE, -6, 1)symbol
FROMv$parameter
WHERE name = 'user_dump_dest') b,
(SELECTinstance_name FROMv$instance) c,
(SELECTspid
FROMv$session s,v$process p,v$mystat m
WHERE s.paddr= p.addrAND s.sid = m.sid AND m.statistic#= 0) d
TRACE_FILE
--------------------------------------------------------------------------------
/u01/app/oracle/admin/dave/udump/dave_ora_7215.trc
整个Trace 的内容如下:
[oracle@qs-dmm-rh2 udump]$ cat dave_ora_7215.trc
/u01/app/oracle/admin/dave/udump/dave_ora_7215.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 -Production
With the Partitioning, OLAP, Data Mining and Real ApplicationTesting options
ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1
System name: Linux
Node name: qs-dmm-rh2
Release: 2.6.18-194.el5
Version: #1 SMP Tue Mar16 21:52:43 EDT 2010
Machine: i686
Instance name: dave
Redo thread mounted by this instance: 0 <none>
Oracle process number: 15
Unix process pid: 7215, image: oracle@qs-dmm-rh2 (TNS V1-V3)
*** ACTION NAME:() 2011-03-17 22:05:46.401
*** MODULE NAME:(sqlplus@qs-dmm-rh2 (TNS V1-V3)) 2011-03-1722:05:46.401
*** SERVICE NAME:() 2011-03-17 22:05:46.401
*** SESSION ID:(159.1) 2011-03-17 22:05:46.401
ORA-01160: file is not a data file
ORA-01110: data file : '/u01/app/oracle/oradata/dave/temp01.dbf'
*** 2011-03-17 22:08:25.791
Control file created with size 370 blocks
*** 2011-03-17 22:10:21.444
tkcrrsarc: (WARN) Failed to find ARCH for message (message:0x1)
tkcrrpa: (WARN) Failed initial attempt to send ARCH message(message:0x1)
kwqmnich: current time:: 14: 10: 24
kwqmnich: instance no 0 check_only flag 1
kwqmnich: initialized job cache structure
krvscm(+): Validating controlfile with logical metadata
krvscm(+): Initial controlfile state
krvscm(+): kccdiflg [400001]kccdifl2 [1000]
krvscm(+): kccdi2ldscn[0x0000.00000000]
krvscm(+): kccdi2lrscn[0x0000.00000000]
krvscm(+): Inspecting logical metadata
krvscm(+): Metadata state
krvscm(+): hasPrepSwitchSta[0]
krvscm(+): hasPrepSwitchPri[0]
krvscm(+): hasReceivedDict[0]
krvscm(+): hasDumpedDict [0]
krvscm(+): hasCommittedBor[0]
krvscm(+): hasSwitchedFromPri [0]
krvscm(+): hasStartedTa [0]
krvscm(+): hasValidSess [0]
krvscm(+): hasTxnConsistency[0]
krvscm(+): hasCleanlyShutdown [0]
krvscm(+): Generating new controlfile state from metadata
krvscm(+): Updating controlfile with new state
krvscm(+): New controlfile state
krvscm(+): kccdiflg [400001]kccdifl2 [1000]
krvscm(+): kccdi2ldscn[0x0000.00000000]
krvscm(+): kccdi2lrscn[0x0000.00000000]
krvscm(+): Updating SGA associated with controlfile state
krvscm(+): Validation complete
*** 2011-03-17 22:13:21.115
-- The following are current System-scope REDO Log Archival related
-- parameters and can be included in the database initializationfile.
--
-- LOG_ARCHIVE_DEST=''
-- LOG_ARCHIVE_DUPLEX_DEST=''
--
-- LOG_ARCHIVE_FORMAT=%t_%s_%r.dbf
--
-- DB_UNIQUE_NAME="dave_st"
--
-- LOG_ARCHIVE_CONFIG='SEND, RECEIVE'
-- LOG_ARCHIVE_CONFIG='DG_CONFIG=("dave_pd")'
-- LOG_ARCHIVE_MAX_PROCESSES=2
-- STANDBY_FILE_MANAGEMENT=AUTO
-- STANDBY_ARCHIVE_DEST=/u01/archivelog
-- FAL_CLIENT=dave_st
-- FAL_SERVER=dave_pd
--
-- LOG_ARCHIVE_DEST_2='SERVICE=dave_pd'
-- LOG_ARCHIVE_DEST_2='OPTIONAL REOPEN=120 NODELAY'
-- LOG_ARCHIVE_DEST_2='LGWR NOAFFIRM NOEXPEDITE NOVERIFYASYNC=61440'
-- LOG_ARCHIVE_DEST_2='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_2='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED'
-- LOG_ARCHIVE_DEST_2='DB_UNIQUE_NAME=dave_pd'
-- LOG_ARCHIVE_DEST_2='VALID_FOR=(STANDBY_LOGFILE,STANDBY_ROLE)'
-- LOG_ARCHIVE_DEST_STATE_2=ENABLE
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/u01/archivelog'
-- LOG_ARCHIVE_DEST_1='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_1='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_1='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_1='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED'
-- LOG_ARCHIVE_DEST_1='DB_UNIQUE_NAME=dave_st'
-- 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 setopens
-- the database with the NORESETLOGS option and should be used onlyif
-- the current versions of all online logs are available. The second
-- set opens the database with the RESETLOGS option and should beused
-- if online logs are unavailable.
-- The appropriate set of statements can be copiedfrom the trace into
-- a script file, edited as necessary, andexecuted when there is a
-- need to re-create the control file.
--
-- Set#1. NORESETLOGS case
--对使用noresetlogs 的说明
--
-- 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 STANDBYDATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "DAVE" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 30
MAXINSTANCES 1
MAXLOGHISTORY 292
LOGFILE
GROUP 1'/u01/app/oracle/oradata/dave/redo01.log' SIZE 50M,
GROUP 2'/u01/app/oracle/oradata/dave/redo02.log' SIZE 50M,
GROUP 3'/u01/app/oracle/oradata/dave/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/dave/system01.dbf',
'/u01/app/oracle/oradata/dave/undotbs01.dbf',
'/u01/app/oracle/oradata/dave/sysaux01.dbf',
'/u01/app/oracle/oradata/dave/users01.dbf'
CHARACTER SET ZHS16GBK
;
--以上是创建控制文件的语法
-- 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/archivelog/1_1_746031707.dbf';
-- Recovery is required if any of the datafiles are restoredbackups,
-- or if the last shutdown was not normal orimmediate.
RECOVER DATABASE
-- All logs need archiving and a log switch isneeded.
ALTER SYSTEM ARCHIVE LOG ALL;
-- 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/dave/temp01.dbf'
SIZE 32505856 REUSE AUTOEXTEND OFF;
--这里是要注意的地方,重建控制文件的时候,不能写上临时表空间,等控制文件创建完毕之后,在手工的执行SQL加上临时表空间。
-- End of tempfile additions.
--
-- Set#2. RESETLOGS case
--第二种情况,使用resetlogs 的说明
--
-- 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 STANDBYDATABASE TO MAXIMIZE PERFORMANCE
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "DAVE" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 2
MAXDATAFILES 30
MAXINSTANCES 1
MAXLOGHISTORY 292
LOGFILE
GROUP 1'/u01/app/oracle/oradata/dave/redo01.log' SIZE 50M,
GROUP 2'/u01/app/oracle/oradata/dave/redo02.log' SIZE 50M,
GROUP 3 '/u01/app/oracle/oradata/dave/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/u01/app/oracle/oradata/dave/system01.dbf',
'/u01/app/oracle/oradata/dave/undotbs01.dbf',
'/u01/app/oracle/oradata/dave/sysaux01.dbf',
'/u01/app/oracle/oradata/dave/users01.dbf'
CHARACTER SET ZHS16GBK
;
-- 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/archivelog/1_1_746031707.dbf';
-- Recovery is required if any of the datafilesare 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/dave/temp01.dbf'
SIZE 32505856 REUSE AUTOEXTEND OFF;
-- End of tempfile additions.
--
注意里面的几个参数:
(1) MAXDATAFILES
The MAXDATAFILES optionof CREATE DATABASE determines the number of data files a database can have.With Oracle Real Application Clusters, databases tend to have more data filesand log files than an exclusive mounted database.
The MAXINSTANCES optionof CREATE DATABASE limits the number of instances that can access a databaseconcurrently. The default value for this option underz/OS is 15. Set MAXINSTANCES to a value greater than the maximum numberof instances you expect to run concurrently.
(3)MAXLOGFILE and MAXLOGMEMBERS
The MAXLOGFILES optionof CREATE DATABASE specifies the maximum number of redo log groups that can becreated for the database. The MAXLOGMEMBERS option specifies the maximum numberof members or number of copies per group. Set MAXLOGFILES to the maximum numberof instances you plan to run concurrently multiplied by the maximum anticipatednumber of groups per thread.
The MAXLOGHISTORY optionof CREATE DATABASE specifies the maximum number of redolog files that can be recorded in the log history of the control file.The log history is used for automatic media recovery of Oracle Real ApplicationClusters.
ForOracle Real Application Clusters, set MAXLOGHISTORY to a large value, such as100. The control file can then store information about this number ofredo log files. When the log history exceeds this limit, the Oracle serveroverwrites the oldest entries in the log history. Thedefault for MAXLOGHISTORY is 0 (zero), which disables log history.
这4个参数中,我们在创建DB 时需要注意的是MAXDATAFILES 和MAXLOGHISTORY。 因为默认值较小。 在创建DB 时就需要把这2个参数设置成较大值。
比如MAXDATAFILES 设置成8k,MAXLOGHISTORY 设置成1k。
与这几个参数相关的错误:
ORA-01164: MAXLOGFILES may not exceed string
Cause: MAXLOGFILES specified on the command line too large.
Action: Resubmit the command with a smaller MAXLOGFILES
ORA-01165:MAXDATAFILES may not exceed string
Cause: MAXDATAFILES specified on the command line too large.
Action: Resubmit the command with a smaller MAXDATAFILES
ORA-01166:file number string is larger than string (string)
Cause: File mentioned in CREATE CONTROLFILE has a file number whichis larger than that specified for MAXDATAFILES or MAXLOGFILES.
Action: Increase the maximum specified on the command line.
三. 控制文件的重建
不到最后时刻,如三个控制文件都已损坏,又没有控制文件的备份。还是不要重建控制文件,处理不好就会有数据丢失。
(1)db 启动到mount状态
SQL> startup nomount
(2)创建控制文件
create controlfile reuse database dave noresetlogsarchivelog
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/dave/redo01.log',
GROUP 2 '/u01/app/oracle/oradata/dave/redo02.log',
GROUP 3 '/u01/app/oracle/oradata/dave/redo03.log'
DATAFILE
'/u01/app/oracle/oradata/dave/sysaux01.dbf',
'/u01/app/oracle/oradata/dave/system01.dbf',
'/u01/app/oracle/oradata/dave/undotbs01.dbf',
'/u01/app/oracle/oradata/dave/users01.dbf'
CHARACTER SET ZHS16GBK;
我这里使用的是noresetlogs,所以直接open数据库就可以了:
SQL>alter database open;
如果是resetlogs 创建的控制文件,那么我们就需要使用:
SQL>alter database open resetlogs;
来打开DB.
(3)添加TEMP 表空间
SQL> ALTER TABLESPACE TEMP ADD TEMPFILE'/u01/app/oracle/oradata/dave/temp01.dbf' size 100M;
Tablespace altered.
注意:
如果使用resetlogs 打开的数据库,就需要对DB做一次备份。
resetlogs命令表示一个数据库逻辑生存期的结束和另一个数据库逻辑生存期的开始,每次使用resetlogs命令的时候,SCN不会被重置,不过oracle会重置日志序列号,而且会重置联机重做日志内容.
这样做是为了防止不完全恢复后日志序列会发生冲突(因为现有日志和数据文件间有了时间差)。
四. 不重建控制文件的情况清理控制文件中记录
控制文件将内部数据记录分为两类:循环重用记录 和 非循环重用记录。
(1)循环重用记录包含可以从控制文件中删除的信息。如: RMAN 备份记录,归档日志历史信息,循环重用记录可以被删除,并且不会影响产品数据库。
(2)非循环重用记录是那些不能被删除的记录。 非循环重用记录包括 数据文件列表 和日志文件列表。
我们可以通过重建控制文件或者设置control_file_record_keep_time=0来重用这些记录。
4.1 手工清理v$archived_log记录
参考:
Removingentries in v$archived_log referencing a particluar DEST_ID [ID 845361.1]
示例:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 3
Current log sequence 3
我们查看当前的archivelist是3个。 实际上个数据库我做过多次的open resetlogs。所以我们查询v$archived_log视图,会查看到很多之前的信息。
SQL> select resetlogs_id,sequence# fromv$archived_log order by 1;
RESETLOGS_ID SEQUENCE#
------------ ----------
806357067 50
806357067 51
806357067 52
806357067 53
806357067 54
806357067 56
806357067 54
806357067 51
806357067 50
806357067 53
806357067 52
806357067 55
810588833 1
810588833 2
810588833 11
810588833 9
810588833 3
810588833 4
810588833 5
810588833 6
810588833 7
810588833 8
810588833 9
810588833 10
811750169 1
811750169 1
811750169 2
811767774 1
811767774 3
811767774 5
811767774 4
811767774 2
811767774 1
811767774 3
811767774 5
811767774 4
811767774 4
811767774 3
811767774 2
811773498 1
811773498 2
811773498 6
811773498 3
811773498 4
811773498 5
811773498 9
811773498 2
811773498 1
811773498 2
811773498 1
811773498 8
811773498 7
811773498 2
811773498 1
811867931 1
811867931 2
56 rows selected.
SQL>
我们可以使用dbms_backup_restore.resetCfileSection清除控制文件中的相关记录:
SQL> execute sys.dbms_backup_restore.resetCfileSection(11);
PL/SQL procedure successfully completed.
验证:
SQL> select resetlogs_id,sequence# fromv$archived_log order by 1;
no rows selected
这里所有的记录都被删除了。
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 3
Current log sequence 3
SQL>
注意:
我们清空这部分信息,并不影响我们RMAN的恢复,只要归档文件物理存在就可以了。
可以用rman的catalog将现有的archive log注册进来
RMAN> catalog start with '/data/archivelog';
4.2 手工清理v$rman_status 记录
v$rman_status视图记录了如下类型的操作:
SQL> select distinct operation from v$rman_status;
OPERATION
------------------------------------------------------------------
RESTORE
RESTORING AND APPLYING LOGS
RMAN
INCREMENTAL BACKUP RESTORE
DELETE
REPORT
VERIFYING FILES FOR RECOVERY
RECOVER
ALTER DB
STARTING MEDIA RECOVERY
BACKUP
LIST
12 rows selected.
SQL> select count(*) from v$rman_status;
COUNT(*)
----------
141
--清除RMAN_STATUS 记录
SQL> execute sys.dbms_backup_restore.resetCfileSection(28);
PL/SQL procedure successfully completed.
--验证:
SQL> select count(*) from v$rman_status;
COUNT(*)
----------
0
4.3 关于resetCfileSection函数中ID号的说明
在4.1和4.2中我们分别使用了11和28的id。 我们这里看一下这里为什么是这2个号。
在如下的脚本:
$ORACLE_HOME/rdbms/admin/dbmsbkrs.sql
我们可以看到dbms_backup_restore包的创建代码。 在这段代码中给了我们定义的说明。
-- Valid record types are defined as thefollowing constants:
RTYP_DB_INFO constant binary_integer := 0;
RTYP_CKPTPROG constant binary_integer := 1;
RTYP_THREAD constant binary_integer := 2;
RTYP_LOGFILE constant binary_integer := 3;
RTYP_DATAFILE constant binary_integer := 4;
RTYP_FILENAME constant binary_integer := 5;
RTYP_TABLESPACE constant binary_integer := 6;
RTYP_RESERVED1 constant binary_integer := 7;
RTYP_TEMPFILE constant binary_integer := 7;
RTYP_RMAN_CONFIGURATION constant binary_integer := 8;
RTYP_LOG_HISTORY constant binary_integer := 9;
RTYP_OFFLINE_RANGE constant binary_integer := 10;
RTYP_ARCHIVED_LOG constant binary_integer := 11;
RTYP_BACKUP_SET constant binary_integer := 12;
RTYP_BACKUP_PIECE constant binary_integer := 13;
RTYP_BACKUP_DFILE constant binary_integer := 14;
RTYP_BACKUP_LOG constant binary_integer := 15;
RTYP_DFILE_COPY constant binary_integer := 16;
RTYP_BACKUP_DFILE_CORR constant binary_integer := 17;
RTYP_DFILE_COPY_CORR constant binary_integer := 18;
RTYP_DELETED_OBJECT constant binary_integer := 19;
RTYP_RESERVED3 constant binary_integer := 20;
RTYP_PROXY constant binary_integer := 20;
RTYP_RESERVED4 constant binary_integer := 21;
RTYP_BACKUP_SPFILE constant binary_integer := 21;
RTYP_DB2 constant binary_integer := 22;
RTYP_INCARNATION constant binary_integer := 23;
RTYP_FLASHBACK constant binary_integer := 24;
RTYP_RA_INFO constant binary_integer := 25;
RTYP_INST_RSVT constant binary_integer := 26;
RTYP_AGED_FILES constant binary_integer := 27;
RTYP_RMAN_STATUS constant binary_integer := 28;
RTYP_THREAD_INST constant binary_integer := 29;
RTYP_MTR constant binary_integer := 30;
RTYP_DFH constant binary_integer := 31;
RTYP_SDM constant binary_integer := 32;
RTYP_RSP constant binary_integer := 33;
RTYP_NRR constant binary_integer := 34;
RTYP_BLOCK_CORRUPTION constant binary_integer := 35;
RTYP_ACM_OPERATION constant binary_integer := 36;
RTYP_FOREIGN_ARCHIVED_LOG constantbinary_integer := 37;
通过以上的说明,可以理解,我们这里为什么ID是11和28了。
--------------------------------------------------------------------------------------------
版权所有,文章允许转载,但必须以链接方式注明源地址,否则追究法律责任!
Skype: tianlesoftware
QQ: tianlesoftware@gmail.com
Email: tianlesoftware@gmail.com
Blog: http://blog.csdn.net/tianlesoftware
Weibo: http://weibo.com/tianlesoftware
Twitter: http://twitter.com/tianlesoftware
Facebook: http://www.facebook.com/tianlesoftware
Linkedin: http://cn.linkedin.com/in/tianlesoftware