Disabling a SQL plan baseline in Oracle means turning off one accepted plan so the optimizer can't select it, usually by setting that plan's ENABLED flag to NO in DBA_SQL_PLAN_BASELINES, or by blocking all baselines for a statement so it optimizes as if none existed. The condition that trips people up: a baseline stays visible in the dictionary with its origin and timestamps intact, so "disabled" is a status, not a deletion. Everything below depends on which scope you actually want neutralized: one plan, every baseline for one SQL statement, or every baseline in the whole database.
The usual trigger is a plan that looked good when it was captured and looks wrong after data growth, an Oracle upgrade, or a schema change. Maybe a baseline captured during a maintenance window now produces a nested-loop join that doesn't finish. Disabling it is reversible and leaves an audit trail, which is why it's the first move before anyone reaches for DBMS_SQLTUNE.DROP_SQL_PLAN_BASELINE.
Prerequisites: privileges, versions, and a before-state snapshot
You need the EXECUTE privilege on DBMS_SQLTUNE and SELECT on the data dictionary views that hold baseline metadata — DBA_SQL_PLAN_BASELINES or, from your own account, USER_SQL_PLAN_BASELINES. On a multitenant database you connect to the PDB that owns the SQL, not to the root. These procedures require the database to be running with the SQL Management Base configured; DBMS_SQLTUNE has shipped with Oracle Database since 10g, though baseline support arrived in 11g, and the accepted-plan behavior below is what 11g onward through current 19c and 23ai releases use.
Before touching anything, record what exists. Run this against the target statement, identified by its SQL ID or by text with sql_text =>:
Pull the SQL_HANDLE and the PLAN_NAME values. The handle is the stable identifier of the statement's baseline set; plan names are per-plan. Save the output somewhere — in a comment in the change script, in your ticket system, wherever. This snapshot is your rollback record, and it's also the check that the change actually landed later.
One more thing to confirm: whether the baseline affects the statement at all. A baseline only overrides the optimizer if the initialization parameter optimizer_use_sql_plan_baselines is TRUE (the default). If someone set it to FALSE at the session or system level, no baseline is being used and disabling one changes nothing. Check with SHOW PARAMETER optimizer_use_sql_plan_baselines.
Disable a single baseline with DBMS_SQLTUNE
The workhorse is DBMS_SQLTUNE.ALTER_SQL_PLAN_BASELINE, which accepts a list of attribute/value pairs. The attribute to change is enabled, and the new value is NO. You must supply both identifiers: the SQL_HANDLE and either the PLAN_NAME or a NULL plan name. Passing a plan name targets that one plan.
Run this as the schema owner or a privileged user:
The call returns without error if it applied the change. It does not print a report; success is verified from the dictionary. Query the view again with the same plan name and look for ENABLED = NO in the row. If the plan name matches nothing, the call silently does nothing — the procedure is idempotent on nonexistent plans in most cases, so the view is the only reliable confirmation. To disable every accepted plan for one statement, pass plan_name => NULL:
That second form is the one to use when you suspect several baselines compete for the same statement and you want the optimizer to see none of them. You can also remove the whole set from consideration by emptying the statement's baseline list, which changes nothing about the plans themselves:
That last call assigns an empty SQL text to the handle, which effectively detaches the baseline set from the SQL. It's a niche move; the normal way to make a set "not apply" is changing enabled on the plans. Reserved for cases where a specific statement keeps pulling in plans you can't otherwise neutralize. Don't overuse it, because it makes the dictionary harder to read later.
Which form should you pick? If you have one bad plan among several accepted plans, disabling just that plan lets the remaining plans stay eligible, and the optimizer picks among them. If every plan in the set is misbehaving, disable the whole set. Working one plan at a time is the reversible check — you watch the execution plan on the next execution before committing to more.
Disable every baseline in the database
The bulk form takes a sql_handle of NULL with the same enabled => 'NO' pair. That flips every plan baseline in the current container off, which in a multitenant database is the PDB you're connected to, not the CDB root:
On a busy database that's an immediate, statement-level change for every SQL statement carrying an accepted plan baseline. Queries that were pinned to their former plans become free to re-optimize, and some of them will. On a critical OLTP system this is not a change to make during peak hours, and it's not something the optimizer will quietly reverse; the reverse is another ALTER_SQL_PLAN_BASELINE with 'YES'. Treat the bulk form as a last-resort switch when a systemic problem — say, a bad OPTIMIZER_FEATURES_ENABLE setting that skewed all captures — is forcing you to reset the whole baseline regime.
You can also turn off baseline usage entirely rather than disabling individual baselines:
or system-wide with ALTER SYSTEM ... SCOPE=BOTH. That disables every baseline, everywhere, at the parameter level. It's a bigger hammer than the procedure call, because it changes optimizer behavior for statements that have perfectly good baselines. In practice it gets used for a quick test: set it at session level, run the suspicious statement, and compare execution plans. If the plan changes and the problem goes away, you've isolated a baseline as the culprit. Then revert to TRUE and surgically disable the specific plan.
Worked scenario: one statement, a growing table, and a stabilized plan
Concrete version makes the trade-offs clearer. Some months back, an accounts-payable module in a 19c database captured a baseline for a reporting query during a low-volume period. The accepted plan, let's call it PLAN_A, uses nested-loop joins. Volumes have grown tenfold, and now that plan takes minutes on a table that has thirty million rows, while the original code was written for the six-million-row version. The database has a small window; the DBA wants to hand the optimizer back its freedom for this one SQL ID.
First, identify the affected handle:
Check enabled and fixed. If FIXED = YES, the plan was explicitly marked fixed at capture and is a harder case: fixed plans outrank non-fixed ones, and even a re-optimized plan will not be selected over a fixed plan. You cannot simply "disable" a fixed plan into submission — alter fixed to NO first, or accept that the fixed baseline will keep winning. In the worked example, say FIXED = NO and ENABLED = YES.
Disable the plan:
Confirm:
Expect ENABLED = NO, ACCEPTED = YES. The plan still exists, still has its accepted flag and its timestamps. That combination is what you want: the optimizer will not use it, but the history is preserved.
Next, get the actual plan for the statement. Find the SQL ID from V$SQL by matching text, then:
Compare against the new plan the optimizer produces when you test the statement with the baseline disabled at session level. If the new plan is material — for example a hash join returning more rows per join, fewer logical reads — then the disable is doing its job. If the plan is still the old one, the statement is likely reusing a cached cursor; purge it with ALTER SYSTEM FLUSH SHARED_POOL (or wait for aging) before concluding anything. More than one disable operation is wasted because a cursor in memory hasn't been repopulated.
If the old plan still comes back even after a fresh parse, check whether the plan name you disabled matches the plan actually in use. Baseline-driven plans carry their plan name in V$SQL as PLAN_NAME in the auxiliary view V$SQL_PLAN; you can join to confirm which baseline enforced the current plan. A mismatch here is the most common "I disabled it but nothing happened" report.
Verifying the change: success, failure, and what the optimizer reports
Success looks like three things at once: ENABLED = NO in the dictionary, no baseline selected for the statement's next execution, and the new execution plan appearing in V$SQL_PLAN or via DBMS_XPLAN. The authoritative check is the last one — the dictionary only records intent.
A few failure modes are worth recognizing on sight.
The plan row still shows ENABLED = YES. The ALTER_SQL_PLAN_BASELINE call didn't match the handle/plan name pair. Re-read the exact values from the view; case matters and exact spelling matters. Enumeration of the view shows no baseline for the statement at all, but the plan is stable. The statement may be governed by a SQL Profile (DBA_SQL_PROFILES), an SQL Patch, or a fixed system parameter. Check V$SQL.PLAN_HASH_VALUE and the SQL tuning advisor records before chasing baselines. You changed enabled, but the execution plan is unchanged on the next execution. The cursor is still in memory. Flush shared pool on a test system, or wait for the cursor to age out on production; don't flush production for a test. The plan is disabled but performance is worse. That's possible: the accepted plan may have been choosing the lesser evil compared to bad statistics, stale indexes, or missing cardinality feedback. Disabling a baseline doesn't refresh statistics or invalidate cursors on its own. Run DBMS_STATS.GATHER_TABLE_STATS on the relevant tables and, for the cursor, examine whether the new plan is itself the problem. The right order is usually: fix statistics, then touch baselines.
Disable versus drop, disable versus disable-for-all: a trade-off table
Two distinct questions get confused here. Disabling is reversible, keeps audit history, and changes which plans are eligible. Dropping is destructive of the baseline evidence and generally not advisable without a clear reason.
| Action | Procedure call | Baseline row remains | Reversible by | Suitable when |
|---|---|---|---|---|
| Disable one plan | alter_sql_plan_baseline ... enabled => 'NO' | Yes, with timestamps | Setting enabled => 'YES' | One accepted plan is making things worse |
| Disable all plans for a statement | Same, with plan_name => NULL | Yes | Same call with 'YES' | Multiple competing baselines on one statement |
| Disable every baseline in the PDB | sql_handle => NULL, plan_name => NULL | Yes | Same call with 'YES' | Systemic issue; rare |
| Drop one baseline | DBMS_SQLTUNE.DROP_SQL_PLAN_BASELINE(plan_name => ...) | Removed | Not directly; needs recapture | Baseline is obsolete and you're confident |
| Disable use globally | ALTER SYSTEM SET optimizer_use_sql_plan_baselines = FALSE | Yes, untouched | ALTER SYSTEM SET ... = TRUE | Testing, or urgent troubleshooting |
A note on "disable" in the everyday sense of "get this plan out of the way": for the question's purposes, both the enabled => 'NO' call and the parameter toggle count. They differ in blast radius. The procedure targets baselines; the parameter disables the whole mechanism. A document title that says "disable all SQL plan baselines" usually means either the bulk procedure call or the parameter toggle, and the operations team should know which one was run. Record it.
There's also the fixed attribute, and it's worth giving its own sentence because it trips up so many. In 11g through 19c, if a plan has FIXED = YES, the optimizer selects it over non-fixed plans even if the other plans in the set are accepted. If you disable a plan that is FIXED, it will not be used — but any plan left in the set that's also fixed will compete. Audit the FIXED flags on the set before assuming you've removed the tilt.
Restoring plans the optimizer stopped using (what disabled baselines do to an evolve plan)
When you disable an accepted plan, the statement re-optimizes. The new plan may be better, or it may be an unstable one that was never captured. Oracle has an evolution mechanism, DBMS_SQLTUNE.EVOLVE_SQL_PLAN_BASELINE, which tests possible plans and accepts those that perform at least as well as the existing set. A disabled plan is not automatically re-enabled by evolution — evolution works on candidates and compares them with the enabled set. So disable doesn't mean the plan will disappear from the report, only that it's out of the running.
In practice, the pattern I'd follow is: disable, correct the underlying cause (statistics or indexes), then run the SQL Tuning Advisor and let a well-tested plan evolve into the set as a new accepted baseline. That sequence is safer than dropping the baseline and letting the optimizer find its own way with no safety rail.
Re-enabling, for completeness, is the same call with 'YES':
You don't have to recreate the baseline. That's the whole value of disabling over dropping.
Which versions and environments change the mechanics
On 11g and 12c, DBA_SQL_PLAN_BASELINES is the first place to look; earlier 11g point releases show the same columns. From 12c onward the SQL Management Base moved its storage tables from SYSAUX to the shared dictionary (with automatic space management), but the view and the procedure signatures are unchanged. In 18c and 19c, ALTER_SQL_PLAN_BASELINE accepts the same attribute_name => 'enabled' and attribute_value => 'NO' pair; the change between releases is not in how baselines are disabled but in how much they're auto-captured when OPTIMIZER_CAPTURE_SQL_PLAN_BASELINES is TRUE.
In multitenant environments, ALLEL_SQL_PLAN_BASELINES at the root does not directly alter PDB baselines; the call must be issued in the target PDB. On a RAC database there's no per-instance difference in baseline metadata, so one session's change applies cluster-wide, and a running cursor on another instance is not forcibly invalidated. Version 23ai keeps the model but tends to spreadsheet less SQL; I'd still check DBA_SQL_PLAN_BASELINES first and consult the version-specific documentation for any behavior change in the space-management subsystem before bulk operations.
Can disabling a baseline ever be the wrong move?
Yes, in three situations worth flagging. First, when the "bad" plan is the only accepted plan and the alternative is a plan you've never seen — you're trading a known plan for an unknown one, and on a high-volume OLTP path that's a risk. Test with the session parameter on a clone first, or at least grab a 10053 or 10046 trace of the new plan before letting it loose in production.
Second, when the plan was captured deliberately for a compliance or audit reason — a fixed plan written into a change record — disable it with the change ticket open and cite the ticket, because audit evidence of why the pin was lifted matters as much as the pin itself.
Third, when disabling a plan makes the statement choose a plan that Oracle's plan evolution had previously rejected. In that case you're overriding the database's own judgment, and you need to know why the candidate was rejected before you side with it.
There's a subtler operational point. The ALTER_SQL_PLAN_BASELINE call takes effect for new parses; existing cursors in the library cache still execute the plan they were compiled with until they age out or are invalidated. For a quick controlled test, invalidate with a small, targeted cursor flush rather than a system-wide FLUSH SHARED_POOL. And on a busy system, this means a session that's currently executing the "bad" plan can keep doing so for a while after your disable call. That's expected, not a failure of the procedure.
Finally, if after disabling, fixing statistics, and testing the new plan you're convinced the accepted plan should never come back, evolve or capture a replacement and consider dropping the disabled baseline after the change is validated. Don't drop it in the same change window — leave the evidence around through the verification period. The default I've seen work well is: disable now, decide about dropping in the next maintenance window, and record both in the change record.