Oracle控制文件操作
控制文件是连接instance和 database的纽带。记录了database的结构信息。
控制文件是1个2进制文件。记录的是当前database的状态。
控制文件可以有多个,在参数文件中通过control_files参数指定位置,在需要向控制文件写入时,会同步的向多个控制文件写入。读取控制文件时,只会读取第一个控制文件。如果任意一个控制文件损坏,则实例会abort。
控制文件只能和1个database相关联。
控制文件是在创建database的时候创建的。也可以在启动到nomount状态时重建。
与control file相关的视图
v$controlfile:当前instance中所有的控制文件的信息。
v$controlfile_record_section: 控制文件中所有的section信息。
查看当前控制文件信息:
select * from v$controlfile;
select * from v$parameter where name like '%control%';
show parameter control;
select * from v$controlfile_record_section;
用命令修改控制文件的路径
alter system set control_files='/u01/app/oracle/oradata/saigon/control01.ctl',
'/u01/app/oracle/oradata/saigon/control02.ctl',
'/u01/app/oracle/oradata/saigon/control03.ctl' scope=spfile;
使用spfile增加控制文件个数或修改控制文件路径
(1)利用v$controlfile 来获取现有控制文件名字和位置.
(2)修改spfile,使用
alter system set control_files=
'D:\DISK3\CONTROL01.CTL',
'D:\DISK6\CONTROL02.CTL',
'D:\DISK9\CONTROL03.CTL' SCOPE=SPFIL;
(3)正常关闭数据库,(shutdown,shutdown immediate).
(4)使用操作系统的复制命令将现有控制文件复制到指定位置.
(5)重新启动oracle数据库(startup)
(6)利用数据字段v$controlfile来验证新的控制文件名字是否正确.
(7)如有错误,重复上述操作:如果无误,删除原有的控制文件.
使用pfile增加控制文件个数或修改控制文件路径
1.干净的关闭数据库。
2.在操作系统上复制1个新的控制文件并改名。
3.在initSID.ora中的control_files参数中添加之前的参数文件。
4.启动数据库。
在oracle运行过程中备份控制文件
1.alter database backup controlfile to 'D:\aaa.bak';
2.alter database backup controlfile to trace; 把控制文件翻译成创建控制文件的脚本,路径在用户警告文件的目录下(可以通过show parameter user_dump;查看),后缀名为trc。
或根据下面方式找到:
SELECT d.VALUE
|| '/'
|| LOWER (RTRIM (i.INSTANCE, CHR (0)))
|| '_ora_'
|| p.spid
|| '.trc' trace_file_name
FROM (SELECT p.spid
FROM v$mystat m, v$session s, v$process p
WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
(SELECT t.INSTANCE
FROM v$thread t, v$parameter v
WHERE v.NAME = 'thread'
AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
(SELECT VALUE
FROM v$parameter
WHERE NAME = 'user_dump_dest') d
/
3.
run{
backup current controlfile format'/backup1/controlfile_%d_%s.ctl';
}
控制文件的的恢复
resetlog方式打开数据只要拥有当前的日志文件是可以实现完全恢复的。
是否需要使用resetlogs方式打开,则取决于是否使用的是备份的控制文件。
如果使用的是备份的控制文件则需要使用resetlogs方式打开数据库;
如果拥有当前的控制文件或者通过重建控制文件来恢复,就不需要通过resetlogs方式打开。
RMAN>restore controlfile to '/tmp/control01.ctl' from 'c-3152029224-20051221-00'
-------恢复控制文件用户resetlogs方式打开
run{
startup force nomount;
set dbid=
restore controlfile from autobackup;
alter database mount;
recover database;
alter database open resetlogs;
}
-------恢复控制文件用正常方式打开
1.startup nomount;
2.RMAN>restore controlfile from autobackup;
3.alter database mount;
4.SQL>alter database backup controlfile to trace;
5.找到trace文件
SELECT d.VALUE
|| '/'
|| LOWER (RTRIM (i.INSTANCE, CHR (0)))
|| '_ora_'
|| p.spid
|| '.trc' trace_file_name
FROM (SELECT p.spid
FROM v$mystat m, v$session s, v$process p
WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
(SELECT t.INSTANCE
FROM v$thread t, v$parameter v
WHERE v.NAME = 'thread'
AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
(SELECT VALUE
FROM v$parameter
WHERE NAME = 'user_dump_dest') d
/
6.重建控制文件打开数据库
重建控制文件方法如下:
A,确定控制文件,重做日志文件,数据文件位置(A某些情况下需要);
select * from v$controlfile;
select * from v$logfile;
select file#,name from v$datafile;
B,生成可以重建控制文件的脚本
alter database backup controlfile to trace;
C,获取trc文件位置的脚本
SELECT d.VALUE
|| '/'
|| LOWER (RTRIM (i.INSTANCE, CHR (0)))
|| '_ora_'
|| p.spid
|| '.trc' trace_file_name
FROM (SELECT p.spid
FROM v$mystat m, v$session s, v$process p
WHERE m.statistic# = 1 AND s.SID = m.SID AND p.addr = s.paddr) p,
(SELECT t.INSTANCE
FROM v$thread t, v$parameter v
WHERE v.NAME = 'thread'
AND (v.VALUE = 0 OR t.thread# = TO_NUMBER (v.VALUE))) i,
(SELECT VALUE
FROM v$parameter
WHERE NAME = 'user_dump_dest') d
/
D,查看trc文件内容
[oracle@orcl admin]$ cat /home/oracle/admin/orcl/udump/orcl_ora_10202.trc
/home/oracle/admin/orcl/udump/orcl_ora_10202.trc
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
ORACLE_HOME = /home/oracle/oracle
System name: Linux
Node name: orcl
Release: 2.6.18-164.el5
Version: #1 SMP Tue Aug 18 15:51:54 EDT 2009
Machine: i686
Instance name: orcl
Redo thread mounted by this instance: 1
Oracle process number: 15
Unix process pid: 10202, image: oracle@orcl (TNS V1-V3)
*** SERVICE NAME:(SYS$USERS) 2012-05-27 12:14:16.466
*** SESSION ID:(159.3) 2012-05-27 12:14:16.466
*** 2012-05-27 12:14:16.466
-- 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=2
-- STANDBY_FILE_MANAGEMENT=MANUAL
-- STANDBY_ARCHIVE_DEST=?/dbs/arch
-- FAL_CLIENT=''
-- FAL_SERVER=''
--
-- LOG_ARCHIVE_DEST_10='LOCATION=USE_DB_RECOVERY_FILE_DEST'
-- LOG_ARCHIVE_DEST_10='OPTIONAL REOPEN=300 NODELAY'
-- LOG_ARCHIVE_DEST_10='ARCH NOAFFIRM NOEXPEDITE NOVERIFY SYNC'
-- LOG_ARCHIVE_DEST_10='REGISTER NOALTERNATE NODEPENDENCY'
-- LOG_ARCHIVE_DEST_10='NOMAX_FAILURE NOQUOTA_SIZE NOQUOTA_USED NODB_UNIQUE_NAME'
-- LOG_ARCHIVE_DEST_10='VALID_FOR=(PRIMARY_ROLE,ONLINE_LOGFILES)'
-- LOG_ARCHIVE_DEST_STATE_10=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 NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8ISO8859P1
;
-- 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 '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/o1_mf_1_1_%u_.arc';
-- Recovery is required if any of the datafiles are restored backups,
-- or if the last shutdown was not normal or immediate.
RECOVER DATABASE
-- 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 '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 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 NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8ISO8859P1
;
-- 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 '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/o1_mf_1_1_%u_.arc';
-- ALTER DATABASE REGISTER LOGFILE '/home/oracle/flash_recovery_area/ORCL/archivelog/2012_05_27/o1_mf_1_1_%u_.arc';
-- 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 '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
-- End of tempfile additions.
E,获取创建控制文件的脚本,根据数据库不同状况,可以选择是使用RESETLOGS(没有重做日志的情况)/NORESETLOGS(有重做日志的情况)来重建控制文件,下面为NORESETLOGS.
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8ISO8859P1;
RECOVER DATABASE
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
F,运行脚本重建控制文件
SQL> set echo on
SQL> STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "ORCL" NORESETLOGS NOARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/oradata/orcl/redo01.log' SIZE 50M,
GROUP 2 '/home/oracle/oradata/orcl/redo02.log' SIZE 50M,
GROUP 3 '/home/oracle/oradata/orcl/redo03.log' SIZE 50M
-- STANDBY LOGFILE
DATAFILE
'/home/oracle/oradata/orcl/system01.dbf',
'/home/oracle/oradata/orcl/undotbs01.dbf',
'/home/oracle/oradata/orcl/sysaux01.dbf',
'/home/oracle/oradata/orcl/users01.dbf',
'/home/oracle/oradata/orcl/example01.dbf'
CHARACTER SET WE8ISO8859P1;
RECOVER DATABASE
ALTER DATABASE OPEN;
ALTER TABLESPACE TEMP ADD TEMPFILE '/home/oracle/oradata/orcl/temp01.dbf'
SIZE 22020096 REUSE AUTOEXTEND ON NEXT 655360 MAXSIZE 32767M;
ORACLE instance started.
Total System Global Area 167772160 bytes
Fixed Size 1218316 bytes
Variable Size 71305460 bytes
Database Buffers 92274688 bytes
Redo Buffers 2973696 bytes
SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Control file created.
SQL> Media recovery complete.
SQL>
Database altered.
SQL> 2
Tablespace altered.
Oracle控制文件操作的更多相关文章
- oracle 控制文件的重建
目录 oracle 控制文件的重建 NORESETLOGS RESETLOGS oracle 控制文件的重建 不到最后时刻,如三个控制文件都已损坏,又没有控制文件的备份.还是不要重建控制文件,处理不好 ...
- Oracle 控制文件(CONTROLFILE)
一.Oracle 控制文件 为二进制文件,初始化大小由CREATE DATABASE指定,可以使用RMAN备份 记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等 ...
- Oracle控制文件
一.Oracle 控制文件 为二进制文件,初始化大小由CREATE DATABASE指定,可以使用RMAN备份 记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息等 ...
- Oracle 控制文件损坏解决方案
Oracle 控制文件损坏解决方案 故障一:丢失(损坏)一个控制文件 前台报错:ORA-00205:error in identifying control file,check alert log ...
- Oracle控制文件多路复用以及Oracle备份重建控制文件
控制文件中记录了oracle数据库的物理结构,也就是记录了数据库数据文件和日志文件的位置,控制文件中还记录了多种SCN,用这些SCN来确定数据文件和日志文件是否是正确的.如果不正确那么数据库就需要恢复 ...
- oracle控制文件问题
下午时连接数据库突然发现连不上了,监听报错找不到服务,于是登录数据库所在服务器,查看监听状态,oracle:lsnrctl status 监听状态正常,登入数据库查看[oracle@frkdb1 ~] ...
- Oracle数据库体系结构(4)oracle控制文件
控制文件的概述 1.控制文件是oracle数据库非常重要的物理文件,描述了整个数据库的物理结构信息,包括数据库名称.数据文件与重做日志文件的名称与位置,日志序列号等信息.数据库实例根据初始化参数CON ...
- oracle 控制文件多路复用
网上有很多关于控制文件的操作,我大概看了下.有很多都是炒来炒去转来转去.下面以自己理解和操作为例来对oracle的控制文件进行下介绍. 首先介绍下控制文件 在oralce数据库中,控制文件是一个很小的 ...
- oracle控制文件丢失恢复
在学习群里有个同学误删除了控制文件,于是我也把自己数据库的控制文件删除了,看看能不能进行恢复,以下是整个实验的过程~~在做之前,先看看控制文件的备份方式:1.生成可以重建控制文件的脚本.2.备份二进制 ...
随机推荐
- 高仿114la网址导航源码完整最新版
给大家本人我精心模仿的高仿114la网址导航源码,我们都知道114la网址导航的影响力,喜欢的朋友可以下载学习一下. 由于文件较大,没有上传了,下载地址在下面有的. 附源码下载: 114la网站导航 ...
- CLR执行模型 流程总结(图)
如有错误,还望指出:
- 去掉Qt加载png图像文件时候的iccp警告
用QML加载png文件时显示如下警告(图像正常加载显示) libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP ...
- 基于visual Studio2013解决C语言竞赛题之1031猜数
题目 解决代码及点评 /* 31. 猜号码∶由随机函数产生一个1至1000之间的整数,让人猜之. 计算机仅回答人猜的数大.小还是相等,当人猜对时, 由计算机打印出人 ...
- [Java][activiti]Activiti这个过程委托功能[getAssignee()与getOwner()差异]
一.流程图: 二.流程定义文件: AssigneeUserAndGroup.bpmn 三.单元測试: ProcessTestDelegateTask.java 四.主要运行语句 // 签收 taskS ...
- Swift - 添加、修改、删除通讯录联系人
使用AddressBook.framework框架,我们除了可以很方便的获取通信录里的联系人.同时,还能对通讯录进行新增.修改.删除联系人操作. (注意:这些操作同查询一样,首先需要发起授权请求) 1 ...
- Swift - 使用NSURLSession加载数据、下载、上传文件
NSURLSession类支持三种类型的任务:加载数据.下载和上传.下面通过样例分别进行介绍. 1,使用Data Task加载数据 使用全局的sharedSession()和dataTaskWithR ...
- C语言,realloc
void * realloc ( void * ptr, size_t new_size ); 关于realloc的行为方式,结合源码总结为:1. realloc失败的时候,返回NULL: 2. re ...
- 1352 - Colored Cubes (枚举方法)
There are several colored cubes. All of them are of the same size but they may be colored differentl ...
- Linux 安装Redis全过程日志
wget http://download.redis.io/redis-stable.tar.gz tar xvzf redis-stable.tar.gz cd redis-stable make ...