Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Search and replace editor command in vi Linux/Unix
  • pvmehta.com SQL scripts
    Find which sessions is accessing object that prevent your session to have exclusive locks in Oracle Oracle
  • Configure ssh authentications for RAC Oracle
  • Oracle Connections expire_time and firewall Oracle
  • Gather Stats manually using DBMS_STATS after disabling DBMS_SCHEDULER jobs as previous entry Oracle
  • mutex in Oracle 10.2.0.2 or Oracle 10g Oracle
  • In Addition to previous note, following grants needed on PERFSTAT user. Oracle
  • DBMS_Shared_pool pinning triggers Oracle
  • Oracle 10g Installation/Applying Patches Tips Oracle
  • move_arch_files.ksh Linux/Unix
  • checking redhat linux version Linux/Unix
  • how to find OS block size Oracle
  • Deleting first line and lastline of a file using sed Linux/Unix
  • configUOCIOTTO.ora Oracle
  • Good notes for shared pool Oracle

DBMS_PROFILER for tuning PLSQL programs.

Posted on 21-Apr-2006 By Admin No Comments on DBMS_PROFILER for tuning PLSQL programs.

Sometimes when all the SQL statements are well tuned but the routine still takes noticeable time to execute.

DBMS_PROFILER

Oracle 8i provides a new tool called PL/SQL Profiler. This is a powerful tool to analyze a Program unit execution and determine the runtime behavior.

It gives execution time for individual statemenets in procedure, functtion or package.

This process will be implemented with DBMS_PROFILER package.

Following stats can be generated using this package:

Total # of times each line was executed.

Time spent executing each line. This include SQL statements.

Minimum and maximum duration spent on a specific line of code.

Code that is actually being executed for a given scenario.

CREATION of DBMS_PROFILER Package:

The DBMS_PROFILER package is not automatically created during default installation or creation of the database.

Need to create the package using the profload.sql script. (From $ORACLE_HOME/rdbms/admin)

Create tables for storing statistics either in one central user or in each individual user, using proftab.sql (From $ORACLE_HOME/rdbms/admin). If tables are created in one central user, like SYS, then grant DML privileges to all other users. Create public synonym on the tables with the same name. The tables created are:

PLSQL_PROFILER_RUNS: Run-specific information for the PL/SQL profiler

PLSQL_PROFILER_UNITS: Information about each library unit in a run

PLSQL_PROFILER_DATA: Accumulated data from all profiler runs.

A sequence PLSQL_PROFILER_RUNNUMBER provides the run id.

DBMS_PROFILER.START_PROFILER

This function tells oracle to start the monitoring process.

An identifier needs to be provided wit each run that is used later to retrieve the statistics.

For example,

v_runstatus := dbms_profiler.start_profiler(‘am’ || to_char(sysdate));

DBMS_PROFILER.STOP_PROFILER

This function tells Oracle to stop the monitoring.

For example,

v_runstatus := dbms_profiler.stop_profiler;

DBMS_PROFILER.FLUSH_DATA

The data collected for an execution is held in the memory. This function tells oracle to save this data in profiler tables and clear the memory.

For example,

v_runstatus := dbms_profiler.flush_data;

All above three functions return the following values :

0 : Successful completion.

1 : Incorrect parameters passed (error_parm).

2 : Data flush operation failed (error_io)

-1 : Mismatch between package and database implementation (error_version).

EXAMPLE USING DBMS_PROFILER

I created a small procedure in MCIF schema as following:

This is the procedure i want to tune and observer its runtime behaviour.

procedure pvm

as

begin

dbms_output.put_line(‘Hello World’);

end;

/

/**********************************

** call_prof.SQL, start and trace the procedure. This will also give a RUNID that will be used for

** check_prof.sql and eval_prof.sql scripts.

**********************************/

set head off

set pages 0

select decode(dbms_profiler.start_profiler, ‘0’, ‘Profiler started’, ‘Profiler error’)

from dual;

—< place your routine in the below block >—

set serveroutput on

declare

l_status varchar2(200);

begin

pvm;

end;

/

select decode(dbms_profiler.stop_profiler, ‘0’, ‘Profiler stopped’, ‘Profiler error’) from dual;

select decode(dbms_profiler.flush_data, ‘0’, ‘Profiler flushed’, ‘Profiler error’) from dual;

select ‘runid:’ || plsql_profiler_runnumber.currval from dual;

set head on

set pages 200

This Above PLSQL block will also give you RUNID which you need to monitor. To view more details about RUNID use following script:

/*********************************

*** check_prof.sql. Chech RUNID wise details.

*********************************/

column runid format 99999999

column run_owner format a30

column run_date format a20

column run_comment format a30

column run_total_time format 9999999999999999

column secs format 99999999

set lines 132

set pages 300

SELECT runid,

run_owner,

run_date,

run_comment,

run_total_time/1000000000 as secs

FROM plsql_profiler_runs

