top of page

Recover a Dropped or Damaged Table with RMAN RECOVER TABLE: A Step-by-Step Guide

OmerNarman
Aug 25
6 min read

Updated: Oct 24

It is one of the most common calls a DBA receives: "Someone dropped a table" or "A script updated every row by mistake, can we get yesterday's data back?" Restoring the whole database to an earlier time would lose every other change made since then, so that is rarely acceptable.


Since Oracle Database 12c, RMAN can recover a single table or partition to a point in time from your normal backups. In this post we go through the whole process step by step, starting with the faster options you should always check first.



How RMAN RECOVER TABLE Works

It helps to understand what RMAN does behind the scenes, because it explains the space and time requirements:


  1. RMAN creates a temporary auxiliary instance on the same server.

  2. It restores the SYSTEM, SYSAUX and UNDO tablespaces, plus only the tablespaces that contain the table, into an auxiliary destination.

  3. It recovers that small auxiliary database to the time (or SCN) you asked for.

  4. It exports the table with Data Pump from the auxiliary database.

  5. It imports the table into your live database (optionally under a new name).

  6. It removes the auxiliary instance and its files.


Your production database stays open during the whole process.



Prerequisites

  • The database is in ARCHIVELOG mode and you have a backup taken before the target time, plus all archived logs from that backup up to the target time.

  • Free disk space in the auxiliary destination for SYSTEM, SYSAUX, UNDO and the table's tablespaces.

  • The table is not owned by SYS and is not in the SYSTEM or SYSAUX tablespace.

  • Enterprise Edition (the feature is part of RMAN in EE).



Step 1: Check the Recycle Bin First

If the table was dropped (not truncated or updated) and the recycle bin is on, the fastest fix takes seconds. A dropped table is only renamed to a BIN$ name until space pressure purges it.


SQL

SHOW PARAMETER recyclebin

SELECT owner, original_name, object_name, droptime, can_undrop

FROM dba_recyclebin

WHERE original_name = 'ORDERS';

-- If found, restore it (indexes and constraints come back with BIN$ names)

FLASHBACK TABLE sales.orders TO BEFORE DROP;

-- If a new table with the same name already exists

FLASHBACK TABLE sales.orders TO BEFORE DROP RENAME TO orders_restored;


What to expect: If CAN_UNDROP is YES, the FLASHBACK TABLE command restores the table immediately. Rename the indexes back to their original names afterwards. If the table is not in the recycle bin (dropped with PURGE, or purged), continue with the next step.



Step 2: Check Whether Flashback Query Is Enough

If rows were deleted or updated, and it happened recently, the old versions may still be in UNDO. Flashback query reads the table as it was at an earlier time without any restore.


SQL

-- How far back does UNDO usually reach?

SHOW PARAMETER undo_retention

-- Look at the data as it was 30 minutes ago

SELECT COUNT(*)

FROM sales.orders AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '30' MINUTE);

-- Save the old version into a new table

CREATE TABLE sales.orders_before_fix AS

SELECT * FROM sales.orders AS OF TIMESTAMP

TO_TIMESTAMP('2026-08-24 14:05:00','YYYY-MM-DD HH24:MI:SS');


What to expect: If the query works, you can copy the correct rows back. If you get ORA-01555 (snapshot too old) or ORA-08180, the undo is gone and you need RMAN.



Step 3: Find the Exact Point in Time to Recover To

You must choose a time just before the damage. The more accurate it is, the less data you lose. Good sources are the application team, the unified audit trail, LogMiner, or the alert log for DDL. Converting the time to an SCN makes the recovery precise.


SQL

-- If unified auditing records DROP TABLE, it gives the exact time

SELECT event_timestamp, dbusername, action_name, object_schema, object_name

FROM unified_audit_trail

WHERE object_name = 'ORDERS'

AND action_name IN ('DROP TABLE','TRUNCATE TABLE')

ORDER BY event_timestamp DESC;

-- Convert the chosen time to an SCN

SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('2026-08-24 14:05:00','YYYY-MM-DD HH24:MI:SS')) AS scn

FROM dual;


What to expect: You now have a target time or SCN. Write it down. TIMESTAMP_TO_SCN only works for times still recorded in the SCN-to-time mapping (SMON_SCN_TIME). If it fails, use UNTIL TIME in RMAN instead.



Step 4: Confirm That Backups Cover the Target Time

RMAN needs a backup of the relevant datafiles from before the target time and archived logs up to that time. Check this before you start, so you do not discover a gap after an hour of restore.


RMAN

rman target /

RMAN> LIST BACKUP OF DATABASE SUMMARY;

RMAN> RESTORE DATABASE

UNTIL TIME "TO_DATE('2026-08-24 14:05','YYYY-MM-DD HH24:MI')"

PREVIEW SUMMARY;


What this does: RESTORE ... PREVIEW lists the backup pieces and archived logs RMAN would use without restoring anything. If it reports missing archived logs, restore them from tape or another copy first.



Step 5: Prepare the Auxiliary Destination

RMAN writes the temporary auxiliary database here. It needs room for SYSTEM, SYSAUX, UNDO and the tablespace(s) that hold the table. Use a local file system with plenty of space, and never a location used by production files.


