How to Recover Dropped Tables in Distributed Databases: Three Methods Compared
This article details three recovery methods for accidentally dropped tables in distributed databases—full backup plus incremental logs, flashback technology using recycle bins, and delayed replication—providing step-by-step procedures for GoldenDB and GaussDB, and comparing their recovery time objectives, deployment complexity, cost, and technical limitations.
Reading font
Data integrity is a fundamental requirement for database availability. During actual database change operations, accidental DROP TABLE or TRUNCATE commands can disrupt business access. This article introduces and compares three data recovery solutions for the dropped-table scenario in distributed databases.
1. Overview of Recovery Solutions
When a table is mistakenly deleted in a distributed database, three main recovery approaches exist:
Backup + Incremental Logs : Requires a full backup. Incremental logs are replayed on top of that backup while skipping the erroneous operation. Recovery time grows with data volume and log size; the application cannot access the affected table during the process.
Flashback Technology : Uses the recycle bin and undo logs. A DROP TABLE is essentially a rename that moves the table to the recycle bin. If the recycle bin has space and hasn't been purged, the table can be restored in seconds, independent of database size.
Delayed Replication : A standby cluster replicates the primary with a configurable delay. When a logical error occurs on the primary, the standby skips the offending transaction and catches up, then takes over. This avoids a full backup restore but requires deploying and maintaining an extra standby cluster.
In a dropped-table failure, only access to that table fails; other tables remain accessible. The following sections detail each method.
2. Distributed Database Recovery Methods
2.1 Recovery via Backup + Incremental Logs (GoldenDB Example)
Full backups and incremental logs form the basis of database integrity. Important systems often run daily full or incremental backups. Recovery first restores to the backup point, then replays incremental logs to a point-in-time recovery (PITR) consistent timestamp. For a dropped table, the offending log entry must be skipped. In a distributed database, data across multiple shards and the compute-layer metadata must also be restored. The steps below use GoldenDB as an example.
Step 1: Restore Table Schema
Recover the table structure from saved DDL statements for later schema restoration.
Step 2: Locate the Drop Operation GTID on Each Shard Primary
Log in to each shard's primary node, parse the binary log, and extract the GTID of the DROP TABLE statement.
$ mysqlbinlog -vv mysql-bin.xxx | grep -i -B20 'drop table'Output example:
SET @@SESSION.GTID_NEXT='xxxx'/*!*/;
DROP TABLE xx.xx /*generated by server*/Step 3: Restore a Standby Node from Full Backup
Select a standby node to recover. Stop the standby, then restore from the full backup.
## Stop standby
$ dbmoni -stop
## Restore standby
$ restore.py --full_backup_filename=xx --my_cnf=xx.cnf --db_user=xx --db_password=xxStep 4: Replay Binlog to Current State, Skipping the Drop GTID
Verify standby state: dbagent not started, database instance running. $ dbstate Set gtid_next to the captured GTID and execute an empty transaction to skip the drop:
> set @@session.gtid_next='xxxx';
> begin;
> commit;Start dbagent, join the standby to the cluster, and enable automatic replication.
## Start standby
$ dbmoni -startStep 5: Verify Primary-Standby Sync
$ show slave status \G
$ show tables like 'xx'The previously dropped table data is now present on the standby.
Step 6: Failover to Recovered Standby
Promote the recovered standby to primary. The old primary becomes a standby but is now inconsistent; it must be repaired.
Step 7: Update Proxy Metadata
Although data nodes have the table, the compute layer lacks its metadata. Log in to the proxy node and update metadata using the recovered schema information.
Step 8: Repair Other Standbys
Initiate a new full backup on the new primary and restore other standbys from it. Note that taking a backup on the primary incurs performance overhead (increased latency, I/O impact).
This method's RTO depends on full backup restore time plus incremental log replay. During recovery, business access to the table fails. When running with a single primary, configuration adjustments (e.g., high/low watermarks, master election weights) may be needed to prioritize availability.
2.2 Recovery via Flashback Space (GaussDB Example)
Flashback recovery leverages the recycle bin mechanism. When a user executes DROP TABLE, the database does not immediately delete physical files; it moves the table to the recycle bin — a "soft delete" where objects remain in the database but are invisible. Multiple distributed databases support flashback, including TiDB, GaussDB, OceanBase, and GoldenDB. In GaussDB, the recycle bin is controlled by the parameter enable_recyclebin. Retention time is set by recyclebin_retention_time; objects exceeding this age are auto-purged. Flashback recovery takes seconds and is independent of database size.
Syntax examples:
# Flashback dropped table
TIMECAPSULE TABLE { table_name } TO BEFORE DROP [RENAME TO new_tablename]
# Flashback truncated table
TIMECAPSULE TABLE { table_name } TO BEFORE TRUNCATEStep 1: Check Recycle Bin
gaussdb=# SELECT * FROM gs_recyclebin;Output shows the dropped table test with recycle name BIN$42C23EB5699$9737$0==$0, operation type d (drop), and restore/purge flags set to true.
Step 2: Flashback the Dropped Table
gaussdb=# TIMECAPSULE TABLE test to before drop;Table data is restored immediately.
Flashback is powerful but limited by:
Flashback time-point restriction : Can only roll back to a point after flashback was enabled, and only to the most recent transaction commit point. Errors occurring before enablement cannot be recovered.
Old-version retention time : Depends on retained old versions. If cleaned up, rollback to those points is impossible. Users must configure retention appropriately.
Additionally, flashback only supports certain DDL operations (e.g., drop table, truncate table). It cannot recover dropped databases, dropped columns, or hardware-induced inconsistencies.
2.3 Recovery via Delayed Replication
This approach was covered in "Domestic Distributed Database Disaster Recovery and High Availability Implementation" (https://mp.weixin.qq.com/s?__biz=MzI3MzUzMjIxNA==&mid=2247485746&idx=1&sn=15cfca38f07898e511ba2f06ad26cb4a&scene=21#wechat_redirect). Examples include OceanBase's physical standby and GoldenDB's DRSP disaster recovery cluster. A delayed standby cluster is built alongside the production cluster with a configured replication lag. When the primary suffers a logical error, the standby skips the offending transaction, syncs up, and takes over. The principle resembles backup+log replay but omits the full backup restore, reducing RTO. The trade-off is higher deployment cost: a separate standby cluster must be provisioned solely for failure scenarios. Cost-benefit analysis is essential, especially since other preventive measures exist.
2.4 Comparison of Recovery Solutions
The three solutions are compared across four dimensions:
Recovery RTO
Backup + Incremental Logs: Long — full backup restore plus incremental log replay.
Flashback: Seconds-level recovery.
Delayed Replication: Longer — depends on log sync and replay time.
Deployment Complexity
Backup + Incremental Logs: Mature but operationally complex. Requires locating drop GTID, designating a standby, skipping GTID, restoring standby.
Flashback: Simple; relies on built-in database functionality.
Delayed Replication: Immature and complex; depends on database HA architecture implementation.
Deployment Cost
Backup + Incremental Logs: Low — uses existing architecture, no extra cost.
Flashback: Moderate — extra storage for recycle bin; enabling flashback impacts performance somewhat.
Delayed Replication: High — requires an additional standby cluster.
Technical Limitations
Backup + Incremental Logs: None.
Flashback: Logical recovery only; supports limited DDL (drop/truncate table); retention time limits apply.
Delayed Replication: Limited by configured delay window; if delay expires, the error has already replicated to standby.
Reference Materials
GoldenDB Distributed Database Backup and Recovery
GaussDB Database Flashback Recovery
Domestic Distributed Database Delayed Replication Implementation (https://mp.weixin.qq.com/s?__biz=MzI3MzUzMjIxNA==&mid=2247485746&idx=1&sn=15cfca38f07898e511ba2f06ad26cb4a&scene=21#wechat_redirect)
In practice, if the database supports flashback, prefer that method for fast RTO. When flashback is unavailable or immature, fall back to full backup recovery, which is mature and widely applicable.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.