首先根据官方文档我们了解下控制文件的概念
从glossary这里理解为
一个二进制文件,它记录了一个数据库的物理结构、redo log的名称和位置,数据库的创建时间戳、当前日志的序列号、检查点信息等
A binary file that records the physical structure of a database and contains the names and locations of redo log files, the time stamp of the database creation, the current log sequence number, checkpoint information, and so on.
http://docs.oracle.com/cd/E11882_01/server.112/e40540/glossary.htm#CNCPT89131
从oracle概念文档中中的解释是
数据库控制文件是一个进与一个数据库关联的二进制文件,每个数据库有唯一的一个控制文件(这里是逻辑上的)尽管它可能可能有相同的副本
Overview of Control Files
The database control file is a small binary file associated with only one database. Each database has one unique control file, although it may maintain identical copies of it.
使用控制文件
oracle数据库通常使用控制文件查找数据库文件并通过它来管理数据库状态,控制文件包含诸如下列信息:
*数据库名称和数据库唯一标识符(DBID)
*数据库创建时间戳
*包含数据库文件、在线重做日志文件和归档重做日志文件的信息
*表空间信息
*RMAN备份
Use of Control Files
The control file is the root file that Oracle Database uses to find database files and to manage the state of the database generally. A control file contains information such as the following:
* The database name and database unique identifier (DBID)
* The time stamp of database creation
* Information about data files, online redo log files, and archived redo log files
* Tablespace information
*
RMAN backups
控制文件有以下作用|目的
控制文件包含打开数据库文件需要的数据文件、在线重做日志文件等信息
控制文件跟踪数据库的改变,例如:当一个管理员添加、重命名或者删除一个数据文件或在线重做日志文件,数据库会更新控制文件以体现这次的改变
控制文件包含数据库未打开(is not open)时必须能访问的元数据文件
例如:控制文件包含数据恢复数据库需要的信息,包括检查点,检查点表示当实例开始需要恢复时的重做流中的SCN,检查点SCN保证每次提交更改都已保存在磁盘上的数据文件中。至少每三秒,检查点进程把重做日志中的检查点位置信息记录在控制文件。
Oracle数据库在数据库使用期间持续对控制文件读取和写入,并且在数据库打开状态下一定可以进行写入。
例如:恢复数据库时读取控制文件中的所有数据文件名称,其他操作,例如添加一个数据文件,更新信息储存在控制文件
The control file serves the following purposes:
■ It contains information about data files, online redo log files, and so on that are
required to open the database.
The control file tracks structural changes to the database. For example, when an
administrator adds, renames, or drops a data file or online redo log file, the
database updates the control file to reflect this change.
■ It contains metadata that must be accessible when the database is not open.
For example, the control file contains information required to recover the database,
including checkpoints. A checkpoint indicates the SCN in the redo stream where
instance recovery would be required to begin (see “Overview of Instance
Recovery” on page 13-12). Every committed change before a checkpoint SCN is
guaranteed to be saved on disk in the data files. At least every three seconds the
checkpoint process records information in the control file about the checkpoint
position in the online redo log.
Oracle Database reads and writes to the control file continuously during database use
and must be available for writing whenever the database is open. For example,
recovering a database involves reading from the control file the names of all the data
files contained in the database. Other operations, such as adding a data file, update the
information stored in the control file.
多个控制文件
Oracle数据库能够打开多个相同的控制文件,并且被同一个数据库写。通过在不同的磁盘上多路复用控制文件,数据库可以获得冗余,避免单点故障。
Multiple Control Files
Oracle Database enables multiple, identical control files to be open concurrently and
written for the same database. By multiplexing a control file on different disks, the
database can achieve redundancy and thereby avoid a single point of failure.
这里oracle给我们一个建议,应该在不同的磁盘上保存多个控制文件副本
Note: Oracle recommends that you maintain multiple control file copies, each on a different disk
如果控制文件变得不可用,当尝试访问损坏的的控制文件时,数据库实例将失败,当前控制文件有副本存在时,数据库可以重新挂载和打开,不需要通过介质恢复(将重做或增量备份应用于数据块或备份数据文件),如果数据库的所有的控制文件都丢失,实例将失败,并且需要介质恢复。当前备份不可用时,只能使用旧的控制文件备份,介质恢复并不简单。
If a control file becomes unusable, then the database instance fails when it attempts to
access the damaged control file. When other current control file copies exist, the
database can be remounted and opened without media recovery. If all control files of a
database are lost, however, then the instance fails and media recovery is required.
Media recovery is not straightforward if an older backup of a control file must be used
because a current copy is not available.
控制文件的结构
控制文件储存关于数据库不同部分的信息,每个部分记录数据库的一个方面。例如,控制文件中
一个部分跟踪数据文件并包含一组记录,每个数据文件一个。每个部分存储在多个逻辑控制文件块中。记录可以跨块。
控制文件包含以下类型的记录:
循环重用记录
这些记录包含非关键信息,如果需要可能会被覆盖。当所有记录插槽都都已满时,数据库可以扩展控制文件,为新的纪录构造空间或重写老的记录,例如,包括记录归档重做日志文件和RMAN备份。
非循环重用记录
这些记录包含不经常改变的和不能重写的关键信息,例如包括表空间、数据文件、在线重做日志文件和重做线程。Oracle数据库从不重用这些记录,除非相应的对象从表空间中与已经删除
像动态性能试图中描述的,你可以查看动态性能视图,也被称为 V$views,这个试图储存了控制文件信息。例如你可以查询V$DATABASE 可以获得数据库的名称和数据库的唯一标识符(DBID)。但是只有数据库可以修改控制文件中的信息。
读取和写入控制文件块和读取和写入数据文件块是不同的。对于控制文件,Oracle数据库直接从磁盘中读取和写入程序全局区(PGA)。每个进程为控制文件块分配一定量的PGA内存。
Control File Structure
Information about the database is stored in different sections of the control file. Each
section is a set of records about an aspect of the database. For example, one section in
the control file tracks data files and contains a set of records, one for each data file.
Each section is stored in multiple logical control file blocks. Records can span blocks
within a section.
The control file contains the following types of records:
■ Circular reuse records
These records contain noncritical information that is eligible to be overwritten if
needed. When all available record slots are full, the database either expands the
control file to make room for a new record or overwrites the oldest record.
Examples include records about archived redo log files and RMAN backups.
■ Noncircular reuse records
These records contain critical information that does not change often and cannot
be overwritten. Examples of information include tablespaces, data files, online
redo log files, and redo threads. Oracle Database never reuses these records unless
the corresponding object is dropped from the tablespace.
As explained in “Overview of the Dynamic Performance Views” on page 6-5, you can
query the dynamic performance views, also known as V$views, to view the
information stored in the control file. For example, you can query V$DATABASE to
obtain the database name and DBID. However, only the database can modify the
information in the control file.
Reading and writing the control file blocks is different from reading and writing data
blocks. For the control file, Oracle Database reads and writes directly from the disk to
the program global area (PGA). Each process allocates a certain amount of its PGA
memory for control file blocks