ORACLE begin backup and tablespace full checkpoint

alter tablespace &name begin backup;其作用无非就是2点:
1、冻结住数据文件文件头scn,日志应用从冻结scn开始恢复
2、处于归档模式的数据库,可以在线拷贝数据文件,并在防止在数据文件拷贝过程中,出现分裂块。
下面研究一下begin backup和checkpoint的关系
版本为
[quote]SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
PL/SQL Release 9.2.0.4.0 - Production
CORE 9.2.0.3.0 Production
TNS for Linux: Version 9.2.0.4.0 - Production
NLSRTL Version 9.2.0.4.0 - Production[/quote]
创建一张测试表格
[quote]SQL> alter system checkpoint;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> create table test.t as select * from sys.obj$;

Table created.

SQL> alter tablespace test begin backup;

Tablespace altered.

SQL> alter system switch logfile;

System altered.

SQL> select FILE_ID,BLOCK_ID,BLOCKS from dba_extents where SEGMENT_NAME='T' and OWNER='TEST' order by 1,2;

FILE_ID BLOCK_ID BLOCKS
---------- ---------- ----------
10 9 8
10 17 8
10 25 8
10 33 8
10 41 8
10 49 8
10 57 8
10 65 8
10 73 8
10 81 8
10 89 8

FILE_ID BLOCK_ID BLOCKS
---------- ---------- ----------
10 97 8
10 105 8
10 113 8
10 121 8
10 129 8
11 9 128
12 9 128

18 rows selected.
[/quote]

将begin backup命令发起时对应的scn dump 出来
[quote]SQL> alter system dump logfile '/archlog/dbtest/arc_1_8004.dbf' layer 23 opcode 1;

System altered.[/quote]
在跟踪文件可以看到
[quote]REDO RECORD - Thread:1 RBA: 0x001f44.0000185b.0010 LEN: 0x0168 VLD: 0x02
SCN: 0x08dc.db658f3b SUBSCN: 1 07/10/2009 09:07:41
CHANGE #1 MEDIA RECOVERY MARKER SCN:0x0000.00000000 SEQ: 0 OP:23.1
Block Written - afn: 12 rdba: 0x03000002(12,2)
scn: 0x08dc.db658f2c seq: 0x02 flg:0x04
Block Written - afn: 12 rdba: 0x03000009(12,9)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 12 rdba: 0x03000003(12,3)
scn: 0x08dc.db658f2c seq: 0x01 flg:0x04
Block Written - afn: 12 rdba: 0x0300000a(12,10)
scn: 0x08dc.db658f31 seq: 0x02 flg:0x04
Block Written - afn: 11 rdba: 0x02c00002(11,2)
scn: 0x08dc.db658f28 seq: 0x02 flg:0x04
Block Written - afn: 11 rdba: 0x02c00009(11,9)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 11 rdba: 0x02c00003(11,3)
scn: 0x08dc.db658f28 seq: 0x01 flg:0x04
Block Written - afn: 11 rdba: 0x02c0000a(11,10)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800002(10,2)
scn: 0x08dc.db658f27 seq: 0x02 flg:0x04
Block Written - afn: 10 rdba: 0x0280000b(10,11)
scn: 0x08dc.db658f33 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800009(10,9)
scn: 0x08dc.db658f31 seq: 0x03 flg:0x04
Block Written - afn: 10 rdba: 0x02800029(10,41)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800049(10,73)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800069(10,105)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800003(10,3)
scn: 0x08dc.db658f27 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x0280000a(10,10)
scn: 0x08dc.db658f31 seq: 0x0c flg:0x04
Block Written - afn: 10 rdba: 0x02800019(10,25)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800039(10,57)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800059(10,89)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04
Block Written - afn: 10 rdba: 0x02800079(10,121)
scn: 0x08dc.db658f31 seq: 0x01 flg:0x04[/quote]
[b]可以看到begin backup并没有在表空间级别做全量checkpoint[/b],再对该表空间做end backup,结果会怎么样呢?
[quote]SQL> alter system switch logfile;

System altered.

SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /archlog/dbtest
Oldest online log sequence 8003
Next log sequence to archive 8005
Current log sequence 8005
SQL> delete from test.t;

30135 rows deleted.

SQL> alter tablespace test end backup;

Tablespace altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system dump logfile '/archlog/dbtest/arc_1_8004.dbf' layer 23 opcode 1;

