2.控制文件相关知识详解

目录

1.本文概要

2  控制文件的创建脚本获取方式

3、重建控制文件

6、创建控制文件中 使用resetlog 和noresetlog的区别

7、控制文件相关的视图

8、控制文件内容的管理维护


1.本文概要

本文记录,学习控制文件内容的笔记。通过结合MOS资料库、广大网友的出色文章、自己实践而来。本文主要分常常用到的几个角度去记录

1、控制文件的创建脚本获取方式 ---主要用于重建控制文件

2、重建控制文件

3、控制文件的常见备份方式

4、控制文件的内容解析

5、创建控制文件中 使用resetlog 和noresetlog的区别

6、控制文件相关的视图

7、控制文件内容的管理维护

2  控制文件的创建脚本获取方式

常见的,如果控制文件丢失或者没有备份的情况下,就需要重建控制文件,重建控制文件之前需要获取DDL脚本,常见的获取方法如下:

方法1:直接转储到自定义指定文件

alter database backup controlfile to trace as '/home/oracle/1.txt' ;

方法2:转储到追踪文件

 alter database backup controlfile to trace;

 查看用户转储路径

SQL> alter database backup controlfile to trace;

SQL> show parameter user_dump_dest

NAME TYPE VALUE
-------------- ------ ------------------------------------------------
user_dump_dest string /oracle/product/11.1.0/db_1/diag/rdbms/V11/trace

进入到指定路径,最新的追踪文件(.trc)即为转储的文件

cd /oracle/product/11.1.0/db_1/diag/rdbms/V11/trace
ls -ltr

OR 

方法3 

使用下面的方式。下面的方式更简单

SQL> alter database backup controlfile to trace;
Database altered.

SQL> oradebug setmypid;
Statement processed.

SQL> oradebug tracefile_name;
/opt/app/oracle/diag/rdbms/ora11g/ORA11G/trace/ORA11G_ora_17822.trc

上面的几种方式需要在open或者mount才能执行,如果数据库宕机了就不行了。

如果没有备份或者其他途径获取控制文件的脚本情况下,官方给出的处理方法如下:

Under the rare occasion that you do not have a controlfile to either: #以下的情况,可能是不能获取控制文件的情况
1. Restore control file from backup or have a script from a previous generated "backup controlfile to trace script", i.e., when your control file was good. In many cases you may not be able to generate the script
now, if you get any error and does not have any backup of control file, then only option is to go for manual listing of files method mentioned below.
3. or you must create a script from the beginning, by manually listing of all the files, which is risky if you miss out any files, so carefully list all the files.. 
#从备份中恢复控制文件或者使用以前生成的“备份控制文件以跟踪脚本”中的脚本,即当您的控制文件良好时。在许多情况下,可能无法生成脚本,如果遇到任何错误,并且没有任何控制文件的备份,那么唯一的选择就是使用下面提到的手动列出文件的方法
CREATE CONTROLFILE REUSE DATABASE "DBNAME" NORESETLOGS ARCHIVELOG

    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 200
    MAXINSTANCES 8
    MAXLOGHISTORY 2920
Follow the format listing:
- Location of redo logs.
#online redo log的位置
- Location of datafiles #数据文件的位置
- Specifying the characterset. #数据库的字符集
Once you have listed all files correctly you are ready to recreate your controlfile #正确列出所有文件后,即可重新创建控制文件。手动生成控制文件的内容也就以上这些。

关于常用的几个参数解释如下:

 /*MAXDATAFILES */

       The MAXDATAFILES option of 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. #CREATE DATABASE的MAXDATAFILES选项决定数据库可以拥有的数据文件数。使用Oracle Real Application Clusters,数据库往往比独占装载的数据库拥有更多的数据文件和日志文件

/*MAXINSTANCES*/

       The MAXINSTANCES option of 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 #CREATE DATABASE的MAXINSTANCES选项限制了当前可以访问数据库的实例数。在z/OS下,此选项的默认值为15。将MAXINSTANCES设置为一个大于同时运行的最大实例数的值 --主要是针对于RAC中的多实例情况

/*MAXLOGFILES  MAXLOGMEMBERS*/

       The MAXLOGFILES option of 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. #CREATE DATABASE的MAXLOGFILES选项指定可以为数据库创建的重做日志组的最大组数。MAXLOGMEMBERS选项指定每个组的最大成员数或副本数。将MAXLOGFILES设置为计划同时运行的最大实例数乘以每个线程预期的最大组数

/*MAXLOGHISTORY*/

       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 histor

