Oracle exp中compress引數的影響測試

chenoracle發表於2015-08-18

Oracle exp compress 引數的影響測試

 

1 建立表時 initial 預設為 64K ,手動設定為 5M

SQL> create table t1(id number) storage(initial 5m);

 

2 沒有 T1 的相關資料

SQL> select segment_name,bytes,initial_extent from user_segments; 

原因: 在沒有插入資料時,不會分配空間,在使用者段中也查詢不到,這是 11g 的新功能,延時段分配;

 

3 插入資料

SQL> insert into t1 values(1);

SQL> COMMIT;

 

4 t1 表所佔空間為 5M ,初始值 5M

SQL> select segment_name,bytes,initial_extent from user_segments;

T1(bytes=5242880,initial_extent=5242880)

 

5 清空表

SQL> truncate table t1;

 

6 t1 表所佔空間變成 initial 初始值 5M

SQL> select segment_name,bytes,initial_extent from user_segments;

T1(bytes=5242880,initial_extent=5242880)

 

SQL> select 5242880/1024/1024 from dual; ---5M

清空表後,t1 仍然佔有5M 的空間,即初始區分配的大小

 

7 更改 initial 引數

SQL> alter table t1 move storage(initial 64K);

 

SQL> select segment_name,bytes,initial_extent from user_segments;

T1( bytes=65536 ,initial_extent=65536)

 

8 插入資料

SQL> insert into t1 select level as id from dual connect by level<=100;

 

9 t1 表所佔空間為 64K

SQL> select segment_name,bytes,initial_extent from user_segments;

T1(bytes=65536,initial_extent=65536)

因為插入的資料很小,不足64K ,所以區的個數沒有增加

 

10 清空表 t1

SQL> truncate table t1;

 

SQL> select segment_name,bytes,initial_extent from user_segments;

T1(bytes=65536,initial_extent=65536)

 

11 插入大量資料

SQL> insert into t1 select level as id from dual connect by level<=1000000;

 

12 查詢 , t1 所佔空間 13M ,區擴充套件 28

SQL> select segment_name,bytes,initial_extent from user_segments;

T1(bytes=13631488,initial_extent=65536,extents=28)

 

select 13631488/1024/1024 from dual;---13M

 

13 exp 匯出 t1( 不指定 compress 引數,則預設 Y)

[oracle11@back ~]$ exp chen/chen file=a.dmp tables=t1

......

About to export specified tables via Conventional Path ...

. . exporting table                             T1    1000000 rows exported

Export terminated successfully without warnings.

......

 

14 匯入

SQL> show user

USER is "CHEN"

 

SQL> drop table t1 purge;

 

[oracle11@back ~]$ imp chen/chen file=a.dmp fromuser=chen touser=chen ignore=y

......

. importing CHEN's objects into CHEN

. . importing table                           "T1"    1000000 rows imported

Import terminated successfully without warnings.

......

 

SQL> col segment_name for a25

SQL> select segment_name,bytes,initial_extent,EXTENTS from user_segments;

 

SEGMENT_NAME                   BYTES INITIAL_EXTENTS EXTENTS

------------------------- ---------- --------------  -------

T1                          13631488       13631488     1

.....

 

10 rows selected.

匯入後表 t1 初始值 自動變成所有區的 總和 區由 28 個變成1 ,也就是將 28 個區壓縮成一個區 ,這是由於 compress=Y 引數引起的。

compress=Y 主要目的是 為了消除儲存碎片 ,以保證某張表的所有記錄都儲存在連續的空間裡。

但是負面效應很明顯,且自 oracle9i 開始,使用了本地管理的表空間,儲存碎片的問題應該比低版本好多了。

 

15 更改 t1 初始值為 64K

SQL> alter table t1 move storage(initial 64k);

 

SQL> select segment_name,bytes,initial_extent from user_segments;

 

SEGMENT_NAME                   BYTES INITIAL_EXTENT

------------------------- ---------- --------------

T1                          13631488          65536

......

 

10 rows selected.

 

16 重新匯出匯入 , 指定 compress=n

[oracle11@back ~]$ rm -rf a.dmp

[oracle11@back ~]$ exp chen/chen file=a.dmp tables=t1 compress=n

......

About to export specified tables via Conventional Path ...

. . exporting table                             T1    1000000 rows exported

Export terminated successfully without warnings.

......

 

SQL> drop table t1 purge;

 

[oracle11@back ~]$ imp chen/chen file=a.dmp fromuser=chen touser=chen ignore=y

......

. importing CHEN's objects into CHEN

. . importing table                           "T1"    1000000 rows imported

Import terminated successfully without warnings.

......

 

17 匯出時取消壓縮 (compress=N), 初始值和區的個數不變

SQL> select segment_name,bytes,initial_extent from user_segments;

 

SEGMENT_NAME                   BYTES INITIAL_EXTENT  EXTENTS

------------------------- ---------- --------------  -------

T1                          13631488          65536     28

......

10 rows selected.

歡迎關注我的微信公眾號"IT小Chen",共同學習,共同成長!!!

Oracle exp中compress引數的影響測試

Oracle exp中compress引數的影響測試



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

相關文章