System altered.[/quote]
在跟踪文件从没有看到任何关于数据块写的信息,[b]也就是说end backup没有对表空间级别做ckpt[/b]
[quote]DUMP OF REDO FROM FILE '/archlog/dbtest/arc_1_8005.dbf'
Opcode 23.1 only
DBA's: (file # 0, block # 0) thru (file # 65534, block # 4194303)
RBA's: 0x000000.00000000.0000 thru 0xffffffff.ffffffff.ffff
SCN's scn: 0x0000.00000000 thru scn: 0xffff.ffffffff
Times: creation thru eternity
FILE HEADER:
Software vsn=153092096=0x9200000, Compatibility Vsn=153092096=0x9200000
Db ID=1066056642=0x3f8abbc2, Db Name='DBTEST'
Activation ID=1073569894=0x3ffd6066
Control Seq=272930=0x42a22, File size=204800=0x32000
File Number=2, Blksiz=512, File Type=2 LOG
descrip:"Thread 0001, Seq# 0000008005, SCN 0x08dcdb658f42-0x08dcdb6591c6"
thread: 1 nab: 0x6a96 seq: 0x00001f45 hws: 0x2 eot: 0 dis: 0
reset logs count: 0x2892d6ec scn: 0x0883.2a4722f6
Low scn: 0x08dc.db658f42 07/10/2009 09:07:48
Next scn: 0x08dc.db6591c6 07/10/2009 09:08:51
Enabled scn: 0x0883.2a4722f6 03/05/2009 14:38:36
Thread closed scn: 0x08dc.db658f42 07/10/2009 09:07:48
Log format vsn: 0x8000000 Disk cksum: 0xc265 Calc cksum: 0xc265
Terminal Recovery Stamp scn: 0x0000.00000000 01/01/1988 00:00:00
Most recent redo scn: 0x0000.00000000
Largest LWN: 0 blocks
End-of-redo stream : No
Unprotected mode
Miscellaneous flags: 0x11
END OF REDO DUMP[/quote]

从理论上来讲,对表空间做offline,就会对表空间做全量ckpt,我再对该表空间做offline
[quote]SQL> alter tablespace test offline;

Tablespace altered.

SQL> alter system switch logfile;

System altered.

SQL> alter system dump logfile '/archlog/dbtest/arc_1_8006.dbf' layer 23 opcode 1;

System altered.[/quote]
在跟踪文件可以看到,[b]将dba_extents涉及到得block全部dump出来了[/b]
[quote] Block Written - afn: 11 rdba: 0x02c0005a(11,90)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c0005b(11,91)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c0005d(11,93)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c0005e(11,94)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c00060(11,96)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c00062(11,98)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c00064(11,100)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c00067(11,103)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c00069(11,105)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c0006b(11,107)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c0006e(11,110)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06
Block Written - afn: 11 rdba: 0x02c00070(11,112)
scn: 0x08dc.db6591bf seq: 0x01 flg:0x06[/quote]
...

再来研究一下10g
[quote]SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Linux: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production

SQL> select count(*) from ttt.ttt;

COUNT(*)
----------
50650

SQL> alter system checkpoint;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> select TABLESPACE_NAME,FILE_ID,BLOCK_ID,BLOCKS from dba_extents where SEGMENT_NAME='TTT' and OWNER='TTT' order by 3,4;

TABLESPACE_NAME FILE_ID BLOCK_ID BLOCKS
------------------------------ ---------- ---------- ----------
TT 7 145 8
TT 7 153 8
TT 7 161 8
TT 7 169 8
TT 7 177 8
TT 7 185 8
TT 7 193 8
TT 7 201 8
TT 7 209 8
TT 7 217 8
TT 7 225 8

TABLESPACE_NAME FILE_ID BLOCK_ID BLOCKS
------------------------------ ---------- ---------- ----------
TT 7 233 8
TT 7 241 8
TT 7 249 8
TT 7 257 8
TT 7 521 8
TT 7 649 128
TT 7 777 128
TT 7 905 128
TT 7 1033 128

20 rows selected.

SQL> delete from ttt.ttt;

50650 rows deleted.

SQL> alter tablespace tt begin backup;

Tablespace altered.

SQL> alter system dump logfile '/archlog/mctest/1_49401_679664461.dbf' layer 23 opcode 1;

System altered.[/quote]
从相关跟踪文件,可以看到dba_extents涉及到得block全部刷新到数据文件中,[b]即在10g中
begin backup是对表空间做全量ckpt的[/b]
[quote]
Block Written - afn: 7 rdba: 0x01c002d9 BFT:(1024,29360857) non-BFT:(7,729)
scn: 0x08dc.db69bb5a seq: 0x01 flg:0x06
Block Written - afn: 7 rdba: 0x01c002da BFT:(1024,29360858) non-BFT:(7,730)
scn: 0x08dc.db69bb5a seq: 0x01 flg:0x06
Block Written - afn: 7 rdba: 0x01c002db BFT:(1024,29360859) non-BFT:(7,731)
scn: 0x08dc.db69bb5a seq: 0x01 flg:0x06
Block Written - afn: 7 rdba: 0x01c002dc BFT:(1024,29360860) non-BFT:(7,732)
scn: 0x08dc.db69bb5a seq: 0x01 flg:0x06
Block Written - afn: 7 rdba: 0x01c002dd BFT:(1024,29360861) non-BFT:(7,733)
scn: 0x08dc.db69bb5a seq: 0x01 flg:0x06
Block Written - afn: 7 rdba: 0x01c002de BFT:(1024,29360862) non-BFT:(7,734)
scn: 0x08dc.db69bb5a seq: 0x01 flg:0x06
Block Written - afn: 7 rdba: 0x01c002df BFT:(1024,29360863) non-BFT:(7,735)
。。。
[ora10g@mcprod udump]$ cat mctest_ora_9400.trc|grep "non-BFT:(7"|wc -l
619[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值