oracle 11.2.0.4使用dbms_stats收集統計資訊statistics及刪除和還原相關測試之一
測試結論
1,oracle 11.2.0.4,手工建立表並插入資料, 不會馬上收集統計資訊
2, 收集統計資訊 exec dbms_stats.gather_table_stats(user,'t_stat',cascade=>true);
3,備份統計資訊 exec dbms_stats.create_stat_table(user,'stat_t_stat');
exec dbms_stats.export_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy');
4,刪除統計資訊
exec dbms_stats.delete_table_stats(user,'t_stat');
5,還原統計資訊
exec dbms_stats.import_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy',true,true);
測試明細
1,作業系統版本
[oracle@mygirl ~]$ more /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
2,資料庫版本
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
3,構建測試表及資料
SQL> conn user_zxy/system
Connected.
SQL> create table t_stat(a int,b int);
Table created.
SQL> insert into t_stat select level,level+3 from dual connect by level<=10;
10 rows created.
SQL> commit;
Commit complete.
4,新建測試表不會收集統計資訊
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> select table_name,column_name,num_distinct,low_value,high_value,num_nulls,num_buckets,last_analyzed,sample_size,histogram from user_tab_col_statistics where lower(table_name)='t_stat';
no rows selected
SQL> select count(*) from user_tables where lower(table_name)='t_stat';
COUNT(*)
----------
1
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
------------------------------ ---------- ---------- ------------ ---------
T_STAT
5,手工收集統計資訊
SQL> exec dbms_stats.gather_table_stats(user,'t_stat',cascade=>true);
PL/SQL procedure successfully completed.
6,手工收集統計資訊後則有了統計資訊
1* select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat'
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANALYZED
------------------------------ ---------- ---------- ------------ -------------------
T_STAT 10 5 0 2017-05-29 22:17:24
SQL> r
1* select table_name,column_name,num_distinct,low_value,high_value,num_nulls,num_buckets,last_analyzed,sample_size,histogram from user_tab_col_statistics where lower(table_name)='t_stat'
TABLE_NAME COLUMN_NAME NUM_DISTINCT LOW_VALUE HIGH_VALUE NUM_NULLS NUM_BUCKETS LAST_ANALYZED SAMPLE_SIZE HISTOGRAM
--------------- --------------- ------------ ------------------------------ -------------------- ---------- ----------- ------------------- ----------- ---------------
T_STAT A 10 C102 C10B 0 1 2017-05-29 22:17:24 10 NONE
T_STAT B 10 C105 C10E 0 1 2017-05-29 22:17:24 10 NONE
7,手工刪除統計資訊
SQL> exec dbms_stats.delete_table_stats(user,'t_stat');
PL/SQL procedure successfully completed.
8,手工刪除統計資訊後則沒有統計資訊了
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANALYZED
--------------- ---------- ---------- ------------ -------------------
T_STAT
SQL> select table_name,column_name,num_distinct,low_value,high_value,num_nulls,num_buckets,last_analyzed,sample_size,histogram from user_tab_col_statistics where lower(table_name)='t_stat';
no rows selected
9,手工刪除紡計資訊前備份統計資訊然後還原統計資訊
SQL> exec dbms_stats.create_stat_table(user,'stat_t_stat');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats(user,'t_stat',cascade=>true);
PL/SQL procedure successfully completed.
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
--------------- ---------- ---------- ------------ ---------
T_STAT 10 5 0 29-MAY-17
SQL> exec dbms_stats.export_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.delete_table_stats(user,'t_stat');
PL/SQL procedure successfully completed.
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
--------------- ---------- ---------- ------------ ---------
T_STAT
SQL> exec dbms_stats.import_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy',true,true);
PL/SQL procedure successfully completed.
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
--------------- ---------- ---------- ------------ ---------
T_STAT 10 5 0 29-MAY-17
1,oracle 11.2.0.4,手工建立表並插入資料, 不會馬上收集統計資訊
2, 收集統計資訊 exec dbms_stats.gather_table_stats(user,'t_stat',cascade=>true);
3,備份統計資訊 exec dbms_stats.create_stat_table(user,'stat_t_stat');
exec dbms_stats.export_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy');
4,刪除統計資訊
exec dbms_stats.delete_table_stats(user,'t_stat');
5,還原統計資訊
exec dbms_stats.import_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy',true,true);
測試明細
1,作業系統版本
[oracle@mygirl ~]$ more /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
2,資料庫版本
SQL> select * from v$version where rownum=1;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
3,構建測試表及資料
SQL> conn user_zxy/system
Connected.
SQL> create table t_stat(a int,b int);
Table created.
SQL> insert into t_stat select level,level+3 from dual connect by level<=10;
10 rows created.
SQL> commit;
Commit complete.
4,新建測試表不會收集統計資訊
alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
SQL> select table_name,column_name,num_distinct,low_value,high_value,num_nulls,num_buckets,last_analyzed,sample_size,histogram from user_tab_col_statistics where lower(table_name)='t_stat';
no rows selected
SQL> select count(*) from user_tables where lower(table_name)='t_stat';
COUNT(*)
----------
1
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
------------------------------ ---------- ---------- ------------ ---------
T_STAT
5,手工收集統計資訊
SQL> exec dbms_stats.gather_table_stats(user,'t_stat',cascade=>true);
PL/SQL procedure successfully completed.
6,手工收集統計資訊後則有了統計資訊
1* select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat'
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANALYZED
------------------------------ ---------- ---------- ------------ -------------------
T_STAT 10 5 0 2017-05-29 22:17:24
SQL> r
1* select table_name,column_name,num_distinct,low_value,high_value,num_nulls,num_buckets,last_analyzed,sample_size,histogram from user_tab_col_statistics where lower(table_name)='t_stat'
TABLE_NAME COLUMN_NAME NUM_DISTINCT LOW_VALUE HIGH_VALUE NUM_NULLS NUM_BUCKETS LAST_ANALYZED SAMPLE_SIZE HISTOGRAM
--------------- --------------- ------------ ------------------------------ -------------------- ---------- ----------- ------------------- ----------- ---------------
T_STAT A 10 C102 C10B 0 1 2017-05-29 22:17:24 10 NONE
T_STAT B 10 C105 C10E 0 1 2017-05-29 22:17:24 10 NONE
7,手工刪除統計資訊
SQL> exec dbms_stats.delete_table_stats(user,'t_stat');
PL/SQL procedure successfully completed.
8,手工刪除統計資訊後則沒有統計資訊了
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANALYZED
--------------- ---------- ---------- ------------ -------------------
T_STAT
SQL> select table_name,column_name,num_distinct,low_value,high_value,num_nulls,num_buckets,last_analyzed,sample_size,histogram from user_tab_col_statistics where lower(table_name)='t_stat';
no rows selected
9,手工刪除紡計資訊前備份統計資訊然後還原統計資訊
SQL> exec dbms_stats.create_stat_table(user,'stat_t_stat');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.gather_table_stats(user,'t_stat',cascade=>true);
PL/SQL procedure successfully completed.
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
--------------- ---------- ---------- ------------ ---------
T_STAT 10 5 0 29-MAY-17
SQL> exec dbms_stats.export_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy');
PL/SQL procedure successfully completed.
SQL> exec dbms_stats.delete_table_stats(user,'t_stat');
PL/SQL procedure successfully completed.
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
--------------- ---------- ---------- ------------ ---------
T_STAT
SQL> exec dbms_stats.import_table_stats('user_zxy','t_stat',null,'stat_t_stat',null,true,'user_zxy',true,true);
PL/SQL procedure successfully completed.
SQL> select table_name,num_rows,blocks,empty_blocks,last_analyzed from user_tables where lower(table_name)='t_stat';
TABLE_NAME NUM_ROWS BLOCKS EMPTY_BLOCKS LAST_ANAL
--------------- ---------- ---------- ------------ ---------
T_STAT 10 5 0 29-MAY-17
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-2140042/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle統計資訊 使用dbms_stats包收集統計資料Oracle
- DBMS_STATS收集統計資訊的問題及解決
- Fixed Objects Statistics統計資訊收集 - 2Object
- 關於oracle自動收集統計資訊Oracle
- Oracle收集統計資訊Oracle
- Oracle 統計資訊收集Oracle
- 收集oracle統計資訊Oracle
- ORACLE 收集統計資訊Oracle
- Oracle刪除效率測試Oracle
- [轉] oracle統計資訊(statistics)和直方圖(histogram)Oracle直方圖Histogram
- Oracle統計資訊的收集和維護Oracle
- 使用dbms_stats包收集統計資料(zt)
- oracle 10g_10.2.0.5如何合理高效使用dbms_stats收集統計資訊呢_part1Oracle 10g
- oracle 10g_10.2.0.5如何合理高效使用dbms_stats收集統計資訊呢_part2Oracle 10g
- oracle統計資訊包--dbms_stats介紹Oracle
- 【統計資訊】Oracle常用的收集統計資訊方式Oracle
- 關閉及開啟oracle10g統計資訊自動收集功能Oracle
- oracle 12c pdb測試:建立、開關、刪除Oracle
- [筆記]statistics資訊的收集筆記
- oracle 11.2.0.4之oracle database db link之測試明細之一OracleDatabase
- 使用DBMS_STATS收集系統狀態
- Oracle統計資訊自動收集Oracle
- oracle收集統計資訊job停止Oracle
- 關閉及開啟oracle10g統計資訊自動收集功能(轉)Oracle
- 關於dbms_stats對系統統計資訊的管理
- oracle刪除使用者後的恢復測試Oracle
- 用DBMS_STATS匯入匯出oracle統計資訊Oracle
- Oracle10g 自動統計資訊(dbms_stats)Oracle
- 滲透測試-資訊收集
- oracle 統計資訊檢視與收集Oracle
- oracle 11g統計資訊收集Oracle
- ORACLE 統計資訊的收集與管理Oracle
- oracle 快速刪除和快速插入的方法之一Oracle
- 深入分割槽表的增量統計資訊收集技術(incremetal statistics collection)REM
- oracle11g同義詞synonym建立及授權且刪除相關測試Oracle
- oracle 統計資訊過期判斷和自動收集Oracle
- 【Oracle】 RAC 環境刪除oracle 之一Oracle
- [Oracle] Oracle收集統計資訊的取樣比例Oracle