Oracle體繫結構知識點的運用

來源:互聯網
上載者:User

標籤:

體繫結構方面的最佳化問題:

  1. 設資料庫很大,訪問量非常高,共用池很小:這樣共用池裡面就無法儲存很多解析過得sql語句,導致很多硬解析,這樣資料庫就非常緩慢。這個時候要加大共用池。如果是自動管理,就加大SGA的大小。
  2. 設:某平時不經常訪問的資料庫的主機才4G記憶體,去開闢了3G的SGA,500m的PGA,由於OS作業系統記憶體不足,導致主機運行緩慢,我們要減少SGA大小。
  3. 如果由於資料緩衝區過小而產生的大量物理讀,則要增大SGA。
  4. 如果排序使用了暫存資料表空間,就說明PGA過小,如果系統有額外的大量記憶體,可以考慮多分配一部分給PGA(一般是OLAP系統)
  5. 如果資料庫有大量的更新操作,產生大量的日誌導致日誌切換頻繁,在日誌切換過程中,資料庫會停滯運行,為了提高效能,需要加大記錄檔的大小。
  6. 如果某個應用因為老是查出ORA-01555錯誤而無法把值給下一個模組使用,導致生產出現故障。需要檢查為什麼這個sql執行這麼慢。最佳化的方法:加索引,清理曆史資料,讓表的記錄小一點,或者增大undo_retention的值(這個值只是建議值,非強制),也可以增大undo資料表空間。

具體的sql最佳化:

  1. 構造環境 + 未最佳化(單車速度:40+秒
    sqlplus drop table t purge;create table t (x int);alter system flush shared_pool;set timing on
    create or replace procedure proc1as begin    for i in 1..100000    loop        execute immediate        ‘insert into t values(‘||i||’)’;    commit;    end loop;end;/
    exec proc1;
    col sql_text format a30
    set pagesize 1000
    select t.sql_text,t.sql_id,t.parse_calls,t.executions from v$sql t where sql_text like ‘%insert into t values%‘ and rownum<100;
  2. ##resetpool.sql:
    drop table t purge;create table t(x int);alter system flush shared_pool;set pagesize 1000col sql_text format a30
  3. 綁定變數,摩托速度:8+秒
    create or replace procedure proc2asbegin        for i in 1..100000        loop                execute immediate                ‘insert into t values( :x )‘ using i;                commit;        end loop;end;/
    select t.sql_text,t.sql_id,t.parse_calls,t.executions from v$sql t where sql_text like ‘%insert into t values%‘;
  4. 靜態改寫,汽車速度:6+秒
    create or replace procedure proc3asbegin        for i in 1..100000        loop                insert into t values( i );                commit;        end loop;end;/
  5. 批量提交,動車速度:2秒
    create or replace procedure proc4asbegin        for i in 1..100000        loop                insert into t values( i );        end loop;commit;end;/
  6. 集合寫法,飛機速度:.14秒
    insert into t select rownum from dual connect by level <=100000;
  7. 直接路徑,火箭速度:.89秒,在10萬的時候是.23所以需要量才能看得出來快了。
    create table t as select rownum x from dual connect by level <= 1000000;
  8. 並行設定,飛船速度:需要有多cpu:本機實測1.05秒比6效能差,一般在機器空閑而且效能強大時用。
    create table t nologging parallel 4 as select rownum x from dual connect by level <=1000000;

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.