一、控制文件
oracle的控制文件是极其重要的文件,它是一个较小的二进制文件。
记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等等
在参数文件中描述其位置,个数等等。
在mount阶段被读取,open阶段一直被使用
一个控制文件只能属于一个数据库
控制文件的任意修改将写入到初始化参数中指定的所有控制文件中,读取时则仅读取第一个控制文件
控制文件中包含的内容:
- 数据库的名字、ID、创建的时间戳
- 表空间的名字
- 联机日志文件、数据文件的位置、个数、名字
- 联机日志的Sequence号码
- 检查点的信息
- 撤销段的开始或结束
- 归档信息
- 备份信息
二、查看控制文件的相关定义
1.使用相关视图来查看
V$CONTROLFILE --列出实例中所有控制文件的名字及状态信息
V$PARAMETER --列出所有参数的位置及状态信息
V$CONTROLFILE_RECORD_SECTION --列出控制文件中记录的部分信息
SHOW PARAMETER CONTROL_FILES --列出控制文件的名字、状态、位置等
2.使用strings命令查看
strings $ORACLE_BASE/oradata/orcl/control01.ct
3.备份控制文件到可查看文件
SQL> alter database backup controlfile to trace as '/tmp/ctl.txt';
--或者使用
SQL> host strings /u01/app/oracle/oradata/orcl/control01.ctl > /tmp/ctl.txt
cat /tmp/ctl.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="orcl"
--
-- 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_3='LOCATION=/u03/ARCHLOG/'
-- LOG_ARCHIVE_DEST_3='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_3='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_3='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_3='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_3='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_3=ENABLE
--
-- LOG_ARCHIVE_DEST_2='LOCATION=/u02/ARCHLOG/'
-- LOG_ARCHIVE_DEST_2='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_2='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_2='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_2='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_2='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_2=ENABLE
--
-- LOG_ARCHIVE_DEST_1='LOCATION=/u01/ARCHLOG/'
-- LOG_ARCHIVE_DEST_1='MANDATORY 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 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 "ORCL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 (
'/u01/orcl/onlinelog/redo1a.log',
'/u02/orcl/onlinelog/redo1b.log',
'/u03/orcl/onlinelog/redo1c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 2 (
'/u01/orcl/onlinelog/redo2a.log',
'/u02/orcl/onlinelog/redo2b.log',
'/u03/orcl/onlinelog/redo2c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 3 (
'/u01/orcl/onlinelog/redo3a.log',
'/u02/orcl/onlinelog/redo3b.log',
'/u03/orcl/onlinelog/redo3c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 4 (
'/u01/orcl/onlinelog/redo4a.log',
'/u02/orcl/onlinelog/redo4b.log',
'/u03/orcl/onlinelog/redo4c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 5 '/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/o1_mf_5_d678b9q8_.log' SIZE 100M BLOCKSIZE 512
-- STANDBY LOGFILE DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/test.dbf',
'/u01/app/oracle/oradata/orcl/bk02.dbf'
CHARACTER SET AL32UTF8
; -- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO RECOVERY WINDOW OF 3 DAYS');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE','DISK TO ''/u02/database/orcl/backup/rman/20161228/orcl_lev0_201612280036_%F''');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- 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 '/u03/ARCHLOG/1_1_930793088.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u03/ARCHLOG/1_1_931117309.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u03/ARCHLOG/1_1_931133551.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u03/ARCHLOG/1_1_931634970.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 '/u01/app/oracle/oradata/orcl/temp01.dbf'
SIZE 31457280 REUSE AUTOEXTEND ON NEXT 8192 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 "ORCL" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 (
'/u01/orcl/onlinelog/redo1a.log',
'/u02/orcl/onlinelog/redo1b.log',
'/u03/orcl/onlinelog/redo1c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 2 (
'/u01/orcl/onlinelog/redo2a.log',
'/u02/orcl/onlinelog/redo2b.log',
'/u03/orcl/onlinelog/redo2c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 3 (
'/u01/orcl/onlinelog/redo3a.log',
'/u02/orcl/onlinelog/redo3b.log',
'/u03/orcl/onlinelog/redo3c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 4 (
'/u01/orcl/onlinelog/redo4a.log',
'/u02/orcl/onlinelog/redo4b.log',
'/u03/orcl/onlinelog/redo4c.log'
) SIZE 50M BLOCKSIZE 512,
GROUP 5 '/u01/app/oracle/flash_recovery_area/ORCL/onlinelog/o1_mf_5_d678b9q8_.log' SIZE 100M BLOCKSIZE 512
-- STANDBY LOGFILE DATAFILE
'/u01/app/oracle/oradata/orcl/system01.dbf',
'/u01/app/oracle/oradata/orcl/sysaux01.dbf',
'/u01/app/oracle/oradata/orcl/undotbs01.dbf',
'/u01/app/oracle/oradata/orcl/users01.dbf',
'/u01/app/oracle/oradata/orcl/test.dbf',
'/u01/app/oracle/oradata/orcl/bk02.dbf'
CHARACTER SET AL32UTF8
; -- Configure RMAN configuration record 1
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('RETENTION POLICY','TO RECOVERY WINDOW OF 3 DAYS');
-- Configure RMAN configuration record 2
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('BACKUP OPTIMIZATION','ON');
-- Configure RMAN configuration record 3
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE','DISK TO ''/u02/database/orcl/backup/rman/20161228/orcl_lev0_201612280036_%F''');
-- Configure RMAN configuration record 4
VARIABLE RECNO NUMBER;
EXECUTE :RECNO := SYS.DBMS_BACKUP_RESTORE.SETCONFIG('CONTROLFILE AUTOBACKUP','ON');
-- 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 '/u03/ARCHLOG/1_1_930793088.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u03/ARCHLOG/1_1_931117309.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u03/ARCHLOG/1_1_931133551.dbf';
-- ALTER DATABASE REGISTER LOGFILE '/u03/ARCHLOG/1_1_931634970.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/orcl/temp01.dbf'
SIZE 31457280 REUSE AUTOEXTEND ON NEXT 8192 MAXSIZE 32767M;
-- End of tempfile additions.
--
三、控制文件的管理
1.控制文件的移动实例
目的:将闪回区的控制文件移到指定位置
--查看控制文件的配置
SQL> select * from v$controlfile; STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
------- ------------------------------ --- ---------- --------------
/u01/app/oracle/oradata/orcl/c NO 16384 618
ontrol01.ctl /u01/app/oracle/flash_recovery NO 16384 618
_area/control02.ctl
--修改控制文件的位置
SQL> alter system set control_files=
2 '/u01/app/oracle/oradata/orcl/control01.ctl',
3 '/u02/control02.ctl'
4 scope=spfile; 系统已更改。
--关闭数据库
SQL> shutdown immediate
--拷贝物理文件到指定位置
SQL> host cp /u01/app/oracle/oradata/orcl/control01.ctl /u02/control02.ctl
--启动数据库,验证
SQL> startup SQL> select * from v$controlfile; STATUS NAME IS_ BLOCK_SIZE FILE_SIZE_BLKS
------- ------------------------------ --- ---------- --------------
/u01/app/oracle/oradata/orcl/c NO 16384 618
ontrol01.ctl /u02/control02.ctl NO 16384 618
--删除以前的控制文件
SQL> host rm /u01/app/oracle/flash_recovery_area/control02.ctl
如果启动的时候出现版本不一致,使用高版本覆盖低版本
2.备份控制文件
--用于归档模式下的恢复,直接覆盖到控制文件
SQL> alter database backup controlfile to '/u01/app/oracle/control.bak';
--用于重建控制文件
SQL> alter database backup controlfile to trace as '/u01/app/oracle/recreate_controlfile.txt';
--使用RMAN备份
RMAN> backup current controlfile;
3. 控制文件的恢复管理
控制文件版本不一致的问题
用较新版本的控制文件覆盖旧版本的控制文件
直接修改参数control_file
丢失问题
归档模式下
当归档日志全的时候,先做全备,然后使用备份的控制文件恢复即可
当归档日志不全的时候,先做全备,然后建立新的控制文件即可
非归档模式下
先做全备,然后建立新的控制文件即可