Skip to main content

How to Run the SQL Tuning Advisor

🧱 How to Run SQL Tuning Advisor (STA) in Oracle

The SQL Tuning Advisor (STA) is a powerful tool in Oracle that helps database administrators identify and resolve performance issues in SQL statements. This guide provides a step-by-step approach to using STA effectively.

In this guide, we'll walk you through a clean and safe method to create a new tuning task, execute it, check its status, and view the recommendations.


πŸ”§ Step-by-Step Instructions

1️⃣ Create the Tuning Task for the Given SQL_ID

DECLARE
  l_sql_tune_task_id  VARCHAR2(100);
BEGIN
  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                          sql_id      => 'abc123xyz7890',
                          scope       => DBMS_SQLTUNE.scope_comprehensive,
                          time_limit  => 60,
                          task_name   => 'abc123xyz7890_tuning_task',
                          description => 'Tuning task for statement abc123xyz7890');
  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

Note: Replace 'abc123xyz7890' with your actual SQL_ID.

2️⃣ Execute the Tuning Task

EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'abc123xyz7890_tuning_task');

3️⃣ Check the Status of the Tuning Task

SELECT TASK_NAME, STATUS 
FROM DBA_ADVISOR_LOG 
WHERE TASK_NAME = 'abc123xyz7890_tuning_task';

4️⃣ View the Tuning Advice

SET LONG 65536
SET LONGCHUNKSIZE 65536
SET LINESIZE 999
SET PAGESIZE 999

SELECT DBMS_SQLTUNE.report_tuning_task('abc123xyz7890_tuning_task') FROM dual;

Note: Share this output with the team requesting the STA analysis.


⚙️ Additional Options

πŸ—‘️ Drop a Tuning Task

EXEC DBMS_SQLTUNE.drop_tuning_task('abc123xyz7890_tuning_task');

⏸️ Interrupt a Tuning Task

EXEC DBMS_SQLTUNE.interrupt_tuning_task(task_name => 'abc123xyz7890_tuning_task');

▶️ Resume a Tuning Task

EXEC DBMS_SQLTUNE.resume_tuning_task(task_name => 'abc123xyz7890_tuning_task');

⚠️ Handling Common Errors

❌ Error: ORA-13780 – SQL Statement Does Not Exist

This error occurs when the SQL_ID isn't present in the cursor cache but exists in the AWR snapshots. To address this, identify the relevant snapshot IDs and create the tuning task using them:

DECLARE
  l_sql_tune_task_id VARCHAR2(100);
BEGIN
  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                          begin_snap => 51164,
                          end_snap   => 51165,
                          sql_id     => 'abc123xyz7890',
                          scope      => DBMS_SQLTUNE.scope_comprehensive,
                          time_limit => 3600,
                          task_name  => 'abc123xyz7890_tuning_task',
                          description=> 'Tuning task for statement abc123xyz7890');
  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/

Note: Replace 51164 and 51165 with your actual snapshot IDs.

⏱️ Error: ORA-13639 – Operation Interrupted Due to Timeout

This indicates that the tuning task exceeded its time limit. To resolve this, increase the time_limit parameter when creating the tuning task:

DECLARE
  l_sql_tune_task_id VARCHAR2(100);
BEGIN
  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                          begin_snap => 51164,
                          end_snap   => 51165,
                          sql_id     => 'sample123sqlid',
                          scope      => DBMS_SQLTUNE.scope_comprehensive,
                          time_limit => 7200, -- Increased time limit in seconds
                          task_name  => 'sample123sqlid_tuning_task',
                          description=> 'Tuning task for statement sample123sqlid');
  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
Adjust the time_limit value depending on the complexity of the SQL statement.

🎯 This method is an efficient way for Oracle DBAs to run the SQL Tuning Advisor without having to manually intervene and continuously adjust settings.

Comments

Popular posts from this blog

πŸš€ Automating Oracle Database Patching with Ansible: A Complete Guide

Oracle database patching has long been the bane of DBAs everywhere. It's a critical task that requires precision, expertise, and often results in extended maintenance windows. What if I told you that you could automate this entire process, reducing both risk and downtime while ensuring consistency across your Oracle estate? πŸ’‘ In this comprehensive guide, I'll walk you through a production-ready Ansible playbook that completely automates Oracle patch application using OPatch. Whether you're managing a single Oracle instance or hundreds of databases across your enterprise, this solution will transform your patch management strategy! 🎯 πŸ”₯ The Challenge: Why Oracle Patching is Complex Before diving into the solution, let's understand why Oracle patching is so challenging: πŸ”— Multiple dependencies : OPatch versions, Oracle Home configurations, running processes ⚠️ Risk of corruption : Incorrect patch application can render databases unusable ⏰ Downtime requirements : Da...

🐳Oracle 19c Database Deployment with Docker

Oracle 19c Database Deployment with Docker 🐳 Oracle 19c Database Deployment with Docker Welcome to this comprehensive guide on deploying, configuring, and managing Oracle 19c Database using Docker containers. This blog will walk you through the entire process from setup to production best practices with practical code examples. Docker provides an excellent way to run Oracle databases in isolated, portable containers, making it easy to deploy and manage Oracle 19c instances for development, testing, and production environments. This approach offers numerous benefits: πŸ”’ Isolation : Run Oracle in a containerized environment without affecting your host system 🚚 Portability : Easily move your database between different environments πŸ”„ Reproducibility : Quickly spin up identical database instances ⚡ Resource Efficiency : Use Docker's resource management capabilities to control CPU, memory, and stor...

πŸš€ DB BOT: Real-Time Oracle & GoldenGate Monitoring in Slack

In today's fast-paced DevOps environment, quick access to database metrics is essential. This blog will walk you through creating a Slack bot that provides real-time monitoring of Oracle databases and Golden Gate replication. With simple slash commands, your team can check tablespace usage, Flash Recovery Area status, and Golden Gate replication health directly in Slack. Project Overview Our "DB Bot" offers these key capabilities: Monitor tablespace usage across multiple Oracle databases Check Flash Recovery Area (FRA) status on multiple databases View GoldenGate process status across different servers List GoldenGate credential stores Monitor replication lag in GoldenGate Prerequisites Node.js v14+ Python 3.6+ Oracle client libraries (instantclient_21_19) Access to Oracle databases and GoldenGate servers A Slack workspace with permissions to add apps   Project Structure oracle-slack-bot...