欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-05-29 12:41:34
[20190515]热备份模式与rman冲突.txt--//别人的系统做dg时打开热备份模式,忘记关闭,做rman备份时报错。做一个记录。--//实际上也怪自己,实施时没有讲清楚。通过例子说明:1.环境:SCOTT@book> @ ver1PORT_STRING VERSION BANNER x86 ......

[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开始恢复需要读取的归档大大减少.