[20150308]熱備份和資料庫檢查點.txt

lfree發表於2015-03-09

[20150308]熱備份和資料庫檢查點.txt

--今天看書,提到在熱備份前,會做了一個資料檔案檢查點操作.
--實際上這個很好理解:

開始熱備份時候,做了一個資料檔案檢查點操作,因為熱備份時備份要產生的日誌很大,資料庫必須要知道那個時候開始,做這項工作。
保證了在熱備份期間,只有在發出熱備份命令之後的時間裡修改的塊可能會被寫到資料檔案上。

--自己做一個簡單檢查:

SCOTT@test> @ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.3.0     Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

RMAN> report schema ;
Report of database schema for database with db_unique_name TEST
List of Permanent Datafiles
===========================
File Size(MB) Tablespace           RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1    780      SYSTEM               ***     /u01/app/oracle11g/oradata/test/system01.dbf
2    1000     SYSAUX               ***     /u01/app/oracle11g/oradata/test/sysaux01.dbf
3    848      UNDOTBS1             ***     /u01/app/oracle11g/oradata/test/undotbs01.dbf
4    864      USERS                ***     /u01/app/oracle11g/oradata/test/users01.dbf
5    100      EXAMPLE              ***     /u01/app/oracle11g/oradata/test/example01.dbf
6    64       RMAN                 ***     /u01/app/oracle11g/oradata/test/rman01.dbf
7    64       TOOLS                ***     /u01/app/oracle11g/oradata/test/tools01.dbf
8    64       TEST                 ***     /u01/app/oracle11g/oradata/test/test01.dbf
9    64       TESTMSSM             ***     /u01/app/oracle11g/oradata/test/testmssm01.dbf
10   4        UNDOTBS2             ***     /u01/app/oracle11g/oradata/test/undotbs02.dbf
11   102      TEST16K              ***     /u01/app/oracle11g/oradata/test/test16k01.dbf
12   1        TOOLSX               ***     /u01/app/oracle11g/oradata/test/tools01x.dbf
13   50       TBS_TS1              ***     /u01/app/oracle11g/oradata/test/tbs_ts1_01.dbf
14   127      TBS_TS2              ***     /u01/app/oracle11g/oradata/test/tbs_ts2_01.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace           Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1    339      TEMP                 32767       /u01/app/oracle11g/oradata/test/temp01.dbf

SCOTT@test> SELECT file#, CHECKPOINT_CHANGE#, CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT  FROM v$datafile_header;
       FILE# CHECKPOINT_CHANGE# CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT
------------ ------------------ ---------------- ----------------- ------- ----------------
           1        12005514399                7        3011113647 ONLINE         856622640
           2        12005514399             2140        3011113647 ONLINE         856622634
           3        12005514399       3241444492        3011113647 ONLINE         856622635
           4        12005514399            17993        3011113647 ONLINE         856622644
           5        12005514399           973735        3011113647 ONLINE         856622637
           6        12005514399          1412559        3011113647 ONLINE         856622603
           7        12005514399          4383251        3011113647 ONLINE         856622632
           8        12005514399         13169364        3011113647 ONLINE         856622634
           9        12005514399       3223747107        3011113647 ONLINE         856622632
          10        12005514399      12002485849        3011113647 ONLINE               151
          11        12005514399      11673111577        3011113647 ONLINE              1117
          12        12005514399      11994962958        3011113647 ONLINE               475
          13        12005514399      11992635787        3011113647 ONLINE               588
          14        12005514399      11992670578        3011113647 ONLINE               586
14 rows selected.

--對file#=4 表空間users做熱備份。當前CHECKPOINT_CHANGE#=12005514399,CHECKPOINT_COUNT=856622644.

2.開始測試:
SCOTT@test> select rowid,dept.* from dept;
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AABBrlAAEAAAAWDAAB           10 ACCOUNTING     new york
AABBrlAAEAAAAWDAAC           20 RESEARCH       dallas1
AABBrlAAEAAAAWDAAD           30 SALES          chicago
AABBrlAAEAAAAWDAAE           40 OPERATIONS     boston

SCOTT@test> @lookup_rowid AABBrlAAEAAAAWDAAB
      OBJECT         FILE        BLOCK          ROW DBA                  TEXT
------------ ------------ ------------ ------------ -------------------- ----------------------------------------
      269029            4         1411            1 4,1411               alter system dump datafile 4 block 1411
                                                                        
SCOTT@test> update dept set loc=upper(loc) ;
4 rows updated.
--不提交。切換另外的會話,注意執行如下命令alter tablespace users begin backup ;會隱含發commit命令。

SCOTT@test> alter tablespace users begin backup ;
Tablespace altered.

SCOTT@test> SELECT file#, CHECKPOINT_CHANGE#, CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT  FROM v$datafile_header;
       FILE# CHECKPOINT_CHANGE# CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT
