Skip to main content

Steps to Purge SQL Plan from the Shared Pool

🧱 Steps to Purge SQL Plan from the Shared Pool

In some cases, after assigning an SQL profile for a particular SQL_ID, it may not be used as expected. This guide will help you ensure that the SQL profile is being used and, if necessary, purge the SQL plan from the shared pool to force the system to reoptimize and apply the assigned SQL profile.


πŸ”§ Step-by-Step Instructions

1️⃣ Verify if the SQL Profile is Being Used

Before purging any SQL plan, you should first check if the assigned SQL profile is being used. Run the following query to check:

select distinct
    p.name sql_profile_name,
    s.sql_id
from
    dba_sql_profiles p,
    DBA_HIST_SQLSTAT s
where
    p.name = s.sql_profile
    and sql_id = '5dj81jnf8t03a';  -- Replace with your SQL_ID

If the profile is being used, the output will display the associated SQL profile name. Alternatively, you can use the DBMS_XPLAN function to check the SQL profile:

SELECT * FROM TABLE(DBMS_XPLAN.display_cursor('&sqlid'));

If the profile is being used, you will see a note like the following:

Note
-----
   - SQL profile SYS_SQLPROF_02630dc612e60001 used for this statement

2️⃣ Find the SQL Plan's Address and Hash Value

If the SQL profile is not being applied, the next step is to find the address and hash value of the SQL plan for your SQL_ID. Run the following query to retrieve this information:

SELECT ADDRESS, HASH_VALUE 
FROM V$SQLAREA 
WHERE SQL_ID = '5dj81jnf8t03a';  -- Replace with your SQL_ID

The output will provide the address and hash value, as shown below:

ADDRESS          HASH_VALUE
----------------  ----------
00000010B774F9D8  478969962

3️⃣ Purge the SQL Plan from the Shared Pool

Once you have the address and hash value, you can purge the SQL plan from the shared pool by executing the following command:

EXEC DBMS_SHARED_POOL.PURGE('00000010B774F9D8, 478969962', 'C');

In this command:

  • '00000010B774F9D8' is the ADDRESS of the plan.
  • '478969962' is the HASH_VALUE.
  • 'C' specifies that the cursor (SQL plan) should be purged.

4️⃣ Verify if the SQL Plan is Flushed from Memory

After purging the plan, check again to see if it has been removed from memory by running this query:

SELECT ADDRESS, HASH_VALUE 
FROM V$SQLAREA 
WHERE SQL_ID = '5dj81jnf8t03a';  -- Replace with your SQL_ID

If no rows are returned, the plan has been successfully flushed out from memory.

5️⃣ Recheck if the SQL Profile is Now Being Used

Finally, go back to Step 1 and verify again if the SQL profile is now being applied. If the profile is being used, you have successfully ensured that the assigned SQL profile is applied to the SQL_ID.


🧠 Why Purge SQL Plans?

  • Forces the database to reoptimize a query, applying the latest SQL profile and any optimizations.
  • Helps in situations where the database isn't using the assigned profile as expected.
  • Clears any plans that might have been stuck in memory, preventing performance issues.

🚨 Best Practices

  • Only purge SQL plans when necessary to avoid unnecessary performance overhead.
  • Ensure that the SQL profile is correctly created and assigned before purging the plan.
  • Use DBMS_SHARED_POOL.PURGE carefully as it affects the shared pool memory.

🎯 This process helps ensure that your Oracle database is using the correct SQL profile and that the system is optimized for query performance.

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...

Mastering Oracle RAC with CRSCTL commands

Mastering Oracle Clusterware Administration: Essential Commands & Best Practices Oracle Clusterware is a key component for managing cluster environments, ensuring high availability and resource management for Oracle databases. Below are essential commands for managing Oracle Clusterware effectively. What is crsctl? crsctl (Cluster Ready Services Control) is a command-line utility provided by Oracle to manage Oracle Clusterware. It allows administrators to start, stop, check, and configure various aspects of cluster services. With crsctl , DBAs can control cluster resources, manage voting disks, check the status of Oracle High Availability Services, and ensure the proper functioning of Oracle RAC environments. Starting and Stopping Oracle Clusterware On Local Node Stop Clusterware: crsctl stop cluster Start Clusterware: crsctl start cluster On RAC Standalone/Oracle Restart Stop Cluster: crsctl stop has Start Cluster: crsctl start has On All Nodes or All Hub Nodes Start Clusterware:...