sar -n ALL 1
ORACLE DATABASE PROBLEM AND SOLUTIONS
Dream Always Dream , if you don't work on it : Real-world Oracle DBA troubleshooting guides for RAC, Data Guard, RMAN, performance tuning, upgrades, backups, and cloud migration. Tested in production environments.
Thursday, July 30, 2026
How to Check SQL_IDs Having Multiple PLAN_HASH_VALUE ?
identify SQL_IDs having multiple PLAN_HASH_VALUEs by grouping on SQL_ID and counting distinct PLAN_HASH_VALUE. This is very useful for finding SQLs with plan instability or plan changes.
Oracle execution plans can be checked from the cursor cache using views like V$SQL, and detailed plans can be displayed using DBMS_XPLAN.DISPLAY_CURSOR .
Oracle documents that DBMS_XPLAN can display plans from cached cursors, AWR, SQL tuning sets, and SQL plan baseline
1. Check SQL_IDs Having Multiple PLAN_HASH_VALUEs in Current Memory
Use this query on V$SQL.
Meaning
SQL_ID: SQL statement identifierPLAN_COUNT: number of different plans used by the SQLPLAN_HASH_VALUES: list of plan hash valuesTOTAL_EXECUTIONS: total executions from cursor cache
If one SQL_ID has more than one PLAN_HASH_VALUE, it means Oracle has generated multiple execution plans for the same SQL.
2. Detailed Child Cursor Level Query
This gives more detail for each SQL_ID, child cursor, and plan hash value.
This is useful when you want to see which child cursor used which plan.
3. Group PLAN_HASH_VALUE Against Each SQL_ID
If you want a grouped summary of all SQL_IDs and their plan hash values:
This output shows one row per:
Example output:
4. Check Only One Specific SQL_ID
If you want to check plan hash values for one SQL ID:
Example:
5. Historical Check from AWR
If you want to check SQL_IDs with multiple plans historically, use DBA_HIST_SQLSTAT.
Use this when the SQL is not present in V$SQL, or you want to analyze old plan changes. Oracle documents that DBMS_XPLAN.DISPLAY_AWR can display execution plans stored in AWR. [docs.oracle.com]
6. Historical Grouping by SQL_ID and PLAN_HASH_VALUE
This is good for performance comparison between plans.
7. Best Query for Plan Instability Report
For DBA troubleshooting, this is usually the most useful query:
This shows SQLs that had multiple plans and consumed the most elapsed time.
8. RAC-Aware Query
If your database is RAC, include INST_ID from GV$SQL.
To find SQL_IDs with multiple plans across RAC:
9. Display Execution Plan for Each PLAN_HASH_VALUE
After finding multiple plan hash values, display the plan using:
For historical AWR plan:
Recommended Quick Script
Plan Hash Grouping Summary
Use this if your goal is simply:
“Group plan hash value against SQL ID.”
SQL_IDs having multiple plan hash values and executions more than 5
SQL_IDs Having More Than One PLAN_HASH_VALUE
Yes, to find SQL_IDs where PLAN_HASH_VALUE is more than 1, meaning the same SQL_ID has used multiple execution plans, use COUNT(DISTINCT plan_hash_value) > 1.
SQL_IDs Having More Than One PLAN_HASH_VALUE
If You Also Want Executions Greater Than 5
Detailed Output Per SQL_ID and PLAN_HASH_VALUE
Use this after identifying SQL_IDs with multiple plans:
Best RAC Version Using GV$SQL
If it is a RAC database, use this:
Key Condition
This is the main condition to find SQL IDs having multiple plan hash values.
DBA Tip
If a SQL_ID has multiple PLAN_HASH_VALUEs, check:
- Statistics changes
- Bind peeking
- Adaptive cursor sharing
- Different optimizer environment
- Index creation or drop
- SQL profile
- SQL baseline
- Object invalidation
- RAC instance-specific plan difference
Step by Step How to Check PLAN_HASH_VALUE Against SQL_ID in Oracle ?
Check PLAN_HASH_VALUE Against SQL_ID in Oracle ?
1. Objective
To verify which PLAN_HASH_VALUE is associated with a specific SQL_ID in Oracle.
This is useful when:
- Checking if SQL execution plan changed
- Troubleshooting SQL performance issues
- Comparing current and historical plans
- Validating SQL Plan Baseline usage
- Investigating plan regression
2. Required Input
You need the SQL ID.
Example:
If you do not have the SQL ID, you can search it from V$SQL using part of the SQL text.
3. Check Current PLAN_HASH_VALUE from Cursor Cache
Use this query when the SQL is currently present in the shared pool.
Example
How to Read the Output
If output shows:
It means the same SQL ID has multiple child cursors and multiple execution plans.
4. Check Distinct PLAN_HASH_VALUE for a SQL_ID
Use this if you only want the list of unique plan hash values.
Example
5. Check PLAN_HASH_VALUE with Execution Statistics
This query helps identify which plan is used most frequently.
Interpretation
CHILD_COUNTshows how many child cursors used the same plan.TOTAL_EXECUTIONSshows how often that plan was executed.- Multiple
PLAN_HASH_VALUEentries can indicate plan changes or different optimizer choices.
6. Display Current Execution Plan Using DBMS_XPLAN
Use DBMS_XPLAN.DISPLAY_CURSOR to see the actual cached execution plan. Oracle documentation states that DISPLAY_CURSOR displays the execution plan of a loaded cursor.
Example
Notes
cursor_child_no => NULLdisplays all child cursors for that SQL ID.ALLSTATS LASTshows actual runtime statistics for the last execution if statistics are available.- If no rows are returned, the SQL may not be available in the cursor cache.
7. Display Plan for a Specific Child Cursor
If the SQL ID has multiple child cursors, check a specific one.
Example
This is useful when bind values, optimizer outlines, or child cursor differences need to be reviewed.
8. Check Historical PLAN_HASH_VALUE from AWR
If the SQL is no longer in memory, check AWR history.
Example
Oracle documentation confirms that DBMS_XPLAN can display execution plans stored in AWR using DISPLAY_AWR
9. Display Historical Execution Plan from AWR
Use this when you know the historical PLAN_HASH_VALUE.
Example
10. Check Plan Changes Over Time
This query shows when each plan was used across AWR snapshots.
This is helpful for identifying whether a SQL performance issue started after a plan change.
11. Check SQL Plan Baseline for the SQL_ID
If SQL Plan Management is used, check whether the SQL has a baseline.
Oracle documentation states that DBMS_XPLAN can also display execution plans from SQL plan baselines.
12. Display SQL Plan Baseline
If you get a SQL_HANDLE from the previous query, use:
13. Complete Quick-Check Script
Use this as a ready-to-run script.
14. Common Issues and Checks
Issue 1: No rows from V$SQL
Possible reasons:
- SQL aged out of shared pool
- SQL not executed recently
- Wrong SQL ID
- Query executed in another PDB or RAC instance
Use AWR:
Issue 2: Multiple PLAN_HASH_VALUE values
Possible reasons:
- Bind peeking
- Adaptive cursor sharing
- Statistics changed
- Different optimizer environment
- SQL profile or baseline added
- Object/index changes
Issue 3: DBMS_XPLAN.DISPLAY_CURSOR gives insufficient data
Try enhanced format:
Final Recommended Flow
Best Quick Query
If you need only one query to check the plan hash value for a SQL ID:
Troubleshooting Privileges
You may need access to views like V$SQL, V$SQL_PLAN, V$SESSION, and V$SQL_PLAN_STATISTICS_ALL for DISPLAY_CURSOR; Oracle documents these privilege requirements for DBMS_XPLAN.DISPLAY_CURSOR.
How to check execution plan hash value (PLAN_HASH_VALUE) for a specific SQL_ID ?
Check execution plan hash value (PLAN_HASH_VALUE) for a specific SQL_ID
If you want to check the execution plan hash value (PLAN_HASH_VALUE) for a specific SQL_ID in Oracle, use one of these queries:
Current Cursor Cache (V$SQL)
Historical Plans from AWR (DBA_HIST_SQLSTAT)
Get Detailed Plan Information (DBMS_XPLAN)
For the current plan in memory:
Check All Plans Associated with a SQL_ID
Check SQL Plan Baselines (if used)
Example
For SQL_ID 5g8t1m9n2abc3:
This will return the plan hash value(s) Oracle is currently using for that SQL statement. If multiple rows are returned, the SQL has been executed with different plans (e.g., due to Adaptive Plans, bind peeking, or plan evolution).
How to Run Oracle SQL tuning Advisor against sql_id ?
Run SQL tuning Advisor against sql_id :
@?/rdbms/admin/sqltrpt.sql
TASK_13481
It will prompt you for the SQL details, usually SQL_ID, tuning scope, and report options depending on your Oracle version.
1. Check available SQL Tuning Advisor tasks
Run as DBA/SYS:
For your specific task:
Expected status should ideally be:
If the task is not completed, do not accept the profile yet.
2. Check SQL Tuning Advisor executions for the task
3. Check findings for the task
Look for findings related to:
4. Check recommendations for the task
If SQL Profile is recommended, you should see a recommendation type related to SQL Profile.
5. Generate SQL Tuning Advisor report before accepting profile
If your Oracle version does not accept owner_name, use:
Review the report carefully before accepting. SQL Tuning Advisor can recommend SQL Profiles, indexes, stats collection, SQL rewrite, or SQL Plan Baselines.
6. Check if SQL Profile already exists
Before running ACCEPT_SQL_PROFILE, check existing profiles:
Search for a profile related to this task or SQL:
7. Accept SQL Profile from the task
Your command is broadly correct:
I usually prefer giving the profile a meaningful name:
Use this only after the report confirms a SQL Profile recommendation with good estimated benefit.
8. Verify the accepted SQL Profile
Check if it is enabled:
Expected:
9. Disable or drop if needed
Disable profile:
Drop profile:
Recommended validation sequence
For your case, run in this order:
Only after confirming the recommendation, execute:
Monday, July 27, 2026
How to know and troubleshoot how much time a session has waited on each wait event ?
If you want to know how much time a session has waited on each wait event, here are the most useful queries.
1. Current Session Wait Information
For a specific session:
This shows the current wait event and how long the session has been waiting.
2. Session Wait History (Recent Waits)
Output example:
This is usually the first query I use.
3. Total Time Spent by a Session in Each Wait Event
Example:
4. All Active Sessions with Their Top Waits
5. Using ASH (Last 1 Hour)
If Diagnostics Pack is licensed:
Note: Each ASH sample ≈ 1 second.
6. Historical Session Waits from AWR
7. Find the Top Wait Event for a Session
Most Useful DBA Query
Replace 123 with the session ID:
To get the total wait time aggregated by wait event across all logged-in sessions, use:
If you also want to see the number of sessions affected by each wait event:
To identify the top wait events by active user:
And if you're troubleshooting performance, exclude idle waits:
This last query is typically the most useful because it highlights only the waits that contribute to database response-time issues.
How to troubleshoot and get to know about current top wait events since oracle database instance startup ?
To get the current top wait events since instance startup, use:
Top Wait Events by Total Wait Time (%)
Current Active Waits (Right Now)
Top Wait Events from ASH (Last 1 Hour)
AWR Top Wait Events for Last 24 Hours
Quick DBA Query (Most Useful)
This gives the top waits consuming database time:
If you're investigating a performance issue right now, also run:
This shows the exact sessions, SQL_IDs, and wait events currently contributing to the database slowdown.
Monitor network speed
sar -n ALL 1
-
C:\Users\Administrator.ANURAG-PC>tnsping ducat TNS Ping Utility for 32-bit Windows: Version 11.2.0.1.0 - Production on 27-DEC-2017 21:...
-
Error while starting ./runInstaller for oracle 19c installation on Linux 8 [oracle@ip-192-168-43-225 oracle]$ ./runInstaller /u01/or...
-
Install CSSCAN login with SYS user @?/rdbms/admin/csminst.sql ############### csscan \"sys as sysdba\" full=y ...