[20160112]rman会备份空块吗.txt
-- 论坛上有人问的问题,我认为会的,那些delete完所有数据的block会备份的:
http://www.itpub.net/thread-2050864-1-1.html
如果是从未被使用过的block,rman不会备份。但那些delete完所有数据的block,rman会备份吗?
--我以前做过测试关于truncate的情况:
http://blog.itpub.net/267265/viewspace-750049/
1.测试环境:
SCOTT@book> @ &r/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
CREATE TABLESPACE SUGAR DATAFILE
'/mnt/ramdisk/book/sugar01.dbf' SIZE 100M AUTOEXTEND ON NEXT 64M MAXSIZE UNLIMITED
NOLOGGING
ONLINE
EXTENT MANAGEMENT LOCAL AUTOALLOCATE
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
--上面没有任何对象.
RMAN> backup tablespace sugar format '/home/oracle/backup/sugar1_%u' ;
$ ll -l /home/oracle/backup/
total 1068
-rw-r----- 1 oracle oinstall 1089536 2016-01-12 15:31:28 sugar1_16qr6omg
2.建立表在其表空间上面:
SCOTT@book> create table tt1 tablespace sugar as select rownum id,'TESTTESTTEST' name from dual connect by level<=2e5;
Table created.
SCOTT@book> select bytes,blocks from dba_segments where owner=user and segment_name='TT1';
BYTES BLOCKS
---------- ----------
6291456 768
RMAN> backup tablespace sugar format '/home/oracle/backup/sugar2_%u' ;
$ ll -l /home/oracle/backup/
total 8288
-rw-r----- 1 oracle oinstall 1089536 2016-01-12 15:31:28 sugar1_16qr6omg
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:34:36 sugar2_17qr6osc
3.删除全部后在备份看看:
SCOTT@book> delete from tt1 ;
200000 rows deleted.
SCOTT@book> commit ;
Commit complete.
SCOTT@book> alter system checkpoint;
System altered.
SCOTT@book> select bytes,blocks from dba_segments where owner=user and segment_name='TT1';
BYTES BLOCKS
---------- ----------
6291456 768
--占用空间依旧.
RMAN> backup tablespace sugar format '/home/oracle/backup/sugar3_%u' ;
$ ll -l /home/oracle/backup/
total 15508
-rw-r----- 1 oracle oinstall 1089536 2016-01-12 15:31:28 sugar1_16qr6omg
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:34:36 sugar2_17qr6osc
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:36:09 sugar3_18qr6ov9
--可以发现即使全部删除了数据,这些块还是会备份的.
$ strings sugar3_18qr6ov9 | grep "TESTTESTTEST" |wc
200000 200000 2799557
--以上语句也可以看出来,备份存在2e5次TESTTESTTEST字串.
4.truncate后再测试:
SCOTT@book> truncate table tt1;
Table truncated.
SCOTT@book> select bytes,blocks from dba_segments where owner=user and segment_name='TT1';
BYTES BLOCKS
---------- ----------
65536 8
RMAN> backup tablespace sugar format '/home/oracle/backup/sugar4_%u' ;
$ ll -l /home/oracle/backup/
total 17088
-rw-r----- 1 oracle oinstall 1089536 2016-01-12 15:31:28 sugar1_16qr6omg
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:34:36 sugar2_17qr6osc
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:36:09 sugar3_18qr6ov9
-rw-r----- 1 oracle oinstall 1613824 2016-01-12 15:38:55 sugar4_19qr6p4f
--可以发现truncate的备份明显变小.
$ strings sugar4_19qr6p4f | grep "TESTTESTTEST" |wc
18672 18672 261350
--即使这样,在备份中还是存在18672个TESTTESTTEST字符串.
--而且上面第4次备份比第1次备份 1613824-1089536=524288,多了512K.也就是说明即使我truncate表,oracle也不是备份8块(64K).而是还多备份512K数据.
--512/8=64 也就是多备份64块.
5.继续探究:
SCOTT@book> drop table tt1 purge ;
Table dropped.
SCOTT@book> create table tt1 tablespace sugar as select rownum id,to_char(rownum,'000000')||'TESTAA' name from dual connect by level<=2e5;
Table created.
SCOTT@book> truncate table tt1;
Table truncated.
RMAN> backup tablespace sugar format '/home/oracle/backup/sugar5_%u' ;
$ ll -l /home/oracle/backup/su*
-rw-r----- 1 oracle oinstall 1089536 2016-01-12 15:31:28 /home/oracle/backup/sugar1_16qr6omg
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:34:36 /home/oracle/backup/sugar2_17qr6osc
-rw-r----- 1 oracle oinstall 7380992 2016-01-12 15:36:09 /home/oracle/backup/sugar3_18qr6ov9
-rw-r----- 1 oracle oinstall 1613824 2016-01-12 15:38:55 /home/oracle/backup/sugar4_19qr6p4f
-rw-r----- 1 oracle oinstall 1613824 2016-01-12 16:24:02 /home/oracle/backup/sugar5_1fqr6rp2
$ strings sugar5_1fqr6rp2 | grep "TESTAA" |wc
17877 17877 268097
$ strings sugar5_1bqr6qf2 | grep "TESTAAA" > aaa.txt
$ head aaa.txt
000319TESTAA,
000318TESTAA,
000317TESTAA,
000316TESTAA,
000315TESTAA,
000314TESTAA,
000313TESTAA,
000312TESTAA,
000311TESTAA,
000310TESTAA,
--如果你注意看结尾逗号,ascii 对应2c 实际上就是记录的开始.这样结尾不是逗号的就是该块的第一条记录.
$ grep -v ",$" aaa.txt
000001TESTAA
000320TESTAA
000634TESTAA
000948TESTAA
001262TESTAA
001576TESTAA
001890TESTAA
002204TESTAA
002518TESTAA
002832TESTAA
003146TESTAA
003460TESTAA
003774TESTAA
004088TESTAA
004402TESTAA
004716TESTAA
005030TESTAA
005344TESTAA
005658TESTAA
005972TESTAA
006286TESTAA
006600TESTAA
006914TESTAA
007228TESTAA
007542TESTAA
007856TESTAA
008170TESTAA
008484TESTAA
008798TESTAA
009112TESTAA
009426TESTAA
009740TESTAA
010052TESTAA
010353TESTAA
010654TESTAA
010955TESTAA
011256TESTAA
011557TESTAA
011858TESTAA
012159TESTAA
012460TESTAA
012761TESTAA
013062TESTAA
013363TESTAA
013664TESTAA
013965TESTAA
014266TESTAA
014567TESTAA
014868TESTAA
015169TESTAA
015470TESTAA
015771TESTAA
016072TESTAA
016373TESTAA
016674TESTAA
016975TESTAA
017276TESTAA
017577TESTAA
$ grep -v ",$" aaa.txt |wc
58 58 812
--也就是读取了58块.
6.重复:
--删除表重建建立:
SCOTT@book> drop table tt1 purge ;
Table dropped.
SCOTT@book> create table tt1 tablespace sugar as select rownum id,to_char(rownum,'000000')||'TESTAA' name from dual connect by level<=2e5;
Table created.
--编辑建立如下脚本:
SELECT DBMS_ROWID.ROWID_BLOCK_NUMBER (ROWID) N10
,DBMS_ROWID.ROWID_ROW_NUMBER (ROWID) N20
FROM tt1
WHERE id IN (1
,320
,634
,948
,1262
,1576
,1890
,2204
,2518
,2832
,3146
,3460
,3774
,4088
,4402
,4716
,5030
,5344
,5658
,5972
,6286
,6600
,6914
,7228
,7542
,7856
,8170
,8484
,8798
,9112
,9426
,9740
,10052
,10353
,10654
,10955
,11256
,11557
,11858
,12159
,12460
,12761
,13062
,13363
,13664
,13965
,14266
,14567
,14868
,15169
,15470
,15771
,16072
,16373
,16674
,16975
,17276
,17577) order by 1;
SCOTT@book> @ /home/oracle/backup/bbb.txt
N10 N20
--------------------- ----------
131 0
132 0
133 0
134 0
135 0
136 0
137 0
138 0
139 0
140 0
141 0
142 0
143 0
145 0
146 0
147 0
148 0
149 0
150 0
151 0
152 0
153 0
154 0
155 0
156 0
157 0
158 0
159 0
161 0
162 0
163 0
164 0
165 0
166 0
167 0
168 0
169 0
170 0
171 0
172 0
173 0
174 0
175 0
177 0
178 0
179 0
180 0
181 0
182 0
183 0
184 0
185 0
186 0
187 0
188 0
189 0
190 0
191 0
58 rows selected.
WITH a
AS ( SELECT 130 + ROWNUM x
FROM DUAL
CONNECT BY LEVEL <= 61)
SELECT x
FROM a
WHERE x NOT IN (SELECT DBMS_ROWID.ROWID_BLOCK_NUMBER (ROWID) N10
-- ,DBMS_ROWID.ROWID_ROW_NUMBER (ROWID) N20
FROM tt1
WHERE id IN (1
,320
,634
,948
,1262
,1576
,1890
,2204
,2518
,2832
,3146
,3460
,3774
,4088
,4402
,4716
,5030
,5344
,5658
,5972
,6286
,6600
,6914
,7228
,7542
,7856
,8170
,8484
,8798
,9112
,9426
,9740
,10052
,10353
,10654
,10955
,11256
,11557
,11858
,12159
,12460
,12761
,13062
,13363
,13664
,13965
,14266
,14567
,14868
,15169
,15470
,15771
,16072
,16373
,16674
,16975
,17276
,17577));
X
----------
160
176
144
3 rows selected.
--从块131开始,144,160,176没有读取.
alter system dump datafile 6 block 144 ;
alter system dump datafile 6 block 160 ;
alter system dump datafile 6 block 176 ;
--检查转储frmt: 0x02 chkval: 0x98b4 type: 0x20=FIRST LEVEL BITMAP BLOCK.
--也就是一级位图.
SCOTT@book> column PARTITION_NAME noprint
SCOTT@book> select * from dba_extents where owner=user and segment_name='TT1';
OWNER SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------ -------------------- ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------
SCOTT TT1 TABLE SUGAR 0 6 128 65536 8 6
SCOTT TT1 TABLE SUGAR 1 6 136 65536 8 6
SCOTT TT1 TABLE SUGAR 2 6 144 65536 8 6
SCOTT TT1 TABLE SUGAR 3 6 152 65536 8 6
SCOTT TT1 TABLE SUGAR 4 6 160 65536 8 6
SCOTT TT1 TABLE SUGAR 5 6 168 65536 8 6
SCOTT TT1 TABLE SUGAR 6 6 176 65536 8 6
SCOTT TT1 TABLE SUGAR 7 6 184 65536 8 6
SCOTT TT1 TABLE SUGAR 8 6 192 65536 8 6
SCOTT TT1 TABLE SUGAR 9 6 200 65536 8 6
SCOTT TT1 TABLE SUGAR 10 6 208 65536 8 6
SCOTT TT1 TABLE SUGAR 11 6 216 65536 8 6
SCOTT TT1 TABLE SUGAR 12 6 224 65536 8 6
SCOTT TT1 TABLE SUGAR 13 6 232 65536 8 6
SCOTT TT1 TABLE SUGAR 14 6 240 65536 8 6
SCOTT TT1 TABLE SUGAR 15 6 248 65536 8 6
SCOTT TT1 TABLE SUGAR 16 6 256 1048576 128 6
SCOTT TT1 TABLE SUGAR 17 6 384 1048576 128 6
SCOTT TT1 TABLE SUGAR 18 6 512 1048576 128 6
SCOTT TT1 TABLE SUGAR 19 6 640 1048576 128 6
SCOTT TT1 TABLE SUGAR 20 6 768 1048576 128 6
21 rows selected.
--很明显即使你truncate表,前面的64块也是备份的.这样truncate后还多了512K,对于8k的数据块.