Thursday, September 20, 2007

Oracle11g SNAPSHOT standby database

Till now you have come across two types of standby databases namely Physical standby database and Logical standby database. From Oracle 11g onwards there is one more addition to this. It is called Snapshot standby database.

Snapshot standby is updatable version of the standby database. It is created from the existing standby database .You can modify the database and again you can convert it back to the physical standby database. The snapshot standby database receives the archive logs(redo) from the primary database but does not apply the redo in standby .It is automatically applied when you convert the snapshot standby database back to physical standby database and the conversion can be done at any point of time! So data from the primary database is always protected .It gives data protection and disaster recovery exactly like the physical standby database.


Why you need a snapshot standby database??


As told earlier snapshot standby database is updatable. It provides the replicated version of the primary database which can be used for development, testing and reporting purposes. You can always refresh the snapshot standby database to be in sync with the primary by converting it to physical standby database. Again you can convert to snapshot version do the testing and resynchronize with primary. This cycle can be repeated any number of times!

The conversion from physical standby to snapshot standby database and vice versa can be done in three ways.
1.Dataguard Broker(If the physical standby is managed by DGMGRL)
2.Enterprise Manager(If the physical standby is managed by DGMGRL)
3.Manual method.

Let us see how you can convert the physical standby database to snapshot standby database manually. This can be done by issuing the below SQL command in the physical standby database.

Sql>alter database convert to snapshot standby;

If the standby database is a RAC setup then you need to shutdown all the instances except one on which you will be using the conversion commands.

You may wonder how you will be able to get back to the original state .Here Oracle uses its own features within, nothing else! Oracle uses restore point and flashback feature to accomplish this. If you remember, restore point and flashback database concepts were first introduced in Oracle10g.

When you convert the physical standby database to snapshot standby database a guaranteed restore point is created. This guaranteed restore point is used to flashback a snapshot standby database to its original state. The name of this guaranteed restore points begins with ‘SNAPSHOT_STANDBY_REQUIRED_’. The database is dismounted during this conversion and you have to restart the database (which will be the snapshot standby database).

Once it is converted the database can be opened in read/write mode, you can update the database. Meanwhile you will be receiving the redo from the primary, which will be automatically applied when snapshot standby database is converted back to physical standby database.

Now, to convert the snapshot standby back to the physical standby state use the following SQL command:

Sql>alter database convert to physical standby;

Using the guaranteed restore point the snapshot standby database will be flashed back to its original state and subsequently the restore point will be dropped. After the conversion the redo will be applied which were received by the snapshot standby database.

Note:

When you convert a physical standby database to snapshot standby database, Then

• Redo gap detection and resolution will work as before.
• You cannot perform switchover or failover on a snapshot standby database. To perform role transitions you have to convert the snapshot standby database back to physical standby database.
• If the primary database has a new incarnation (because of Flashback database or Open resetlogs ),the snapshot database continue to receive the redo from the primary.
• In case of role transition of one of the standby database (like failover or switchover), the snapshot standby database continues to receive the redo from the new primary.

Comments are always welcome :-)

Friday, August 17, 2007

Listener hangs in Oracle 10g and no new connections are allowed

Just when I was thinking how boring my job as DBA was (doing the same routine work and nothing new to implement until you convince everyone and take approvals from them!!) I was made to feel that DBA work is not at all boring if you are at the receiving end :-) . I was suddenly bombarded with mails from the users saying that they are not able to connect to the database. As usual I checked the listener status and replied to some of them saying that there is no problem with the listener as such but would get back to them with a solution. It was a production database, the pressure on me was mounting every second. I was not sure what to do? Reply to the users or solve the problem :-)

The database version was of Oracle 10.2.0.1 running on Linux RHEL 4..The listener seemed to be in hung state and moreover there were no errors in the listener log file.

I don’t know what came to my mind I thought of checking the listener process using the ps command. I was surprised to see a child process forked automatically with the same name of the current listener.

$ ps -ef |grep tns
oracle 2310 1 0 Jul 17 ? 72:00 /oracle/ora10g/db/bin/tnslsnr oprem -inherit
oracle 6573 2310 0 14:19:23 ? 0:00 /oracle/ora10g/db/bin/tnslsnr oprem –inherit

I killed the child process and then reloaded the listener. Phew!!...it worked.The users were able to connect to the database now.

Later I found that this is an Oracle bug (No.4518443).

Some of the possible solutions for the above problem are:

1. Kill the child process using kill command and then reload the listener process.

2. Add the following parameter in the listener.ora file and restart the listener process.

SUBSCRIBE_FOR_NODE_DOWN_EVENT_LISTENER_NAME=OFF

Where listener_name is the listener name (here it would be oprem)

3. Apply Patch.

4. Rename the ons.config file and restart the listener. (path:$ORACLE_HOME/opmn/conf)

This problem is fixed in 10.2.0.3

Note: If you add the above parameter for a listener.ora in RAC setup, then Fast Application Notification (FAN) will not work.

For patch and more details on this refer to metalink note: 340091.1

Hope this was useful to you guys.

Monday, August 13, 2007

Sometimes something goes unnoticed...

ORA-01194: File 5 needs media recovery to be consistent


When you get the above error if you decide that you have to recover the datafile (or database), think twice. Always you may not have to recover the file. I had faced this scenario in one of the client places. Though the initial plan was to restore the datafile from the backup and recover, I had to change my mind.

Now the scenario…I was informed that a guy at the client site had restarted the database (on windows) and they could not open the database because of the datafile inconsistency. After some searching I could find that the problem was with the backup process!!

It happened so that when the hot backup (user-managed) of the database was being taken, that guy had shutdown the database. Now, while restarting the database a particular datafile was asking for media recovery. When checked I found that the datafile was still in backup mode. i.e. the database was shutdown when the backup was going on. Now, the solution is simple. Mount the database and use alter database datafile 5 end backup command and open the database. There is absolutely no need to recover the datafile!! J

So what exactly happened here?!? Well, nothing strange happened. It is a normal oracle behavior, nothing else. When the instance was restarted, the datafile which was in the backup mode will look old because the datafile header is freezed with older SCN. So it will (and it shouldJ) ask for recovery. That’s it!

Generally on unix servers if you issue normal shutdown commands (except abort!!) on the database when the hot backup is going on, shutdown wont happen. It will throw an error saying that the datafile is in backup mode. So there is very less chance of facing this scenario on unix servers.

But in windows, it is general practice to shutdown the database using the OracleService on the services window. In this case even if the backup is happening database goes down with shutdown abort command internally. You won’t come to know that shutdown abort has happened.

You can even face this scenario when the instance crashes during backup (hot backup).You try to restart the instance without knowing that backup was active during the instance crash and end up with the same error.

So, don’t panic… Take it easy!!!