Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Oracle Standby Database Library Index from Metalink Oracle
  • fdisk -l explaination about Primary-Logical-Extended Partitions Linux/Unix
  • Adding or Dropping Online Redo Log Files When Physical Standby in place Oracle
  • Jai Shree Ram Oracle
  • Gather Stats manually using DBMS_STATS after disabling DBMS_SCHEDULER jobs as previous entry Oracle
  • Jai Shree Ram Oracle
  • oracle 11g RAC on vmware Oracle
  • Set Role explaination. Oracle
  • New OFA for 11g Oracle
  • Backup and Recovery Scenarios Oracle
  • Exadata Basics Oracle
  • Best approach for Oracle database patching sequence to latest/required patchset along with CPU/PSU/any-other-one-off patch ID 865255.1 Oracle
  • chk_space_SID.ksh Linux/Unix
  • Running select from V$ views from remote server Linux/Unix
  • RAC with RHEL4 and 11g Oracle

Trace a SQL session from another session using ORADEBUG

Posted on 30-Sep-202530-Sep-2025 By Admin No Comments on Trace a SQL session from another session using ORADEBUG

Find the SPID from Oracle’s SID using below SQL.

REM **** This is used to get SPID from SID.
col username format a30
col machine format a20
col program format a40
accept _sid prompt 'Enter Oracle Session ID ->'
select a.sid, b.pid, b.spid, a.username,
a.program,a.machine
from v$session a,V$process b
where a.paddr = b.addr
and   a.sid = &_sid
/

Use ORADEBUG command as below.

oradebug setospid <SPID_FROM_QRY>
oradebug unlilimit
oradebug tracefile_name
oradebug event 10046 trace name context forever, level 12
—- Run some queries for which you want traces.
oradebug event 10046 trace name context off

Now, we have tracefile_name available. Use TKPROF utility to analyze the tracefile contents generated via 10046 trace as below: 

 🔹 What is tkprof?

tkprof is a utility that formats Oracle SQL trace files into human-readable reports.

Suppose you have a trace file: ora_1234.trc

Run:

tkprof ora_1234.trc report.prf sys=no sort=exeela,fchela
  • sys=no → exclude SYS schema SQL (noise)

  • sort=exeela,fchela → sort by execution elapsed time and fetch elapsed time

Now open report.prf to analyze performance.


🔹 Common tkprof Options

OptionPurpose
sys=noExcludes recursive SQL from SYS
sort=optionSorts SQLs by performance metric
explain=user/passwordAdds explain plan info
aggregate=yes/noWhether to group identical SQLs
insert=filename.sqlCreates a SQL script of all statements

🔹 Cheat Sheet – Most Useful sort Options

Sort OptionMeaning
prselaParse elapsed time
prscpuParse CPU time
exeelaExecution elapsed time
execpuExecution CPU time
fchelaFetch elapsed time
fetchpuFetch CPU time
diskDisk reads
queryConsistent gets
currentCurrent (buffer) gets
rowsRows processed

👉 Example:

tkprof ora_1234.trc top_sql.prf sys=no sort=exeela,disk,rows

This shows the most expensive SQLs by elapsed time, disk reads, and rows processed.

Oracle, SQL scripts

Post navigation

Previous Post: SQL Server Vs Oracle Architecture difference

Related Posts

  • eplan9i.sql Oracle
  • Rman Notes -1 Oracle
  • This is from Temi Oracle
  • Oracle Standby Database Library Index from Metalink Oracle
  • Pending Distributed Transations Oracle
  • Good Oracle Architecture In Short and point to point 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 (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • 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

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • Monitor and Trace Unix processes using truss Linux/Unix
  • How to choose Driver table in SQL statement Oracle
  • ipcs -l Linux/Unix
  • Metalink Note: Note:250655.1 : ADDM Basics USING THE AUTOMATIC DATABASE DIAGNOSTIC MONITOR Oracle
  • Configure ssh authentications for RAC Oracle
  • Find execution plan from dba_hist_sql_plan for a specific SQL_ID and PLAN_HASH_VALUE fplan.sql Oracle
  • Useful Solaris Commands on 28-SEP-2005 Linux/Unix

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme