Chapter 16 · Flashback Technologies, Recycle Bin, Data Archive, and Recovery Without Restore

Flashback Version Query and Transaction Query for Change Investigation

Build a committed-change timeline with VERSIONS BETWEEN and VERSIONS_* pseudocolumns, then add FLASHBACK_TRANSACTION_QUERY only on entitled offerings with its powerful transaction-wide privilege and supplemental-logging dependency.

Advanced120–140 minutesVersion timeline + transaction-query boundaryVersion Query runnable in FreeTransaction Query/Backout not licensed in FreeLast reviewed: August 2026

Learning outcomes

ServiceHub discovers that case 701 changed from OPEN to HOLD, then to CLOSED, and was later deleted. A single AS OF query answers only one point in time. Flashback Version Query returns the committed row versions across an interval and exposes the transaction identifier that produced each version. Flashback Transaction Query can add user/transaction/undo-SQL metadata—but current 26ai licensing does not permit that feature in Oracle AI Database Free.

01

Use VERSIONS BETWEEN SCN/TIMESTAMP with VERSIONS_START*, VERSIONS_END*, VERSIONS_OPERATION, and VERSIONS_XID.

02

Build an investigation timeline from committed row versions rather than treating the feature as permanent auditing.

03

Explain that Version Query is undo/history-dependent and can lose older evidence.

04

Record the current licensing boundary: Flashback Transaction Query and Flashback Transaction are not available in Free.

05

On entitled deployments, use FLASHBACK_TRANSACTION_QUERY narrowly by XID with SELECT ANY TRANSACTION and supplemental-logging awareness.

Generation-time baseline, feature matrix, and safety boundary

Mandatory examples target Oracle AI Database Free 26ai, reviewed against RU 23.26.3, SQL Developer 26.2, and SQLcl 26.2.1. Free is limited to 2 foreground CPU cores, 2 GB combined SGA/PGA RAM, 12 GB user data, and one installation per logical environment; it receives no Oracle patches or Support service requests. The course CDB/PDB baseline is FREE/FREEPDB1. Basic Flashback Query/Version Query and Flashback Table/Database paths are used locally where safe. The current 26ai licensing matrix marks Flashback Transaction Query and Flashback Transaction unavailable in Free, so those are entitlement-gated extensions rather than mandatory Free commands. No flashback feature is presented as a substitute for RMAN backups and restore drills from Chapter 15.

1. Version Query returns committed lifespans

VERSIONS BETWEEN returns row versions that existed during an SCN/time interval. A new committed version is created by a transaction that changes the row. The pseudocolumns describe when a version began/ended, whether the change was an insert/update/delete, and which transaction identifier (VERSIONS_XID) created it.

Pseudocolumn Meaning
VERSIONS_STARTSCN/TIME SCN/time when this version became current
VERSIONS_ENDSCN/TIME SCN/time when a later version replaced it
VERSIONS_OPERATION I, U, or D for the transaction producing the version
VERSIONS_XID Transaction identifier that produced the version

2. Reproducible Free timeline lab

sql · create one tracked business row
BEGIN  EXECUTE IMMEDIATE 'DROP TABLE servicehub_version_case PURGE';EXCEPTION WHEN OTHERS THEN  IF SQLCODE != -942 THEN RAISE; END IF;END;/CREATE TABLE servicehub_version_case (  case_id NUMBER PRIMARY KEY,  status_code VARCHAR2(12) NOT NULL,  amount NUMBER(10,2) NOT NULL);-- Oracle documentation recommends allowing time after CREATE TABLE-- before version-query test transactions.BEGIN DBMS_SESSION.SLEEP(15); END;/VARIABLE start_scn NUMBERBEGIN :start_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER; END;/INSERT INTO servicehub_version_case VALUES (701,'OPEN',100);COMMIT;UPDATE servicehub_version_case SET status_code='HOLD',amount=150 WHERE case_id=701;COMMIT;UPDATE servicehub_version_case SET status_code='CLOSED',amount=175 WHERE case_id=701;COMMIT;DELETE FROM servicehub_version_case WHERE case_id=701;COMMIT;VARIABLE end_scn NUMBERBEGIN :end_scn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER; END;/

3. Build the version timeline

sql · all retained committed versions for case 701
SELECT  versions_startscn AS start_scn,  versions_endscn   AS end_scn,  versions_operation AS op,  RAWTOHEX(versions_xid) AS xid_hex,  case_id,  status_code,  amountFROM servicehub_version_caseVERSIONS BETWEEN SCN :start_scn AND :end_scnWHERE case_id=701ORDER BY versions_startscn NULLS FIRST;

Expected history contains the inserted/updated/deleted lifespans while the necessary history remains available. A version row with delete operation represents the row version involved in deletion; the current query after the final commit returns no case 701.

4. The XID is the bridge to transaction metadata

On an offering entitled to Flashback Transaction Query, FLASHBACK_TRANSACTION_QUERY can show transaction start/commit SCNs and times, logon user, operation, table/row identifiers, and generated UNDO_SQL. Oracle requires the powerful SELECT ANY TRANSACTION privilege to query this view.

Current Free licensing boundary

The August 2026 26ai Licensing Information matrix marks Flashback Transaction Query = N and Flashback Transaction = N for Oracle AI Database Free. Do not run these features merely because dictionary objects or package symbols are visible. Use the Free Version Query timeline above for the mandatory lab.

sql · entitled deployment only — use the captured XID, not an unbounded scan
SELECT  xid,  start_scn,  commit_scn,  start_timestamp,  commit_timestamp,  logon_user,  operation,  table_owner,  table_name,  row_id,  undo_sqlFROM flashback_transaction_queryWHERE xid = HEXTORAW(:xid_hex);

Oracle explicitly warns that scanning FLASHBACK_TRANSACTION_QUERY without an XID predicate can scan many unrelated rows. Narrow the investigation to transaction identifiers discovered from Version Query or other evidence.

5. Supplemental logging affects transaction-query fidelity

Current Oracle documentation says the database should have at least minimal supplemental logging enabled to avoid unpredictable Flashback Transaction Query behavior. Additional key/column logging can be required for reliable dependency/undo SQL reconstruction.

sql · read-only logging inventory — entitled design path
SELECT supplemental_log_data_min,       supplemental_log_data_pk,       supplemental_log_data_ui,       supplemental_log_data_fk,       supplemental_log_data_allFROM v$database;

Enabling supplemental logging is a CDB/database logging-policy change that increases redo. Do not enable it only to satisfy a lab; coordinate it with GoldenGate/Data Guard/audit/change-data-capture needs and redo capacity.

6. UNDO_SQL is evidence, not an automatic repair script

The generated UNDO_SQL represents the logical inverse of a DML operation when enough information exists. Executing it blindly can violate current constraints or overwrite later legitimate transactions. Flashback Transaction Backout is a separate feature that evaluates dependencies and applies compensating transactions; it too is not licensed in Free.

Investigation-first rule

Use transaction metadata to explain who/what/when and to design the repair. Re-run current-state checks before applying any inverse DML because the database may have changed since the incident.

7. Deliberately wrong: treat Version Query as a permanent audit log

Undo-backed row versions can expire. Version Query may show less history tomorrow than today. Even long-term Flashback Time Travel has a configured retention/purge lifecycle and is not the same as a security audit trail. Regulatory attribution usually needs Unified Auditing/application identity/context plus controlled retention.

sql · undo evidence supporting the current timeline window
SELECT *FROM (  SELECT    begin_time,end_time,tuned_undoretention,    maxquerylen,ssolderrcnt,undoblks  FROM v$undostat  ORDER BY end_time DESC)FETCH FIRST 12 ROWS ONLY;

8. Cleanup

sql · cleanup
DROP TABLE servicehub_version_case PURGE;

9. Production judgment

Use Version Query quickly after an incident to reconstruct the committed row timeline and extract XIDs. Preserve findings outside volatile undo before evidence expires. Use Transaction Query only on an entitled offering, grant SELECT ANY TRANSACTION to a tightly controlled forensic role, and enable supplemental logging only as part of an intentional logging architecture.

No pack or restart is required for Version Query. Lesson 3 turns investigation into recovery: Flashback Table rewinds a table's current data using undo, while Flashback Drop retrieves a dropped object from the recycle bin without using the same undo mechanism.

Check your understanding

  1. What does VERSIONS_XID identify?
  2. Does Version Query return uncommitted row versions?
  3. Is Flashback Transaction Query licensed in Oracle AI Database Free?
  4. What system privilege is required to query FLASHBACK_TRANSACTION_QUERY?
  5. Why should UNDO_SQL not be executed blindly?
Review the answers

It identifies the transaction that produced the corresponding committed row version.

No. Flashback Version Query reconstructs committed versions in the requested interval.

No. The current 26ai licensing matrix marks it unavailable in Free.

SELECT ANY TRANSACTION.

Later valid changes or constraints may make the historical inverse incorrect or dangerous in the current database state.

Authoritative references

Keep knowledge open

Help the academy stay free and grow.

If these tutorials save you time, a small donation supports new lessons, technical review, diagrams, examples, and long-term maintenance.

ETHEthereum / ERC-20 only
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0

Send only Ethereum or ERC-20 compatible assets to this address.