CREATE DATABASE的MAXLOGHISTORY选项指定可以记录在控制文件的日志历史记录中的重做日志文件的最大数量。日志历史记录用于RAC的介质恢复。

对于Oracle Real Application Clusters,请将MAXLOGHISTORY设置为较大的值,例如100。然后,控制文件可以存储关于这个数量的重做日志文件的信息。当日志历史记录超过此限制时,Oracle服务器会覆盖日志历史记录中最旧的条目。MAXLOGHISTORY的默认值为0(零),这将禁用日志历史记录

3、重建控制文件

oracle 官方给出的建议重建控制文件的场景:

You should only recreate your control file under the following circumstances:
1、All current copies of the control file have been lost or are corrupted.
2、You are restoring a backup in which the control file is corrupted or missing.
3、You need to change a hard limit database parameter in the controlfile.
4、If you are moving your database to another server and files are located in a different location.
Oracle Customer Support advises you to. 

1、 控制文件的所有当前副本都已丢失或损坏。

2、 您正在还原控制文件已损坏或丢失的备份。

3、 您需要更改控制文件中的硬限制数据库参数。

4、 如果要将数据库移动到另一台服务器,并且文件位于不同的位置

获取到的控制文件脚本,一般的格式如下:

CREATE CONTROLFILE REUSE DATABASE "V11" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/oradata/V11/redo01.log' SIZE 50M,
GROUP 2 '/oradata/V11/redo02.log' SIZE 50M,
GROUP 3 '/oradata/V11/redo03.log' SIZE 50M
DATAFILE
'/oradata/V11/system01.dbf',
'/oradata/V11/sysaux01.dbf',
'/oradata/V11/undotbs01.dbf',
'/oradata/V11/user01.dbf'
CHARACTER SET WE8MSWIN1252;

重建步骤如下(其实trace得到的控制文件内容,已经提供了重建控制文件的步骤和内容,直接copy执行即可):

step1:将数据库开启到nomount

startup nomount;  

如果是RAC环境需要只开启一个节点为nomount,其他节点关闭。并将 cluster_database 集群参数设置为false。重建完成再改回来

step2:执行上面的控制文件DDL

一般执行完成控制文件DDL,会自动开启到mount状态

step3:核对db status

select open_mode from gv$database ;

step4:尝试进行恢复 数据库

SQL> recover database;

step5:打开数据库

SQL> Alter database open;

