Friday 26 June 2015

Switching over to a Logical Standby :

Switching over to a logical standby is simpler because the database is already open for reading and writing, but there is a second set of steps that guarantee the safety of your data if a failure occurs after the switchover but before the the new logical standby can process transactions. As of Oracle 11g you no longer need to shutdown any database instances to perform the switchover, older versions of Oracle you need to shutdown all auxiliary instances.

Firstly check the state of the primary
Check primary database state     ## It should have a status of "to standby"

select switchover_status from v$database;

Unlike a physical standby which a exact copy of the primary, a logical standby could be different and once the roles are reversed the new logical standby needs to know what the new primary looks like so SQL Apply process can process the redo stream. So to prepare we run the following command on the primary
Prepare the primary standby     alter database prepare to switchover to logical standby;

## confirm that the prepare has started to happen, you should now see "preparing switchover"
select switchover_status from v$database;

Now go to the logical standby and tell it to send the preparation information to the primary in its redo stream
Prepare the logical standby     alter database prepare to switchover to primary;

## confirm that the prepare has started to happen, you should see "preparing dictionary"
select switchover_status from v$database;

## wait a while until the dictionary is built and sent and you should see "preparing switchover"
select switchover_status from v$database;

The logical will commence a dictionary build and put it into the redo stream of the logical standby, which will be sent to the primary. The reason for this step is that new logical standby knows how to apply the redo from the new primary the moment new primary transactions start to generate redo. If you skip this step you will be generating redo from business transactions that will be sent to your logical standby. The new dictionary would then be behind that redo, and if you had a failure of the new primary before the dictionary was sent to the new logical standby, a failover would result in data loss.

Now check the primary again and it should be ready to become the new logical standby, to confirm this use the following command
Check primary database state     ## you should now see its in the state of "to logical standby"

select switchover_status from v$database;

At this point you can cancel the whole switchover as you are not committed yet
cancel the switchover     ## On the primary
alter database prepare to switchover cancel;

## on the logical
alter database prepare to switchover cancel;

If you are happy to continue the switchover then on the primary lets tell it that its going to be a logical standby
switchover the primary to a logical standby     alter database commit to switchover to logical standby;

Your users will now have to wait until the switchover has completed, they may experience significant stalling. Once the switchover is completed and Data Guard enables the Guard on the primary to prevent more updates to the data, as this is now a logical standby database.

Now finish off the logical standby database
switchover the logical standby to a primary     ## check that its ready to become the primary, you should see "to primary"

select switchover_status from v$database

## Complete the switchover
alter database commit to standby to primary;

Start the apply process on the new logical standby
start the apply process     alter database start logical standby apply immediate;

That's it, you should now have a successful switchover, you can use my monitoring section to check everything is working correctly.

That seemed a lot of work above to switchover, if you have a broker configured then it just one command, buts its good to learn what goes on behind the scenes when you use the broker.
Switchover using the broker     DGMGRL> switchover to prod1lr

Don't forget that when you are learning to tail the alert and broker logs when your are playing around with switching over, you get a better understanding on what Oracle is doing.

So the finals checks you need to make before the switchover are

    Make sure that your configuration has been setup properly and has not been altered
    Meet all the Data Prerequisites
    Enable Flashback Database
    Verify that redo is being sent to the standbys and is being applied
    Ensure that the standby will not encounter problems during the switchover due to nologging DML on the primary if you have not enabled FORCE LOGGING.


No comments:

Post a Comment