[20171206]rman與truncate.txt--//昨天下班在回家的路上,突然想起以前遇到的問題,就是truncate表後,rman做備份時會備份多少truncate表的信息,--//當時在itpub上,還存在討論,就是rman會備份空block嗎?參考鏈接:http://www.itpu ...
[20171206]rman與truncate.txt
--//昨天下班在回家的路上,突然想起以前遇到的問題,就是truncate表後,rman做備份時會備份多少truncate表的信息,
--//當時在itpub上,還存在討論,就是rman會備份空block嗎?參考鏈接:http://www.itpub.net/thread-2050864-9-1.html
--//zergduan兄還開了SR,答覆如下:
終於有回覆了
經過dump的確認,unused block compression 特性是在extent一級,而不是在block級啟用:
-------------------------
BEFORE : RelFno: 7, BeginBlock: 128, Flag: 0, First: 50, Free: 63438
BEFORE : FFFFFFFFFFFF0300 0000000000000000 0000000000000000 0000000000000000
AFTER : RelFno: 7, BeginBlock: 128, Flag: 0, First: 1, Free: 63487
AFTER : 0100000000000000 0000000000000000 0000000000000000 0000000000000000
RMAN read that there is one extent to be backup from the table. and I will backup all the blocks. It does not read at BLOCK level.
......
unused block compression doesn't kick in unless all the extents are unused. Granularity can't be changed to a block.
---------------------------
truncate之後,該對象仍然存在,所以,部分extent(比如頭部)中仍然有一些metadata,這樣的extent被認為非空,會被整體備份出來。
由於truncate 並不刪除數據,所以,該塊上仍然保留有您測試的字元串等。所以,通過strings命令可以看到這部分數據。
該問題的重點,我想應該是,最後驗證了 unused block compression 的粒度是在extent級別,不是block。
--//是否跟rman input memory buffer有關.通過例子來來說明:
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
$ cat d2.txt
drop tablespace t01 including contents and datafiles;
drop tablespace t02 including contents and datafiles;
drop tablespace t03 including contents and datafiles;
drop tablespace t04 including contents and datafiles;
drop tablespace t05 including contents and datafiles;
CREATE TABLESPACE T01 DATAFILE '/mnt/ramdisk/book/T01.dbf' SIZE 6M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON;
CREATE TABLESPACE T02 DATAFILE '/mnt/ramdisk/book/T02.dbf' SIZE 6M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON;
CREATE TABLESPACE T03 DATAFILE '/mnt/ramdisk/book/T03.dbf' SIZE 6M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON;
CREATE TABLESPACE T04 DATAFILE '/mnt/ramdisk/book/T04.dbf' SIZE 6M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON;
CREATE TABLESPACE T05 DATAFILE '/mnt/ramdisk/book/T05.dbf' SIZE 6M AUTOEXTEND OFF LOGGING ONLINE EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT AUTO FLASHBACK ON;
create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=1e5;
create table t02 tablespace t02 as select rownum id ,to_char(rownum,'FM000000')||lpad('B',26,'B') name from dual connect by level<=1e5;
create table t03 tablespace t03 as select rownum id ,to_char(rownum,'FM000000')||lpad('C',26,'C') name from dual connect by level<=1e5;
create table t04 tablespace t04 as select rownum id ,to_char(rownum,'FM000000')||lpad('D',26,'D') name from dual connect by level<=1e5;
create table t05 tablespace t05 as select rownum id ,to_char(rownum,'FM000000')||lpad('E',26,'E') name from dual connect by level<=1e5;
alter system checkpoint;
alter system checkpoint;
alter system checkpoint;
2.測試:
--//建立如上表空間:
RMAN> CONFIGURE CHANNEL 1 DEVICE TYPE DISK clear;
old RMAN configuration parameters:
CONFIGURE CHANNEL 1 DEVICE TYPE DISK RATE 128 K;
old RMAN configuration parameters are successfully deleted
RMAN> report schema ;
Report of database schema for database with db_unique_name BOOK
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 760 SYSTEM *** /mnt/ramdisk/book/system01.dbf
2 940 SYSAUX *** /mnt/ramdisk/book/sysaux01.dbf
3 1075 UNDOTBS1 *** /mnt/ramdisk/book/undotbs01.dbf
4 256 USERS *** /mnt/ramdisk/book/users01.dbf
5 346 EXAMPLE *** /mnt/ramdisk/book/example01.dbf
6 40 TEA *** /mnt/ramdisk/book/tea01.dbf
7 6 T01 *** /mnt/ramdisk/book/T01.dbf
8 6 T02 *** /mnt/ramdisk/book/T02.dbf
9 6 T03 *** /mnt/ramdisk/book/T03.dbf
10 6 T04 *** /mnt/ramdisk/book/T04.dbf
11 6 T05 *** /mnt/ramdisk/book/T05.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 414 TEMP 32767 /mnt/ramdisk/book/temp01.dbf
SCOTT@book> truncate table t01 ;
Table truncated.
--//truncate表T01.測試備份看看:
RMAN> backup datafile 7 format '/home/oracle/backup/T1_%U';
Starting backup at 2017-12-06 08:37:56
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=80 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=00007 name=/mnt/ramdisk/book/T01.dbf
channel ORA_DISK_1: starting piece 1 at 2017-12-06 08:37:57
channel ORA_DISK_1: finished piece 1 at 2017-12-06 08:37:58
piece handle=/home/oracle/backup/T1_h7sle5j5_1_1 tag=TAG20171206T083757 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-12-06 08:37:58
$ strings -t d T1_h7sle5j5_1_1 | grep 'AAAAA'|wc
9978 26939 440924
$ strings -t d T1_h7sle5j5_1_1 | grep 'AAAAAA' |head -1
1082678 K 000174AAAAAAAAAAAAAAAAAAAAAAAAAA,
$ strings -t d T1_h7sle5j5_1_1 | grep 'AAAAAA' |tail -1
1581019 009807AAAAAAAAAAAAAAAAAAAAAAAAAA
--//可以確定在備份集合中記錄是那些.因為T02表結構是一樣的.通過T02也可以確定備份記錄的塊號.
SCOTT@book> select rowid,t02.* from t02 where id in (174,9807);
ROWID ID NAME
------------------ ---------- --------------------------------
AAAWLjAAIAAAACDACt 174 000174BBBBBBBBBBBBBBBBBBBBBBBBBB
AAAWLjAAIAAAAC/AAA 9807 009807BBBBBBBBBBBBBBBBBBBBBBBBBB
SCOTT@book> @ &r/rowid AAAWLjAAIAAAACDACt
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90851 8 131 173 0x2000083 8,131 alter system dump datafile 8 block 131 ;
SCOTT@book> @ &r/rowid AAAWLjAAIAAAAC/AAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90851 8 191 0 0x20000BF 8,191 alter system dump datafile 8 block 191 ;
--//總共191-131+1=61,加上前面3塊,就是64塊,也就是 64*8192 = 524288,524288/1024=512K.
--//我以前一直的理解truncate後會備份一些塊,僅僅備份一個extent,這樣僅僅備份64K(8塊).而實際上是512K.
--//為什麼不是1M,而是512K?????
3.測試:
--//測試備份4個文件作為備份集的情況:
RMAN> backup datafile 7,8,9,10 format '/home/oracle/backup/T1234_%U';
Starting backup at 2017-12-06 08:53:53
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=94 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=00007 name=/mnt/ramdisk/book/T01.dbf
input datafile file number=00008 name=/mnt/ramdisk/book/T02.dbf
input datafile file number=00009 name=/mnt/ramdisk/book/T03.dbf
input datafile file number=00010 name=/mnt/ramdisk/book/T04.dbf
channel ORA_DISK_1: starting piece 1 at 2017-12-06 08:53:54
channel ORA_DISK_1: finished piece 1 at 2017-12-06 08:53:55
piece handle=/home/oracle/backup/T1234_h8sle6h2_1_1 tag=TAG20171206T085353 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-12-06 08:53:55
$ strings -t d T1234_h8sle6h2_1_1 | grep 'AAAAA' |head -1
4179254 K 000174AAAAAAAAAAAAAAAAAAAAAAAAAA,
$ strings -t d T1234_h8sle6h2_1_1 | grep 'AAAAA' |tail -1
4677595 009807AAAAAAAAAAAAAAAAAAAAAAAAAA
$ strings -t d T1234_h8sle6h2_1_1 | grep 'AAAAA' |wc
9978 26939 440924
--//與備份1個數據文件一樣,不展開分析了.本來還想測試備份5個數據文件的.
--//因為備份1個文件僅僅備份512K(在truncate後),我開始的理解應該是1M.why?
--//不過我的理解還是和rman input memory buffer有關.
4.測試:
SCOTT@book> drop tablespace t01 including contents and datafiles;
Tablespace dropped.
CREATE TABLESPACE t01 DATAFILE
'/mnt/ramdisk/book/T01.dbf' SIZE 6M AUTOEXTEND OFF
LOGGING
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
--//建立UNIFORM SIZE 1M.
create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=1e5;
SCOTT@book> create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=1e5;
Table created.
SCOTT@book> truncate table t01 ;
Table truncated.
RMAN> backup datafile 7 format '/home/oracle/backup/T1x_%U';
Starting backup at 2017-12-06 09:02:19
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/mnt/ramdisk/book/T01.dbf
channel ORA_DISK_1: starting piece 1 at 2017-12-06 09:02:19
channel ORA_DISK_1: finished piece 1 at 2017-12-06 09:02:20
piece handle=/home/oracle/backup/T1x_h9sle70r_1_1 tag=TAG20171206T090219 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-12-06 09:02:20
$ strings -t d T1x_h9sle70r_1_1 | grep 'AAAAA' |wc
100000 270040 4424269
$ strings -t d T1x_h9sle70r_1_1 | grep 'AAAAA' |head -1
1090870 K 000174AAAAAAAAAAAAAAAAAAAAAAAAAA,
$ strings -t d T1x_h9sle70r_1_1 | grep 'AAAAA' |tail -1
6021081 c< 099859AAAAAAAAAAAAAAAAAAAAAAAAAA
$ strings -t d T1x_h9sle70r_1_1 | grep 'AAAAA' |wc
100000 270040 4424269
--//昏,全部備份.看來沒有這麼簡單.
SCOTT@book> drop table t01 purge ;
Table dropped.
SCOTT@book> create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=1e5;
Table created.
SCOTT@book> select rowid,t01.* from t01 where id in (174,99859);
ROWID ID NAME
------------------ ---------- --------------------------------
AAAWLuAAHAAAACEACt 174 000174AAAAAAAAAAAAAAAAAAAAAAAAAA
AAAWLuAAHAAAALdAAA 99859 099859AAAAAAAAAAAAAAAAAAAAAAAAAA
SCOTT@book> @ &r/rowid AAAWLuAAHAAAACEACt
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90862 7 132 173 0x1C00084 7,132 alter system dump datafile 7 block 132 ;
SCOTT@book> @ &r/rowid AAAWLuAAHAAAALdAAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90862 7 733 0 0x1C002DD 7,733 alter system dump datafile 7 block 733 ;
SCOTT@book> column PARTITION_NAME noprint
SCOTT@book> select * from dba_extents where segment_name='T01';
OWNER SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------ ------------ ------------ --------------- --------- ---------- ---------- ---------- ---------- ------------
SCOTT T01 TABLE T01 0 7 128 1048576 128 7
SCOTT T01 TABLE T01 1 7 256 1048576 128 7
SCOTT T01 TABLE T01 2 7 384 1048576 128 7
SCOTT T01 TABLE T01 3 7 512 1048576 128 7
SCOTT T01 TABLE T01 4 7 640 1048576 128 7
--//難道truncate後rman備份會8個extents嗎?
5.測試:
SCOTT@book> drop tablespace t01 including contents and datafiles;
Tablespace dropped.
CREATE TABLESPACE t01 DATAFILE
'/mnt/ramdisk/book/T01.dbf' SIZE 21M AUTOEXTEND OFF
LOGGING
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;
--//建立UNIFORM SIZE 1M.
create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=4e5;
SCOTT@book> select * from dba_extents where segment_name='T01';
OWNER SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------ ------------ ------------ --------------- --------- ---------- ---------- ---------- ---------- ------------
SCOTT T01 TABLE T01 0 7 128 1048576 128 7
SCOTT T01 TABLE T01 1 7 256 1048576 128 7
SCOTT T01 TABLE T01 2 7 384 1048576 128 7
SCOTT T01 TABLE T01 3 7 512 1048576 128 7
SCOTT T01 TABLE T01 4 7 640 1048576 128 7
SCOTT T01 TABLE T01 5 7 768 1048576 128 7
SCOTT T01 TABLE T01 6 7 896 1048576 128 7
SCOTT T01 TABLE T01 7 7 1024 1048576 128 7
SCOTT T01 TABLE T01 8 7 1152 1048576 128 7
SCOTT T01 TABLE T01 9 7 1280 1048576 128 7
SCOTT T01 TABLE T01 10 7 1408 1048576 128 7
SCOTT T01 TABLE T01 11 7 1536 1048576 128 7
SCOTT T01 TABLE T01 12 7 1664 1048576 128 7
SCOTT T01 TABLE T01 13 7 1792 1048576 128 7
SCOTT T01 TABLE T01 14 7 1920 1048576 128 7
SCOTT T01 TABLE T01 15 7 2048 1048576 128 7
SCOTT T01 TABLE T01 16 7 2176 1048576 128 7
SCOTT T01 TABLE T01 17 7 2304 1048576 128 7
SCOTT T01 TABLE T01 18 7 2432 1048576 128 7
19 rows selected.
SCOTT@book> truncate table t01 ;
Table truncated.
RMAN> backup datafile 7 format '/home/oracle/backup/T1y_%U';
Starting backup at 2017-12-06 09:17:52
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/mnt/ramdisk/book/T01.dbf
channel ORA_DISK_1: starting piece 1 at 2017-12-06 09:17:52
channel ORA_DISK_1: finished piece 1 at 2017-12-06 09:17:53
piece handle=/home/oracle/backup/T1y_hbsle7u0_1_1 tag=TAG20171206T091752 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2017-12-06 09:17:53
$ strings -t d T1y_hbsle7u0_1_1 | grep 'AAAAA' |head -1
1090870 K 000174AAAAAAAAAAAAAAAAAAAAAAAAAA,
$ strings -t d T1y_hbsle7u0_1_1 | grep 'AAAAA' |tail -1
9445337 [L 169075AAAAAAAAAAAAAAAAAAAAAAAAAA
$ strings -t d T1y_hbsle7u0_1_1 | grep 'AAAAA' |wc
169242 456998 7484144
SCOTT@book> drop table t01 purge ;
Table dropped.
SCOTT@book> create table t01 tablespace t01 as select rownum id ,to_char(rownum,'FM000000')||lpad('A',26,'A') name from dual connect by level<=4e5;
Table created.
SCOTT@book> select rowid,t01.* from t01 where id in (174,169075,169242);
ROWID ID NAME
------------------ ---------- --------------------------------
AAAWL0AAHAAAACEACt 174 000174AAAAAAAAAAAAAAAAAAAAAAAAAA
AAAWL0AAHAAAAR/AAA 169075 169075AAAAAAAAAAAAAAAAAAAAAAAAAA
AAAWL0AAHAAAAR/ACn 169242 169242AAAAAAAAAAAAAAAAAAAAAAAAAA
SCOTT@book> @ &r/rowid AAAWL0AAHAAAACEACt
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90868 7 132 173 0x1C00084 7,132 alter system dump datafile 7 block 132 ;
SCOTT@book> @ &r/rowid AAAWL0AAHAAAAR/AAA
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90868 7 1151 0 0x1C0047F 7,1151 alter system dump datafile 7 block 1151
SCOTT@book> @ &r/rowid AAAWL0AAHAAAAR/ACn
OBJECT FILE BLOCK ROW ROWID_DBA DBA TEXT
---------- ---------- ---------- ---------- -------------------- -------------------- ----------------------------------------
90868 7 1151 167 0x1C0047F 7,1151 alter system dump datafile 7 block 1151
--//昏,確實是8個extents.
--//也就是truncate後rman備份信息的量最大是8個extents.有點小疑問,我的測試使用的磁碟空間是連續的,如果離散是否也是這樣,不測試了浪費時間.