## Oracle快照控制文件
??快照控制文件(snapshot control file),顾名思义就是Oracle控制文件的一个副本或者备份。快照控制文件并不多见,在使用RMAN的时候这个快照控制文件才会被使用。
控制文件简单介绍
控制文件是Oracle的重要组成部分,记录了当前数据库的结构信息,同时也包含数据文件,日志文件,归档的信息。记录数据库当前的SCN。
1.什么是快照控制文件
1)为什么要有快照控制文件?
??控制文件在数据库的运行过程中时刻都在发生变化,rman备份需要依赖于控制文件和恢复目录。也就是说在整个rman备份的过程中,控制文件中的检查点信息,SCN信息和记录的文件结构信息这些不能改变,一旦改变那么数据的一致性就无法被保证,那么这个备份也就失去了意义。如果将控制文件锁定确实保证了数据库从备份开始到结束数据的一致性但是在锁定期间数据库便无法正常进行操作,这样的代价一样很大。所以为了解决这个问题快照控制文件应运而生,给备份开始时的控制文件做一个快照,整个备份过程都使用快照控制文件进行备份和同步操作。
2)快照控制文件
??快照控制文件是RMAN在系统指定位置生成的当前控制文件的一个副本。RMAN在备份或同步操作期间对实际的控制文件进行一个短暂的锁定,并根据控制文件内容生成或这刷新快照控制文件,当这个动作完成后rman就切换到使用快照控制文件进行备份和同步。保证了rman备份和同步的过程中使用的控制文件是不变的。
2.快照控制文件的位置
- linux/unix平台: $ORACLE_HOME/dbs/snapcf_sid.f
[oracle@orcldb dbs]$ pwd
/u01/app/oracle/product/11.2.0/db_home1/dbs
[oracle@orcldb dbs]$ ls snapcf_orcl.f
snapcf_orcl.f
- Windows平台:%ORACLE_HOME%\database\snapcf_@.f
1)通过RMAN查询快照控制文件的位置
RMAN> show snapshot controlfile name;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/product/11.2.0/db_home1/dbs/snapcf_orcl.f‘; # default
2) 修改快照控制文件的位置
RMAN> configure snapshot controlfile name to ‘/u01/app/oracle/snapcf_path.f‘;
new RMAN configuration parameters:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/snapcf_path.f‘;
new RMAN configuration parameters are successfully stored
RMAN> show snapshot controlfile name;
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/snapcf_path.f‘;
3.快照控制文件生成过程
1)首先修改一下快照控制文件的存放路径
RMAN> configure snapshot controlfile name to ‘/u01/app/oracle/snapcf_path.f‘;
old RMAN configuration parameters:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/product/11.2.0/db_home1/dbs/snapcf_orcl.f‘;
new RMAN configuration parameters:
CONFIGURE SNAPSHOT CONTROLFILE NAME TO ‘/u01/app/oracle/snapcf_path.f‘;
new RMAN configuration parameters are successfully stored
2)生成快照控制文件
#查看当前目录下并没有快照控制文件
[oracle@orcldb oracle]$ pwd
/u01/app/oracle
[oracle@orcldb oracle]$ ls snapcf_path.f
ls: cannot access snapcf_path.f: No such file or directory
#备份控制文件时会生成快照控制文件
RMAN> backup current controlfile;
Starting backup at 2020-08-12 11:57:38
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=70 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 2020-08-12 11:57:39
channel ORA_DISK_1: finished piece 1 at 2020-08-12 11:57:40
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_08_12/o1_mf_ncnnf_TAG20200812T115738_hm6t5mgw_.bkp tag=TAG20200812T115738 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020-08-12 11:57:40
#再次查看快照控制文件存放路径
[oracle@orcldb oracle]$ ll snapcf_path.f
-rw-r----- 1 oracle oinstall 9748480 Aug 12 11:57 snapcf_path.f
3.1)测试快照控制文件是否会被自动更新
#为系统表空间进行备份
RMAN> backup tablespace system tag=system_tbs_bak;
Starting backup at 2020-08-12 12:06: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=/u01/app/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: starting piece 1 at 2020-08-12 12:06:30
channel ORA_DISK_1: finished piece 1 at 2020-08-12 12:06:45
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_08_12/o1_mf_nnndf_SYSTEM_TBS_BAK_hm6tp69d_.bkp tag=SYSTEM_TBS_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
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 2020-08-12 12:06:46
channel ORA_DISK_1: finished piece 1 at 2020-08-12 12:06:47
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_08_12/o1_mf_ncsnf_SYSTEM_TBS_BAK_hm6tppc8_.bkp tag=SYSTEM_TBS_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020-08-12 12:06:47
#检查快照控制文件是否被更新
[oracle@orcldb oracle]$ ll snapcf_path.f
-rw-r----- 1 oracle oinstall 9748480 Aug 12 12:06 snapcf_path.f
#时间从开始的11:57更新为12:06
3.2)全备方式测试快照控制文件是否会被更新
使用RMAN进行数据库全备期间新增一个表空间观察快照控制文件的变化
#数据库全备
RMAN> backup database tag=full_bak;
Starting backup at 2020-08-12 12:32:45
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=00007 name=/u01/app/oracle/oradata/orcl/datafile/example.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/datafile/rmantest.dbf
input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/datafile/ogg01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2020-08-12 12:32:46
channel ORA_DISK_1: finished piece 1 at 2020-08-12 12:33:01
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_08_12/o1_mf_nnndf_FULL_BAK_hm6w7g0x_.bkp tag=FULL_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
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 2020-08-12 12:33:02
channel ORA_DISK_1: finished piece 1 at 2020-08-12 12:33:03
piece handle=/u01/app/oracle/fast_recovery_area/ORCL/backupset/2020_08_12/o1_mf_ncsnf_FULL_BAK_hm6w7y4f_.bkp tag=FULL_BAK comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020-08-12 12:33:03
#增加表空间
SYS@orcl>create tablespace tbs_test datafile ‘/u01/app/oracle/oradata/orcl/datafile/tbs.dbf‘ size 20M;
Tablespace created.
#查看新增的表空间文件
[oracle@orcldb datafile]$ pwd
/u01/app/oracle/oradata/orcl/datafile
[oracle@orcldb datafile]$ ls tbs.dbf
tbs.dbf
#查看此时快照控制文件,可以看到此时快照表空间中存在新增表空间的信息
[oracle@orcldb oracle]$ ll snapcf_path.f
-rw-r----- 1 oracle oinstall 9748480 Aug 12 12:33 snapcf_path.f
[oracle@orcldb oracle]$ strings ./snapcf_path.f | grep tbs.dbf
/u01/app/oracle/oradata/orcl/datafile/tbs.dbf
分析:
快照控制文件中存在新增的表空间但是在备份过程中这个文件并没有备份,说明新的表空间信息是在最后被刷新到快照控制文件中的。
从上面的测试可知,
- RMAN 开始备份,Oracle检查控制文件与快照控制文件是否一致(如果不存在,从控制文件提取信息创建),不一致则刷新快照控制文件。
- RMAN从快照控制文件读取信息进行备份,此时快照控制文件并不包含新的表空间,因此备份集中没有tbs.dbf
- 备份完成后进行了控制文件与spfile文件自动备份刷新了快照控制文件
- 所以上面的检测中控制文件,快照控制文件,备份的控制文件中都包含新表空间的信息。但却没有备份,因为表空间在备份开始后被添加。
参考:https://blog.csdn.net/leshami/article/details/12754339