Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

Free Oracle Tips

HTML Text

 Home
 E-mail Us
 Oracle Articles



 Oracle Training
 Oracle News

 Oracle Forum
 Class Catalog


 Our Staff
 Our Prices
 Help Wanted!

 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 UNIX
 Oracle UNIX
 Linux
 Oracle Linux
 Monitoring
 Remote help

 Remote plans
 Remote
services
 Oracle C++
 Oracle Java
 Apache
 JDeveloper
 App Server

 Applications
 Oracle Forms
 Oracle Portal
 11i Upgrades
 SQL Server
 Oracle Concepts
 HTML-DB Tips
 Software Help

 Remote Help  
 Development  

 Implementation


 Financials Training
 Oracle 11i
 Oracle Apps 11i
 Oracle Workflow
 Oracle AR 11i Class
 Oracle AP 11i class
 Oracle GL 11i class
 Oracle HR 11i class
 Oracle FA 11i class
 11i Project Mgt
 11i procurement
 11i collections


 Oracle Posters
 Oracle Books

 Oracle Tuning Book
 Oracle RAC Book
 Oracle Security
 Easy Oracle Books
 Oracle Scripts
 SQL Server DBA
 SQL Design Patterns
 WISE
 Excel-DB   


 BC Oracle News


 Rednecks!
 Dress code
 Arabian Stallion

 Burleson Arabians
 Guide Horses
 Don Burleson Blog
 Golf & Travel


 Privacy Policy
 

 

 
 

Oracle SQL top sessions


Oracle Tips by Burleson Consulting
 

This is an excerpt from my latest book "Oracle Tuning: The Definitive Reference", and you can download the working scripts from the code depot. 

Identifying Problem SQL

One short path to identifying performance problems in an Oracle database includes the following steps:

§       Find the sessions responsible for hogging the most resources (I/O, CPU, etc.).

§       Identify the code these sessions are running.

§       Peel away the bad code these sessions have executed from the good and acceptable code.

§       Highlight the worst SQL and then work to tune it for better performance.

This process has been made much easier in Oracle9i and Oracle10g, especially with respect to identifying problem SQL that gets run in a production database. The following sections work through these four steps and see how several performance views can assist in this process.

Find the Problem Sessions

Even if there is no database monitor that offers a top sessions view, it is easy to pinpoint the sessions that are giving the database grief. Different database professionals have their own ideas about what constitutes a top session. Some feel that the sum total of physical I/O alone tells the story, while others look at CPU, and still others use a combination of physical and logical I/O.

 

Whatever the preference, the script in top_20_sessions.sql can be used to quickly bubble to the top twenty sessions in an Oracle database. The initial sort is on physical I/O, but this can be changed to any other column desired.

 

§       top_20_sessions.sql

 

 

select * from

