TKPROF using trace analyzer to trace SQL

Introduction

In this tutorial, we will explore how to use TKPROF with a trace analyzer to trace SQL in an Oracle Database Server. Optimizing SQL performance is crucial for the efficiency and responsiveness of your database applications. One of the powerful tools available for this purpose is TKPROF, a trace file analyzer provided by Oracle.

This guide will introduce you to TKPROF and show you how to use it effectively to trace and analyze SQL performance. By understanding and utilizing TKPROF, you can gain deep insights into your SQL execution, identify performance bottlenecks, and make informed optimizations to enhance your database’s performance.

Syntax of the TKPROF Command

The TKPROF command has several options that allow you to customize its behavior. Here is the syntax:

tkprof tracefile outputfile [explain= ] [table= ]
              [print= ] [insert= ] [sys= ] [sort= ]

Options of TKPROF command

table=schema.tablename: Use 'schema.tablename' with 'explain=' option.
explain=user/password: Connect to ORACLE and issue EXPLAIN PLAN.
print=integer: List only the first 'integer' SQL statements.
aggregate=yes|no: Aggregate multiple trace files.
insert=filename: List SQL statements and data inside INSERT statements.
sys=no: TKPROF does not list SQL statements run as user SYS.
record=filename: Record non-recursive statements found in the trace file.
waits=yes|no: Record summary for any wait events found in the trace file.
sort=option: Set of zero or more of the following sort options:
  prscnt: number of times parse was called
  prscpu: CPU time parsing
  prsela: elapsed time parsing
  prsdsk: number of disk reads during parse
  prsqry: number of buffers for consistent read during parse
  prscu: number of buffers for current read during parse
  prsmis: number of misses in library cache during parse
  execnt: number of times execute was called
  execpu: CPU time spent executing
  exeela: elapsed time executing
  exedsk: number of disk reads during execute
  exeqry: number of buffers for consistent read during execute
  execu: number of buffers for current read during execute
  exerow: number of rows processed during execute
  exemis: number of library cache misses during execute
  fchcnt: number of times fetch was called
  fchcpu: CPU time spent fetching
  fchela: elapsed time fetching
  fchdsk: number of disk reads during fetch
  fchqry: number of buffers for consistent read during fetch
  fchcu: number of buffers for current read during fetch
  fchrow: number of rows fetched
  userid: user ID of the user that parsed the cursor

How to Use Trace Analyzer to Trace SQL

Connect to the Database

[oracle11g@DBdevopsroles ~]$ sqlplus DBUSER/DBUSER@ORACLE_SID
SQL> set termout off
SQL> alter session set timed_statistics = true;
SQL> alter session set sql_trace = true;
SQL> SELECT COUNT(*) from tablename01;
SQL> alter session set sql_trace = false;

Use Trace with TKPROF Command

[oracle11g@DBdevopsroles ~]$ tkprof /app/oracle11g/diag/rdbms/ORACLE_SID/trace/ORACLE_SID_ora_4196.trc ORACLE_SID_ora_4196.txt explain=DBUSER/DBUSER@ORACLE_SID width=200

Confirm Output Destination

SQL> show parameter user_dump_dest
TKPROF using trace analyzer to trace SQL

Conclusion

In this tutorial, we covered how to use the TKPROF command with a trace analyzer to trace SQL in an Oracle Database. Using TKPROF to analyze SQL performance is an invaluable skill for any database administrator or developer. By following the steps outlined in this guide, you should now be able to trace and analyze SQL execution efficiently, uncover performance issues, and implement necessary optimizations.

Continuous monitoring and analysis with TKPROF will ensure that your SQL queries run smoothly and efficiently, contributing to the overall health and performance of your database systems. Keep exploring and mastering TKPROF to become proficient in SQL performance tuning. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology, especially Devops Skill such as Docker, vagrant, git, and so forth. I like open-sources, so I created DevopsRoles.com to share the knowledge I have acquired. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.