Sunteți pe pagina 1din 5

How-to trace oracle sessions?

| Alex Zeng's Blog

http://alexzeng.wordpress.com/2008/08/01/how-to-trace-oracle-sessions/

Alex Zeng's Blog


A Database Engineer's blog auto 90% work; semi-auto the next 9%; for the rest 1%, C'est la vie
GO

HOME HOME

AUTOMATION AUTOMATION

ORACLE

MYSQL MYSQL

MONGODB

CASSANDRA

ABOUT

POSTS

COMMENTS

How to delete duplicated rows

How-To Efficiently Truncate/Drop A Table With Many Extents

Visitor map

How-to trace oracle sessions?


AUGUST 1, 2008 9 COMMENTS

There are lots of methods to trace oracle sessions.

1. alter session set events 10046 trace name context forever,level 12;

Recent Posts
A script to format pseudo code

alter session set tracefile_identifier=10046; alter session set timed_statistics = true; alter session set statistics_level=all; alter session set max_dump_file_size = unlimited;

# Expert Oracle Practices # Troubleshooting Latch Contention How-to avoid ssh prompt for password How-to Find & Replace a string in all files within a directory

Start trace:

# Expert Oracle Practices # Statistics # Expert Oracle Practices # Managing the Very

alter session set events 10046 trace name context forever,level 12;

Large Database # Expert Oracle Practices # Choosing a

Stop trace:

Performance Optimization Method # Expert Oracle Practices # Understanding

alter session set events 10046 trace name context off;

Performance Optimization Methods Oracle session, server process and virtual circuit in shared server mode (MTS)

Note: level can be 4,8,12, only trace your own session

A script to debug cacti A script to check cacti

2. Using package DBMS_MONITOR


# Expert Oracle Practices # PL/SQL and the CBO A script to delete folder later than X days

EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE(session_id => 27, serial_num =>Backup 60,waits => Cacti script EXECUTE DBMS_MONITOR.SESSION_TRACE_DISABLE(session_id => 27, serial_num => 60);
Backup MySQL using mysqldump script # Expert Oracle Practices # Battle Against

Trace a module:

Any Guess Oracle Core # RAC, 1-way, 2-way and 3-way block transfer Oracle Core # Hard parse, soft parse, soft soft parse, no parse at all How to install spine for cacti A script to patch oracle binary Copy and verify file from remote host script How-to setup MySQL HA by using keepalived Evaluate Oracle AWR (Automatic Workload Repository) How-to setup mysql replication in simple steps How-to fix MyISAM table after disk full

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/) 1 of 5

4/17/2013 3:55 AM

How-to trace oracle sessions? | Alex Zeng's Blog

http://alexzeng.wordpress.com/2008/08/01/how-to-trace-oracle-sessions/

Oracle Core # Locks and Latches

EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_ENABLE(

Oracle Core # Transactions and Consistency Recommend a book : Scaling Oracle 8i

service_name=>'vasont.world', module_name=>'VasontU.exe',

Shareplex tips How-to re-instantiate tables with LONG column

action_name=>DBMS_MONITOR.ALL_ACTIONS,waits=>TRUE,

for Oracle logical standby How-to create a SQL test case for Oracle support

binds=>TRUE,instance_name=>NULL); EXECUTE DBMS_MONITOR.SERV_MOD_ACT_TRACE_DISABLE(

How-to rebuild a MongoDB node Oracle Core # How does oracle do a data change Redo and Undo

service_name=>'vasont.world',module_name=>'VasontU.exe');

How-to use scripts to create cacti templates How-to find the SQL that using lots of temp tablespace in Oracle

Note: not available before 10g, can trace any session 3. Using package DBMS_SESSION

How-to restore MongoDB from raw data files Get the final blocker sessions in Oracle Oracle Analytic SQL Example:

EXECUTE DBMS_SESSION.SESSION_TRACE_ENABLE(waits => TRUE,

using windowing_clause How-to flush a SQL out library cache in 11g

binds => TRUE); EXECUTE DBMS_SESSION.SESSION_TRACE_DISABLE();

How-to kill oracle sessions as you wish How-to check an oracle sessions uga/pga How-to drop an active oracle user

Note: only trace your own session

How-to add new device to cacti by script SQL Plan Management handy commands

4. Using package DBMS_SYSTEM

How-to write Python for Oracle How-to write Python for MySQL

