oracle flashback recovery

oracle flashback recovery
The flashback recovery area is mainly set and managed through 3 initialization parameters:
db_recovery_file_dest: specifies the location of the flashback recovery area
db_recovery_file_dest_size: specifies the available space size of the flashback recovery area
db_flashback_retention_target: specifies the time that the database can roll back, unit Minutes, the default is 1440 minutes, that is,

the default value of one day is 1440, and the unit is minute, that is, 24 hours. It should be noted that although this parameter does not directly specify the size of the flash recovery area, it is restricted by it. For example, if the database If there is a data change of about 10%, if the initialization parameter value is set to 1440, the size of the flash recovery area should be at least 10% of the actual capacity of the current database; if the initialization parameter is set to 2880, the size of the flash recovery area should be at least It is 20% of the capacity occupied by the database.
Flashback is also limited by undo_retention default is 900 15 minutes

Enable flashback:
first enable the archive log archivelog list;
startup mount;
alter database flashback on;
select FLASHBACK_ON from v$database; check whether flashback is enabled
alter database flashback off; turn off flashback

select file_type from v $flash_recovery_area_usage; the contents of the flashback recovery area
select * from v $flash_recovery_area_usage; or select * from v $ recovery_file_dest; to view the usage of the recovery area, if the archived log is stored in the directory again and there is no idle database, it will hang live

Flashback includes : Flashback Database, Flashback Drop, Flashback Query (Flashback Query, Flashback Version Query, Flashback Transaction Query) and Flashback Table.
The function of Flashback Database is very similar to the incomplete recovery of RMAN. It can roll back the entire database to the state at a certain point in the past. This function depends on the Flashback log log. Faster and more efficient than RMAN. So Flashback Database can be seen as an alternative to incomplete recovery. But it also has certain limitations:

  1. Flashback Database cannot solve Media Failure, this kind of error RMAN recovery is still the only option
  2. If you delete the data file or use the Shrink technology to reduce the size of the data file, you cannot use the Flashback Database technology to return to the state before the change. At this time, you must first use RMAN to restore the backup file before the deletion or shrinking, and then use Flashback Database executes the rest of Flashback Database.
  3. Flashback Database cannot be used if the control file was restored from a backup, or if it was a rebuilt control file.
  4. The earliest SCN that can be recovered using the Flashback Database lock depends on the earliest SCN recorded in the Flashback Log.

Flashback Database
can build a table to record scn every important operation.
create table test (id int, comments varchar2(20), times date);
insert into test values((select current_scn from v$database),'test', sysdate); Before the important operation, the operation needs to be Flashback Drop
in the mount state. This operation has recyclebin to realize the rollback drop table name purge; (if you add purge, it will be deleted directly and will not enter the recycle bin) show parameter recycle select *from recyclebin You will see your drop operation. If there are multiple results of the same table from the query, it will only restore to the latest table purge table test1. You can delete the latest record. Flashback Query select * from xxx as of timestamp|scn alter session set nls_date_format=' YYYY-MM-DD hh24:mi:ss'; select * from test1 as of timestamp sysdate-2/1440; (query data within a few minutes)
insert image description here







insert image description here




select * from test1 as of timestamp to_timestamp('2023-05-17 15:10:00','YYYY-MM-DD hh24:mi:ss') (the previous data within the specified time) can also use
insert image description here
insert into A select * from A as of scn 1095782; Use scn to restore
or directly restore the table flashback table emp_test to timestamp to_timestamp('2013/11/21 23:14:59','yyyy-mm-dd hh24:mi:ss' ); or flashback table emp_test to scn 2701570;

Flashback Transaction Query
SELECT xid, start_timestamp, operation, table_name, undo_sql
FROM flashback_transaction_query
WHERE table_name = ‘your_table_name’
AND operation IN (‘INSERT’, ‘UPDATE’, ‘DELETE’);

FLASHBACK TRANSACTION ‘’ TO BEFORE COMMIT;

Guess you like

Origin blog.csdn.net/qq_39412605/article/details/130680347