一、Oracle 控制文件

为二进制文件,初始化大小由CREATE DATABASE指定,可以使用RMAN备份

记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等等

在参数文件中描述其位置,个数等等。通常采用分散放开,多路复用的原则。在mount阶段被读取,open阶段一直被使用

维护数据库一致性(数据库启动时会比较控制文件与联机日志文件中的ckpt,即起始scn号,如相等则正常启动,否则需要介质恢复)

一个控制文件只能属于一个数据库

控制文件的任意修改将写入到初始化参数中指定的所有控制文件中,读取时则仅读取第一个控制文件

控制文件只能连接一个数据库,控制文件的大小一般不要超过MB,最多为个,最少一个,互为镜像

控制文件中包含的内容

数据库的名字、ID、创建的时间戳

表空间的名字

联机日志文件、数据文件的位置、个数、名字

联机日志的Sequence号码

检查点的信息

撤销段的开始或结束

归档信息

备份信息

二、查看控制文件的相关信息

1.使用相关视图来查看

V$CONTROLFILE                   --列出实例中所有控制文件的名字及状态信息

SYS@userdata>select * from v$controlfile;

STATUS              NAME                         IS_RECOVE BLOCK_SIZE FILE_SIZE_BLKS
--------------------- -------------------------------------------------- --------- ---------- --------------
/u01/app/oracle/oradata/userdata/control01.ctl NO 16384 508
/u01/app/oracle/oradata/userdata/control02.ctl NO 16384 508
/u01/app/oracle/oradata/userdata/control03.ctl NO 16384 508

V$PARAMETER                     --列出所有参数的位置及状态信息

SYS@userdata>select name,value from v$parameter where name='control_files';

NAME
--------------------------------------------------
VALUE
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
control_files
/u01/app/oracle/oradata/userdata/control01.ctl, /u01/app/oracle/oradata/userdata/control02.ctl, /u01/app/oracle/oradata/userdata/control03.ctl

V$CONTROLFILE_RECORD_SECTION    --列出控制文件中记录的部分信息

SHOW PARAMETER CONTROL_FILES    --列出控制文件的名字、状态、位置等

SYS@userdata>show parameter control_files;

NAME                     TYPE                   VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/userda
ta/control01.ctl, /u01/app/ora
cle/oradata/userdata/control02
.ctl, /u01/app/oracle/oradata/
userdata/control03.ctl

2.使用STRINGS命令来查看控制文件中的具体内容

$ strings /u01/app/oracle/oradata/userdata/control01.ctl

3.备份控制文件到平面文件(然后查看控制文件中的具体内容)

SYS@userdata>alter database backup controlfile  to trace as '/home/oracle/ctl.txt';

Database altered.

4.转储控制文件内容(查看控制文件中的具体内容)

SYS@userdata>alter system set events 'immediate trace name controlf level 10';

System altered.

SYS@userdata>show parameter user_dump;

NAME                     TYPE                   VALUE
------------------------------------ --------------------------------- ------------------------------
user_dump_dest string /u01/app/oracle/admin/userdata
/udump
SYS@userdata>! ls -ltr /u01/app/oracle/admin/userdata/udump
total 1344
-..............
-rw-r----- 1 oracle oinstall 136039 Sep 13 16:49 userdata_ora_9476.trc

或者

