Misoperations such as accidental data updates, accidental data deletions, and accidental table drops are the most common data security risks in database usage. OceanBase Database provides multi-layered data protection: record-level flashback queries allow you to view and retrieve data from any recent historical version; object-level recycle bins enable quick restoration of accidentally dropped tables or databases; and physical-level backup and recovery provide the ultimate protection. This topic simulates two typical types of misoperations to help you experience first-hand how OceanBase Database protects data against misoperations.
This topic covers the following experiences:
- Experience flashback query: Simulate accidental deletion of all data in a table, and use a flashback query to view and retrieve historical data within the
undo_retentiontime window. - Experience flashback delete: Simulate an accidental table drop, and restore the table along with its data from the recycle bin.
- Understand backup and recovery: Learn about the complete set of data protection capabilities, including physical backup and recovery beyond the flashback window.
Note
This topic is based on OceanBase Database V5.0.1 (Community Edition). The commands and feature descriptions in this topic apply to V5.0.1. This topic uses a single-node environment deployed with the All-in-One package in Deploy OceanBase as an example. All operations can be completed in this single-node environment.
Prerequisites
Before you perform the operations described in this topic, ensure that the following conditions are met:
Item |
Description |
|---|---|
| OceanBase Database | The deployment has been completed with the All-in-One package and started successfully (the deployment name is demo). For more information, see Deploy OceanBase. |
| obclient | obclient is installed and can connect to OceanBase Database normally. It is installed automatically when you deploy with the All-in-One package. |
| Access to the sys tenant | You can log in to the sys tenant of the cluster as the root user to perform management operations. The password for the root user of the sys tenant is randomly generated during deployment and is printed in the deployment output; you can also run obd cluster display demo to view it. |
| Multi-tenancy basics | This topic creates a tenant for the experience. For information about tenants and resource pools, see Experience multi-tenancy and resource isolation. |
Overview of data protection capabilities
OceanBase Database provides multi-layered protection against misoperations and for data recovery, and each layer complements the others:
Capability |
Protection level |
Typical scenario |
Recovery method |
|---|---|---|---|
| Flashback query | Record level | An incorrect UPDATE or DELETE that rewrites or loses data. |
Query the historical version with AS OF SNAPSHOT and restore the data. |
| Recycle bin (flashback deletion) | Object level | An incorrect DROP of a table or database. |
Restore the object from the recycle bin with FLASHBACK TABLE ... TO BEFORE DROP. |
| Backup and recovery | Physical level | Storage media failures, data corruption, or historical data beyond the flashback window. | Restore to a specified point in time from log archives and data backups. |
Among these capabilities, flashback queries rely on multi-version data. OceanBase Database controls the retention period of historical versions through the tenant-level parameter undo_retention, whose default value is 1800 (in seconds, that is, 30 minutes). Once the parameter is set, you can query any multi-version data in the range from T - undo_retention to the current time T. To view the value in flash_tenant, execute SHOW PARAMETERS LIKE 'undo_retention'; (it is a tenant-level parameter, so SHOW VARIABLES cannot return it).
Note
- The misoperations and recoveries described in this topic are completed within a few minutes, within the default
undo_retentionwindow, so there is no need to adjust this parameter. If adjustment is required, the tenant administrator can executeALTER SYSTEM SET undo_retention=900;. For details, see undo_retention. - Flashback queries require additional storage space to retain historical data. Increasing
undo_retentionwill lead to storage space amplification. Pay attention to storage space changes after adjustment.
Create a test tenant
Log in to the sys tenant of the cluster as the root user (the password is randomly generated during deployment; obtain it as described in the prerequisites above):
obclient -h127.0.0.1 -uroot@sys -P2881 -p -A oceanbaseCreate a resource unit, resource pool, and tenant named
flash_tenantwith specifications of 2C4G:obclient [oceanbase]> CREATE RESOURCE UNIT flash_unit MAX_CPU=2, MIN_CPU=2, MEMORY_SIZE='4G'; obclient [oceanbase]> CREATE RESOURCE POOL flash_pool UNIT='flash_unit', UNIT_NUM=1, ZONE_LIST=('zone1'); obclient [oceanbase]> CREATE TENANT IF NOT EXISTS flash_tenant CHARSET='utf8mb4', PRIMARY_ZONE='zone1', RESOURCE_POOL_LIST=('flash_pool') SET ob_tcp_invited_nodes='%';Tenant creation takes tens of seconds (about 6 seconds in the environment tested here). No output is displayed during this period, which is normal; just wait for the command to return.
Log in to
flash_tenant(the default password for the root user of a newly created tenant is empty, so just press Enter when prompted). All subsequent operations are performed in this tenant:obclient -h127.0.0.1 -uroot@flash_tenant -P2881 -p -A test
Experience flashback queries
This section first creates a business table and writes data into it to record a point in time before a misoperation. Then, it simulates an accidental deletion of all table data. Finally, it uses a flashback query to view historical data and restore it.
Procedure
Create a test table named
flash_tbland write business data into it:obclient [test]> CREATE TABLE flash_tbl ( id INT PRIMARY KEY, name VARCHAR(32), amount INT ); obclient [test]> INSERT INTO flash_tbl VALUES (1,'alice',1000),(2,'bob',2000),(3,'carol',3000);Confirm that the data was written successfully:
obclient [test]> SELECT * FROM flash_tbl;The return result is as follows:
+----+-------+--------+ | id | name | amount | +----+-------+--------+ | 1 | alice | 1000 | | 2 | bob | 2000 | | 3 | carol | 3000 | +----+-------+--------+ 3 rows in setRecord the time point before the misoperation. Execute the following statement and record the returned time (this example uses
2026-10-12 15:54:41; use the actual time returned by your query):obclient [test]> SELECT NOW();+---------------------+ | NOW() | +---------------------+ | 2026-10-12 15:54:41 | +---------------------+ 1 row in setSimulate the misoperation: execute a
DELETEstatement without aWHEREcondition to accidentally delete all data in the table:obclient [test]> DELETE FROM flash_tbl; Query OK, 3 rows affectedQuery the table again; the data is lost:
obclient [test]> SELECT * FROM flash_tbl; Empty setConvert the time recorded in step 3 to a nanosecond timestamp. In MySQL-compatible mode, you can specify a historical time for a flashback query using
AS OF SNAPSHOT, where the timestamp unit is nanoseconds. You can use thetime_to_usecfunction for conversion (replace the time in the example with the actual time you recorded in step 3):obclient [test]> SELECT time_to_usec('2026-10-12 15:54:41') * 1000;+---------------------------------------------+ | time_to_usec('2026-10-12 15:54:41') * 1000 | +---------------------------------------------+ | 1791791681000000000 | +---------------------------------------------+ 1 row in setRecord the returned value (in this example, it is
1791791681000000000), which will be used to specify the historical point in subsequent flashback queries.Execute the flashback query to view the data before the accidental deletion:
obclient [test]> SELECT * FROM flash_tbl AS OF SNAPSHOT 1791791681000000000;The return result shows the three rows of data from before the accidental deletion:
+----+-------+--------+ | id | name | amount | +----+-------+--------+ | 1 | alice | 1000 | | 2 | bob | 2000 | | 3 | carol | 3000 | +----+-------+--------+ 3 rows in setAfter confirming the historical data is correct, use the result of the flashback query as the data source to restore the accidentally deleted data back into the table:
obclient [test]> INSERT INTO flash_tbl SELECT * FROM flash_tbl AS OF SNAPSHOT 1791791681000000000;Query OK, 3 rows affected Records: 3 Duplicates: 0 Warnings: 0Verify that the data has been restored:
obclient [test]> SELECT * FROM flash_tbl;If the return result is identical to the state before the misoperation, the data has been successfully restored:
+----+-------+--------+ | id | name | amount | +----+-------+--------+ | 1 | alice | 1000 | | 2 | bob | 2000 | | 3 | carol | 3000 | +----+-------+--------+ 3 rows in set
Interpretation
Observation |
Expected behavior |
Description |
|---|---|---|
| Regular queries after the accidental deletion | Empty set |
The data has been deleted and cannot be seen through regular queries. |
| Flashback query | Returns all data from before the accidental deletion. | Reads a snapshot of a specified point in time based on multi-version data. |
| Data recovery | After the data is restored, the table contains three rows again. | The flashback query result is used as the data source and restored online through INSERT INTO SELECT. |
| Recovery method | Completed online, with no backup set required. | The data can be retrieved directly within the undo_retention window. |
Note
- The syntax for flashback queries varies by tenant mode: MySQL-compatible mode uses
AS OF SNAPSHOT, Oracle-compatible mode usesAS OF SCNandAS OF TIMESTAMP. The starting point of the timestamp is 08:00:00 on January 1, 1970, Beijing Time. - A flashback query is a query statement. To restore data, you must use the query result to supplement the data via methods such as
INSERT INTO SELECT. It is recommended to first confirm the historical data is correct using a flashback query before performing restoration. - If DDL operations occur within the
undo_retentiontime window, the system will report an error when flashback querying data from before a DDL operation for creating, dropping, or dropping columns (for example,ERROR 1412,Unable to read data -- Table definition has changed; in practice, this error can also be triggered if the snapshot point is too close to the table creation operation. Wait a few seconds and then re-convert and query using a later point in time). For adding columns, all newly added columns will have default values during flashback query. - If the table being queried has been dropped into the recycle bin, you need to restore the table from the recycle bin first. For details, see the Experience flashback deletion section of this topic.
- For detailed operations and considerations on flashback queries, see Flashback Query.
Experience flashback deletion
Accidentally dropping a table is a more serious misoperation than accidentally deleting rows. OceanBase Database provides a recycle bin feature: after the recycle bin is enabled, objects such as tables and databases dropped by the DROP statement are moved to the recycle bin instead of being deleted directly, and can be restored quickly with the FLASHBACK statement.
Procedure
Create another test table
flash_drop_tbland write data into it:obclient [test]> CREATE TABLE flash_drop_tbl ( id INT PRIMARY KEY, remark VARCHAR(64) ); obclient [test]> INSERT INTO flash_drop_tbl VALUES (1,'critical data'),(2,'daily report'); Query OK, 2 rows affectedCheck the status of the recycle bin feature. The recycle bin is controlled by the system variable
recyclebin. It is disabled by default for new tenants:obclient [test]> SHOW VARIABLES LIKE 'recyclebin';+---------------+-------+ | Variable_name | Value | +---------------+-------+ | recyclebin | OFF | +---------------+-------+ 1 row in setIt is recommended to enable the recycle bin before simulating the accidental deletion operation. The enabling methods are as follows:
- Enable globally (recommended): Execute
SET GLOBAL recyclebin = on;. Modifications to global variables do not take effect in the current session. You need to exit the current session and log in toflash_tenantagain for the change to take effect. - Enable for the current session only: Execute
SET @@recyclebin = on;, which takes effect only for the current session.
After the recycle bin is enabled, re-execute
SHOW VARIABLES LIKE 'recyclebin';and confirm thatONis returned before you continue with the subsequent steps (the following steps assume that the recycle bin is enabled).- Enable globally (recommended): Execute
Simulate the misoperation: accidentally drop the table
flash_drop_tbl:obclient [test]> DROP TABLE flash_drop_tbl; Query OK, 0 rows affectedCheck the recycle bin to confirm that the deleted table has entered the recycle bin:
obclient [test]> SHOW RECYCLEBIN;A sample return result is as follows (
OBJECT_NAMEis automatically generated by the system, in the format__recycle_$_<internal number>_<timestamp>, which is different from the tenant's externalTENANT_ID. Record the actual object name returned in your environment):+------------------------------------+----------------+-------+----------------------------+ | OBJECT_NAME | ORIGINAL_NAME | TYPE | CREATETIME | +------------------------------------+----------------+-------+----------------------------+ | __recycle_$_10001_1791791724617904 | flash_drop_tbl | TABLE | 2026-10-12 15:55:24.617397 | +------------------------------------+----------------+-------+----------------------------+ 1 row in setDescription of each field in the result:
FieldDescriptionOBJECT_NAMEThe name of the object in the recycle bin, globally unique. ORIGINAL_NAMEThe name of the object before it was deleted. TYPEThe type of the object, such as table, database, index, or tenant. CREATETIMEThe time when the object entered the recycle bin. Restore the table from the recycle bin:
obclient [test]> FLASHBACK TABLE flash_drop_tbl TO BEFORE DROP; Query OK, 0 rows affectedIn the
FLASHBACK TABLEstatement, you can specify either the original name of the table (such asflash_drop_tblin this example) or the name of the object in the recycle bin (such as__recycle_$_10001_1791791724617904). Because the names of objects in the recycle bin are globally unique, when multiple original objects with the same name exist in the recycle bin, we recommend that you use the recycle bin object name to make sure that the expected object is restored.Verify that the table and data have been restored:
obclient [test]> SELECT * FROM flash_drop_tbl;+----+---------------+ | id | remark | +----+---------------+ | 1 | critical data | | 2 | daily report | +----+---------------+ 2 rows in set
Interpretation
Observation |
Expected behavior |
Description |
|---|---|---|
| After DROP TABLE | The table is moved to the recycle bin instead of being deleted directly. | When the recycle bin is enabled, dropped objects still occupy storage space. |
| SHOW RECYCLEBIN | The recycle bin record of the table object is visible. | It contains the recycle bin object name, original name, object type, and time of entry. |
| After FLASHBACK TABLE | The table is restored along with its data and indexes. | The restored table still belongs to the database from which it was dropped. |
| Recovery method | Completed online, with no backup set required. | Suitable for quick recovery after an accidental drop. |
Note
- Objects moved to the recycle bin still occupy storage space. After confirming they are no longer needed, you can use the
PURGEstatement to clean up the recycle bin and free up space. For more information, see Clean up the recycle bin. - You can rename an object to be restored (
RENAME TO), but the name must not duplicate an existing object's name. For a MySQL-compatible tenant, if the database to which a table belongs has been deleted before restoring the table from the recycle bin, you must restore the database first and then restore the table. - MySQL-compatible user tenants support managing recycle bin objects including databases, tables, and indexes. When an index is directly deleted, it does not enter the recycle bin. When a table is deleted, the indexes on that table enter the recycle bin along with the primary table.
More data protection capabilities
Flashback queries and the recycle bin are suitable for recovering data shortly after an accidental operation occurs. When an accidental operation exceeds the undo_retention time window, or in scenarios such as storage media failure or data center-level disasters, backup and recovery capabilities are required as a last resort:
- Physical backup: Consists of two main functions: log archiving and data backup. Log backup continuously maintains the logs generated by the tenant, while data backup maintains backups of snapshot points. Combining the two allows data to be restored to a specified point in time.
- Recovery capability: Supports restoring a tenant to a specified point in time, and also supports table-level recovery, restoring a specified table from backup data into an existing tenant.
Note
For the architecture and complete operations of backup and recovery, see Backup architecture. To get started with physical backup and recovery, see Simplified experience with physical backup and recovery, which provides a minimal example for initiating log archiving, data backup, and recovery.
Next steps
After you complete the experiences in this topic, you can explore the following:
- Experience online DDL: Execute common DDL operations such as adding columns and creating indexes on a test table with continuous read and write activity, and observe business continuity. For more information, see Experience online DDL.
- Deepen your understanding of backup and recovery: Learn about the complete process of log archiving and data backup. For more information, see Simplified experience with physical backup and recovery.
- Review data efficiency capabilities: Learn about parallel import and high compression. For more information, see Experience parallel import and high compression.
References
- For detailed operations and examples of flashback queries, see Flashback query.
- For an introduction to the principle of flashback queries, see Flashback query (Data Protection).
- For detailed descriptions of the tenant-level parameter
undo_retention, see undo_retention. - For features and limitations of the recycle bin, see Recycle bin overview.
- For switching the recycle bin on or off, see Enable or disable the recycle bin.
- For viewing objects in the recycle bin, see View recycle bin objects.
- For the complete syntax of restoring recycle bin objects, see Restore recycle bin objects.
- For cleaning up recycle bin space, see Clean up the recycle bin.
- For an architecture description of backup and recovery, see Backup architecture.
- For a streamlined experience with physical backup and restore, see Streamlined physical backup and restore.