PolarDB for PostgreSQL(Compatible with Oracle) does not provide undo logs. Your accidental operations may cause data loss. For example, data may be lost after you execute the DROP TABLE statement. The drop flashback feature on PolarDB for PostgreSQL(Compatible with Oracle) allows you to quickly restore deleted tables and view and clear the recycle bin. These serves the purpose of recovering data.
Precautions
- We recommend that you enable the drop flashback feature when you delete important tables. Use caution when you perform routine operations.
- When the drop flashback feature is enabled, the deleted table is moved to the space which runs in recycle bin mode. The table is not deleted in the true sense, so the space occupied by the table is not released. Therefore, large disk space may be occupied when a lot of data is accumulated. We recommend that you clear the recycle bin on a regular basis.
- In this case, your attempt to remove the dependencies of the deleted table may fail, because the table is not actually deleted and the table still use these dependencies.
- Because the deleted table is moved to the space which runs in recyclebin mode. Try to avoid creating a mode with the name recyclebin, because the table in recyclebin mode will be cleared by the
purge recyclebin
statement. - When the drop flashback feature is enabled, the following operations are not supported:
- The deleted partitioned table and temporary tables cannot be flashed back. Partitioned table and temporary tables are actually deleted and cannot be restored.
- The
sql_drop
event trigger is not supported.
Parameters
Parameter | Data type | Description |
---|---|---|
polar_enable_flashback_drop | BOOL | Specifies whether to enable the drop flashback feature. Default value: OFF. Valid values:
|
Syntax
The drop flashback feature supports the following SQL statements:
- Delete a policy
drop table table_name; # Move the table to the space which runs in recycle bin mode. drop table table_name purge; # Delete the table, which cannot be restored.
- Restore a deleted table
flashback table table_name to before drop; # Restore the deleted table (the latest table is restored if the table has the same name as other tables). flashback table table_name to before drop rename to table_name_1; # Restore and rename the deleted table.
- Permanently delete files from the recycle bin
purge table table_name;
Note The oldest table is deleted if the table has the same name as other tables. - Clear the recycle bin
purge recyclebin;
Note The polar_super_user permissions are required when you clear the recycle bin. - View recycle bin information
show recyclebin;
Examples
- Prepare data for the test:
Create the
test1
and tabletest2
tables and insert data to them.
A similar output is displayed:CREATE TABLE test1(id int primary key, name text); CREATE TABLE test2(id int primary key, name text); INSERT INTO test1 select t,repeat('test1',1024) from generate_series(1, 10000) as t; INSERT INTO test2 select t,repeat('test2',1024) from generate_series(1, 10000) as t; \dt
List of relations Schema | Name | Type | Owner --------+-------+-------+---------- public | test1 | table | postgres public | test2 | table | postgres (2 rows)
- Delete the tables and view the recycle bin.
- Delete the
test1
andtest2
tables.
A similar output is displayed:DROP TABLE test1; DROP TABLE test2; \dt
Did not find any relations.
- View the recycle bin.
A similar output is displayed:show recyclebin;
table_catalog | table_name | table_type ---------------+-----------------------------+------------ postgres | public$test1$69461331094004 | BASE TABLE postgres | public$test2$69461332967609 | BASE TABLE (2 rows)
- Delete the
- Flash back the deleted tables:
- Restore the deleted tables.
A similar output is displayed:FLASHBACK TABLE test1 TO BEFORE DROP; FLASHBACK TABLE test2 TO BEFORE DROP RENAME TO test3; \dt
List of relations Schema | Name | Type | Owner --------+-------+-------+---------- public | test1 | table | postgres public | test3 | table | postgres (2 rows)
Note Thetest2
table is renamedtest3
. - View the restored data. View the data in the
test1
table.
A similar output is displayed:SELECT count(*) FROM test1;
count ------- 10000 (1 row)
View the data in thetest3
table.
A similar output is displayed:SELECT count(*) FROM test3;
count ------- 10000 (1 row)
- Restore the deleted tables.