When dealing with Oracle sequences it is well known that cached sequences values are not lost following a tidy shutdown of a single database instance whereas a brut shutdown will generate a loss of sequences values. I did the experiment under Oracle-Linux and Oracle-Windows and results are shown below:
1.Oracle-Linux Fedora 16
SQL> create sequence mho_seq; Sequence created. SQL> select sequence_name, cache_size from all_sequences where sequence_name = 'MHO_SEQ'; SEQUENCE_NAME CACHE_SIZE ------------------------------ ---------- MHO_SEQ 20 SQL> select mho_seq.nextval from dual; NEXTVAL ---------- 1 SQL> select mho_seq.nextval from dual; NEXTVAL ---------- 2 SQL> select mho_seq.nextval from dual; NEXTVAL ---------- 3 SQL> shutdown Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 1673965568 bytes Fixed Size 1336932 bytes Variable Size 1090521500 bytes Database Buffers 570425344 bytes Redo Buffers 11681792 bytes Database mounted. Database opened. SQL> select mho_seq.nextval from dual; NEXTVAL ---------- 4
After a normal shutdown we didn’t loss any sequence value. Let’s now stop the database abruptly. One way to do this is to kill an internal Oracle process like SMON for example
[oracle@localhost mho]$ ps -ef | grep smon oracle 4470 1 0 08:54 ? 00:00:00 ora_smon_DB11G oracle 4597 4541 0 08:55 pts/3 00:00:00 grep --color=auto smon [oracle@localhost mho]$ kill -9 4470 [oracle@localhost mho]$ SQL> select mho_seq.nextval from dual; select mho_seq.nextval from dual * ERROR at line 1: ORA-03135: connection lost contact Process ID: 4516 Session ID: 125 Serial number: 5 SQL> startup ORACLE instance started. Total System Global Area 1673965568 bytes Fixed Size 1336932 bytes Variable Size 1090521500 bytes Database Buffers 570425344 bytes Redo Buffers 11681792 bytes Database mounted. Database opened. SQL> select mho_seq.nextval from dual; NEXTVAL ---------- 24
And see now how we went from value 4 to value 24!. We lost 20 cached values.
2.Oracle-Windows
I was not going to write this because it brings nothing new per regard to what happened under Linux operation system but I thought it is worth saying few words on the brut manner I used to simulate the oracle database crash and its consequences. You may have already guessed that I used the famous and easy windows ‘emergency exit’: ctlr+alt+delete to kill the process named Oracle. So I did, and, unfortunately when I wanted to restart the database the following internal error kicks off:
mohamed: mhouri> startup Instance ORACLE lancÚe. Total System Global Area 535662592 bytes Fixed Size 1375792 bytes Variable Size 289407440 bytes Database Buffers 239075328 bytes Redo Buffers 5804032 bytes Base de donnÚes montÚe. ORA-00600: code d'erreur interne, arguments : [kcratr_nab_less_than_odr], [1], [1410], [10771], [11555], [], [], [], [], [], [], []
Thanks to Nassyam Basha who pointed me to the this blog article, I have recovered up my Oracle-Windows database using the following steps;
mhouri> Startup mount ; Instance ORACLE lancÚe. Total System Global Area 535662592 bytes Fixed Size 1375792 bytes Variable Size 289407440 bytes Database Buffers 239075328 bytes Redo Buffers 5804032 bytes Base de donnÚes montÚe. mhouri> Show parameter control_files VALUE ----------------------------------------------- C:\APP\MOHAMED\ORADATA\MHOURI\MHOURI\CONTROL01.CTL, C:\APP\MOHAMED\FLASH_RECOVERY_AREA\MHOURI\ARCHIVELOG\MHOURI\CONTROL02.CTL mhouri> select a.member,a.group#,b.status from v$logfile a ,v$log b where a.group#=b.group# and b.status='CURRENT'; MEMBER GROUP# STATUS ----------------------------------------------- ------- ------- C:\APP\MOHAMED\ORADATA\MHOURI\MHOURI\REDO03.LOG 3 CURRENT mhouri> Shutdown abort ; Instance ORACLE arrÛtÚe. mhouri> Startup mount ; Instance ORACLE lancÚe. Total System Global Area 535662592 bytes Fixed Size 1375792 bytes Variable Size 289407440 bytes Database Buffers 239075328 bytes Redo Buffers 5804032 bytes Base de donnÚes montÚe. mhouri> recover database using backup controlfile until cancel ; ORA-00279: changement 32458110 gÚnÚrÚ Ó 02/02/2013 17:00:53 requis pour thread 1 ORA-00289: suggestion : C:\APP\MOHAMED\FLASH_RECOVERY_AREA\MHOURI\ARCHIVELOG\MHOURI\ARCHIVELOG\2013_02_03\O1_MF_1_1410_%U_.ARC ORA-00280: le changement 32458110 pour le thread 1 se trouve au no de sÚquence 1410 Indiquer le journal : {<RET>=suggÚrÚ | nomfichier | AUTO | CANCEL} C:\APP\MOHAMED\ORADATA\MHOURI\MHOURI\REDO03.LOG Fichier journal appliquÚ. RÚcupÚration aprÞs dÚfaillance matÚrielle terminÚe. mhouri> Alter database open resetlogs ; Base de donnÚes modifiÚe.
This finally brings my windows database up.
The bottom lines:
1. Loosing oracle sequence values is more an effect of stress on the shared pool and excessive rollbacks then anything else.
2. I went from proofing to myself that a cached sequence values are not lost following a tidy database shutdown to stuff related to recovering my database following an ora-6000 error