Oracle確定到期的統計資訊

來源:互聯網
上載者:User

Youmust regularly gather statistics on database objects as thesedatabase objects are modified over time. To determine whether agiven database object needs new database statistics, OracleDatabase provides a table monitoring facility. This monitoring isenabled by default when STATISTICS_LEVEL is set toTYPICAL orALL.

經過一段時間,隨著資料庫物件被修改,必須定期搜集統計資訊。為了確定資料庫物件需要新的資料庫統計資訊,oracle資料庫提供了一個表監控特性。當STATISTICS_LEVEL設定為TYPICALALL時,表監控特性預設是啟動的。

 

Monitoring tracks the approximate number of INSERTs,UPDATEs, andDELETEs for that table andwhether the table has been truncated since the last time statisticswere gathered. You can access information about changes of tablesin theUSER_TAB_MODIFICATIONS view. Following adata-modification, there may be a few minutes delay while OracleDatabase propagates the information to this view. Use theDBMS_STATS.FLUSH_DATABASE_MONITORING_INFO procedure toimmediately reflect the outstanding monitored information kept inthe memory.

 

表監控特性跟蹤從最後一次統計搜集後,表的insert、update、delete操作的近似數,和表是否被truncate。可以通過查詢USER_TAB_MODIFICATIONS視圖獲得關於表變化的資訊。資料修改後,通過USER_TAB_MODIFICATIONS擷取修改資訊可能有一些延時。使用DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO立即將延時資訊保持到記憶體中。

 

TheGATHER_DATABASE_STATS orGATHER_SCHEMA_STATS procedures gather new statisticsfor tables with stale statistics when theOPTIONSparameter is set to GATHER STALE orGATHERAUTO. If a monitored table has been modified more than10%, then these statistics are considered stale and gatheredagain.

 

當屬性OPTIONS設定為GATHER STALEor GATHERAUTOGATHER_DATABASE_STATSGATHER_SCHEMA_STATS為有到期統計資訊的表搜集新的統計資訊,如果一個監控的表修改超過了10%,則統計資訊被認為到期,需再次搜集。

 

部分實驗如下:


SQL> select * from test01;

A B
---------- ----------
21 10
9 10
22 10
23 10
24 10
25 10
1 1
2 2
44 44
55 55

10 rowsselected. ------表資料10行

SQL> select * fromuser_tab_modifications;

no rowsselected ------實驗前已對測試庫做了搜集統計資訊,此時顯示為空白

SQL> insert into test01 values(66,66);

1 row created.

SQL> commit;

Commit complete.

SQL> select * from user_tab_modifications;

no rowsselected ------表的修改未及時顯示

SQL> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO; ------將修改的資訊keep到記憶體

PL/SQL procedure successfully completed.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 10 0 NO ------ 1 代表剛才的1條insert

 

為更好的展現監控資訊,接著進行update、delete、truncate操作示範:


SQL> update test01 set a=77 where b=66;

1 row updated.

SQL> commit;

Commit complete.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 1 0 0 NO

SQL> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;

PL/SQL procedure successfully completed.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 1 1 0 NO

SQL> delete from test01 where a=77;

1 row deleted.

SQL> commit;

Commit complete.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 1 1 0 NO

SQL> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;

PL/SQL procedure successfully completed.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 1 1 1 NO

SQL> truncate table test01;

Table truncated.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 1 1 1 NO

SQL> exec DBMS_STATS.FLUSH_DATABASE_MONITORING_INFO;

PL/SQL procedure successfully completed.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

TABLE_NAME INSERTS UPDATES DELETES TRU
------------------------------ ---------- ---------- -------------
TEST01 1 1 11YES

 

對錶test01執行搜集統計資訊,監控表的資訊會清除:


SQL> execdbms_stats.gather_table_stats(null,'test01');



PL/SQL procedure successfully completed.

SQL> selecttable_name,INSERTS,UPDATES,DELETES,truncated fromuser_tab_modifications;

no rows selected

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.