[20121127]rman備份資料檔案大小與truncate.txt

lfree發表於2012-11-27
[20121127]rman備份資料檔案大小與truncate.txt

記得以前看rman的書,rman僅僅備份已經格式話的塊,如果這樣一個表被truncate後,即使空間回收了。但是在rman備份時,備份大小不會變畫太多,這些前面使用的塊一定會備份。

自己做一個測試看看。

1.建立測試環境:
SQL> select * from v$version where rownum<=1;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

--建立表空間AAA
CREATE TABLESPACE AAA DATAFILE
  '/u01/app/oracle11g/oradata/test/aaa01.dbf' SIZE 64M AUTOEXTEND ON NEXT 16M MAXSIZE UNLIMITED
LOGGING
PERMANENT
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

$ ls -l /u01/app/oracle11g/oradata/test/aaa01.dbf
-rw-r-----  1 oracle11g oinstall 67117056 Nov 27 10:28 /u01/app/oracle11g/oradata/test/aaa01.dbf

--使用rman備份。
RMAN> backup datafile 11 format '/data/testtest/aaa1_%U';

Starting backup at 2012-11-27 10:32:26
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=134 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/u01/app/oracle11g/oradata/test/aaa01.dbf
channel ORA_DISK_1: starting piece 1 at 2012-11-27 10:32:27
channel ORA_DISK_1: finished piece 1 at 2012-11-27 10:32:29
piece handle=/data/testtest/aaa1_0unrbn1r_1_1 tag=TAG20121127T103227 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:02
Finished backup at 2012-11-27 10:32:29

$ ll /data/testtest/aaa*
-rw-r-----  1 oracle11g oinstall 1089536 Nov 27 10:32 /data/testtest/aaa1_0unrbn1r_1_1
$ du -sk /data/testtest/aaa*
1068    /data/testtest/aaa1_0unrbn1r_1_1
--備份檔案大小僅僅1068K。

--查詢字串BOOTSTRAP$不存在。
$ strings /u01/app/oracle11g/oradata/test/aaa01.dbf | grep 'BOOTSTRAP\$'
$ strings /data/testtest/aaa1_0unrbn1r_1_1 | grep 'BOOTSTRAP\$'

2.在表空間AAA上建立表看看情況:
SQL> create table t  tablespace aaa as select * from dba_objects ;
Table created.

SQL> select bytes,blocks from dba_segments where wner=user and segment_name='T';

     BYTES     BLOCKS
---------- ----------
   9437184       1152
--大小僅僅9M

SQL> insert into t  select * from t;
75198 rows created.

SQL> insert into t  select * from t;
150396 rows created.

SQL> commit ;
Commit complete.

SQL> select bytes,blocks from dba_segments where wner=user and segment_name='T';

     BYTES     BLOCKS
---------- ----------
  35651584       4352

--大小僅僅35M.

RMAN> backup datafile 11 format '/data/testtest/aaa2_%U';

Starting backup at 2012-11-27 10:40:38
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=196 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/u01/app/oracle11g/oradata/test/aaa01.dbf
channel ORA_DISK_1: starting piece 1 at 2012-11-27 10:40:43
channel ORA_DISK_1: finished piece 1 at 2012-11-27 10:40:50
piece handle=/data/testtest/aaa2_0vnrbnhb_1_1 tag=TAG20121127T104042 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 2012-11-27 10:40:50

$ ll /data/testtest/aaa*
-rw-r-----  1 oracle11g oinstall  1089536 Nov 27 10:32 /data/testtest/aaa1_0unrbn1r_1_1
-rw-r-----  1 oracle11g oinstall 36741120 Nov 27 10:40 /data/testtest/aaa2_0vnrbnhb_1_1

$ strings /u01/app/oracle11g/oradata/test/aaa01.dbf | grep 'BOOTSTRAP\$'
BOOTSTRAP$
BOOTSTRAP$
BOOTSTRAP$
BOOTSTRAP$
$ strings /data/testtest/aaa2_0vnrbnhb_1_1 | grep 'BOOTSTRAP\$'
BOOTSTRAP$
BOOTSTRAP$
BOOTSTRAP$
BOOTSTRAP$
--可以發現備份存在字串BOOTSTRAP$,正好4次。

