Oracle FLASHBACK: flashback table and flashback drop

Source: Internet
Author: User

In Oracle 10 Gb, the flash back family is divided into the following members:
Flashback Database
Flashback drop
Flashback table
Flashback query (flashback query, flashback version query, and flashback transaction query)
The following describes flashback drop and flashback table.

Flashback drop

Flashback drop occurs from Oracle 10 GB and is used to restore objects accidentally deleted by users (including tables and indexes). This technology relies on tablespace Recycle Bin (tablespace recycle bin ), this function is very similar to the recycle bin of windows.
This function has no relationship with the flashback parameter and does not require row movement for tables.
Tested SQL> alter database flashback off can flash back to drop the table.
Flashback does not support objects in the SYS user. System tablespace and cannot be obtained from the recycle bin. Therefore, show recyclebin is empty when sys or system users log on.
1. tablespace Recycle Bin
Starting from Oracle 10 Gb, each tablespace has a logical region called the recycle bin. When you run the drop command, the deleted table and associated objects (including indexes and constraints) of the table are deleted, trigger, lob segment, and LOB index segment) will not be physically deleted. These objects are first transferred to the recycle bin, which provides users with a possibility of recovery.
The recyclebin initialization parameter is used to control whether to enable the recyclebin function. The default value is on and can be disabled with off.
SQL> show parameter Recycle
Recyclebin string on

Disable this function:
SQL> alter system set recyclebin = off;
SQL> alter system set recyclebin = on;
SQL> alter session set recyclebin = off;
SQL> alter session set recyclebin = on;
After the deletion is disabled, the deleted object will be deleted directly and will not be written to recycle. Of course, when you delete the object, specify the purge parameter, and the table will be deleted directly without being written to recyclebin.

The recycle bin area of a tablespace is only a logical region, instead of physically setting a partition from the tablespace for the recycle bin. Therefore, the recycle bin area shares the storage region of the tablespace with common objects, or the Recycle Bin object needs to snatch the storage space from the common object. When space is insufficient, Oracle overwrites the objects in recycle bin in the first-in-first-out order. You can also manually delete the space occupied by the recycle bin.

1). Purge tablespace tablespace_name: used to clear the recycle bin of the tablespace
2). Purge tablespace tablespace_name user user_name: clears the objects of the specified user in the recycle bin of the specified tablespace.
3). Purge recyclebin: deletes the objects in the recycle bin of the current user.
4). Purge dba_recyclebin: deletes the objects in recycle bin of all users. This Command requires sysdba permission.
5). Drop table table_name purge: delete objects permanently and cannot be restored using flashback instead of in recycle bin.
6). Purge index recycle_bin_object_name: When you want to release the space of the recycle bin and restore the table, you can release the space occupied by the index of the object to relieve the space pressure. Because indexes can be rebuilt.

2. Flashback drop instance operation

The following operations are performed when the system parameter recyclebin = on:
1. SQL> drop table test1;
Table dropped.

2. View recyclebin Information
SQL> Col origninal_name format A15;
SQL> Col Type format A15;
SQL> select object_name, original_name, type from user_recyclebin;

Object_name original_name type
---------------------------------------------------------------------
Bin $ fr5 g/49 + sz2oesrtx4uchg = $0 idx_testid Index
Bin $ x1ey4htfseilywuq7kkm + W ==$ 0 test1 table
SQL> show recyclebin; -- note that this is the sqlplus command
Original Name recyclebin name object type drop time
-----------------------------------------------------------------------------
Test1 bin $ x1ey4htfseilywuq7kkm + W ==$ 0 table 2012-01-13: 16: 35: 24

3. Flash the deleted table back
SQL> flashback table test1 to before drop;
Flashback complete.
SQL> select * From test1;
ID name
--------------------
3763392

In this case, after table test1 is deleted, an object test1 (table or procedure...) with the same name is created. You need to rename it when flashing back.
Flashback table test1 to before drop Rename to testx
Another case is that tables with the same name are repeatedly dropped to the recyclebin, and the following principle is followed.
Once the flash recovery is completed, the objects in the recycle bin disappear.
SQL> select object_name, original_name, type from user_recyclebin;
No rows selected

