儲存過程優化(DBMS_HPROF)
今天介紹推薦一個11g以後優化儲存過程的利器“DBMS_HPROF”,官方推薦11g以上可以使用DBMS_HPROF來分析優化儲存過程。具體使用方法如下。資料庫版本(11.2.0.4.0)
1.Unlock Scott
SQL> conn /as sysdba
Connected.
SQL> alter user scott account unlock;
User altered.
SQL> alter user scott identified by oracle;
User altered.
2.Create procedure p1 with user Scott
Create or replace procedure p1 is
N number;
Procedure p2 is
begin
select count(*) into n from emp;
end;
begin
for j in 1..1000 loop
p2;
end loop;
end;
/
3.Create Directory Alias and profiling results in a trace file
SQL> Create or replace directory prof_dir as '/dwtest/dba';
Directory created.
4.grant execute on DBMS_HPROF to scott
SQL> grant execute on DBMS_HPROF to scott;
Grant succeeded.
5.enable Dbms_hprof and generate t.trc
Begin
Dbms_hprof.start_profiling('PROF_DIR','t.trc');
End;
/
SQL> Begin
2 Dbms_hprof.start_profiling('PROF_DIR','t.trc');
3 End;
4 /
PL/SQL procedure successfully completed.
6.User Scott execu P1
SQL> conn scott/oracle
Connected.
SQL> begin
2 p1;
3 end;
4 /
PL/SQL procedure successfully completed.
7.disable Dbms_hprof
SQL> begin
2 dbms_hprof.stop_profiling;
3 end;
4 /
PL/SQL procedure successfully completed.
8.In order to process the captured information, additional tables and database objects related to the profiling utility need to be created within the SCOTT schema. The Hierarchical Profiler tables can be created by running
SQL> @?/rdbms/admin/dbmshptab.sql
Table dropped.
Table dropped.
Table dropped.
Sequence dropped.
Table created.
Comment created.
Table created.
Comment created.
Table created.
Comment created.
Sequence created.
9.Display some of the newly created tables
SQL> SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME LIKE 'DBMSHP_%';
TABLE_NAME
------------------------------
DBMSHP_RUNS
DBMSHP_PARENT_CHILD_INFO
DBMSHP_FUNCTION_INFO
10.DBMS_HPROF.ANALYZE processes the raw trace file generated by data collection component and produces hierarchial information in hierarchial profiler database tables created by executing the above script. The following SQL illustrates how to run this command in SQL*Plus
SQL> Var runid number;
SQL>
SQL> Begin
2 :runid:=dbms_hprof.analyze(location=>'PROF_DIR', filename=>'t.trc',run_comment=>'Run one');
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> SQL> print :runid;
RUNID
----------
1
11.The command line plshprof utility can be used to generate html report. The following command runs the plshprof utility and generates a file (t.html) based on the profile information captured within file t.trc. Notice that the output file name is simply 't' and the report automatically assigns the html extension.
hostname:/dwtest/dba$plshprof -output /dwtest/dba/t /dwtest/dba/t.trc
PLSHPROF: Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
[3 symbols processed]
[Report written to '/dwtest/dba/t.html']
hostname:/dwtest/dba$ls -l
total 144
-rw-r--r-- 1 oracle dba 2461 May 30 17:54 t.html
-rw-r--r-- 1 oracle dba 245 May 30 17:48 t.trc
-rw-r--r-- 1 oracle dba 1039 May 30 17:54 t_2c.html
-rw-r--r-- 1 oracle dba 1067 May 30 17:54 t_2f.html
-rw-r--r-- 1 oracle dba 890 May 30 17:54 t_2n.html
-rw-r--r-- 1 oracle dba 1858 May 30 17:54 t_fn.html
-rw-r--r-- 1 oracle dba 2304 May 30 17:54 t_md.html
-rw-r--r-- 1 oracle dba 2298 May 30 17:54 t_mf.html
-rw-r--r-- 1 oracle dba 2296 May 30 17:54 t_ms.html
-rw-r--r-- 1 oracle dba 787 May 30 17:54 t_nsc.html
-rw-r--r-- 1 oracle dba 815 May 30 17:54 t_nsf.html
-rw-r--r-- 1 oracle dba 682 May 30 17:54 t_nsp.html
-rw-r--r-- 1 oracle dba 5098 May 30 17:54 t_pc.html
-rw-r--r-- 1 oracle dba 2055 May 30 17:54 t_tc.html
-rw-r--r-- 1 oracle dba 1937 May 30 17:54 t_td.html
-rw-r--r-- 1 oracle dba 2083 May 30 17:54 t_tf.html
-rw-r--r-- 1 oracle dba 1929 May 30 17:54 t_ts.html
12.Display design sketch
########################################################################################
版權所有,文章允許轉載,但必須以連結方式註明源地址,否則追究法律責任!【QQ交流群:53993419】
QQ:14040928 E-mail:dbadoudou@163.com
本文連結: http://blog.itpub.net/26442936/viewspace-2109404/
########################################################################################
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26442936/viewspace-2109404/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle優化案例-儲存過程的優化思路(二十三)Oracle優化儲存過程
- MySQL優化---儲存過程和儲存函式-1-轉自部落格園MySql優化儲存過程儲存函式
- SQL Server儲存過程的優缺點SQLServer儲存過程
- Oracle儲存過程乾貨(一):儲存過程基礎Oracle儲存過程
- SQL 儲存過程裡呼叫另一個儲存過程SQL儲存過程
- 儲存過程與儲存函式儲存過程儲存函式
- SQLSERVER儲存過程SQLServer儲存過程
- 呼叫儲存過程儲存過程
- mysql 儲存過程MySql儲存過程
- unidac儲存過程儲存過程
- firedac儲存過程儲存過程
- Oracle儲存過程Oracle儲存過程
- JdbcTemplate調儲存過程JDBC儲存過程
- 造數儲存過程儲存過程
- 儲存過程——遊標儲存過程
- 儲存過程 傳 datatable儲存過程
- JAVA儲存過程(轉)Java儲存過程
- MySQL之儲存過程MySql儲存過程
- oracle的儲存過程Oracle儲存過程
- MySQL---------儲存過程MySql儲存過程
- linux呼叫儲存過程Linux儲存過程
- Winform呼叫儲存過程ORM儲存過程
- mysql儲存過程整理MySql儲存過程
- Oracle儲存過程-1Oracle儲存過程
- Sql儲存過程分頁--臨時表儲存SQL儲存過程
- mongo 儲存過程詳解Go儲存過程
- Sqlserver中的儲存過程SQLServer儲存過程
- SQL 分頁儲存過程SQL儲存過程
- 原創:oracle 儲存過程Oracle儲存過程
- jsp中呼叫儲存過程JS儲存過程
- 資料庫儲存過程資料庫儲存過程
- mybatis儲存過程返回listMyBatis儲存過程
- Mysql 儲存過程的使用MySql儲存過程
- mysql如何呼叫儲存過程MySql儲存過程
- mysql和orcale的儲存過程和儲存函式MySql儲存過程儲存函式
- mssql 儲存過程呼叫另一個儲存過程中的結果的方法分享SQL儲存過程
- MySQL儲存過程 (即函式)MySql儲存過程函式
- SqlServer-儲存過程分頁SQLServer儲存過程
- openGauss 支援儲存過程除錯儲存過程除錯