SERPland Blog

SQL Trace with Oracle Database

· 551 words · 3 minutes to read

Enable SQL Trace for my own single session:

ALTER SESSION SET SQL_TRACE = TRUE;

Or use a pl/sql program instead:

begin dbms_session.set_sql_trace(true); end;

For other sessions you can use:

BEGIN sys.DBMS_SYSTEM.set_sql_trace_in_session(,,TRUE); END;

Whereby and is to be determined as follows:

SELECT username, sid, serial# FROM v$session WHERE username=xxx

The moreover you can steere whether the trace file contains time measurements:

ALTER SESSION SET TIMED_STATISTCS = TRUE

The trace file lies on the data base server (udump directory) and can be read by means of ftp

get oracle tracefile via ftp

The tracefile can than be visualized. It’s recommended to use TOAD’s TKPROF utility.

Alternatevely, a similar functionality as the SQL_TRACE with TKPROF, described above, can be made also with the Trivadis Utiltity „Explainer “. The Explainer for the SQL statement also materials out and spends also the number of Rows in the Execution plan! Note: In the Tool the COMMAND

ALTER SESSION SET STATISTICS_LEVEL = ALL

needs to be set.


Update 2024

SQL Trace with Oracle Database 🔗

The information provided in the text about enabling SQL Trace for Oracle Database sessions is still valid for the years 2021 to 2024. Enabling SQL Trace for a single session using the command ALTER SESSION SET SQL TRACE TRUE or using a PL/SQL program with dbms_session.set_sql_trace(true) are common practices for performance tuning and debugging in Oracle Database.

In the year 2024, Oracle Database continues to be a popular choice for many organizations for storing and managing their data. The execution plan functionality, SQL tracing capabilities, and tools like TKPROF are still essential for database administrators and developers to optimize the performance of their SQL queries.

However, there have been some updates and advancements in this area over the years. Oracle has introduced new features and tools to enhance performance monitoring and tuning. For example, in recent versions of Oracle Database, there are improvements in automatic SQL tuning and real-time SQL monitoring, which provide more insights into query performance.

Additionally, with the increasing adoption of cloud technologies and containerization, Oracle Database can now be deployed in cloud environments such as Oracle Cloud Infrastructure (OCI) or container platforms like Kubernetes. These changes have implications for how SQL tracing and performance tuning are done in modern Oracle Database environments.

It is worth mentioning that in the year 2024, organizations are increasingly looking into automation and machine learning-based approaches for performance optimization in Oracle Database. Tools that can analyze and recommend optimizations for SQL queries based on historical performance data are gaining popularity.

In conclusion, while the fundamental concepts of SQL tracing with Oracle Database remain the same, there have been updates and advancements in the tools and techniques available for performance tuning and monitoring. Database professionals in 2024 should stay informed about these developments to make the most out of Oracle Database’s capabilities.

Updates in 2024: 🔗

  1. Automated Performance Optimization: Organizations are leveraging automation and machine learning for optimizing SQL query performance in Oracle Database.

  2. Cloud Deployment: Oracle Database is now commonly deployed in cloud environments like Oracle Cloud Infrastructure (OCI) and container platforms such as Kubernetes.

  3. Real-time Monitoring: New features for real-time SQL monitoring and automatic SQL tuning have been introduced in recent versions of Oracle Database.

  4. Enhanced Tools: There are advancements in tools and utilities for performance tuning, beyond TKPROF, to meet the evolving needs of database administrators and developers.