Skip to content

Dropped or Truncated a Table? What to Do First

By Srinivasan Krishnappa · Ransomware & database recovery engineer · 656+ ransomware recoveries
5 min read
Need this solved now? We have already solved 656+ ransomware and data recovery cases. Call +91 74187 05822, WhatsApp us or email info [at] asittech.com. Free assessment; no data, no charge.

An accidental DROP TABLE, TRUNCATE or unfiltered DELETE on a production database is one of the most common ways to lose data, and it is usually noticed within minutes. What happens next matters more than what was lost. The data is often still recoverable, but a busy database keeps writing, and every new write can overwrite the space and the log records that a recovery depends on.

Limit further writes

If the application can be paused, or the database put into a restricted or read-only mode, do that first. Avoid maintenance jobs in the meantime: index rebuilds, VACUUM FULL, file shrinking and log truncation all reduce what can be recovered. Repeatedly restarting the database is also best avoided, because crash recovery and checkpoints rewrite files.

Work out which statement it was

DELETE, TRUNCATE and DROP behave differently. A DELETE is normally logged row by row, so it is often the easiest to reverse. TRUNCATE and DROP release the table's storage in one step and log much less, which changes what can be recovered and how. Whether these statements can be rolled back also depends on the database engine: in some, they can be rolled back if the transaction is still open, and in others they take effect immediately. If the session that ran the statement is still open and uncommitted, check the engine's behaviour before closing it.

Point-in-time recovery is usually the cleanest route

If there is a full backup and the transaction logs since then, whether SQL Server log backups, MySQL binary logs, archived PostgreSQL WAL or Oracle archived redo logs, the database can be restored to a moment just before the mistake. Do that on a separate server or instance, so the production database and the evidence in it are not overwritten, and then copy the recovered table back.

Check for built-in undo features

Some platforms keep a way back. Oracle's recycle bin can hold a dropped table so that it can be restored with FLASHBACK TABLE, unless it was dropped with PURGE or the space was reclaimed. Storage, virtual machine or database snapshots may hold a copy from before the mistake, if any existed. It is worth asking whether one of these was in place before assuming the only option is a backup.

If there is no usable backup

Deleted rows and released pages often remain in the data files until something overwrites them, which means file-level recovery is sometimes possible even without a backup. How much can be recovered depends on the engine, on the statement, and above all on how much writing has happened since. Take an image or a copy of the data files and logs straight away, and work from the copy. Nothing about this is guaranteed.

Reducing the risk next time

Limit who can run DROP and TRUNCATE on production, test that backups actually restore, and keep transaction log or binary log archiving switched on so that point-in-time recovery is possible. A restore that has never been tested is a hope, not a plan.

Database recovery →

Facing this problem? Contact us now.

We have already solved 656+ ransomware and data recovery cases: encrypted and corrupted SQL Server, Oracle and MySQL databases, Tally, Busy and Marg ERP data, Veeam backups, VMware and Hyper-V virtual machines, RAID and NAS. Send us the details and we tell you what we can recover.

  • ✓ Free assessment before you pay anything
  • ✓ No data, no charge
  • ✓ NDA on request

Email: info [at] asittech.com · Mon–Fri, 9:00–18:00 IST

Request assessmentEmergency