Possible Duplicate:
Oracle RAC and sequences
I have a Oracle RAC configured in my local environment. I analyzed a problem with Sequnce that the number generated by nextVal are not ordered. Suppose First time I get value as 1 , the second time get get value as 21 (I have configured the sequence as with default CACHE 20 and NOORDER ).
On searching I found the solution that, I need to Order the sequence. I have question which is better option to go with,
1) CACHE and ORDER
2) NOCACHE and ORDER
I want to know which one of the above is better option and why?
Secondly, Can I achieve the ordering if I alter the sequence to be NOCACHE irrespective of ORDER/NOORDER.
Thanks
yes as NOCACHE is effectively order as you're forcing a write to the sys.seq$ table on each increment, which has to serialise over nodes too.
--
I would dispute the accepted answer in that possible duplicate. there is a huge difference in CACHE + ORDER and NOCACHE in RAC. You are not negating the CACHE with ORDER; just reducing its effectiveness. I've personally seen performance of a middle tier application degrade drastically as they used NOCACHE on a sequence and were accessing on multiple nodes at once. We switched their sequence to ORDER CACHE (as they wanted an cross-rac order). and performance drastically improved.
in summary: The sequence speed will be from fastest to slowest as "CACHE NOORDER"->"CACHE ORDER" and way way WAY behind "NOCACHE".
This is easily testable too:
So we start with a standard sequence:
ie CACHE with no order. Now we fire up two sessions. I'm using a 4 node RAC database 10.2.0.4 in this test:
my test script is simply
now we run the first test (CACHE NOORDER):
so 7-8 seconds to select 100,000 iterations of the sequence.
Now lets try NOCACHE (ORDER vs NOORDER is irrelavant for this, as we are forcing a write to seq$ for every call to the sequence).
so we've jumped from 8 seconds to 8 MINUTES for the same work set.
what about CACHE + ORDER?
so in summary for 100,000 single call fetches CACHE NOORDER = 8 seconds NOCACHE = 8 minutes CACHE ORDER = 25 seconds
for cache order, oracle does do a lot of pinging between the RAC nodes , but it DOESNT have to write stuff back to seq$ until the cache size is used up, as its all done in memory.
i would if i were you, set an appropriate cache size (p.s. a high cache size doesn't put a load on the box memory, as oracle doesn't store all the numbers in RAM; only the current + final number) and consider ORDER if required.