How to Use SQL Trace and TKPROF in Oracle 19c Database

YouTube video


In this article, we will explore the process of using SQL Trace and TKPROF in Oracle 19c database. These are powerful tools that can help in monitoring and diagnosing the performance of applications running on an Oracle server. We will discuss the steps involved in enabling SQL Trace, generating trace files, and analyzing them using TKPROF. By following these steps, you can gain valuable insights into the performance of your application and identify areas for improvement.

Understanding SQL Trace and TKPROF

SQL Trace and TKPROF are performance diagnostic tools provided by Oracle. SQL Trace facility provides detailed performance information about individual SQL statements. It generates statistics related to execution and fetch counts, elapsed times, physical and logical IOs, and other important metrics. TKPROF, on the other hand, is used to format the contents of the trace files generated by the SQL Trace facility into a human-readable format.

Enabling SQL Trace

To enable SQL Trace facility, you need to set certain initialization parameters. These parameters determine when tracing should be enabled and what information should be recorded. Once the SQL Trace facility is enabled, performance statistics for all executed SQL statements in a session or instance are placed into trace files. It’s important to note that enabling SQL Trace does come with some overhead, but it is insignificant compared to the inefficiencies caused by the application itself.

Analyzing Trace Files with TKPROF

Once the trace files are generated, you can use TKPROF to analyze them. TKPROF can format the trace files into a more readable output, making it easier to understand the performance characteristics of your application. It can also generate execution plans for SQL statements and provide information about the resources consumed by each statement.

Step by Step Process

Step 1: Enabling SQL Trace

  1. Set the necessary initialization parameters to enable trace files generation.
  2. Make sure you know how to distinguish trace files by name and location.
  3. Ensure that your operating system has enough disk space to accommodate the generated trace files.
  4. Understand that trace files can be owned by an operating system user other than yourself, so ensure you have access to them.

Step 2: Enabling SQL Trace for a Session or Instance

  1. For a session: set the session-level parameter alter session set sql_trace=true/false.
  2. For an instance: set the instance-level parameter alter system set sql_trace=true/false.

Step 3: Formatting Trace Files with TKPROF

  1. Use TKPROF to format the trace files into a more readable output.
  2. TKPROF can generate execution plans and provide statistics on SQL statements.
  3. Use TKPROF options to filter out unnecessary information and focus on resource-intensive statements.

Step 4: Interpreting TKPROF Output

  1. The TKPROF output provides valuable information about the efficiency and performance of your application.
  2. The output includes statistics such as execution and fetch counts, physical and logical IOs, and CPU time spent.
  3. Be cautious of the accuracy of timing statistics for operations that execute very quickly.


In this article, we have discussed the process of using SQL Trace and TKPROF in Oracle 19c database. By enabling SQL Trace and analyzing the generated trace files using TKPROF, you can gain insights into the performance of your application and identify areas for improvement. It’s important to follow the steps outlined in this article and carefully interpret the TKPROF output to make informed decisions about performance tuning.