如何正確地分析Oracle資料庫模式,表及索引

來源:互聯網
上載者:User

在Oracle 資料庫中,我們經常需要去手工分析表和索引,還有某個模式下所有的表和索引等等。oracle 提供了兩種分析方法,分別是dbms_stats 包和analyze 命令。這些是我們在日常專案管理中的真實使用的方法,供參考。

在10g 中分析某一個使用者下所有的對象,如user_miki 使用者

sys.dbms_stats.gather_schema_stats(ownname => 'user_miki',estimate_percent => 30,method_opt => 'FOR ALL INDEXED COLUMNS SIZE AUTO',cascade => true,options => 'GATHER');

這是我在項目中分析一個使用者所有對象的分析方法,取樣比例為30% ,分析所有索引欄位,產生直條圖,並且也分析索引。

在10g 中分析某一個使用者下某一個表及其索引,如user_miki 使用者下info 表和它的索引

execute dbms_stats.gather_table_stats(ownname => 'user_miki',tabname => 'info',estimate_percent => 30,method_opt => 'for all indexed columns size auto');

這是我在項目中單獨分析一個使用者中一張表的分析方法,取樣比例為30% ,分析所有索引欄位,產生直條圖,並且也分析索引。

我們在google 時,還能看到使用analzye  命令分析表的方法。
analyze table   table_name compute statistics;
這個會將索引和表一起分析;
analyze table table_name compute statistics for table;
這個僅分析表;
analyze table table_name compute statistics for all columns;
這個僅分析表,和上面所有的欄位,產生直條圖
analyze table table_name compute statistics for all indexed columns;
這個僅分析表,和上面所有建立索引的欄位,產生直條圖
在9i 中,我們常常使用analyze 方法,在10g 以後,就改為dbms_stats.gather_schema_stats 類似的包來分析資料庫對象了。
10g 的分析函數包比9i 的analyze 方法更靈活一些。
在10g 中,會有個系統的計劃任務,每天10 點和周末兩天都自動分析新的資料庫物件和它認為統計資訊已經到期的資料庫物件。這個分析結果有時候不靠譜。
因此,我都採用10g 中提供的dbms_stats.gather_schema_stats 方法作為補充,設定一個計劃任務定期去分析業務使用者下所有資料庫物件。

更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.