Oracle 鎖定暫存資料表統計資訊

來源:互聯網
上載者:User

標籤:style   ar   color   os   sp   on   bs   ef   tt   

  全域暫存資料表的統計資訊是不能被收集的,如果被收集,它的統計資訊肯定為0,會造成執行計畫不準,所以要鎖定它的統計資訊,禁止系統自動收集。

--先解鎖表的統計資訊,然後刪除表的統計資訊,最後鎖住表的統計資訊

declare

  v_sqlvarchar2(500);

  cursor rowList1 is

   select‘begin dbms_stats.unlock_table_stats(user,‘‘‘ || table_name ||‘‘‘); end;‘

     from user_tables s

   where s.temporary = ‘Y‘; 

  cursor rowList2 is

   select‘begin dbms_stats.delete_table_stats(user,‘‘‘ || table_name ||‘‘‘); end;‘

     from user_tables s

   where s.temporary = ‘Y‘;

  cursor rowList3 is

   select‘begin dbms_stats.lock_table_stats(user,‘‘‘ || table_name ||‘‘‘); end;‘

     from user_tables s

   where s.temporary = ‘Y‘;  

begin

  open rowList1;

  open rowList2;

  open rowList3;

  loop

    fetch rowList1  into v_sql;

       executeimmediate v_sql;

    exitwhen rowList1%notfound;

  endloop;

  loop

    fetch rowList2  into v_sql;

       executeimmediate v_sql;

    exitwhen rowList2%notfound;

  endloop;

  loop

    fetch rowList3  into v_sql;

       executeimmediate v_sql;

    exitwhen rowList3%notfound;

  endloop;   

  close rowList1;

  close rowList2;

  close rowList3;

end;

-- STATTYPE_LOCKED=‘ALL‘意思是表的統計資訊被鎖

select s.table_name,s.STATTYPE_LOCKEDfrom user_TAB_STATISTICS s  where s.STATTYPE_LOCKED=‘ALL‘;

Oracle 鎖定暫存資料表統計資訊

聯繫我們

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