Deleted rows can often be recovered, but only if you act before the storage that held them gets overwritten and only if you know which layer deleted them: the application, a database statement, a replication or migration job, or a storage-level wipe. The first practical step is not running a recovery tool. It is stopping writes to the affected system, capturing what happened, and identifying your recovery surface — backups, point-in-time logs, transaction logs, replication replicas, or undelete features. Which of those exist determines whether you get exact rows back, a partial reconstruction, or nothing.
This guide covers the realistic recovery sequence across common systems, the conditions that make recovery possible, how to verify you actually restored the right rows, and when to stop and escalate. It does not assume any specific database; where behavior differs by product or version, it says so and tells you what to check rather than guessing.
Stop writes and preserve the evidence first
Every additional write to the affected system raises the chance that deleted data becomes unrecoverable at the storage layer and complicates log-based recovery. So the order matters more than the tool.
1: Freeze the blast radius. Put the affected application into read-only mode if you can, pause ingestion jobs, and stop scheduled batch processes that write to the same tables. If the deletion came from a bad migration or script, halt the job that ran it. 2: Do not restart or reconfigure the server yet. Restarting can trigger crash recovery, checkpointing, or log truncation. Some engines rotate or recycle logs on startup; you want those files intact first. 3: Record the timeline. Note when the deletion was noticed, the approximate time it happened, which account or service ran it, and the query or job involved. Timestamps drive every later recovery decision, and they need to be in the database's own time zone, not your laptop's. 4: Snapshot what still exists. If your platform supports volume snapshots or a storage-level copy, take one now before any recovery attempt. This preserves the current state so a failed recovery doesn't leave you worse off. 5: Copy logs before they age out. Transaction logs, binary logs, write-ahead logs, and archive logs have retention windows that may be as short as minutes in high-churn systems. Copy the relevant files to separate storage.
Success at this stage looks like: no new writes reaching the affected tables, a documented timeline, and preserved copies of logs and snapshots. If you can't stop writes — for example, a live production system with no maintenance window — you can still proceed, but every step carries more risk and log-based recovery becomes time-critical.
Identify which layer deleted the rows
Recovery paths diverge sharply depending on who did the deleting, and using the wrong one wastes your best window.
Application-level delete (soft delete flag, "remove" button): The row may still be physically present with a deleted flag or moved to a recycle bin or archive table. Check the schema for status or deleted-at columns and look for shadow tables before anything else. A single SQL DELETE, TRUNCATE, or DROP: Points you toward transaction logs or point-in-time restore. A migration or ETL job: May have deleted rows across many tables; the original job definition tells you the scope and order. A storage or file-level wipe: Backup and snapshot recovery, not SQL logs. Replication or sync errors: A replica or downstream system may still hold the rows, or may already have propagated the delete. Check replica lag and whether the delete has replicated.
Confirming the layer prevents the most common wasted effort: restoring a full database backup when the rows were only soft-deleted, or hunting through logs when the data was overwritten by a bulk import.
Check the cheapest recoveries before touching backups
Backups and point-in-time restores are powerful but disruptive. Look for lower-cost paths first.
Soft-delete and recycle-bin features. Many applications and some database platforms keep deleted rows in a quarantine table, a trash schema, or an undo area for a retention period. Query the schema for tables or columns whose names suggest deletion state. If the rows are there, restoring them is a normal INSERT ... SELECT back into the live table, and you avoid a full restore entirely.
Dependent objects and denormalized copies. Reporting tables, audit logs, change-data-capture streams, search indexes, caches, and even email notifications sometimes retain field values from deleted rows. These rarely give you a complete, consistent row, but they can reconstruct enough to identify what was lost and to confirm the deletion timestamp.
Replicas and read replicas. If a replica lags behind the primary by more than the time since deletion, it may still contain the rows. The safe move is to promote nothing and instead copy the needed rows out of the replica into a staging table, then reconcile. Verify that the replica hasn't already applied the delete; lag is your friend only while it lasts.
Application-level versioning. If the app stores row history or an event log (common in event-sourced designs), the delete may be represented as an event that can be replayed or reversed.
If any of these yields the rows, stop here. You've recovered without a restore, which is almost always the least risky outcome.
Use point-in-time recovery and transaction logs
When rows were hard-deleted, the reliable path is usually the database's own recovery mechanism: transaction logs (or the equivalent) combined with a base backup. The principle is the same across engines even though the commands and file formats differ.
Step 1: Find the deletion timestamp with precision. Compare application logs, audit logs, or row counts over time to narrow down when the rows disappeared. If you have an audit trail that records the statement, use its timestamp. This timestamp is the target for "restore to just before the delete."
Step 2: Restore a base backup to a separate instance. Never restore over the production system. Bring up a new instance from the most recent full backup that predates the deletion, then apply transaction logs forward to your target time. This is point-in-time recovery (PITR), and it's the standard mechanism in PostgreSQL, SQL Server, MySQL with binary logs and a base backup, Oracle, and most managed cloud databases.
Step 3: Extract the rows. On the restored instance, select the affected rows into a staging table. Export them, then insert them into production through a controlled script, handling primary-key conflicts and foreign-key dependencies. For large volumes, insert in batches and verify counts at each step.
Step 4: Reconcile. Compare the restored row set against what the application expects. Check that dependent rows (child tables, indexes, sequences) are consistent. If the delete cascaded to child tables, you may need to restore those too.
Managed database services usually offer a console or API for PITR to a new instance. The exact retention window varies by service and plan — commonly a few days to a few weeks — so confirm the window before you rely on it. Where the platform also exposes a "flashback" or "time travel" query feature, that can let you read historical data without a full restore.
A worked verification check: if your backup was taken at 02:00 and the delete happened at 14:30, you restore to 14:29:59, then confirm the row count in the staging table matches the count from the last known-good audit snapshot taken before 14:30. If the counts diverge, your log chain has a gap or the delete happened earlier than you thought.
Where this fails: if the logs were truncated, the retention window passed, or the storage was physically overwritten, log-based recovery cannot reconstruct the rows. That's the stop condition for escalating to storage-level recovery or accepting the loss.
Recover from file-system or storage snapshots
If database-level logs are gone but you have volume snapshots, storage-level recovery may still work. The caution here is consistency: a file-level snapshot of a live database can capture a torn or inconsistent state. Mount the snapshot on a separate machine, start a copy of the database against it, and let the engine's crash-recovery process bring it to a consistent point. Then extract the rows and copy them into production. Filesystem-level undelete tools are a last resort and are unreliable on files that have been overwritten; they're more appropriate for recovering a whole lost file than for pulling individual rows out of an active database file.
Rebuild from derived data when logs and backups are gone
Sometimes the only surviving evidence is indirect. Audit tables, change-data-capture targets, search indexes, message queues, and application event logs can be mined to reconstruct deleted rows. This is slow and rarely exact — you may recover field values but lose timestamps, IDs, or relationships — so treat it as reconstruction rather than restoration. Before investing, confirm the derived source actually captured the column values you need and wasn't itself filtered or truncated. Document which fields are reliable and which were inferred, because that distinction matters to anyone using the data later.
Verify the recovery before you call it done
A restore isn't finished until you've checked it.
Row counts and checksums match the pre-delete audit snapshot. Primary keys and unique constraints are intact, with no duplicate or orphaned rows. Foreign-key relationships hold; child rows either exist or are intentionally absent. Application behavior is sane: the UI reads the rows back, search indexes are rebuilt if needed, and caches are invalidated. The deletion cause is understood and fixed — otherwise the same script or bug deletes the rows again after you restore them.
Keep the restored data in a staging area until the application owner signs off. Log the recovery steps and the root cause so the next incident is faster.
Prevent the next deletion from becoming an incident
The cheapest recovery is the one you never need. A few measures cover most real failures:
Soft deletes with a retention window for user-facing delete operations, so "delete" moves rows to a recoverable state. Restricted delete permissions and reviewed migrations; require a WHERE clause and a dry-run count before bulk deletes. Audit logging that captures the statement, user, and timestamp for destructive operations. Tested backups with known retention windows, and a documented PITR procedure you've actually rehearsed on a staging system. Lagging read replicas deliberately kept behind the primary, so a recent mistake hasn't propagated to all copies.
When to stop and escalate
Stop attempting recovery yourself and involve a database administrator or your platform's support when: writes cannot be stopped and logs are about to expire; the storage has been physically overwritten or the volume lost; the affected database spans replicas or shards with inconsistent state; the data is regulated or subject to legal hold; or you're considering a production restore without a verified staging restore first. These are not judgment calls you want to make under pressure at 3 a.m. without a second set of eyes.
FAQ
Can I recover deleted rows if I have no backups at all?
Sometimes, but only from residual sources: soft-delete tables, replicas that haven't applied the delete, audit logs, or derived copies. If none exist and the storage has been overwritten, recovery usually isn't possible. Don't pay for "undelete" tools that promise otherwise without a specific, verifiable mechanism.
Does deleting rows free space immediately?
Often not. Many engines mark space reusable but don't zero it, which is one reason recovery sometimes succeeds shortly after a delete. It also means you shouldn't count on that space staying recoverable; overwriting happens as new writes arrive.
How long do I have?
It depends on the system: log retention windows (often days to weeks), snapshot retention, and how fast new writes overwrite freed space. There's no universal answer — check your platform's configured retention and act sooner rather than later.
Can a read replica help me recover?
Only if it still holds the rows. If replication lag hasn't reached the delete, copy the rows out of the replica quickly; if the delete has already replicated, the replica is no help.