資料泵匯出索引資料和統計資訊嗎

redhouser發表於2012-03-22

關於在資料泵問題:
(1)索引資料匯出嗎?
(2)源表統計資料匯出/匯入嗎?

1建立測試表
drop table test;
create table test
as
select dbms_random.string('x',50) as x from dual
connect by level<=1e6;

create index idx_test_x on test(x);

begin
  dbms_stats.gather_table_stats(user,'TEST');
end;

select table_name,num_rows,blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_tables where table_name='TEST';
TABLE_NAME   NUM_ROWS     BLOCKS L_ANAY
---------- ---------- ---------- --------------------
TEST           997971       7884 20140315 153237

select index_name,leaf_blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_indexes where table_name='TEST';
INDEX_NAME      LEAF_BLOCKS L_ANAY
--------------- ----------- --------------------
IDX_TEST_X             8467 20140315 153238

col segment_name for a20
select segment_name,bytes/1024/1024 from user_segments where segment_name in('TEST','IDX_TEST_X');
SEGMENT_NAME         BYTES/1024/1024
-------------------- ---------------
TEST                              62
IDX_TEST_X                        72


2修改統計資料
begin
  dbms_stats.set_table_stats(ownname => user,tabname => 'TEST',numrows => 1000,numblks => 100);
end;


begin
  dbms_stats.set_index_stats(ownname => user,indname => 'IDX_TEST_X',numlblks => 100);
end;


select table_name,num_rows,blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_tables where table_name='TEST';
TABLE_NAME   NUM_ROWS     BLOCKS L_ANAY
---------- ---------- ---------- --------------------
TEST             1000        100 20140315 153457


select index_name,leaf_blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_indexes where table_name='TEST';
INDEX_NAME      LEAF_BLOCKS L_ANAY
--------------- ----------- --------------------
IDX_TEST_X              100 20140315 153457

3包含/不包含索引匯出
(1)不包含索引匯出
mah]$ expdp \'sys/sys as sysdba\' directory='DMP_DIR' tables=MH.TEST dumpfile=test.dmp exclude=INDEX estimate=statistics
Export: Release 10.2.0.1.0 - Production on Saturday, 15 March, 2014 15:36:19
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SYS"."SYS_EXPORT_TABLE_01":  'sys/******** AS SYSDBA' directory=DMP_DIR tables=MH.TEST dumpfile=test.dmp exclude=INDEX estimate=statistics
Estimate in progress using STATISTICS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
.  estimated "MH"."TEST"                                 54.86 KB   ==>estimate=blocks時,估計為62 MB
Total estimation using STATISTICS method: 54.86 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "MH"."TEST"                                 52.45 MB 1000000 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
  /home/oracle/mah/test.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 15:36:26


(2)包含索引匯出
[oracle@rhel5 mah]$ expdp \'sys/sys as sysdba\' directory='DMP_DIR' tables=MH.TEST dumpfile=test2.dmp  estimate=statistics
Export: Release 10.2.0.1.0 - Production on Saturday, 15 March, 2014 15:37:22
Copyright (c) 2003, 2005, Oracle.  All rights reserved.
Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Starting "SYS"."SYS_EXPORT_TABLE_01":  'sys/******** AS SYSDBA' directory=DMP_DIR tables=MH.TEST dumpfile=test2.dmp estimate=statistics
Estimate in progress using STATISTICS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
.  estimated "MH"."TEST"                                 54.86 KB
Total estimation using STATISTICS method: 54.86 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/INDEX/INDEX
Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTICS/INDEX_STATISTICS
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "MH"."TEST"                                 52.45 MB 1000000 rows
Master table "SYS"."SYS_EXPORT_TABLE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLE_01 is:
  /home/oracle/mah/test2.dmp
Job "SYS"."SYS_EXPORT_TABLE_01" successfully completed at 15:37:30


匯出檔案比較:
[oracle@rhel5 mah]$ ls -lrt
-rw-r----- 1 oracle oinstall 55070720 Mar 15 15:36 test.dmp
-rw-r----- 1 oracle oinstall 55078912 Mar 15 15:37 test2.dmp  ==>含索引

==>兩個檔案大小差異極小(8192bytes),因TEST表上索引列較大(50bytes*1000000rows),不可能含索引資料;多出來的資料塊僅包含索引結構.

4匯入
(1)刪除表MH.TEST後:
impdp \'sys/sys as sysdba\' directory='DMP_DIR' tables=MH.TEST dumpfile=test.dmp
SQL> select table_name,num_rows,blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_tables where table_name='TEST';

TABLE_NAME   NUM_ROWS     BLOCKS L_ANAY
---------- ---------- ---------- --------------------
TEST             1000        100 20140315 153457

SQL> select index_name,leaf_blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_indexes where table_name='TEST';

no rows selected

(2)刪除表MH.TEST後:
impdp \'sys/sys as sysdba\' directory='DMP_DIR' tables=MH.TEST dumpfile=test2.dmp

SQL> select table_name,num_rows,blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_tables where table_name='TEST';

TABLE_NAME   NUM_ROWS     BLOCKS L_ANAY
---------- ---------- ---------- --------------------
TEST             1000        100 20140315 153457

SQL> select index_name,leaf_blocks,to_char(last_analyzed,'YYYYMMDD hh24miss') as l_anay from user_indexes where table_name='TEST';

INDEX_NAME      LEAF_BLOCKS L_ANAY
--------------- ----------- --------------------
IDX_TEST_X              100 20140315 153457

==>行數和資料塊是匯出時設定的統計資訊,而不是資料本身真實分佈資訊,包括索引和表上的上次分析時間


5結論
(1)expdp不匯出索引資料,僅匯出索引DDL
(2)expdp/impdp分別匯出/匯入統計資料

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

相關文章