------------ ------------------ ---------------- ----------------- ------- ----------------
           1        12005514399                7        3011113647 ONLINE         856622640
           2        12005514399             2140        3011113647 ONLINE         856622634
           3        12005514399       3241444492        3011113647 ONLINE         856622635
           4        12005514724            17993        3011113647 ONLINE         856622645
           5        12005514399           973735        3011113647 ONLINE         856622637
           6        12005514399          1412559        3011113647 ONLINE         856622603
           7        12005514399          4383251        3011113647 ONLINE         856622632
           8        12005514399         13169364        3011113647 ONLINE         856622634
           9        12005514399       3223747107        3011113647 ONLINE         856622632
          10        12005514399      12002485849        3011113647 ONLINE               151
          11        12005514399      11673111577        3011113647 ONLINE              1117
          12        12005514399      11994962958        3011113647 ONLINE               475
          13        12005514399      11992635787        3011113647 ONLINE               588
          14        12005514399      11992670578        3011113647 ONLINE               586

14 rows selected.

--注意看file#=4,CHECKPOINT_CHANGE#現在是12005514724,CHECKPOINT_COUNT=856622645,CHECKPOINT_COUNT也增加1次。

--透過bbed 觀察,我並沒有執行alter systenm checkpoint,可以發現bbed觀察對應資料塊,可以發現修改資訊已經寫磁碟。
BBED> set dba  4,1411
        DBA             0x01000583 (16778627 4,1411)

BBED> p *kdbr[1]
rowdata[151]
------------
ub1 rowdata[151]                            @8146     0x2c

BBED> x /rncc
rowdata[151]                                @8146
------------
flag@8146: 0x2c (KDRHFL, KDRHFF, KDRHFH)
lock@8147: 0x03
cols@8148:    3

col    0[2] @8149: 10
col   1[10] @8152: ACCOUNTING
col    2[8] @8163: NEW YORK

SCOTT@test> set numw 12
SCOTT@test> select * from v$backup ;
       FILE# STATUS                  CHANGE# TIME
------------ ------------------ ------------ -------------------
           1 NOT ACTIVE                    0
           2 NOT ACTIVE                    0
           3 NOT ACTIVE                    0
           4 ACTIVE              12005514724 2015-03-09 08:43:00
           5 NOT ACTIVE                    0
           6 NOT ACTIVE           3011239824 2012-11-08 15:43:19
           7 NOT ACTIVE                    0
           8 NOT ACTIVE           3268230043 2014-03-20 10:13:21
           9 NOT ACTIVE                    0
          10 NOT ACTIVE                    0
          11 NOT ACTIVE                    0
          12 NOT ACTIVE                    0
          13 NOT ACTIVE                    0
          14 NOT ACTIVE                    0

14 rows selected.

--結束熱備份:
SCOTT@test> alter tablespace users end backup ;
Tablespace altered.

SCOTT@test> SELECT file#, CHECKPOINT_CHANGE#, CREATION_CHANGE#  , RESETLOGS_CHANGE#,status, CHECKPOINT_COUNT  FROM v$datafile_header;
       FILE# CHECKPOINT_CHANGE# CREATION_CHANGE# RESETLOGS_CHANGE# STATUS  CHECKPOINT_COUNT
------------ ------------------ ---------------- ----------------- ------- ----------------
           1        12005514399                7        3011113647 ONLINE         856622640
           2        12005514399             2140        3011113647 ONLINE         856622634
           3        12005514399       3241444492        3011113647 ONLINE         856622635
           4        12005514724            17993        3011113647 ONLINE         856622646
           5        12005514399           973735        3011113647 ONLINE         856622637
           6        12005514399          1412559        3011113647 ONLINE         856622603
           7        12005514399          4383251        3011113647 ONLINE         856622632
           8        12005514399         13169364        3011113647 ONLINE         856622634
           9        12005514399       3223747107        3011113647 ONLINE         856622632
          10        12005514399      12002485849        3011113647 ONLINE               151
          11        12005514399      11673111577        3011113647 ONLINE              1117
          12        12005514399      11994962958        3011113647 ONLINE               475
          13        12005514399      11992635787        3011113647 ONLINE               588
          14        12005514399      11992670578        3011113647 ONLINE               586
14 rows selected.

--注意看file#=4,CHECKPOINT_CHANGE#現在是12005514724(沒變),CHECKPOINT_COUNT=856622646,CHECKPOINT_COUNT又增加1次。

SCOTT@test> rollback ;
Rollback complete.

SCOTT@test> select rowid,dept.* from dept;
ROWID                    DEPTNO DNAME          LOC
------------------ ------------ -------------- -------------
AABBrlAAEAAAAWDAAB           10 ACCOUNTING     new york
AABBrlAAEAAAAWDAAC           20 RESEARCH       dallas1
AABBrlAAEAAAAWDAAD           30 SALES          chicago
AABBrlAAEAAAAWDAAE           40 OPERATIONS     boston

--可以發現在做熱備份前,資料庫會對涉及到的做了一個資料檔案檢查點操作.

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

相關文章