Databases 5 min read

Recovering Deleted Databases, Tables, and Partitions in StarRocks

This guide explains how to recover accidentally dropped databases, tables, and partitions in StarRocks using the RECOVER command, covering the 1-day default retention window, configuration options, limitations like TRUNCATE and FORCE drops, and practical step-by-step examples with renaming strategies.

Lakehouse Research Base
Lakehouse Research Base
Lakehouse Research Base
Recovering Deleted Databases, Tables, and Partitions in StarRocks

Background

A colleague reported a missing table early in the morning, prompting an investigation into StarRocks table recovery procedures.

Recovery Capabilities and Limitations

StarRocks cannot recover tables removed with TRUNCATE TABLE. However, databases, tables, or partitions deleted via DROP operations can be restored using the RECOVER command, but only within a specific time window.

The retention window is controlled by the FE dynamic parameter catalog_trash_expire_second, which defaults to 1 day (86400 seconds). After this period, recovery is impossible.

Configuration Details

Temporary Change (Runtime Only)

The parameter can be adjusted at runtime without restarting the FE. The following screenshot shows the temporary modification interface:

Temporary configuration change for catalog_trash_expire_second
Temporary configuration change for catalog_trash_expire_second

Permanent Change (fe.conf)

For persistence across restarts, modify fe.conf and restart the FE. The screenshot below illustrates the permanent configuration:

Permanent configuration change in fe.conf
Permanent configuration change in fe.conf

Critical Limitations

Only the most recently deleted metadata can be recovered (default 1 day, configurable via catalog_trash_expire_second in fe.conf).

If a new object with the same name and type is created after deletion, the previously dropped metadata cannot be recovered.

Tables dropped with DROP TABLE ... FORCE are not recoverable. The following screenshot shows the error when attempting to recover a force-dropped table:

Error recovering force-dropped table
Error recovering force-dropped table

RECOVER Command Syntax

Recover Database

RECOVER DATABASE <db_name>;

Recover Table

RECOVER TABLE [db_name.]table_name;

Recover Partition

RECOVER PARTITION partition_name FROM [db_name.]table_name;

Practical Examples

Recover a database named example_db: RECOVER DATABASE example_db; Recover a table named example_tbl in example_db: RECOVER TABLE example_db.example_tbl; Recover partition p1 from table example_tbl:

RECOVER PARTITION p1 FROM example_tbl;

Real-World Recovery Walkthrough

The author documents an actual incident where a table was dropped and a replacement table created, then the original needed restoration:

# Drop the original table
DROP TABLE starrocks_audit_tbl_bak0806_bak;

# Create a new table with the same name
CREATE TABLE starrocks_audit_tbl_bak0806_bak (...);

# Discover issues with the new table; need to restore the old one
# Rename the new table (DO NOT drop it, or it will overwrite the dropped table's metadata!)
ALTER TABLE starrocks_audit_tbl_bak0806_bak RENAME starrocks_audit_tbl_bak0806_bak_new;

# Recover the original table
RECOVER TABLE starrocks_audit_tbl_bak0806_bak;

# Verify data restoration
SELECT COUNT(*) FROM starrocks_audit_tbl_bak0806_bak;

The following screenshot confirms successful recovery:

Verification of recovered table data
Verification of recovered table data

Database Recovery Demonstration

Screenshot showing the process of recovering a dropped database:

Database recovery process
Database recovery process

Partition Recovery Demonstration

(1) Drop a partition:

Dropping a partition
Dropping a partition

(2) Recover the partition data:

Recovering a partition
Recovering a partition

Production Best Practices

To prevent accidental data loss, the author recommends:

Revoking DROP permissions for developers in production environments.

Requiring review/approval for all DDL operations.

Using RENAME to back up tables before updates, enabling quick rollback.

Only cleaning up renamed backups after the new version is verified stable.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

StarRocksdatabase recoveryDROP TABLEtable recoverycatalog_trash_expire_secondpartition recoveryRECOVER commandTRUNCATE TABLE
Lakehouse Research Base
Written by

Lakehouse Research Base

Focused on technical sharing in the data field, covering a tech stack that includes Hadoop, Spark, Flink, Kafka, Fluss, Paimon, Iceberg, StarRocks, ClickHouse, ES, Milvus, and more. Welcome to follow.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.