How to get table back once it is deleted
flashback table <table> to timestamp <when it was good>;
flashback table orders to timestamp systimestamp - interval '1' hour;
alter table <table> enable row movement;
select * from <table> as of timestamp systimestamp - interval '1' hour;
select * from <table> as of scn 1234567;
insert into table select * from <table> as of timestamp sysdate – interval '1' hour where <conditions to find the rows>;
select * from <table> as of timestamp sysdate – interval '1' hourminus select * from <table>;
insert into <table> select * from <table> as of timestamp sysdate – interval '1' hour minus select * from <table>;
update <table> curset (col1, col2, col3) = ( select col1, col2, col3 from <table> as of timestamp systimestamp – interval '1' hour old where cur.primary_key = old.primary_key)where <rows to update>;
Flashback has some limitation :
- Oracle only ensures you can query as far back as the value of your “undo_retention” parameter.
- Oracle is unable to query across many forms of DDL. So if you change a table's structure there's a good chance Flashback Query will fail.
alter system set undo_retention = 86400 scope = both;
create flashback archive <archive> tablespace <tablespace> retention 1 year;
alter table <table> flashback archive <archive>;
- Being able to query across DDL
- Having a larger window of time to recover data
flashback table <table> to before drop;
select * from recyclebin;
drop table <table> purge;
purge table <table>;
purge recyclebin;
To use Flashback Database you need to do some initial setup. There are two ways to enable this:
- Enable Flashback Database
- Create a restore point
Firstly, your database must be running in archivelog mode. Assuming this is the case, the process for enabling it is:
- Configure the fast recovery area
- Set the DB_flashback_retention_target parameter (optional)
- Enable Flashback Database
alter system set DB_RECOVERY_FILE_DEST = '/u01/oradata/recovery_area' scope=both;alter system set DB_RECOVERY_FILE_DEST_SIZE = 10G scope=both;
1 alter system set DB_flashback_retention_target = 10080 scope=both;alter database flashback on;create restore point <restore_point> guarantee flashback database;
Two key use cases for this are:
- An extra safety net for database releases
- Reverting test databases to a known state
Comments
Post a Comment