How to recover data deleted by oracle by mistake

When learning the database, we just take the attitude of learning and consider how to use the database command statement, and have not thought that if we misuse it at work, it may lead to irreparable losses. When I actually ran into these questions at work, I started looking for answers.
Today, we mainly take the oracle database as an example to introduce the solution to the deletion of data in the table.
There are three ways to delete data in a table (regardless of full database backup and use of archived logs) :
· delete (delete a record)
· drop or truncate to delete data in
the
table method, if you have not done a lot of operations after deleting the data (as long as you ensure that the block of the deleted data is not overwritten), you can use the flashback method to directly retrieve the deleted data.
The specific steps are:
* Determine the time to delete the data (in The time before the data is deleted is fine, but it is best to delete the data at the time point)
*Use the following statement to find out the deleted data: select * from table name as of timestamp to_timestamp('delete time point','yyyy-mm-dd hh24 :mi:ss')
*Re-insert the deleted data into the original table:
     insert into table name(select * from table name as of timestamp to_timestamp('delete time point','yyyy-mm-dd hh24:mi:ss') ); pay attention to ensure that the primary key is not repeated.
If the table structure has not changed, you can also directly use flashback to restore the data.
The specific steps are:
Table flashback requires the user to have the permission to flash any table
 ·alter table table name enable row movement
 ·flashback table table name to timestamp to_timestamp(delete time point','yyyy-mm-dd hh24:mi:ss')
2. The solution
principle of drop accidental deletion: because oracle is deleting the table When the block occupied by the table is not emptied directly, oracle puts the information of these deleted tables into a virtual container "recycle bin", but only marks the data block of the table that can be overwritten, so in the block It can be restored before being reused.
Specific steps:
* Query the "recycle bin" or query the user_table view to find the dropped table:
 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 all Renamed, the field table_name or object_name is the name of the table stored in the recycle bin after deletion.
*If you can still remember the table name, you can directly restore it with the following statement:
  flashback table The original table name to before drop
 If you can’t remember it , you can also directly use the table name of the recycle bin to restore, and then rename it, refer to the following statement:
  flashback table "table name in the recycle bin (eg: Bin$DSbdfd4rdfdfdfegdfsf==$0)" to before drop rename to new table name
In addition to the above basic functions, oracle's flashback function can also flashback the entire database:
using the database flashback function, the database can be returned to a certain state in the past, 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:
Oracle provides the above mechanism to ensure safe operation, but also Another problem arises, that is, the space occupation. Due to the operation of the above mechanism, the space will not be automatically reclaimed after dropping a table or deleting data. For some tables that are determined not to be used, the space should be reclaimed at the same time when deleting, which can be as follows 2 ways:
  1. Truncate by truncate. (But data recovery cannot be performed)
  2. Add the purge option to drop: drop table table name purge

     This option also has the following uses:
  you can also delete the table permanently by deleting the recyclebin area, the original delete table drop table emp cascade constraints
   purge table emp;
   delete the current user's recycle bin:
    purge recyclebin;
   delete all users' data in the recycle bin:
   purge dba_recyclebin
Source: original website Beijing Beiya Data Recovery Center, reprint must indicate the source.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326272806&siteId=291194637