ORDER BY runid

/

/**********************************

*** evel_prof.sql .There are many third party tools available to provide customized reports based on this data. Oracle provides profrep.sql and profsum.sql to evaluate data (present in plsqldemo). Following script will provide line by line execution details. The execution time is stored in milli-seconds.

**********************************/

undef runid

undef owner

undef name

column text format a50

set lines 151

set verify off

select s.line “Line”, p.total_occur “Occur”, p.total_time “Msec”, s.text “Text”

from all_source s, (select u.unit_owner, u.unit_name, u.unit_type, d.line#,

d.total_occur, d.total_time/1000000 total_time

from plsql_profiler_data d, plsql_profiler_units u

where u.runid = &&runid

and u.runid = d.runid

and u.unit_number = d.unit_number) p

where s.owner = p.unit_owner (+)

and s.name = p.unit_name (+)

and s.type = p.unit_type (+)

and s.line = p.line# (+)

and s.name = upper(‘&&name’)

and s.owner = upper(‘&&owner’)

order by s.line;

select exec.cnt/total.cnt * 100 “Code% coverage”

from (select count(1) cnt

from plsql_profiler_data d, plsql_profiler_units u

where d.runid = &&runid

and u.runid = d.runid

and u.unit_number = d.unit_number

and u.unit_name = upper(‘&&name’)

and u.unit_owner = upper(‘&&owner’)) total,

(select count(1) cnt

from plsql_profiler_data d, plsql_profiler_units u

where d.runid = &&runid

and u.runid = d.runid

and u.unit_number = d.unit_number

and u.unit_name = upper(‘&&name’)

and u.unit_owner = upper(‘&&owner’)

and d.total_occur > 0) exec;

undef runid

undef owner

undef name

/****************************

MY executions

****************************/

5:47:18 temp@AWRTEST:-> @call_prof

Profiler started

1 row selected.

Elapsed: 00:00:00.01

Hello World

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.00

Profiler stopped

1 row selected.

Elapsed: 00:00:00.04

Profiler flushed

1 row selected.

Elapsed: 00:00:00.01

runid:12

1 row selected.

Elapsed: 00:00:00.00

15:47:28 temp@AWRTEST:-> @check_prof

RUNID RUN_OWNER RUN_DATE RUN_COMMENT SECS

——— —————————— ——————– —————————— ———

1 MCIF 16-MAR-06 pvm: 16-MAR-06 0

2 MCIF 16-MAR-06 16-MAR-06 0

3 SYS 21-APR-06 21-APR-06 0

4 MCIF 21-APR-06 21-APR-06 0

5 MCIF 21-APR-06 21-APR-06 0

6 MCIF 21-APR-06 21-APR-06 0

7 MCIF 21-APR-06 21-APR-06 0

8 SYS 21-APR-06 21-APR-06 0

9 MCIF 21-APR-06 21-APR-06 0

10 MCIF 21-APR-06 21-APR-06 0

11 MCIF 21-APR-06 21-APR-06 0

12 MCIF 21-APR-06 21-APR-06 0

12 rows selected.

Elapsed: 00:00:00.01

15:48:16 temp@AWRTEST:-> @eval_prof

Enter value for runid: 12

Enter value for name: pvm

Enter value for owner: MCIF

Line Occur Msec Text

——— ——— ——— ————————————————–

1 0 .00367 procedure pvm

2 as

3 begin

4 1 .030977 dbms_output.put_line(‘Hello World’);

5 1 .003687 end;

5 rows selected.

Elapsed: 00:00:00.23

Code% coverage

————–

66.666667

1 row selected.

Elapsed: 00:00:00.04

15:49:07 temp@AWRTEST:->

Oracle, SQL scripts

Post navigation

Previous Post: Renaming the column name
Next Post: SCRIPT TO LIST RECURSIVE DEPENDENCY BETWEEN OBJECTS UTLDTREE.sql

Related Posts

  • _B_TREE_BITMAP_PLANS issue during 8.1.7 to 9.2.0.8 upgrade Oracle
  • Temporary tablespace explaination Oracle
  • Find All internal Parameters Oracle
  • find_err.sql for finding errors from dba_errors. Oracle
  • longtx.sql Oracle
  • fkwoindex.sql /* Find FK without Index */ Oracle

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (392)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025
  • V$INSTANCE of Oracle in MYSQL24-Jul-2025
  • Day to day MYSQL DBA operations (Compared with Oracle DBA)24-Jul-2025
  • MYSQL and Oracle Comparison for Oracle DBA24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Jai Shree Ram PHP/MYSQL/Wordpress
  • v$event_name Oracle
  • Temporary Tablespace Information and restriction. Oracle
  • How do I get Oracle to automatically start when my server boots up? Oracle
  • Getting started with notebook Python/PySpark
  • sql_plan9i.sql Oracle
  • newupload.html PHP/MYSQL/Wordpress
  • GSQ.sql Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme