[20190515]热备份模式与rman冲突.txt

时间:2022-12-08 10:12:43

[20190515]热备份模式与rman冲突.txt

--//别人的系统做dg时打开热备份模式,忘记关闭,做rman备份时报错。做一个记录。
--//实际上也怪自己,实施时没有讲清楚。通过例子说明:

1.环境:
SCOTT@book> @ ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

SYS@book> alter database begin backup;
Database altered.

--//实际上这样做dg,如果数据库不大,对于文件系统的数据库还是很快的,特别目录结构一样的情况。
--//为了避免输入口令,最好先做ssh相互认证。
--//cd /mnt/ramdisk/book
--//ls -1 *.dbf| xargs -I{} -P 4 scp {} oracle@192.168.100.40:/mnt/ramdisk/book
--//或者
--//scp -r /mnt/ramdisk/book/*.dbf oracle@192.168.100.40:/mnt/ramdisk/book/

2.主库做rman备份:
SYS@book> select * from v$backup;
FILE# STATUS     CHANGE# TIME
----- ------ ----------- -------------------
    1 ACTIVE 15677701496 2019-05-21 08:40:13
    2 ACTIVE 15677701496 2019-05-21 08:40:13
    3 ACTIVE 15677701496 2019-05-21 08:40:13
    4 ACTIVE 15677701496 2019-05-21 08:40:13
    5 ACTIVE 15677701496 2019-05-21 08:40:13
    6 ACTIVE 15677701496 2019-05-21 08:40:13
    7 ACTIVE 15677701496 2019-05-21 08:40:13
    8 ACTIVE 15677701496 2019-05-21 08:40:13
    9 ACTIVE 15677701496 2019-05-21 08:40:13
   10 ACTIVE 15677701496 2019-05-21 08:40:13
   11 ACTIVE 15677701496 2019-05-21 08:40:13
   12 ACTIVE 15677701496 2019-05-21 08:40:13
   13 ACTIVE 15677701496 2019-05-21 08:40:13
13 rows selected.

RMAN> backup database format '/home/oracle/backup/book_%U';

Starting backup at 2019-05-21 08:42:53
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=17 device type=DISK
RMAN-06554: WARNING: file 1 is in backup mode
RMAN-06554: WARNING: file 2 is in backup mode
RMAN-06554: WARNING: file 3 is in backup mode
RMAN-06554: WARNING: file 4 is in backup mode
RMAN-06554: WARNING: file 5 is in backup mode
RMAN-06554: WARNING: file 6 is in backup mode
RMAN-06554: WARNING: file 7 is in backup mode
RMAN-06554: WARNING: file 8 is in backup mode
RMAN-06554: WARNING: file 9 is in backup mode
RMAN-06554: WARNING: file 10 is in backup mode
RMAN-06554: WARNING: file 11 is in backup mode
RMAN-06554: WARNING: file 12 is in backup mode
RMAN-06554: WARNING: file 13 is in backup mode
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00002 name=/mnt/ramdisk/book/sysaux01.dbf
input datafile file number=00003 name=/mnt/ramdisk/book/undotbs01.dbf
input datafile file number=00001 name=/mnt/ramdisk/book/system01.dbf
input datafile file number=00005 name=/mnt/ramdisk/book/example01.dbf
input datafile file number=00004 name=/mnt/ramdisk/book/users01.dbf
input datafile file number=00007 name=/mnt/ramdisk/book/undotbs02.dbf
input datafile file number=00008 name=/mnt/ramdisk/book/undotbs03.dbf
input datafile file number=00006 name=/mnt/ramdisk/book/tea01.dbf
input datafile file number=00009 name=/mnt/ramdisk/book/T01.dbf
input datafile file number=00010 name=/mnt/ramdisk/book/T02.dbf
input datafile file number=00011 name=/mnt/ramdisk/book/T03.dbf
input datafile file number=00012 name=/mnt/ramdisk/book/T04.dbf
input datafile file number=00013 name=/mnt/ramdisk/book/T05.dbf
channel ORA_DISK_1: starting piece 1 at 2019-05-21 08:42:53
channel ORA_DISK_1: finished piece 1 at 2019-05-21 08:43:08
piece handle=/home/oracle/backup/book_2pu2394d_1_1 tag=TAG20190521T084253 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 2019-05-21 08:43:09
channel ORA_DISK_1: finished piece 1 at 2019-05-21 08:43:11
piece handle=/home/oracle/backup/book_2qu2394s_1_1 tag=TAG20190521T084253 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2019-05-21 08:43:11
--//注:实际上也备份成功了,不过最好不要这样.

$ ls -l /home/oracle/backup/book_2pu2394d_1_1
-rw-r----- 1 oracle oinstall 2380603392 2019-05-21 08:42:59 /home/oracle/backup/book_2pu2394d_1_1

3.解决很简单,关闭热备份模式就ok了:
SYS@book> alter database end backup;
Database altered.

SYS@book> select * from v$backup;
       FILE# STATUS                  CHANGE# TIME