step6:恢复临时文件 (必须在DB OPEN状态下,mount或者nomount情况下都不能执行temp  add

alter tablespace temp add tempfile '/oradata/V11/temp01.dbf' reuse;

附录:导出的控制文件完整内容

#从内容可以看出,系统自动生成的控制文件的trace 已经完整的分别给出了 resetlog 和noresetlog 方式下重建控制文件的步骤。根据自己对应情况,直接copy执行即可。注意辨别哈,行首带--的是注释,别搞错了。

[oracle@dba1 ~]$ more 1.txt 
-- 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="xxxx"
--
-- 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=/data/app/oracle/product/11.2.0.4/db_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 "xxxx" NORESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 200
    MAXINSTANCES 8
    MAXLOGHISTORY 2920
LOGFILE
  GROUP 1 '/data/oradata/xxxx/onlinelog/o1_mf_1_lt1f299x_.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/data/oradata/xxxx/onlinelog/o1_mf_2_lt1f29d5_.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/data/oradata/xxxx/onlinelog/o1_mf_3_lt1f29g5_.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/data/oradata/xxxx/datafile/o1_mf_system_lt18z4d9_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_sysaux_lt1b3n65_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_undotbs1_lt19jhn7_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_users_lt19p93x_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_tbs_bssa_lt192toc_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_tbs_bssa_lt19nysf_.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 '/data/app/oracle/product/11.2.0.4/db_1/dbs/arch1_1_824297850.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/data/app/oracle/product/11.2.0.4/db_1/dbs/arch1_1_1113747990.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/data/app/oracle/product/11.2.0.4/db_1/dbs/arch1_1_1158061129.dbf';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE

-- All logs need archiving and a log switch is needed.
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 '/data/oradata/xxxx/datafile/o1_mf_temp_lt1f2by7_.tmp'
     SIZE 101711872  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
ALTER TABLESPACE TEMP1 ADD TEMPFILE '/data/oradata/TEMP11.dbf'
     SIZE 1024M REUSE AUTOEXTEND ON NEXT 1024M 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 "xxxx" RESETLOGS  ARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 200
    MAXINSTANCES 8
    MAXLOGHISTORY 2920
LOGFILE
  GROUP 1 '/data/oradata/xxxx/onlinelog/o1_mf_1_lt1f299x_.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 2 '/data/oradata/xxxx/onlinelog/o1_mf_2_lt1f29d5_.log'  SIZE 50M BLOCKSIZE 512,
  GROUP 3 '/data/oradata/xxxx/onlinelog/o1_mf_3_lt1f29g5_.log'  SIZE 50M BLOCKSIZE 512
-- STANDBY LOGFILE
DATAFILE
  '/data/oradata/xxxx/datafile/o1_mf_system_lt18z4d9_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_sysaux_lt1b3n65_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_undotbs1_lt19jhn7_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_users_lt19p93x_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_tbs_bssa_lt192toc_.dbf',
  '/data/oradata/xxxx/datafile/o1_mf_tbs_bssa_lt19nysf_.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 '/data/app/oracle/product/11.2.0.4/db_1/dbs/arch1_1_824297850.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/data/app/oracle/product/11.2.0.4/db_1/dbs/arch1_1_1113747990.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/data/app/oracle/product/11.2.0.4/db_1/dbs/arch1_1_1158061129.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 '/data/oradata/xxxx/datafile/o1_mf_temp_lt1f2by7_.tmp'
     SIZE 101711872  REUSE AUTOEXTEND ON NEXT 655360  MAXSIZE 32767M;
ALTER TABLESPACE TEMP1 ADD TEMPFILE '/data/oradata/TEMP11.dbf'
     SIZE 1024M REUSE AUTOEXTEND ON NEXT 1024M MAXSIZE 32767M;
-- End of tempfile additions.
--

6、创建控制文件中 使用resetlog 和noresetlog的区别

关于这者的不同,其实在control trace 的文件已经给出:

Below are two sets of SQL statements, each of which creates a new control file and uses it to open the database. #下面是两组SQL语句,每一组都创建一个新的控制文件,并使用它打开数据库

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. # 第一组打开具有NORESETLOGS选项的数据库,并且仅当所有online logs的当前版本都可用。

The second set opens the database with the RESETLOGS option and should be used if online logs are unavailable.  # 第二组打开具有RESETLOGS选项的数据库,并且仅当所有online logs不可用

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

#使用NORESETLOGS的情况下:RMAN 恢复需要用的数据将丢失(即控制文件中的备份信息将被清理掉导致备份文件无用)、同时日志(online redo log )可能会被用于介质恢复(这就是要求all online logs are available的根因),所以使用这个选项必须确保所有 online redo log 可用。创建控制文件完成后,DB将mount。 后面这个调整 DG保护模式的 --后续还需要测试下才能验证

--     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

#使用RESETLOGS的情况下:RMAN 恢复需要用的数据将丢失(即控制文件中的备份信息将被清理掉导致备份文件无用)、日志(online redo log )因为序列被重置导致日志文件数据丢失。同时备份也将置为无效。使用这个选项仅当online redo log 被损坏或者丢失。创建控制文件完成后,DB将mount。 后面这个调整 DG保护模式的 --后续还需要测试下才能验证

7、控制文件相关的视图

可以通过视图获取到控制文件的存放内容及控制文件信息。常用的视图:

1、select * from v$controlfile_record_section; --列出了控制文件中的内容,内容所在的区域,每个区域的大小等 具体内容可以根据视图所示,将对应的块 号dump出来看

2、select * from v$controlfile  --包含控制文件的路径、所使用的块大小、文件的尺寸

8、控制文件内容的管理维护

控制文件存放的内容可以大概描述为两类:一类是 可重用记录 和 非重用记录。 

1.可重用或循环使用的记录包含可以从控制文件中删除的信息。such as: RMAN 备份记录、归档日志历史信息、循环重用记录可以被删除,并且不会影响数据库运行。  

2.非重用记录是那些不能被删除的记录。 非重用记录包括 数据文件列表 和日志文件列表(online redo log and standby redo log )。
    我们可以通过重建控制文件或者设置control_file_record_keep_time=0来重用这些记录

一般控制文件中存放的内容是可以清理的,但是需要根据官方的规范来。

官方的MOS文档:清理v$archived_log条目,进而清理控制文件区域。

Removing entries in v$archived_log referencing a particluar DEST_ID (Doc ID 845361.1)

一般条目清理很少进行,所以需要进行的情况下。按照文档测试了,即可实施。在这里就不展开了

后面还有好多内容,有时间再更新了。。。。

  • 21
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值