Flashbacktable drop is not supported after recyclebin is set to off.
SQL> alter system set recyclebin = off;
System altered.
SQL> drop table test1;
Table dropped.
SQL> select object_name, original_name, type from user_recyclebin;
No rows selected

Notes for Flashback drop:
1). It can only be used for non-system tablespace and locally managed tablespace.
2). The reference constraints of the object will not be restored. The foreign key constraints pointing to the object need to be rebuilt.
3) whether the object can be restored successfully depends on whether the object space is overwritten and reused.
4 ). when you delete a table, the materialized view that depends on the table is also deleted, but the materialized view is not placed in the recycle bin. Therefore, when you execute flashback table to before drop, you cannot restore the materialized view that depends on it. You need to manually create a new view by the DBA.
5). For objects in recycle bin, only query is supported.

Flashback table

Note that the Sys user does not support flashback, as described above.
Flashback table also uses the Undo tablespace content to implement data rollback. This command is relatively simple. Enter flashback table table_name to SCN (to timestamp.
Note: To flashback a table, you must allow row movement of the table.
Alter table table_name row movement;
To check whether row movement is enabled for a table, you can query it in user_tables (or all_tables, dba_tables ),
For example:
SQL> select row_movement from user_tables where table_name = 'test1 ';
Row_move
--------
Disabled
Row movement is not supported at this time.

SQL> select current_scn from V $ database;
Current_scn
-----------
3769840
SQL> Delete from test1;
1 row deleted.
SQL> commit;
Commit complete.
SQL> flashback table test1 to SCN 3769840;
Flashback table test1 to SCN 3769840
*
Error at line 1:
ORA-08189: cannot flashback the table because row movement is not enabled
In this case, the above error occurs because row movement is not supported.
SQL> ALTER TABLE test1 enable row movement;
Table altered.
SQL> flashback table test1 to SCN 3769840;
Flashback complete.
SQL> select * From test1;
ID
----------
1
The flashback table command allows you to operate on multiple tables at the same time. Table names can be separated by commas. If you specify multiple tables when executing a flashback table command, remember that a single flashback table is in the same transaction, so the restoration operations of these tables are either successful or failed.
For example, flashback Table A, B, C to SCN 1103864;

Example of flashback table Houdini to flash back to a certain time point: flashback table test1 to timestamp to_timestamp ('2017-01-16 13:15:08. 232349 ', 'yyyy-MM-DD hh24: MI: SS: ff ')
Oracle also supports creating a 'Restore point' before the operation to mark a recovery point and then use it for future falshback.
Create Restore Point rp_acct_01;
Flashback table Houdini to restore point rp_acct_01;

Drop Restore Point rp_acct_01;

Undo-based table recovery, pay attention to the impact of DDL operations

For example, after truncate table cannot flashback table, an error occurs: ORA-01466: unable to read data-table definition has changed.
Other operations include: Drop/modify column, move table, drop partition (if any), truncate table/partition. These operations will invalidate the Undo tablespace data revocation, applying flashback query to tables that have performed these operations triggers a ORA-01466 error. In addition, although some table structure modification statements do not affect the Undo tablespace revocation record, it is possible that the record duplication in the Undo table cannot be applied due to table structure modification. For example, if a constraint is added, however, the Undo record queried by flashback does not meet the new constraints, and direct recovery is obviously not successful at this time. You can either temporarily disable
Constraints, either through appropriate logic, after processing the data to be restored, then execute recovery.
In addition, flashback query is invalid for dynamic performance views such as V $ tables and x $ tables, but it is effective for data dictionaries such as DBA _ *, all _ *, and user. At the same time, this feature fully supports accessing remote databases, such as select * From TBL @ dblink as of SCN 360.
2. for Undo-based table restoration, flashback table actually performs DML operations (DML locks will be applied to the operated table). Therefore, you need to pay attention to the impact of triggers on it. By default, flashback table to SCN/timestamp will automatically disable triggers that are different from the operating table during execution. If you want to continue using trigger during this period, you can append the triggers after the flashback table
Enable triggers clause.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.