Shell

# Estimate the size you need (run in SQL*Plus)

# SELECT tablespace_name, ROUND(SUM(bytes)/1024/1024/1024,1) gb

# FROM dba_data_files

# WHERE tablespace_name IN ('SYSTEM','SYSAUX','UNDOTBS1','SALES_DATA')

# GROUP BY tablespace_name;

mkdir -p /u05/aux_recover

df -h /u05


What to expect: Free space larger than the total of those tablespaces. If the table is in a huge tablespace, all of it must be restored, so plan the space accordingly.



Step 6: Run RECOVER TABLE

Now the actual recovery. The REMAP TABLE clause imports the recovered table under a new name, so you can compare it with the live table before replacing anything. This is the safest way to work.


RMAN

RMAN> RECOVER TABLE sales.orders

UNTIL SCN 48213377

AUXILIARY DESTINATION '/u05/aux_recover'

REMAP TABLE sales.orders:orders_recovered;


What this does: RMAN performs all the steps described at the start of this post and finally creates SALES.ORDERS_RECOVERED in the live database. You can use UNTIL TIME or UNTIL SEQUENCE instead of UNTIL SCN. Watch the output: you will see the auxiliary instance start, the restore, the recovery, the Data Pump export and import, and finally the cleanup.


For a multitenant database, add the PDB name:


RMAN

RMAN> RECOVER TABLE sales.orders OF PLUGGABLE DATABASE salespdb

UNTIL TIME "TO_DATE('2026-08-24 14:05','YYYY-MM-DD HH24:MI')"

AUXILIARY DESTINATION '/u05/aux_recover'

REMAP TABLE sales.orders:orders_recovered;



Step 7 (Alternative): Create a Dump File Only

Sometimes you do not want RMAN to touch the live database at all, for example when the data must be reviewed first or loaded into a different database. NOTABLEIMPORT stops after the Data Pump export and leaves a dump file.


RMAN

RMAN> RECOVER TABLE sales.orders

UNTIL SCN 48213377

AUXILIARY DESTINATION '/u05/aux_recover'

DATAPUMP DESTINATION '/u05/dumps'

DUMP FILE 'orders_recovered.dmp'

NOTABLEIMPORT;


What to expect: A file /u05/dumps/orders_recovered.dmp that you can import later with impdp wherever you need it.



Step 8: Verify the Recovered Data

Before replacing anything, prove the recovered table is what the business wants. Compare row counts and spot-check the rows that were damaged.


SQL

SELECT COUNT(*) FROM sales.orders_recovered;

-- Rows that exist in the recovered copy but not in the live table

SELECT order_id FROM sales.orders_recovered

MINUS

SELECT order_id FROM sales.orders;

-- Compare a sample of values that were wrongly updated

SELECT r.order_id, r.status AS recovered_status, l.status AS live_status

FROM sales.orders_recovered r

JOIN sales.orders l ON l.order_id = r.order_id

WHERE r.status <> l.status

FETCH FIRST 20 ROWS ONLY;


What to expect: The differences match exactly what the users said was lost or changed. Have the application owner confirm before the next step.



Step 9: Put the Data Back

How you put the data back depends on what happened. Pick the option that loses the least work done since the incident.


SQL

-- Case A: the table was dropped. Rename the recovered copy.

ALTER TABLE sales.orders_recovered RENAME TO orders;

-- Case B: rows were deleted. Insert only the missing rows.

INSERT INTO sales.orders

SELECT * FROM sales.orders_recovered r

WHERE NOT EXISTS (SELECT 1 FROM sales.orders l WHERE l.order_id = r.order_id);

COMMIT;

-- Case C: rows were wrongly updated. Restore the old column values.

MERGE INTO sales.orders l

USING sales.orders_recovered r

ON (l.order_id = r.order_id)

WHEN MATCHED THEN UPDATE SET l.status = r.status

WHERE l.status <> r.status;

COMMIT;


What this does: Case A is a full replacement. Cases B and C keep every valid change made after the incident and repair only the damaged rows. For Case A, remember that RECOVER TABLE brings back the table, its indexes, constraints and grants, but you should re-check dependent objects such as triggers, foreign keys from other tables and synonyms.



Step 10: Clean Up and Recompile

Finally, remove the temporary copy once everyone is happy, and recompile any objects that became invalid.


SQL

-- Cases B and C only. In Case A the recovered copy is now the live table!

DROP TABLE sales.orders_recovered PURGE;

SELECT owner, object_name, object_type

FROM dba_objects

WHERE status = 'INVALID' AND owner = 'SALES';

EXEC UTL_RECOMP.RECOMP_SERIAL('SALES');


Shell

# Confirm RMAN removed the auxiliary files

ls -la /u05/aux_recover



Summary

When a table is lost or damaged, work from the fastest option to the slowest: the recycle bin, then flashback query, then RMAN RECOVER TABLE. With RECOVER TABLE you pick an exact SCN or time, let RMAN build a small auxiliary database, and get the table back under a new name for verification, all while production stays online. Practice this once on a test system, so the first time you run it is not during an incident.

Recent Posts

See All

Comments


bottom of page