Procedure 效能檢測與調整方法
SELECT COUNT (*)
FROM dba_objects
WHERE object_name = 'DBMS_PROFILER'
如果有結果返回說明已經建立了這個Package,就不需要再建立跳過第二步。
2:建立DBMS_PROFILE package
Sys: 建立Package
$ORACLE_HOME/rdbms/admin/proftab.sql
SELECT *
FROM dba_objects
WHERE object_name LIKE '%PROFILE%' AND object_type IN
('TABLE', 'SEQUENCE')
ORDER BY last_ddl_time DESC
SYS PLSQL_PROFILER_DATA
SYS PLSQL_PROFILER_UNITS
SYS PLSQL_PROFILER_RUNS
SYS PLSQL_PROFILER_RUNNUMBER ----就這四個Table.
DECLARE
err NUMBER;
BEGIN
err :=DBMS_PROFILER.start_profiler (TO_CHAR (SYSDATE, 'YYYY-MM-DD
HH24:MI:SS'));
-- You need to test procedure
err := DBMS_PROFILER.stop_profiler;
END;
5:產看test_procedure_name 每句SQL/PLSQL 的執行時間。
SELECT p.unit_name, p.occured, p.tot_time, p.line# line,
SUBSTR (s.text, 1, 75) text
FROM (SELECT u.unit_name, d.total_occur occured, u.unit_type TYPE,
(d.total_time / 1000000000) tot_time, d.line#
FROM SYS.plsql_profiler_units u, SYS.plsql_profiler_data d
WHERE d.runid = u.runid
AND d.unit_number = u.unit_number
AND d.total_occur > 0) p,
SYS.user_source s
WHERE p.unit_name = s.NAME(+)
AND p.line# = s.line(+)
AND p.TYPE = s.TYPE(+)
AND p.unit_name = 'COLL_TEST'
ORDER BY p.unit_name, p.line#;
6:測試用例:
建立procedure:
CREATE OR REPLACE PROCEDURE coll_test
IS
CURSOR big_emp_curs
IS
SELECT ename FROM big_emp;
cnt NUMBER;
ename VARCHAR2 (30);
BEGIN
FOR be_r IN big_emp_curs
LOOP
ename := be_r.ename;
END LOOP;
SELECT COUNT (*) INTO cnt FROM big_emp WHERE ename = 'SCOTT';
SELECT COUNT (*) INTO cnt FROM big_emp;
EXECUTE IMMEDIATE 'CREATE INDEX idx_big_emp ON big_emp(ename)';
SELECT COUNT (*) INTO cnt FROM big_emp WHERE ename = 'SCOTT';
ename := 'DUMMY';
END coll_test;
收集procedure coll_test 執行時間。
DECLARE
err NUMBER;
BEGIN
err :=
DBMS_PROFILER.start_profiler (TO_CHAR (SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
);
coll_test; -- You need to test procedure
err := DBMS_PROFILER.stop_profiler;
END;
檢視收集結果:
SELECT p.unit_name, p.occured, p.tot_time, p.line# line,
SUBSTR (s.text, 1, 75) text
FROM (SELECT u.unit_name, d.total_occur occured, u.unit_type TYPE,
(d.total_time / 1000000000) tot_time, d.line#
FROM SYS.plsql_profiler_units u, SYS.plsql_profiler_data d
WHERE d.runid = u.runid
AND d.unit_number = u.unit_number
AND d.total_occur > 0) p, -- change 28 to the selected runid
SYS.user_source s
WHERE p.unit_name = s.NAME(+)
AND p.line# = s.line(+)
AND p.TYPE = s.TYPE(+)
AND p.unit_name = 'COLL_TEST'
ORDER BY p.unit_name, p.line#;
UNIT_NAME OCCURED TOT_TIME LINE TEXT
--------------- ------- ----------- ---------- --------------------------------------------------
COLL_TEST 1 .000042 1 PROCEDURE coll_test
COLL_TEST 1 .169419 5 SELECT ename FROM big_emp;
COLL_TEST 4733 1.988260 10 FOR be_r IN big_emp_curs
COLL_TEST 473074 .347261 12 ename := be_r.ename;
COLL_TEST 1 .143458 15 SELECT COUNT (*) INTO cnt FROM big_emp WHERE ename = 'SCOTT';
COLL_TEST 1 .117456 17 SELECT COUNT (*) INTO cnt FROM big_emp;
COLL_TEST 1 .123682 20 SELECT COUNT (*) INTO cnt FROM big_emp WHERE ename = 'SCOTT';
COLL_TEST 1 .000006 21 ename := 'DUMMY';
COLL_TEST 1 .000055 22 END coll_test;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/34596/viewspace-592107/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【效能調整】系統檢視(二)
- 【效能調整】系統檢視(一)
- 用於效能調整的動態效能檢視——效能調整手冊和參考
- Oracle效能調整之--DML語句效能調整Oracle
- oracle 效能調整Oracle
- oracle效能調整(1)Oracle
- oracle效能調整(2)Oracle
- ORACLE效能調整--1Oracle
- ORACLE效能調整---2Oracle
- Oracle 效能調整for HWOracle
- (zt)Oracle效能調整Oracle
- oracle效能調整2Oracle
- 【效能調優】效能測試、分析與調優基礎
- mysql效能的檢查和調優方法MySql
- Oracle效能最佳化調整--調整重做機制Oracle
- 網路調整——效能調整手冊和參考
- Oracle效能調整筆記Oracle筆記
- 【效能調整】等待事件(一)事件
- 【效能調整】等待事件(二)事件
- Oracle效能調整-1(轉)Oracle
- Oracle效能調整-2(轉)Oracle
- Oracle效能調整-3(轉)Oracle
- 效能測試之測試分析與調優
- OWI效能診斷與調整實踐指南(1~4)
- Tomcat效能調整完整教程Tomcat
- Oracle效能調整的誤區Oracle
- Oracle高效能SQL調整OracleSQL
- oracle效能調整筆記[zt]Oracle筆記
- ORACLE之常用FAQ:效能調整Oracle
- 【效能調整】海量資料的效能設計
- 效能測試知多少---效能分析與調優的原理
- 讀書筆記-高階owi與oracle效能調整-io筆記Oracle
- 讀書筆記-高階owi與oracle效能調整-segment筆記Oracle
- 讀書筆記-高階owi與oracle效能調整-transaction筆記Oracle
- Oracle Wait Interface效能診斷與調整實踐指南OracleAI
- [書籍] Oracle Database 10g效能調整與優化OracleDatabase優化
- Oracle 9i效能調整 [ZT]Oracle
- oracle效能優化-共享池調整Oracle優化