Monday, January 3, 2011

Oracle dynamic view -- more than 20 mins data lost!!

An interesting question was asked in an interview for DBA and the person started this discussion about V$ views as they are popularly called.
I still prefer to call them by their actual name i.e. Oracle’s dynamic performance views. The behavior and the data expected gets more clear through it's name. These views ONLY have data or information about the instance and hence on reboot or restart of an instance the data would be refreshed and old information would be lost.
The question was rephrased in an interview and asked as a scenario... " In oracle database the information in oracle dynamic view (not dba_ view) more than 20 minutes got lost, what is the reason to result in this? How do you get the information in dynamic view more than 20 minutes?"
I saw people give the answer as recover the database to to the point in time required OR refresh the view, totally way off the mark!!
The dynamic performance views show statistics for the entire instance since the time it was started. So, if the info older than 20 mins is gone, would it would mean that the instance had been restarted 20 mins earlier. 
Dynamic performance views have only the current instance statistics. and recovering a database from backup is not going to recover this statistics. Many of these statistics are tied to the internal implementation of Oracle and therefore are subject to change or deletion without notice, even between patch releases. Application developers should be aware of this and write their code to tolerate missing or extra statistics.
Oracle documentation states...
 "V$SYSSTAT stores instance-wide statistics on resource usage, cumulative since the instance was started."