【RMAN】Oracle中如何备份控制文件?备份控制文件的方式有哪几种?
真题1、 如何备份控制文件?备份控制文件的方式有哪几种?
答案:备份控制文件的方式有多种。
① 备份控制文件可以在线进行:
SQL> ALTER DATABASE BACKUP CONTROLFILE TO '/tmp/control.ctl';--热备份控制文件
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE AS '/home/bk/a.ctl';--得到建立控制文件的脚本,备份为文本文件格式
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE [RESETLOGS|NORESETLOGS];
② RMAN手动备份控制文件:
BACKUP CURRENT CONTROLFILE;
BACKUP CURRENT CONTROLFILE FORMAT '/home/oracle/oracle_bk/orclasm/ctl_%d_%T_%s_%p.bak';
BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/home/oracle/ctl.bak';
BACKUP DATABASE INCLUDE CURRENT CONTROLFILE;
③ 设置RMAN自动备份控制文件:
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/ctl_%f.bak';
然后再通过rman做任何备份操作的同时,都会自动对控制文件做备份。
当数据库处于归档模式且设置了“CONFIGURE CONTROLFILE AUTOBACKUP ON;”时,若数据库的结构发生了变化(例如添加或删除表空间),则也会自动对控制文件进行备份。需要注意的是,从Oracle 11g开始,rman对控制文件自动备份做了延迟处理。在Oracle 10g中,引入了控制文件的自动备份特性。如果数据库的结构发生了变化,那么Oracle会自动将控制文件备份到指定目录中,并且在告警日志中记录相关的信息。前提是数据库处于归档模式,并且CONTROLFILE AUTOBACKUP设置为ON。但是,从Oracle 11gR2开始,引入了控制文件自动备份延迟创建的特性。即使设置了控制文件的自动备份,在数据库结构发现变化的时候也不会立即看到控制文件的备份,而是在300秒(由隐含参数“_controlfile_autobackup_delay”来控制,默认是300秒)后才会看到控制文件被自动做了备份(经过实验测试,发现实际上是10分钟之后)。而且,在告警日志中也只能看到数据库结构发生变化的信息,而看不到控制文件自动备份的信息了,这是Oracle为了改变性能而引入的,防止用户在一个脚本中多次对数据库结构的变化而创建多个控制文件备份。例如CREATE TABLEPACE、DROP LOGFILE、ADD LOGEILE等,那么Oracle 11g只会备份一个控制文件,而不是多个;对于Oracle 10g只要数据库结构改变,就会自动备份一个。MOS文档[ID 1068182.1]对这个问题做了说明。在Oracle 11g中,备份控制文件的后台进程为MMON的奴隶进程,默认会生成一个trace文件,名称为SID__m000_<os_pid>.trc,该trace文件中记录了控制文件自动备份的位置和时间:
Starting control autobackup
*** 2018-03-22 13:46:39.836
Control autobackup written to DISK device
handle '/u05/app/oracle/flash_recovery_area/ORA11G/autobackup/2018_03_22/o1_mf_s_971444798_fc6jszc5_.bkp'
④ 只要是对编号为1的数据文件,即SYSTEM表空间的数据文件做备份时,RMAN也会自动对控制文件做备份。
⑤ 快照控制文件。快照控制文件是由RMAN在系统指定位置生成的当前控制文件的一个副本。当RMAN开始备份时,Oracle会检查系统控制文件与快照控制文件是否一致(如果不存在,那么会从控制文件提取信息创建),若不一致则刷新快照控制文件。RMAN在以下情况中需要快照控制文件:1.同步恢复目录时2.对当前控制文件进行备份时。在RAC环境下,仅仅在实施RMAN备份的节点上需要快照控制文件。
查看快照控制文件的位置:
RMAN> show snapshot controlfile name;
RMAN configuration parameters for database with db_unique_name USBO are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/db_1/dbs/snapcf_lhrdb.f'; # default
Linux/Unix平台为:$ORACLE_HOME/dbs/snapcf_$ORACLE_SID.f
Windows平台为:%ORACLE_HOME%\database\snapcf_%$ORACLE_SID%.f
如果要查看备份的控制文件,那么可以通过:
RMAN> LIST BACKUP OF CONTROLFILE;
一.1.1 备份控制文件
控制文件在ORACLE中的重要性是毋庸置疑的,你看,连RMAN都给予特殊的照顾,在RMAN中备份控制文件的方式是最多的。
1.最简单的方式,通过 CONFIGURE 命令将 CONTROLFILE AUTOBACKUP 置为 ON。
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/ctl_%f.bak';
然后你再通过rman做任何备份操作的同时,都会自动对控制文件做备份。当打开控制文件自动备份功能后,备份控制文件的时候就会自动备份spfile参数文件,备份参数文件的时候也会备份控制文件,这时spfile就会备份2次。
2.对编号为1的数据文件,即SYSTEM表空间的数据文件做备份时,RMAN也会自动对控制文件做备份。
3.手动执行备份命令。
BACKUP CURRENT CONTROLFILE;
backup current controlfile format '/home/oracle/oracle_bk/orclasm/ctl_%d_%T_%s_%p.bak';
BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/home/oracle/ctl.bak';
4.执行BACKUP时指定INCLUDE CURRENT CONTROLFILE参数,例如:
RMAN> BACKUP DATABASE INCLUDE CURRENT CONTROLFILE;
5.SQLPLUS下:
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE as '/home/bk/a.ctl';--得到建立控制文件的脚本
SQL> alter database backup controlfile to '/tmp/control.ctl';--热备份控制文件
6.快照控制文件
Linux/Unix平台为: $ORACLE_HOME/dbs/snapcf_@.f
Windows平台为: %ORACLE_HOME%\database\snapcf_@.f
如果要查看备份的控制文件,可以通过:
RMAN> LIST BACKUP OF CONTROLFILE;
-----------------------------------控制文件
alter session set events 'immediate trace name CONTROLF level 12';
alter database backup controlfile to trace as '/home/bk/a.ctl';
host strings /u01/app/oracle/oradata/orcl/control01.ctl > /u01/app/oracle/ctl.txt
热备:
alter database backup controlfile to '
; --热备份控制文件 alter database backup controlfile to '/home/oracle/ora_bk/control.bk';
alter database backup controlfile to trace as '
;--得到建立控制文件的脚本
RMAN:
backup current controlfile format '/home/oracle/oracle_bk/orclasm/ctl_%d_%T_%s_%p.bak';
backup database include current controlfile;
-- 或者设置RMAN 为自动备份
RMAN > configure controlfile autobackup on;
控制文件备份路径参考之前的rman配置
【OCP真题1】 Which is not a valid way of backing up a control file?
A. Backing up the control file to trace
B. Copying the existing control file of the database to the backup location during a hot backup
C. Copying the existing control file of the database to the backup location during a cold backup
D. Creating a backup control file
E. Using the create controlfile command
Answer: B
一.1.1.1 在线镜像备份
一.1.1.2 自动备份
一、 显式自动备份
二、 隐式自动备份
一.1.1.3 手动备份
一、 备份集备份
二、 镜像复制备份
BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/home/oracle/ctl.bak';
三、 重建脚本
一.1.1.4 控制文件快照
或采用rman恢复: restore controlfile from '/$ORACLE_HOME/dbs/snapcf_br.f';
听说过Oracle 控制文件,还有快照控制文件这个说法呢?没错,尽管快照控制文件很少被提及,但确实是存在,只不过在使用RMAN时这个快照控制文件被使用。回顾一下 Oracle 控制文件,我们知道控制文件是Oracle体系结构中的重要组成部分之一,记录了当前数据库的结构信息,同时也包含数据文件及日志文件的信息以及相关的状态,归档信息,也记录了系统当前SCN的值等等。那快照控制文件也就是控制文件的一个副本,本文介绍了什么是快照控制文件以及何时被使用。
1、快照控制文件
快照控制文件是由RMAN恢复管理器在系统指定位置生成的当前控制文件的一个副本
我们知道控制文件在整个数据库生命期中在不断的时时刻刻发生变化,RMAN备份需要依赖于控制文件或恢复目录,也就是说需要知道备份开始时的检查点SCN以及所有文件结构信息并且在整个备份期间这些信息需要保持一致,但又不能锁定控制文件(锁定操作无法执行检查点,切换日志等)。因此既要保持一致性,又不影响数据库的正常操作。快照控制文件就应运而生了。RMAN只在备份或同步操作期间对实际控制文件进行一个短暂的锁定,并根据其内容来生成或刷新快照控制文件。一旦该动作完成之后,RMAN将切换到使用快照控制文件进行备份及同步操作。从而保证备份期间控制文件,数据文件等等的一致性。
综上所述,其主要作用是使用RMAN同步恢复目录或备份时能得到一个一致性的控制文件。
2、配置快照控制文件
a、快照控制文件位置
快照控制文件的位置取决于不同的系统平台,如果启用了快速闪回区,缺省情况下,生成的快照控制文件并不位于闪回区
Linux/Unix平台为: $ORACLE_HOME/dbs/snapcf_@.f
Windows平台为: %ORACLE_HOME%\database\snapcf_@.f
b、查看快照控制文件位置
[oracle@linux1 dbs]$ export ORACLE_SID=usbo
[oracle@linux1 dbs]$ rman target /
--查看快照控制文件的位置
RMAN> show snapshot controlfile name;
RMAN configuration parameters for database with db_unique_name USBO are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/db_1/dbs/snapcf_usbo.f'; # default
c、修改快照空文件位置
sys@USBO> show parameter db_recov
NAME TYPE VALUE
------------------------------------ --------------------------------- ------------------------------
db_recovery_file_dest string /u03/database/usbo/fr_area
db_recovery_file_dest_size big integer 3852M
sys@USBO> ho ls /u03/database/usbo/fr_area/USBO
archivelog
sys@USBO> ho mkdir -p /u03/database/usbo/fr_area/USBO/snap
--使用configure命令来配置快照控制文件的位置,如下,我们修改到使用闪回区来存放
RMAN> configure snapshot controlfile name to '/u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f';
new RMAN configuration parameters:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f';
new RMAN configuration parameters are successfully stored
--查看修改之后快照控制文件的位置
RMAN> show snapshot controlfile name;
RMAN configuration parameters for database with db_unique_name USBO are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f';
3、演示生成快照控制文件
--下面查看新的快照控制文件位置无任何文件
sys@USBO> ho ls -hltr /u03/database/usbo/fr_area/USBO/snap
total 0
--生成控制文件快照
--在备份控制文件时会生成控制文件快照,如下
RMAN> backup current controlfile;
Starting backup at 2013/10/15 13:46:03
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=143 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 2013/10/15 13:46:05
channel ORA_DISK_1: finished piece 1 at 2013/10/15 13:46:07
piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_10_15/o1_mf_ncnnf_TAG20131015T134604_95sonxsx_.bkp
tag=TAG20131015T134604 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2013/10/15 13:46:07
--我们看以看到已经生成了一个控制文件快照时间为13:46
sys@USBO> ho ls -hltr /u03/database/usbo/fr_area/USBO/snap
total 9.4M
-rw-r----- 1 oracle asmadmin 9.4M Oct 15 13:46 snapcf_usbo.f
--下面我们来备份系统表空间,注意,备份系统表空间时,或者数据库发生结构性变化且开启了控制文件自动备份
--则在备份时即使不指定备份控制文件,控制文件仍然会被自动备份,如下
RMAN> backup tablespace system tag=system_tbs_bak;
Starting backup at 2013/10/15 13:51:30
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u03/database/usbo/oradata/system01.dbf
channel ORA_DISK_1: starting piece 1 at 2013/10/15 13:51:30
channel ORA_DISK_1: finished piece 1 at 2013/10/15 13:52:25
piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_10_15/o1_mf_nnndf_SYSTEM_TBS_BAK_95soz2l6_.bkp
tag=SYSTEM_TBS_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2013/10/15 13:52:29
channel ORA_DISK_1: finished piece 1 at 2013/10/15 13:52:30
piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_10_15/o1_mf_ncsnf_SYSTEM_TBS_BAK_95sp0x7s_.bkp
tag=SYSTEM_TBS_BAK comment=NONE --这个备份集就包含了控制文件与spfile文件的自动备份
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2013/10/15 13:52:30
--检查快照控制文件是否被更新,此时文件的时间发生了变化为13:52,如下
sys@USBO> ho ls -hltr /u03/database/usbo/fr_area/USBO/snap
total 9.4M
-rw-r----- 1 oracle asmadmin 9.4M Oct 15 13:52 snapcf_usbo.f
--下面我们来做一个全备,且在全备期间添加一个新的表空间以观察快照控制文件
RMAN> backup database tag=full_bak;
Starting backup at 2013/10/15 14:02:01 --->全备启动时间为14:02:01
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u03/database/usbo/oradata/system01.dbf
input datafile file number=00002 name=/u03/database/usbo/oradata/sysaux01.dbf
input datafile file number=00003 name=/u03/database/usbo/oradata/undotbs01.dbf
input datafile file number=00004 name=/u03/database/usbo/oradata/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2013/10/15 14:02:01
channel ORA_DISK_1: finished piece 1 at 2013/10/15 14:03:56
piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_10_15/o1_mf_nnndf_FULL_BAK_95splt2p_.bkp tag=FULL_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:55
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2013/10/15 14:04:00
channel ORA_DISK_1: finished piece 1 at 2013/10/15 14:04:02
piece handle=/u03/database/usbo/fr_area/USBO/backupset/2013_10_15/o1_mf_ncsnf_FULL_BAK_95sppjj9_.bkp tag=FULL_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2013/10/15 14:04:02
--我们开启另外一个session,此时时间为14:02:08,我们来添加一个表空间
14:02:08 sys@USBO> create tablespace tbs_test datafile '/u03/database/usbo/oradata/tbs_test.dbf' size 5m;
Tablespace created.
14:02:54 sys@USBO>
--Author : Leshami
--Blog : http://blog.csdn.net/leshami
--查看控制文件中,新添加的表空间信息已经被追加到控制文件
14:06:05 sys@USBO> ho strings /u03/database/usbo/oradata/control01.ctl | grep tbs_test
/u03/database/usbo/oradata/tbs_test.dbf
--同时新添加的表空间信息同样被追到了快照控制文件
14:07:19 sys@USBO> ho ls -hltr /u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f
-rw-r----- 1 oracle asmadmin 9.4M Oct 15 14:04 /u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f
14:07:05 sys@USBO> ho strings /u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f | grep tbs_test
/u03/database/usbo/oradata/tbs_test.dbf
--对于备份期间控制文件的自动备份呢?
--下面的检查结果表明,自动备份的控制文件中也存在新表空间的信息
14:10:49 sys@USBO> ho strings /u03/database/usbo/fr_area/USBO/backupset/2013_10_15/o1_mf_ncsnf_FULL_BAK_95sppjj9_.bkp | grep tbs_test
/u03/database/usbo/oradata/tbs_test.dbf
--查看数据字典信息,表空间已经被添加
14:10:52 sys@USBO> select file#,name from v$datafile;
FILE# NAME
---------- ------------------------------------------------------------
1 /u03/database/usbo/oradata/system01.dbf
2 /u03/database/usbo/oradata/sysaux01.dbf
3 /u03/database/usbo/oradata/undotbs01.dbf
4 /u03/database/usbo/oradata/users01.dbf
5 /u03/database/usbo/oradata/tbs_test.dbf
--从上面的测试可知,
--a、RMAN 开始备份,Oracle检查控制文件与快照控制文件是否一致(如果不存在,从控制文件提取信息创建),不一致则刷新快照控制文件。
--b、RMAN从快照控制文件读取信息进行备份,此时快照控制文件并不包含新的表空间,因此备份集中没有tbs_test.dbf
--c、备份完成后进行了控制文件与spfile文件自动备份
--d、刷新了快照控制文件
--e、所以上面的检测中控制文件,快照控制文件,备份的控制文件中都包含新表空间的信息。但却没有备份,因为表空间在备份开始后被添加。
--删除演示的表空间
14:16:07 sys@USBO> drop tablespace tbs_test including contents and datafiles;
Tablespace dropped.
--将快照控制文件位置调整到缺省路径
RMAN> configure snapshot controlfile name clear;
old RMAN configuration parameters:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u03/database/usbo/fr_area/USBO/snap/snapcf_usbo.f';
RMAN configuration parameters are successfully reset to default value
RMAN> show snapshot controlfile name;
RMAN configuration parameters for database with db_unique_name USBO are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/db_1/dbs/snapcf_usbo.f'; # default
The snapshot control file is a temporary snapshot control file that RMAN creates to re-synchronize from a read-consistent version of the control file. RMAN only needs a snapshot control file when re-synchronizing with the recovery catalog or when making a backup of the current control file. In Oracle RAC, the snapshot control file is only needed on the nodes on which RMAN performs backups; the snapshot control file does not need to be globally available to all instances in an Oracle RAC environment.
RMAN仅当以下情况下需要快照控制文件:1.同步恢复目录时2.对当前控制文件进行备份时。在RAC环境下,仅仅在实施RMAN备份的节点上需要快照控制文件;因此快照控制文件是不需要在所有实例上全局可用的。
You can specify a cluster file system file or a raw device destination for the location of your snapshot control file.
你同样可以使用共享文件系统或裸设备指定快照控制文件的位置。
Run the following RMAN command to determine the configured location of the snapshot control file:
SHOW SNAPSHOT CONTROLFILE NAME;
You can change the configured location of the snapshot control file. For example, on UNIX-based systems you can specify the snapshot control file location as $ORACLE_HOME/dbs/scf/snap_prod.cf by entering the following at the RMAN prompt:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '$ORACLE_HOME/dbs/scf/snap_prod.cf';
This command globally sets the configuration for the location of the snapshot control file throughout your cluster database. Therefore, ensure that the directory $ORACLE_HOME/dbs/scf exists on all nodes that perform backups.
如果快照控制文件配置在共享存储上时:
If one RMAN job is already backing up the control file while another needs to create a new snapshot control file, you may see the following message:
waiting for snapshot control file enqueue
Under normal circumstances, a job that must wait for the control file enqueue waits for a brief interval and then successfully retrieves the enqueue. Recovery Manager makes up to five attempts to get the enqueue and then fails the job. The conflict is usually caused when two jobs are both backing up the control file, and the job that first starts backing up the control file waits for service from the media manager.
这样看来,每个实例使用自己的快照控制文件可以避免以上问题。
配置实例:
--显示快照控制文件位置
RMAN> show snapshot controlfile name;
RMAN configuration parameters are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/10.2.0/db_1/dbs/snapcf_RACDB1.f'; # default
--配置快照控制文件位置(使用ASM或共享文件系统或裸设备)
RMAN> configure snapshot controlfile name to
'+FRA/SNAP/snap_prod.cf';
RMAN> configure snapshot controlfile name to
'/ocfs/oradata/dbs/scf/snap_prod.cf';
RMAN> configure snapshot controlfile name to '/dev/sdj2';
--配置快照控制文件为默认默认值
RMAN> configure snapshot controlfile name clear;
RMAN configuration parameters are successfully reset to default value
11G新特性-控制文件延迟自动备份
在10G中,ORACLE引入了控制文件的自动备份,如果数据库的结构发生了变化,那么ORACLE会自动将控制文件备份到指定目录中。
前提是数据库处于归档模式,并且CONTROLFILE AUTOBACKUP设置为ON。
首先看一下10G的情况:
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Linux: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production
SQL> conn / as sysdba
Connected.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 121
Next log sequence to archive 124
Current log sequence 124
[oracle@dbserver ~]$ rman target /
Recovery Manager: Release 10.2.0.5.0 - Production on Fri Sep 14 11:00:13 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
connected to target database: REPORTDB (DBID=3119636991)
RMAN> show controlfile autobackup;
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN>
这是一个10.2.0.5的数据库,数据库处于归档模式,并且controlfile autobackup设置为ON。
SQL> create tablespace test datafile '/u01/app/oracle/oradata/reportdb/test01.dbf' size 2m;
Tablespace created.
SQL> alter database drop logfile group 5;
Database altered.
日志文件中将会看到控制文件的自动备份情况。
Fri Sep 14 10:32:12 CST 2012
create tablespace test datafile '/u01/app/oracle/oradata/reportdb/test01.dbf' size 2m
Fri Sep 14 10:32:13 CST 2012
Starting control autobackup
Control autobackup written to DISK device
handle '/u01/app/oracle/flash_recovery_area/REPORTDB/autobackup/2012_09_14/o1_mf_s_793967533_8555sgkh_.bkp'
Completed: create tablespace test datafile '/u01/app/oracle/oradata/reportdb/test01.dbf' size 2m
Fri Sep 14 10:32:33 CST 2012
alter database drop logfile group 5
Fri Sep 14 10:32:33 CST 2012
Starting control autobackup
Control autobackup written to DISK device
handle '/u01/app/oracle/flash_recovery_area/REPORTDB/autobackup/2012_09_14/o1_mf_s_793967553_8555t1q6_.bkp'
Completed: alter database drop logfile group 5
ls -ltr 也可以看出文件的创建时间可以看出备份文件被立马创建。
[oracle@dbserver REPORTDB]$ ls -ltr /u01/app/oracle/flash_recovery_area/REPORTDB/autobackup/2012_09_14/
total 36380
-rw-r----- 1 oracle oinstall 7438336 Sep 14 10:32 o1_mf_s_793967533_8555sgkh_.bkp
-rw-r----- 1 oracle oinstall 7438336 Sep 14 10:32 o1_mf_s_793967553_8555t1q6_.bkp
从ORACLE DATABASE 11GR2开始,引入了控制文件自动备份延迟创建的特性。
即使你设置了控制文件的自动备份,在数据库结构发现变化的时候不会立即看到控制文件的备份,而是过一段时间才会看到。这是ORACLE为了改变性能而引入的,防止你在一个脚本中多次对数据库结构的变化而创建多个控制文件备份。譬如CREATE TABLEPACE,DROP LOGFILE,ADD LOGEILE等,11G只会备份一个控制文件,而不是多个。
对于10G只要对数据库结构改变,就会自动备份一个。
上面的例子我创建了一个表空间,删除了一个日志文件组,后台自动生成了2个控制文件备份。
下面看一下11G的情况:
[oracle@db2server ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Sep 11 22:35:09 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: HUATENG (DBID=2134565240)
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/archivelog/autobackup/%F';
new RMAN configuration parameters:
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/archivelog/autobackup/%F';
new RMAN configuration parameters are successfully stored
RMAN> SHOW CONTROLFILE AUTOBACKUP ;
RMAN configuration parameters for database with db_unique_name HUATENG are:
CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN>
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /archivelog
Oldest online log sequence 7
Next log sequence to archive 9
Current log sequence 9
SQL> create tablespace test datafile '/u01/app/oracle/oradata/huateng/test01.dbf' size 2m;
Tablespace created.
Incremental checkpoint up to RBA [0x9.346f.0], current log tail at RBA [0x9.346f.0]
Tue Sep 11 22:38:02 2012
create tablespace test datafile '/u01/app/oracle/oradata/huateng/test01.dbf' size 2m
Completed: create tablespace test datafile '/u01/app/oracle/oradata/huateng/test01.dbf' size 2m
Tue Sep 11 22:38:20 2012
Incremental checkpoint up to RBA [0x9.346f.0], current log tail at RBA [0x9.3501.0]
日志文件中仅仅显示了表空间创建成功的信息,并没有控制文件的自动备份信息。
而且备份目录下也没有发现任何的控制文件备份文件。
[oracle@db2server autobackup]$ pwd
/archivelog/autobackup
[oracle@db2server autobackup]$ ls -ltr
total 0
[oracle@db2server autobackup]$
MOS [ID 1068182.1]对这个问题进行了如下阐述:
In this release, the controlfile autobackups are created by MMON slaves after few minutes of the structural changes, which increases performance.So, It's the expected behaviour to get the controlfile autobackup several minutes after the structural change on the database and it's also expected that no message about controlfile autobackup creation will appear in the alert.log.
There will be generated one MMON slave trace file with the controlfile creation information, that will be a file named: SID__m000_<os_pid>.trc
在经过6分钟后,终于看到备份文件了:
[oracle@db2server autobackup]$ ls -ltr
total 9616
-rw-r----- 1 oracle oinstall 9830400 Sep 11 22:44 c-2134565240-20120911-00
oracle后台进程m000的TRACE文件中记录此次备份信息,ALERT文件中不再记录了。
[oracle@db2server trace]$ more huateng_m000_8971.trc
Trace file /u01/app/oracle/diag/rdbms/huateng/huateng/trace/huateng_m000_8971.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/db11gr2
System name: Linux
Node name: db2server
Release: 2.6.18-92.el5
Version: #1 SMP Tue Jun 10 18:49:47 EDT 2008
Machine: i686
Instance name: huateng
Redo thread mounted by this instance: 1
Oracle process number: 30
Unix process pid: 8971, image: oracle@db2server (M000)
*** 2012-09-11 22:44:03.648
*** SESSION ID:(50.5) 2012-09-11 22:44:03.648
*** CLIENT ID:() 2012-09-11 22:44:03.648
*** SERVICE NAME:(SYS$BACKGROUND) 2012-09-11 22:44:03.648
*** MODULE NAME:(MMON_SLAVE) 2012-09-11 22:44:03.648
*** ACTION NAME:(Autobackup Control File) 2012-09-11 22:44:03.648
Starting control autobackup
*** 2012-09-11 22:44:06.515
Control autobackup written to DISK device
handle '/archivelog/autobackup/c-2134565240-20120911-00'
ORACLE通过隐含参数 _controlfile_autobackup_delay来控制这种行为,默认是300秒。
set line 9999
col NAME format a30
col KSPPDESC format a50
col KSPPSTVL format a20
SELECT a.INDX,
a.KSPPINM NAME,
a.KSPPDESC,
b.KSPPSTVL
FROM x$ksppi a,
x$ksppcv b
WHERE a.INDX = b.INDX
8 and lower(a.KSPPINM) like lower('%?meter%');
Enter value for parameter: controlfile_autobackup
old 8: and lower(a.KSPPINM) like lower('%?meter%')
new 8: and lower(a.KSPPINM) like lower('%controlfile_autobackup%')
INDX NAME KSPPDESC KSPPSTVL
---------- ------------------------------ -------------------------------------------------- --------------------
1226 _controlfile_autobackup_delay time delay (in seconds) for performing controlfile 300
autobackups