execute DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION (sid=>507,

How-to write Python for Cassandra How-to write Python for MongoDB

serial#=>4957,sql_trace=>TRUE); execute DBMS_SYSTEM.SET_SQL_TRACE_IN_SESSION (sid=>507,

How-to use cacti to monitor Cassandra How-to use cacti monitor db

serial#=>4957,sql_trace=>FALSE);

Archives
Note: available in 8i/9i/10g, can trace any session, package is wrapped. 5. oradebug Trace session sid=58;select p.PID,p.SPID from v$process p,v$session s where s.paddr = p.addr and s.sid = 58; PID SPID - 32 12943 connect / as sysdba oradebug setospid 12943 //or oradebug unlimit oradebug event 10046 trace name context forever,level 12 oradebug setorapid 32
Kerry Osborne Pythian Blog Tanel Poder Select Month

Blogroll
Alex Fatkulin Alex Gorbachev Andrey S. Nikolaev Latch, mutex and beyond Cary Millsap Jonathan Lewis

Stop trace: oradebug event 10046 trace name context off Note: available in 8i/9i/10g, can trace any session

Tom Kyte

Meta
Register

6. Using DBMS_SUPPORT exec DBMS_SUPPORT.START_TRACE_IN_SESSION(&SID,

Log in Entries RSS

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/) 2 of 5

4/17/2013 3:55 AM

How-to trace oracle sessions? | Alex Zeng's Blog

http://alexzeng.wordpress.com/2008/08/01/how-to-trace-oracle-sessions/

Comments RSS

waits=>true, binds=>true ); exec DBMS_SUPPORT.STOP_TRACE_IN_SESSION( &SID , null ); NOTE: need to install before use
WordPress.com

SQL> connect / AS SYSDBA SQL> @?\rdbms\admin\dbmssupp.sql SQL> GRANT execute ON dbms_support TO schema_owner; SQL> CREATE PUBLIC SYNONYM dbms_support FOR dbms_support;

7. Using trcsess trcsess [output=output_file_name] [session=session_id] [clientid=client_id] [service=service_name] [action=action_name] [module=module_name] [trace_files]

Trace a module: trcsess service=vasont.world module=VasontU.exe trc.log

8. Tracing whole system

alter system set events '10046 trace name context forever,level 12'; or event="10046 trace name context forever,level 12"

Stop system wider trace:

alter system set events '10046 trace name context off';

9. Using trigger to start traces

There may be some situations where it is necessary to trace

the activity of a specific user. In this case a logon trigger

could be used. An example is provided below:

CREATE OR REPLACE TRIGGER SYS.set_trace AFTER LOGON ON DATABASE WHEN (USER like '&USERNAME') DECLARE lcommand varchar(200); BEGIN EXECUTE IMMEDIATE 'alter session set statistics_level=ALL'; EXECUTE IMMEDIATE 'alter session set max_dump_file_size=UNLIMITED'; EXECUTE IMMEDIATE 'alter session set events ''10046 trace

name context forever, level 12''';

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/) 3 of 5

4/17/2013 3:55 AM

How-to trace oracle sessions? | Alex Zeng's Blog

http://alexzeng.wordpress.com/2008/08/01/how-to-trace-oracle-sessions/

END set_trace; /

Last step, after trace processing, using tkprof

tkprof vasont_ora_22103.trc vasont_ora_22103.trc.log sys=no

waits=yes sort=(prscnt, execnt)

Be the first to like this.


FILED UNDER ORACLE

About Alex Zeng I would be very happy if this blog can help you. I appreciate every honest comments. Please forgive me if I'm too busy to reply your comments in time.

9 Responses to How-to trace oracle sessions?


Pirsey says:
April 22, 2009 at 6:47 am

Hey, cool tips. Perhaps Ill buy a glass of beer to the man from that forum who told me to visit your site
Reply

neworacledba says:
February 26, 2010 at 10:10 pm

this is a great post and most needed for daily operational task
Reply

alan says:
March 11, 2010 at 5:14 pm

Nice reference. Thank you.


Reply

jack Nicholson says:


June 19, 2010 at 7:22 am

Good effort to provide such wonderful tip of session tracing enable in all versions of Oracle. Great work. Keep it up.
Reply

Alex says:
July 28, 2010 at 8:58 am

Another good summary about trace sql, http://www.oracle-base.com/articles/10g/SQLTrace10046TrcsessAndTkprof10g.php


Reply

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/) 4 of 5

4/17/2013 3:55 AM

How-to trace oracle sessions? | Alex Zeng's Blog

http://alexzeng.wordpress.com/2008/08/01/how-to-trace-oracle-sessions/

Alex says:
November 16, 2011 at 8:50 am

I agree with aforesaid, this is short, comprehensive and, what is most important, easy for reading and understanding.
Reply

Alex Zeng says:


December 15, 2011 at 3:16 am

Thanks. -Alex
Reply

joseph says:
March 7, 2012 at 3:06 pm

Thanks Tinku head


Reply

B Beberman says:
November 14, 2012 at 6:44 pm

Tukuchi, Thanks very much for you tip


Reply

Leave a Reply

Blog at WordPress.com .

Theme: Enterprise by StudioPress.

Print to PDF without this message by purchasing novaPDF (http://www.novapdf.com/) 5 of 5

4/17/2013 3:55 AM

S-ar putea să vă placă și