SYS@userdata>oradebug setmypid
Statement processed.
SYS@userdata>select spid from v$process where addr=(select paddr from v$session where sid=(select sid from v$mystat where rownum=1)); SPID
------------------------------------
9476
SYS@userdata>oradebug dump controlf 12
Statement processed.
SYS@userdata>show parameter user_dump; NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
user_dump_dest string /u01/app/oracle/admin/userdata
/udump
SYS@userdata>! ls -lh /u01/app/oracle/admin/userdata/udump/*9476*
-rw-r----- 1 oracle oinstall 182K Sep 13 17:04 /u01/app/oracle/admin/userdata/udump/userdata_ora_9476.trc

三、控制文件个数与位置管理

spfile或pfile都可以实现对控制文件的个数及位置管理

spfile步骤

修改spfile参数中的control_files   -- alter system ... scope = spfile | both |memory

一致性关闭数据库

增加或减少控制文件(cp or mv)

启动数据库使用spfile

验证结果

pfile步骤

一致性关闭数据库

修改pfile参数(vi或vim)   修改*.control_files=......这一段

增加或减少控制文件(cp or mv)

启动数据库使用pfile

验证结果

1. 将控制文件减少到一个

SYS@userdata>show parameter control_files;

NAME                     TYPE                   VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/userda
ta/control01.ctl, /u01/app/ora
cle/oradata/userdata/control02
.ctl, /u01/app/oracle/oradata/
userdata/control03.ctl
SYS@userdata>alter system set control_files='/u01/app/oracle/oradata/userdata/control01.ctl' scope=spfile; System altered. SYS@userdata>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@userdata>startup mount;
ORACLE instance started. Total System Global Area 314572800 bytes
Fixed Size 2083592 bytes
Variable Size 255853816 bytes
Database Buffers 50331648 bytes
Redo Buffers 6303744 bytes
Database mounted.
SYS@userdata>show parameter control_files; NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/userda
ta/control01.ctl

2. 将控制文件恢复到多路复用

SYS@userdata>show parameter control_files;

NAME                     TYPE                   VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/userda
ta/control01.ctl
SYS@userdata>alter system set control_files='/u01/app/oracle/oradata/userdata/control01.ctl','/u01/app/oracle/oradata/userdata/control02.ctl','/u01/app/oracle/oradata/userdata/control03.ctl' scope=spfile; System altered.
SYS@userdata>shutdown immediate;
ORA-01109: database not open Database dismounted.
ORACLE instance shut down.
SYS@userdata>startup mount;
ORACLE instance started. Total System Global Area 314572800 bytes
Fixed Size 2083592 bytes
Variable Size 255853816 bytes
Database Buffers 50331648 bytes
Redo Buffers 6303744 bytes
ORA-00214: control file '/u01/app/oracle/oradata/userdata/control01.ctl' version 740 inconsistent with file '/u01/app/oracle/oradata/userdata/control02.ctl' version 738 SYS@userdata>! cp /u01/app/oracle/oradata/userdata/control01.ctl /u01/app/oracle/oradata/userdata/control02.ctl SYS@userdata>! cp /u01/app/oracle/oradata/userdata/control01.ctl /u01/app/oracle/oradata/userdata/control03.ctl SYS@userdata>alter database mount; Database altered. SYS@userdata>alter database open; Database altered.

四、控制文件的备份

SYS@userdata>alter database backup controlfile to '/home/oracle/ctl_20170913.bak';      #归档模式下备份

Database altered.

SYS@userdata>alter database backup controlfile to trace as '/home/oracle/ctl_20170913.txt';        #归档非非归档均可

Database altered.

RMAN> backup current controlfile format '/home/oracle/ctl_rman.bak';                                #采用rman方式备份

Starting backup at 2017-09-13 17:28:21
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
channel ORA_DISK_1: starting piece 1 at 2017-09-13 17:28:22
channel ORA_DISK_1: finished piece 1 at 2017-09-13 17:28:25
piece handle=/home/oracle/ctl_rman.bak tag=TAG20170913T172821 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:04
Finished backup at 2017-09-13 17:28:25 RMAN> list backup; List of Backup Sets
=================== BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ -------------------
1 Full 7.98M DISK 00:00:02 2017-09-13 17:28:23
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20170913T172821
Piece Name: /home/oracle/ctl_rman.bak
Control File Included: Ckp SCN: 1133796 Ckp time: 2017-09-13 17:28:21

五、控制文件的恢复

1. 非归档模式下控制文件恢复

SYS@userdata>archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /arch
Oldest online log sequence 17
Current log sequence 19
SYS@userdata>show parameter control_files; NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/userda
ta/control01.ctl
SYS@userdata>alter database backup controlfile to trace as '/home/oracle/ctl_20170913.txt'; Database altered. SYS@userdata>create table temp_tb(id int,name varchar2(32)); Table created. SYS@userdata>insert into temp_tb values(1,'bill');
SYS@userdata>insert into temp)tb values(2,'sames'); 1 row created. SYS@userdata>commit; Commit complete. SYS@userdata>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down. SYS@userdata>host rm -rf /u01/app/oracle/oradata/userdata/control01.ctl SYS@userdata>startup;
ORACLE instance started. Total System Global Area 314572800 bytes
Fixed Size 2083592 bytes
Variable Size 255853816 bytes
Database Buffers 50331648 bytes
Redo Buffers 6303744 bytes
ORA-00205: error in identifying control file, check alert log for more info SYS@userdata>host tail -n 10 /u01/app/oracle/admin/userdata/bdump/alert_userdata.log
starting up 1 shared server(s) ...
Wed Sep 13 19:17:55 2017
ALTER DATABASE MOUNT
Wed Sep 13 19:17:55 2017
ORA-00202: control file: '/u01/app/oracle/oradata/userdata/control01.ctl'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Wed Sep 13 19:17:58 2017
ORA-205 signalled during: ALTER DATABASE MOUNT...

可以看到唯一的控制文件丢失后,数据库启动到mount状态下报错,此时只能通过手动新建控制文件的方法来解决,完整的创建控制文件的语句如下所示

--重建控制文件主要有三个需要考虑的是

--搞清各个日志文件的大小及位置

--搞清各个数据文件的位置

--设置正确的字符集

CREATE CONTROLFILE REUSE DATABASE "USERDATA" RESETLOGS  NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 200
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/userdata/redo01.log' SIZE 100M,
GROUP 2 '/u01/app/oracle/oradata/userdata/redo02.log' SIZE 100M,
GROUP 3 '/u01/app/oracle/oradata/userdata/redo03.log' SIZE 100M
DATAFILE
'/u01/app/oracle/oradata/userdata/system01.dbf',
'/u01/app/oracle/oradata/userdata/undotbs01.dbf',
'/u01/app/oracle/oradata/userdata/sysaux01.dbf',
'/u01/app/oracle/oradata/userdata/users01.dbf',
'/u01/app/oracle/oradata/userdata/example01.dbf'
CHARACTER SET AL32UTF8
;
SYS@userdata> CREATE CONTROLFILE REUSE DATABASE "USERDATA" NORESETLOGS  NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 200
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/u01/app/oracle/oradata/userdata/redo01.log' SIZE 100M,
GROUP 2 '/u01/app/oracle/oradata/userdata/redo02.log' SIZE 100M,
GROUP 3 '/u01/app/oracle/oradata/userdata/redo03.log' SIZE 100M
DATAFILE
'/u01/app/oracle/oradata/userdata/system01.dbf',
'/u01/app/oracle/oradata/userdata/undotbs01.dbf',
'/u01/app/oracle/oradata/userdata/sysaux01.dbf',
'/u01/app/oracle/oradata/userdata/users01.dbf',
'/u01/app/oracle/oradata/userdata/example01.dbf'
17 CHARACTER SET AL32UTF8; Control file created. SYS@userdata>alter database open; Database altered. SYS@userdata>select * from temp_tb; ID NAME
---------- --------------------------------------------------
1 bill
2 sames

2. 归档模式下控制文件恢复

SYS@userdata>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch
Oldest online log sequence 19
Next log sequence to archive 21
Current log sequence 21
SYS@userdata>show parameter control_files; NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
control_files string /u01/app/oracle/oradata/userda
ta/control01.ctl
SYS@userdata>insert into temp_tb values(3,'jerry'); 1 row created.
YS@userdata>shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@userdata>host rm -rf /u01/app/oracle/oradata/userdata/control01.ctl
SYS@userdata>startup
ORACLE instance started. Total System Global Area 314572800 bytes
Fixed Size 2083592 bytes
Variable Size 255853816 bytes
Database Buffers 50331648 bytes
Redo Buffers 6303744 bytes
ORA-00205: error in identifying control file, check alert log for more info
SYS@userdata>host tail -n 10 /u01/app/oracle/admin/userdata/bdump/alert_userdata.log
starting up 1 shared server(s) ...
Wed Sep 13 19:59:08 2017
ALTER DATABASE MOUNT
Wed Sep 13 19:59:08 2017
ORA-00202: control file: '/u01/app/oracle/oradata/userdata/control01.ctl'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
Wed Sep 13 19:59:11 2017
ORA-205 signalled during: ALTER DATABASE MOUNT... SYS@userdata>host cp /home/oracle/archctl.ctl /u01/app/oracle/oradata/userdata/control01.ctl
SYS@userdata>alter database mount; Database altered.
SYS@userdata>alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open SYS@userdata>shutdown immediate;
ORA-01109: database not open Database dismounted.
ORACLE instance shut down.
SYS@userdata>startup mount;
ORACLE instance started. Total System Global Area 314572800 bytes
Fixed Size 2083592 bytes
Variable Size 255853816 bytes
Database Buffers 50331648 bytes
Redo Buffers 6303744 bytes
Database mounted.
SYS@userdata>alter database open resetlogs; Database altered. YS@userdata>select * from temp_tb; ID NAME
---------- --------------------------------------------------
1 bill
2 sames
3 jerry SYS@userdata>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /arch
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2
SYS@userdata>select * from temp_tb; ID NAME
---------- --------------------------------------------------
1 bill
2 sames
3 jerry

Oracle控制文件的更多相关文章

  1. oracle 控制文件的重建

    目录 oracle 控制文件的重建 NORESETLOGS RESETLOGS oracle 控制文件的重建 不到最后时刻,如三个控制文件都已损坏,又没有控制文件的备份.还是不要重建控制文件,处理不好 ...

  2. Oracle 控制文件(CONTROLFILE)

    一.Oracle 控制文件 为二进制文件,初始化大小由CREATE DATABASE指定,可以使用RMAN备份 记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等 ...

  3. Oracle 控制文件损坏解决方案

    Oracle 控制文件损坏解决方案 故障一:丢失(损坏)一个控制文件 前台报错:ORA-00205:error in identifying control file,check alert log ...

  4. Oracle控制文件多路复用以及Oracle备份重建控制文件

    控制文件中记录了oracle数据库的物理结构,也就是记录了数据库数据文件和日志文件的位置,控制文件中还记录了多种SCN,用这些SCN来确定数据文件和日志文件是否是正确的.如果不正确那么数据库就需要恢复 ...

  5. oracle控制文件丢失恢复

    在学习群里有个同学误删除了控制文件,于是我也把自己数据库的控制文件删除了,看看能不能进行恢复,以下是整个实验的过程~~在做之前,先看看控制文件的备份方式:1.生成可以重建控制文件的脚本.2.备份二进制 ...

  6. Oracle控制文件丢失,日志文件丢失

    控制文件丢失: alter database backup controlfile to traces; shutdown immediate; @j:\db\script\orcl_ora_ctl_ ...

  7. ORACLE控制文件一致性【weber出品】

    一.首先控制文件有什么作用呢? 控制文件记录了如下信息:1.数据库的创建时间2.数据文件的位置3.日志文件的位置等作用是指导数据库 找到数据文件,日志文件并将数据库启动到 open 状态. 与其用文字 ...

  8. Oracle控制文件操作

    控制文件是连接instance和 database的纽带.记录了database的结构信息. 控制文件是1个2进制文件.记录的是当前database的状态. 控制文件可以有多个,在参数文件中通过con ...

  9. oracle控制文件问题

    下午时连接数据库突然发现连不上了,监听报错找不到服务,于是登录数据库所在服务器,查看监听状态,oracle:lsnrctl status 监听状态正常,登入数据库查看[oracle@frkdb1 ~] ...

随机推荐

  1. CAS Client集群环境的Session问题及解决方案介绍,下篇介绍作者本人项目中的解决方案代码

    CAS Client集群环境的Session问题及解决方案  程序猿讲故事  2016-05-20  原文 [原创申明:文章为原创,欢迎非盈利性转载,但转载必须注明来源] 之前写过一篇文章,介绍单点登 ...

  2. Latex: extra alignment tab has been changed to cr

    参考: Error: extra alignment tab has been changed to \cr Latex: extra alignment tab has been changed t ...

  3. POJ 3279 Fliptile(翻格子)

    POJ 3279 Fliptile(翻格子) Time Limit: 2000MS    Memory Limit: 65536K Description - 题目描述 Farmer John kno ...

  4. JS实现ul,li排序效果

    <!DOCTYPE html> <html> <head> <title>js列表排序</title> <meta charset=& ...

  5. Python Scrapy安装

    直接安装scrapy 各种报错,后来各种百度终于解决了,如下是亲身的经历. pip install scrapy 这样直接会报错. 第一步: 先安装wheel pip install wheel 第二 ...

  6. centos6.6 安装MariaDB

    参考文章:yum安装MariaDB(使用国内镜像快速安装,三分钟安装完毕) 安装环境: virtualbox下CentOS6.6(32位) 遇到的问题: 通过Maria官方提供的安装方式,源是国外的源 ...

  7. VirtualBox--虚拟机网络设置1--(四种方式)

    转载自:https://www.douban.com/group/topic/15558388/ VirtualBox的提供了四种网络接入模式,它们分别是: 1.NAT 网络地址转换模式(NAT,Ne ...

  8. Redis notes

    一. Redis简单介绍 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redis是一个开源的使用AN ...

  9. Web阶段总结以及感受(附带大一结束暑期学习的纲要)

    之前本人大一因为不是计算机专业的,而又喜欢计算机,所以在大一临时转专业到了计算机院(费劲一番波折),冷笑,还好,从大二开始就可以正式学习喜欢的软件了. 首先,前两天看到一个讲座,提到学习方法,并说出总 ...

  10. Qt532,鼠标键盘事件_ZC

    1.判断鼠标左键是否是 按下的状态 void TdrWebview::mouseMoveEvent(QMouseEvent *_pEvent) { if (_pEvent->buttons() ...