(select b.sid sid,

     decode (b.username,null,e.name,b.username) user_name,

     d.spid os_id,

     b.machine machine_name,

     to_char(logon_time,'dd-mon-yy hh:mi:ss pm') logon_time,

    (sum(decode(c.name,'physical reads  ',value,0)) +

     sum(decode(c.name,'physical writes',value,0)) +

     sum(decode(c.name,'physical writes direct',value,0)) +

     sum(decode(c.name,'physical writes direct (lob)',value,0))+

     sum(decode(c.name,'physical reads  direct (lob)',value,0)) +

     sum(decode(c.name,'physical reads   direct',value,0)))

     total_physical_io,

    (sum(decode(c.name,'db block gets',value,0)) +

     sum(decode(c.name,'db block changes',value,0)) +

     sum(decode(c.name,'consistent changes',value,0)) +

     sum(decode(c.name,'consistent gets ',value,0)) )

     total_logical_io,

    (sum(decode(c.name,'session pga memory',value,0))+

     sum(decode(c.name,'session uga memory',value,0)) )

     total_memory_usage,

     sum(decode(c.name,'parse count (total)',value,0)) parses,

     sum(decode(c.name,'cpu used by this session',value,0))

     total_cpu,

     sum(decode(c.name,'parse time cpu',value,0)) parse_cpu,

     sum(decode(c.name,'recursive cpu usage',value,0))

       recursive_cpu,

     sum(decode(c.name,'cpu used by this session',value,0)) -

     sum(decode(c.name,'parse time cpu',value,0)) -

     sum(decode(c.name,'recursive cpu usage',value,0))

       other_cpu,

     sum(decode(c.name,'sorts (disk)',value,0)) disk_sorts,

     sum(decode(c.name,'sorts (memory)',value,0)) memory_sorts,

     sum(decode(c.name,'sorts (rows)',value,0)) rows_sorted,

     sum(decode(c.name,'user commits',value,0)) commits,

     sum(decode(c.name,'user rollbacks',value,0)) rollbacks,

     sum(decode(c.name,'execute count',value,0)) executions

from sys.v_$sesstat  a,

     sys.v_$session b,

     sys.v_$statname c,

     sys.v_$process d,

     sys.v_$bgprocess e

where a.statistic#=c.statistic# and

SEE CODE DEPOT FOR FULL SCRIPTS

      c.NAME in ('physical reads  ',

                 'physical writes',

                 'physical writes direct',

                 'physical reads   direct',

                 'physical writes direct (lob)',

                 'physical reads   direct (lob)',

                 'db block gets',

                 'db block changes',

                 'consistent changes',

                 'consistent gets ',

                 'session pga memory',

                 'session uga memory',

                 'parse count (total)',

                 'CPU used by this session',

                 'parse time cpu',

                 'recursive cpu usage',

                 'sorts (disk)',

                 'sorts (memory)',

                 'sorts (rows)',

                 'user commits',

                 'user rollbacks',

                 'execute count'

)

group by b.sid,

         d.spid,

         decode (b.username,null,e.name,b.username),

         b.machine,

         to_char(logon_time,'dd-mon-yy hh:mi:ss pm')

order by 6 desc)

where rownum < 21

 

SEE CODE DEPOT FOR FULL SCRIPTS

 

The above query can also be modified to exclude Oracle background processes, the SYS and SYSTEM user, etc. The end result should be a current list of top offending sessions in the database as ranked by various performance metrics, which is the normal way to rank problem user accounts. Figure 15.15 shows a sample output of this query:

 

Figure 15.15: The WISE tool sample top_20_sessions.sql query output

 

Some DBAs feel that this method, while useful, lacks depth. Specifically, because DBAs know that a user’s resource consumption is almost always tied to inefficient SQL, they would like to cut to the chase and find the problem sessions in a database that have, for example, caused most of the large table scans on the system or have submitted queries containing Cartesian joins.

 

Such a thing was difficult to determine in earlier versions of Oracle, but fortunately, 9i provides a new performance view that can be used to derive such data. The v$sql_plan  view contains execution plan data for all submitted SQL statements. Such a view provides a wealth of information regarding the performance and efficiency of SQL statements and the sessions that submitted them.

SEE CODE DEPOT FOR FULL SCRIPTS


This is an excerpt from my latest book "Oracle Tuning: The Definitive Reference". 

You can buy it direct from the publisher for 30%-off and get instant access to the code depot of Oracle tuning scripts:

http://www.rampant-books.com/book_2005_1_awr_proactive_tuning.htm

 


    Need an Oracle Health Check?
  • Do you have bad performance after an upgrade?
     
  • Need to certify that your database follows best practices?

BC Oracle performance gurus can quickly certify every aspect of your Oracle database and provide a complete verification that your database is fully optimized.

 

 

 

 
 
 

Oracle performance tuning book

 

 

Oracle performance tuning software

 
Oracle performance tuning software
 
SearchOracle web site
 
Oracle performance Tuning 10g reference poster
 
Oracle performance tuning webcast
 
Oracle training in Linux commands
 
Oracle training Excel
 
Oracle training & performance tuning books
 

 

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals. 
Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.
 
 


Burleson Consulting

The Oracle of database support


 

Copyright © 1996 -  2007 by Burleson Enterprises, Inc. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.


Hit Counter