[20190515]熱備份模式與rman衝突.txt

lfree發表於2019-05-22

[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開始恢復需要讀取的歸檔大大減少.


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/267265/viewspace-2645133/,如需轉載,請註明出處,否則將追究法律責任。

相關文章