I discovered something truly marvellous today while doing a little revision – something I missed in 10g! I had seen restore points in various documentation sets and thought “Oh – its just a tag to flashback to when running flashback-database – Ok fine”. Then when I see references to “Guaranteed restore points” I made an assumption that it just meant that oracle wouldn’t delete the flashback logs it needed to honour the restore point.…
I was kinda correct...However, the interesting part is that to run with guaranteed restore points you don’t actually need to be running in flashback database mode with all the (possible) pain of having flashback logs filling your Flash Recovery Area. Basically as long as you are at least running in archivelog mode, and have a flash_recovery_area defined then you can use guaranteed restore points to flash the database back even without having flashback database (FBD) enabled.
So – how does this work? When FBD is enabled, the before image of a block is written away to the flashback logs at the point a change is made to that block. The flashback logs are analogous to redo logs only the record the “undoing” not the “doing”. As long as we have flashback logs that go back in time to the point at which we want to flash back to, all is good; We can flash back to any time in that timefield. A normal restore point in this scenario is in effect just a tag that identifies a time.
If we create a guaranteed restore point and we DON’T have FBD enabled how can we still flashback? After all, no flashback logs are produced right? Well… oracle does indeed create flashback logs for us when we create the restore point. The difference is that only the first change to a block is written away to the flashback logs – we aren’t saying we want to flashback to any time in this case, just to the guaranteed restore point. Hence any additional changes to a block after the first isn’t needed or recorded. We don’t need all the before-images for every change – just the first “before” image of the blocks that subsequently got changed.
Note that this only works with guaranteed restore points; If you try it with a plain restore point without being in FBD mode you get ;
ORA-38782 cannot flashback database to non-guaranteed restore point "string"
Ok - so a quick walkthrough;
SQL>
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> create restore point rp1;
Restore point created.
SQL> create restore point rp2_guaranteed guarantee flashback database;
create restore point rp2_guaranteed guarantee flashback database
*
ERROR at line 1:
ORA-38784: Cannot create restore point 'RP2_GUARANTEED'.
ORA-38787: Creating the first guaranteed restore point requires mount mode when
flashback database is off.
- Ok so to do the first ever guaranteed restore point we have to do it in mount. This makes some sense as we are changing the Flashback database mode to this new "Flashback Only" style mode.
SQL> shu immediate
.....
SQL> startup mount
.....
Database mounted.
SQL>create restore point rp2_guaranteed guarantee flashback database;
Restore point created.
SQL> alter database open;
Database altered.
SQL>
SQL> create table made_after_restore_point (c1 number);
Table created.
SQL>shu abort
SQL>mount
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
RESTORE POINT ONLY
SQL> flashback database to restore point RP2_GUARANTEED;
Flashback complete.
SQL> desc made_after_restore_point
ERROR:
ORA-04043: object made_after_restore_point does not exist
So - we successfully flashed back to before the table was created - WITHOUT having Flashback Database enabled!
I think thats kinda neat.


