The method of recovery method of recovering the data deletion oracle oracle data deletion of

Oracle accidentally deleted data recovery method

 

Learning database, we are just learning attitude and consider how to use the database command statement, did not thought about work, if misuse it, may lead to irreparable damage. When I met these real problems at work, I started looking for answers.


Today, mainly in the oracle database as an example, a solution with regard to the data in the table deleted. (Without considering the full database backup and use of archive log)
data delete the table, there are three methods:
· the Delete (deleting a record)
· drop or truncate table to delete data

 

1.delete accidentally deleted solution
principle:

Flashback oracle data utilization method provided, if the number of operations do not delete the data (data to be deleted as long as no blocks are overwritten), flashback can use directly back to delete
the specific steps:

* Delete data to determine the time (in the time before deleting data on the line, but the best time is to delete data)

* Identify the deleted data with the following statement: select * from table as of timestamp to_timestamp ( 'deletion time point', 'yyyy-mm-dd hh24: mi: ss')

* The deleted data reinsert the original table:

     insert into table (select * from table as of timestamp to_timestamp ( 'deletion time point', 'yyyy-mm-dd hh24: mi: ss')); attention to ensure that the primary key is not repeated.

If the table structure is not changed, but also can be used as flash back an entire table used to restore the data.

Specific steps:

Table Flashback requires users to have a flash any table permissions

 

 - Enable row movement 

 ·alter table 表名 enable row movement

 - recover table data
 · flashback table table name to timestamp to_timestamp (deleting time ',' yyyy-mm-dd hh24: mi: ss')

 - Close the row movement (  do not forget  )

 ·alter table 表名 disable row movement


2.drop accidentally deleted solution

Principle: As the oracle When you delete a table, the table is not empty the share of direct block, oracle deleted the information in these tables into a virtual container "Recycle Bin", but only made may be coated with the data block table write flag, so before the blocks are not re-use can also be restored.

Specific steps:

* Query the "Recycle Bin" or query user_table views to the lookup table has been deleted:

 · select table_name,dropped from user_tables

 · select object_name,original_name,type,droptime from user_recyclebin

In the above information, the table names are to be renamed before, or table_name field object_name is the table name after deleting stored in the Recycle Bin

* If you can remember the name of the table, it can be recovered directly with the following statement:

  flashback table 原表名 to before drop

 If you can not remember, it can also be used as table name to restore the Recycle Bin, and then rename the reference to the following statement:

  flashback table "table name in the Recycle Bin (eg: Bin $ DSbdfd4rdfdfdfegdfsf == $ 0)" to before drop rename to new table name

oracle flashback addition to the above functions of the basic functions, the entire database can Flashback:

Use Flashback Database feature, you can make a return to the past state of the database, the syntax is as follows:

SQL>alter database flashback on
SQL>flashback database to scn SCNNO;
SQL>flashback database to timestamp to_timestamp('2007-2-12 12:00:00','yyyy-mm-dd hh24:mi:ss');


Summary:
After the oracle to provide above mechanism ensures safe operation, but also generations to another problem is that the space occupied, due to the operation of the above mechanism, using a drop table or delete data, not from space

Dynamic recovery, some are not used to determine the table to be deleted while recovering space, can have the following two ways:

  1, using the truncate manner truncated. (But can not recover the data back)

  2, together with purge option when you drop: drop table table name purge

     This option has the following purposes:

  May also be permanently deleted by deleting recyclebin region table, delete the original table EMP Cascade Constraints Table drop
   purge Table EMP;
   delete the current user's Trash:
    purge recyclebin;
   delete all user data in the trash:
   purge DBA_RECYCLEBIN

Learning database, we are just learning attitude and consider how to use the database command statement, did not thought about work, if misuse it, may lead to irreparable damage. When I met these real problems at work, I started looking for answers.


Today, mainly in the oracle database as an example, a solution with regard to the data in the table deleted. (Without considering the full database backup and use of archive log)
data delete the table, there are three methods:
· the Delete (deleting a record)
· drop or truncate table to delete data

 

1.delete accidentally deleted solution
principle:

Flashback oracle data utilization method provided, if the number of operations do not delete the data (data to be deleted as long as no blocks are overwritten), flashback can use directly back to delete
the specific steps:

* Delete data to determine the time (in the time before deleting data on the line, but the best time is to delete data)

* Identify the deleted data with the following statement: select * from table as of timestamp to_timestamp ( 'deletion time point', 'yyyy-mm-dd hh24: mi: ss')

* The deleted data reinsert the original table:

     insert into table (select * from table as of timestamp to_timestamp ( 'deletion time point', 'yyyy-mm-dd hh24: mi: ss')); attention to ensure that the primary key is not repeated.

If the table structure is not changed, but also can be used as flash back an entire table used to restore the data.

Specific steps:

Table Flashback requires users to have a flash any table permissions

 

 - Enable row movement 

 ·alter table 表名 enable row movement

 - recover table data
 · flashback table table name to timestamp to_timestamp (deleting time ',' yyyy-mm-dd hh24: mi: ss')

 - Close the row movement (  do not forget  )

 ·alter table 表名 disable row movement


2.drop accidentally deleted solution

Principle: As the oracle When you delete a table, the table is not empty the share of direct block, oracle deleted the information in these tables into a virtual container "Recycle Bin", but only made may be coated with the data block table write flag, so before the blocks are not re-use can also be restored.

Specific steps:

* Query the "Recycle Bin" or query user_table views to the lookup table has been deleted:

 · select table_name,dropped from user_tables

 · select object_name,original_name,type,droptime from user_recyclebin

In the above information, the table names are to be renamed before, or table_name field object_name is the table name after deleting stored in the Recycle Bin

* If you can remember the name of the table, it can be recovered directly with the following statement:

  flashback table 原表名 to before drop

 If you can not remember, it can also be used as table name to restore the Recycle Bin, and then rename the reference to the following statement:

  flashback table "table name in the Recycle Bin (eg: Bin $ DSbdfd4rdfdfdfegdfsf == $ 0)" to before drop rename to new table name

oracle flashback addition to the above functions of the basic functions, the entire database can Flashback:

Use Flashback Database feature, you can make a return to the past state of the database, the syntax is as follows:

SQL>alter database flashback on
SQL>flashback database to scn SCNNO;
SQL>flashback database to timestamp to_timestamp('2007-2-12 12:00:00','yyyy-mm-dd hh24:mi:ss');


Summary:
After the oracle to provide above mechanism ensures safe operation, but also generations to another problem is that the space occupied, due to the operation of the above mechanism, using a drop table or delete data, not from space

Dynamic recovery, some are not used to determine the table to be deleted while recovering space, can have the following two ways:

  1, using the truncate manner truncated. (But can not recover the data back)

  2, together with purge option when you drop: drop table table name purge

     This option has the following purposes:

  May also be permanently deleted by deleting recyclebin region table, delete the original table EMP Cascade Constraints Table drop
   purge Table EMP;
   delete the current user's Trash:
    purge recyclebin;
   delete all user data in the trash:
   purge DBA_RECYCLEBIN

Guess you like

Origin www.cnblogs.com/yaoyangding/p/12147875.html