Before going any production upgrade to database we can make a guaranteed restore point to database and if any wrong then we can get back to the restore point state. Guaranteed restore point always ensure that we can get back data to our restore point creation time.
Suppose before upgradation to database I have made an guaranteed restore point to database like,
SQL> create restore point before_upgrade guarantee flashback database;
Restore point created.
SQL> conn arju/a
Connected.
SQL> select count(*) from user_tables;
COUNT(*)
----------
4
SQL> create table after_restore_point (col1 number);
Table created.
SQL> desc after_restore_point;
Name Null? Type
----------------------------------------- -------- ----------------------------
COL1 NUMBER
Now I want to perform flashback database to get back database at the time of creating restore point. To do it follow the following steps,
1. Determine the desired SCN, restore point or point in time for the FLASHBACK DATABASE command.
SQL> select NAME,SCN,GUARANTEE_FLASHBACK_DATABASE,DATABASE_INCARNATION# from v$restore_point;
NAME SCN GUA DATABASE_INCARNATION#
------------------------------ ---------- --- ---------------------
BEFORE_UPGRADE 787027 YES 2
2.Shutdown the database cleanly and mount it.
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP MOUNT;
3.Determine the current window for flashback database.
When flashback logging is enabled, the earliest SCN in the flashback database window can be determined by querying V$FLASHBACK_DATABASE_LOG.
SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME
FROM V$FLASHBACK_DATABASE_LOG;
If you attempt FLASHBACK DATABASE and your target SCN is now outside the flashback window, then FLASHBACK DATABASE will fail with an ORA-38729 error.
So, you can't get back to state to an SCN before OLDEST_FLASHBACK_SCN.
4.Run your RMAN flashback command your restore point or to the desired SCN or to your desired time.
In this case I ran,
SQL> FLASHBACK DATABASE TO RESTORE POINT before_upgrade;
Flashback complete.
You can also use TO SCN Clause and TO TIMESTAMP Clause with FLASHBACK DATABASE.
5. You can verify that you have returned the database to the desired state, by opening the
database read-only and performing some queries to inspect the database contents.Like I perform some operations,
SQL> alter database open read only;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
----------
READ ONLY
SQL> conn arju/a
Connected.
SQL> select count(*) from tabs;
COUNT(*)
----------
4
SQL> desc after_restore_point;
ERROR:
ORA-04043: object after_restore_point does not exist
6) If you are satisfied with the state of your database about flashback then you have two choices.
Choice a) Make the database available for updates by open resetlogs, Once you perform this OPEN RESETLOGS operation, all changes to the database after the target SCN for FLASHBACK DATABASE are abandoned.
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP MOUNT;
SQL>alter database open RESETLOGS;
Choice b) Use the export/data pump export utility to export the objects whose state was corrupted. Then, recover the database to the present time:
RMAN> RECOVER DATABASE;
This step undoes the effect of the Flashback Database, by re-applying all changes in the redo logs to the database, returning it to the most recent SCN.
After re-opening the database read-write, you can import the exported objects using the import utility corresponding to the export utility used earlier.
No comments:
Post a Comment