------------ ------------------ ------------ -------------------
           1 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           2 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           3 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           4 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           5 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           6 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           7 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           8 NOT ACTIVE          15677701496 2019-05-21 08:40:13
           9 NOT ACTIVE          15677701496 2019-05-21 08:40:13
          10 NOT ACTIVE          15677701496 2019-05-21 08:40:13
          11 NOT ACTIVE          15677701496 2019-05-21 08:40:13
          12 NOT ACTIVE          15677701496 2019-05-21 08:40:13
          13 NOT ACTIVE          15677701496 2019-05-21 08:40:13

4.另外的问题:
--//实际上打开热备份并不是"冻结"文件头,仅仅冻结scn.实际上你如果发alter system checkpoint;还是会更新文件头的.
--//并且oracle实际上恢复从这个scn(alter system checkpoint命令的)开始恢复:
--//可以参考链接:http://blog.itpub.net/267265/viewspace-2152909/=>[20180413]热备模式相关问题2.txt

SYS@book> alter tablespace users begin backup ;
Tablespace altered.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header where file# in (1,4);
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                           TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------ ---------------
    1        15677702312 2019-05-21 08:47:46                7            925702 ONLINE             13491 YES /mnt/ramdisk/book/system01.dbf SYSTEM
    4        15677702482 2019-05-21 08:50:00            16143            925702 ONLINE             13491 YES /mnt/ramdisk/book/users01.dbf  USERS

--//CHECKPOINT_CHANGE#发生变化.
SYS@book> alter system checkpoint ;
System altered.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header where file# in (1,4);
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                           TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------ ---------------
    1        15677702587 2019-05-21 08:51:37                7            925702 ONLINE             13492 YES /mnt/ramdisk/book/system01.dbf SYSTEM
    4        15677702482 2019-05-21 08:50:00            16143            925702 ONLINE             13492 YES /mnt/ramdisk/book/users01.dbf  USERS
--//file#=1的 CHECKPOINT_CHANGE#发生变化,但是file#=4的CHECKPOINT_CHANGE#没有变化.CHECKPOINT_COUNT也是增加的.

select 15677702587,trunc(15677702587/power(2,32)) scn_wrap,mod(15677702587,power(2,32))  scn_base from dual
 15677702587     SCN_WRAP     SCN_BASE SCN_WRAP16 SCN_BASE16
------------ ------------ ------------ ---------- ----------
 15677702587            3   2792800699          3   a676c1bb

select 15677702482,trunc(15677702482/power(2,32)) scn_wrap,mod(15677702482,power(2,32))  scn_base from dual
 15677702482     SCN_WRAP     SCN_BASE SCN_WRAP16 SCN_BASE16
------------ ------------ ------------ ---------- ----------
 15677702482            3   2792800594          3   a676c152

BBED> p /d dba 4,1 kcvfh.kcvfhbcp.kcvcpscn
struct kcvcpscn, 8 bytes                    @152
   ub4 kscnbas                              @152      2792800699
   ub2 kscnwrp                              @156      3
--//发出alter system checkpoint时在热备分模式要更新这里的信息.

BBED> p /d dba 4,1 kcvfh.kcvfhckp.kcvcpscn
struct kcvcpscn, 8 bytes                    @484
   ub4 kscnbas                              @484      2792800594
   ub2 kscnwrp                              @488      3
--//文件头scn

SYS@book> alter system checkpoint ;
System altered.

SYS@book> SELECT file#, CHECKPOINT_CHANGE#, CHECKPOINT_TIME,CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT,fuzzy,name,tablespace_name  FROM v$datafile_header where file# in (1,4);
FILE# CHECKPOINT_CHANGE# CHECKPOINT_TIME     CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT FUZ NAME                           TABLESPACE_NAME
----- ------------------ ------------------- ---------------- ----------------- ------- ---------------- --- ------------------------------ ---------------
    1        15677703057 2019-05-21 08:58:26                7            925702 ONLINE             13493 YES /mnt/ramdisk/book/system01.dbf SYSTEM
    4        15677702482 2019-05-21 08:50:00            16143            925702 ONLINE             13493 YES /mnt/ramdisk/book/users01.dbf  USERS

BBED> p /d dba 4,1 kcvfh.kcvfhbcp.kcvcpscn
struct kcvcpscn, 8 bytes                    @152
   ub4 kscnbas                              @152      2792801169
   ub2 kscnwrp                              @156      3

BBED> p /d dba 4,1 kcvfh.kcvfhckp.kcvcpscn
struct kcvcpscn, 8 bytes                    @484
   ub4 kscnbas                              @484      2792800594
   ub2 kscnwrp                              @488      3

select 15677703057,trunc(15677703057/power(2,32)) scn_wrap,mod(15677703057,power(2,32))  scn_base from dual
 15677703057     SCN_WRAP     SCN_BASE SCN_WRAP16 SCN_BASE16
------------ ------------ ------------ ---------- ----------
 15677703057            3   2792801169          3   a676c391

--//kcvfh.kcvfhbcp.kcvcpscn的信息发生了变化.这样恢复实际上从2792801169开始恢复需要读取的归档大大减少.