PerformanceTuning 筆記3 從程式設計師的角度來關注librarycache的使用

snowdba發表於2014-11-17
從程式設計師的角度來關注librarycache的使用

1.使用繫結變數的方式減少硬解析:
select employee_id from emplyees where department_id = 10;
select employee_id from emplyees where department_id = 20;

select employee_id from emplyees where department_id = :dept_id;

2.減少動態生成的SQL語句,必要的時候再用

3.編寫SQL語句是按照統一的命名規範,變數的名字要統一,空格縮排要統一

4.遇到事務儘可能的使用procedure,而不是一堆單獨的SQL語句。procedure編譯後直接呼叫就可以,不再需要解析,因此執行效率高。而且在不同的使用者連線到資料庫時,呼叫儲存過程會減少data dictionary cache。

5.v$sql_shared_cursor檢視可以檢視為什麼已經解析過的SQL沒有被重複利用

6.在高併發的系統上,使用統一的使用者名稱訪問資料比通過同義詞訪問資料好一些,可以節約data dictionary cache
select employee_id from hr.employees where department_id = :dept_id; 

7.最好在應用層來區分連線資料庫的使用者,資料庫層儘量使用少量的使用者來連線,減少data dictionary cache

8.業務高峰期避免DDL操作,比如修改表的結果。修改後該表的parse全部失效。

常用的診斷工具如下:
v$sgastat、v$libraraycache、v$sql、v$sqlarea、v$sqltext、v$db_object_cache

SQL> select * from v$sgastat where name='free memory';

POOL         NAME                            BYTES
------------ -------------------------- ----------
shared pool  free memory                  24325200
large pool   free memory                   7503872
java pool    free memory                   4194304

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29047826/viewspace-1335784/,如需轉載,請註明出處,否則將追究法律責任。

相關文章