3.truncate table t後看看情況:
SQL> truncate table t;
Table truncated.

RMAN> backup datafile 11 format '/data/testtest/aaa3_%U';

Starting backup at 2012-11-27 10:43:04
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=196 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/u01/app/oracle11g/oradata/test/aaa01.dbf
channel ORA_DISK_1: starting piece 1 at 2012-11-27 10:43:07
channel ORA_DISK_1: finished piece 1 at 2012-11-27 10:43:08
piece handle=/data/testtest/aaa3_10nrbnlr_1_1 tag=TAG20121127T104306 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2012-11-27 10:43:08

$ ll /data/testtest/aaa*
-rw-r-----  1 oracle11g oinstall  1089536 Nov 27 10:32 /data/testtest/aaa1_0unrbn1r_1_1
-rw-r-----  1 oracle11g oinstall 36741120 Nov 27 10:40 /data/testtest/aaa2_0vnrbnhb_1_1
-rw-r-----  1 oracle11g oinstall  1613824 Nov 27 10:43 /data/testtest/aaa3_10nrbnlr_1_1
--對比備份檔案可以發現truncate後備份檔案確實變小了。但是比第1次檔案大一點(多512K)。

$ strings /data/testtest/aaa3_10nrbnlr_1_1 | grep 'BOOTSTRAP\$'
BOOTSTRAP$
--從strings過濾來看,truncate表後的備份還是備份1點點對應的塊,但是許多塊並沒有備份。
--也許跟這個有關。
SQL> select bytes,blocks from dba_segments where wner=user and segment_name='T';

     BYTES     BLOCKS
---------- ----------
     65536          8

--這樣看來oracle並不是備份已經格式話的塊。

4.再重新來一次看看。
SQL> insert into t  select * from dba_objects;
75198 rows created.

SQL> insert into t  select * from t;
75198 rows created.

SQL> insert into t  select * from t;
150396 rows created.

SQL> commit ;
Commit complete.

SQL> select bytes,blocks from dba_segments where wner=user and segment_name='T';
     BYTES     BLOCKS
---------- ----------
  35651584       4352

--同樣是truncate操作,但是保留使用空間不回收看看。
SQL> truncate table t reuse storage ;
Table truncated.

SQL> select bytes,blocks from dba_segments where wner=user and segment_name='T';
     BYTES     BLOCKS
---------- ----------
  35651584       4352

RMAN> backup datafile 11 format '/data/testtest/aaa4_%U';

Starting backup at 2012-11-27 11:00:50
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=197 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00011 name=/u01/app/oracle11g/oradata/test/aaa01.dbf
channel ORA_DISK_1: starting piece 1 at 2012-11-27 11:00:55
channel ORA_DISK_1: finished piece 1 at 2012-11-27 11:00:58
piece handle=/data/testtest/aaa4_11nrbon7_1_1 tag=TAG20121127T110054 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 2012-11-27 11:00:58

$ ll /data/testtest/aaa*
-rw-r-----  1 oracle11g oinstall  1089536 Nov 27 10:32 /data/testtest/aaa1_0unrbn1r_1_1
-rw-r-----  1 oracle11g oinstall 36741120 Nov 27 10:40 /data/testtest/aaa2_0vnrbnhb_1_1
-rw-r-----  1 oracle11g oinstall  1613824 Nov 27 10:43 /data/testtest/aaa3_10nrbnlr_1_1
-rw-r-----  1 oracle11g oinstall 36741120 Nov 27 11:00 /data/testtest/aaa4_11nrbon7_1_1

--可以發現aaa2_0vnrbnhb_1_1與aaa4_11nrbon7_1_1大小一致。
--看來以前對這個概念理解存在一些錯誤。

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

相關文章