Oracle: How to Disable Flashback Using DBMS_FLASHBACK.DISABLE
Overview
When working with Oracle Database, there are times when you need to look at data from the past β like rewinding a video to see what happened earlier. Oracle gives you a tool called Flashback to do this. But once you are done looking at past data, you must turn Flashback off. The command to do that is:
1EXEC DBMS_FLASHBACK.DISABLE;
This post explains what this command does, how it works, and when to use it.
What Is Oracle Flashback?
Oracle Flashback Technology is a set of features inside Oracle Database that lets you view or recover past states of data without restoring a full backup.
You can use Oracle Flashback to:
- Query data as it looked at a past point in time
- See the history of changes made to database objects
- Recover tables or rows to a previous state
- Roll back a transaction while the database stays online
The DBMS_FLASHBACK package is the PL/SQL interface that controls session-level Flashback. It lets your current database session "travel back in time" to a specific System Change Number (SCN) or timestamp.
The Code
1EXEC DBMS_FLASHBACK.DISABLE;
Code Breakdown
| Part | Description |
|---|---|
EXEC | Short for EXECUTE β runs a PL/SQL procedure from SQL*Plus or SQLcl |
DBMS_FLASHBACK | The Oracle built-in package that manages session-level Flashback |
.DISABLE | The procedure inside the package that turns Flashback mode off |
Full Syntax (PL/SQL block form)
1BEGIN
2 DBMS_FLASHBACK.DISABLE;
3END;
4/
Both forms do the same thing. The EXEC shortcut is more common for quick, single-line execution in SQL*Plus.
Purpose
DBMS_FLASHBACK.DISABLE turns off Flashback mode for the current database session.
When Flashback mode is active on a session, every query that session runs returns data as it existed at the past SCN or timestamp you set β not the current data. Once you call DISABLE, the session goes back to reading live, current data.
This is important because:
- You cannot run DML (INSERT, UPDATE, DELETE) while Flashback mode is active on a session
- You must call
DISABLEbefore callingENABLEagain with a new time or SCN - Flashback mode ends automatically when the session disconnects, but calling
DISABLEexplicitly is a best practice
A Real-World Example
Here is a common use case β check the salary of an employee as it was on a specific past date, then return to the present:
1-- Step 1: Enable Flashback to a past point in time
2EXECUTE DBMS_FLASHBACK.ENABLE_AT_TIME('30-AUG-2000');
3
4-- Step 2: Query past data
5SELECT salary FROM emp WHERE name = 'Joe';
6
7-- Step 3: Disable Flashback β return to present data
8EXECUTE DBMS_FLASHBACK.DISABLE;
After Step 3, all queries on the session will again return current, live data.
Key Points
- Session-scoped only β
DBMS_FLASHBACK.DISABLEaffects only the current session, not the entire database. Other sessions are not impacted. - No parameters needed β The
DISABLEprocedure takes zero arguments. It is a simple on/off switch. - Required before re-enabling β You must call
DISABLEbefore you can callENABLE_AT_TIMEorENABLE_AT_SYSTEM_CHANGE_NUMBERagain in the same session. - No DML in Flashback mode β While Flashback is enabled on a session, you cannot perform writes (INSERT, UPDATE, DELETE). Call
DISABLEfirst, then do your DML. - Automatic disable on session end β Oracle automatically disables Flashback when your session ends or disconnects, but relying on this is not considered good practice.
- Requires EXECUTE privilege β The user running this must have the
EXECUTEprivilege granted on theDBMS_FLASHBACKpackage.
Insights and Tips
Tip 1 β Always pair ENABLE with DISABLE
Think of Flashback like opening a file. If you open it, always close it. Pair every ENABLE_AT_TIME or ENABLE_AT_SYSTEM_CHANGE_NUMBER call with a matching DISABLE call in your PL/SQL block or script.
Tip 2 β Use inside PL/SQL for safety
When writing stored procedures or scripts, wrap ENABLE and DISABLE inside a BEGIN...EXCEPTION...END block. This makes sure DISABLE is always called, even if an error happens.
1BEGIN
2 DBMS_FLASHBACK.ENABLE_AT_TIME(SYSDATE - 1/24); -- 1 hour ago
3 -- your read-only queries here
4 DBMS_FLASHBACK.DISABLE;
5EXCEPTION
6 WHEN OTHERS THEN
7 DBMS_FLASHBACK.DISABLE; -- always clean up
8 RAISE;
9END;
10/
Tip 3 β DBMS_FLASHBACK vs. AS OF
DBMS_FLASHBACK enables Flashback for the whole session. For a single query, using the AS OF clause is simpler and does not require calling DISABLE:
1SELECT salary FROM emp AS OF TIMESTAMP (SYSDATE - INTERVAL '1' HOUR)
2WHERE name = 'Joe';
Use DBMS_FLASHBACK when you need multiple queries across the same past snapshot.
Tip 4 β This is NOT the same as disabling Flashback Database
EXEC DBMS_FLASHBACK.DISABLE turns off session-level flashback query. It is different from disabling the Flashback Database feature (which uses flashback logs and is set at the database level):
1-- This is database-level flashback, not session-level
2ALTER DATABASE FLASHBACK OFF;
Do not confuse the two.
Required Privilege
To use DBMS_FLASHBACK, the Oracle DBA must grant execute permission to the user:
1GRANT EXECUTE ON DBMS_FLASHBACK TO your_user;
Without this grant, the user will get an ORA-06550 or PLS-00201 error when trying to run the procedure.
References
Oracle 21c Docs β DBMS_FLASHBACK Package Reference β Official Oracle 21c PL/SQL Packages and Types Reference for the full
DBMS_FLASHBACKpackage, including theDISABLEprocedure syntax and examples.Oracle 18c Docs β Using Oracle Flashback Technology β Oracle 18c Application Developer's Guide chapter covering all Flashback features, DBMS_FLASHBACK package usage, and privilege requirements.
Oracle 9.2 Docs β DBMS_FLASHBACK Package β Legacy Oracle 9i/9.2 documentation for DBMS_FLASHBACK, showing original package design including the DISABLE procedure and cursor-based examples.
Oracle ORACLE-BASE β Flashback Query β Practical article by Tim Hall at oracle-base.com showing real-world use of
DBMS_FLASHBACK.DISABLEafter completing a flashback query session.How to Enable and Disable Flashback in Oracle Database β DBAClass β Step-by-step guide covering both session-level and database-level flashback enable/disable commands in Oracle.
Oracle Flashback Technologies Features β Oracle.com β Official Oracle product page describing all Flashback technology features including point-in-time recovery, table flashback, and recycle bin.
How to Use DBMS_FLASHBACK β Alex Lima Blog β Community blog post with practical SQL*Plus examples of enabling and disabling Flashback using the DBMS_FLASHBACK package.
Enable and Disable Flashback for a Table β ProgrammersNotes β Detailed guide covering table-level flashback archive enable/disable using
ALTER TABLE, including useful DBA views likeDBA_FLASHBACK_ARCHIVE_TABLES.Oracle Flashback β DBA Genesis Support Docs β Quick reference guide from DBA Genesis comparing session flashback with Flashback Database and explaining when each feature requires enablement.