A awr of the sequence value in RAC Node 1 was found to have been executed 37855 in two hours.
Select Hibernate_sequence.nextval from dual
Check out the hibernate_sequence cache is actually the default value of 20.
decided to increase the cache to 100
sql>alter sequence hibernate_sequence cache;
After two hours observing this SQL disappears.
How Oracle maintains sequence in a RAC environment. The experiment is as follows
Sql>create sequence Hibernate_sequence
MinValue 1
MaxValue 9999999
Start with 1
Increment by 1
Cache 20;
Sql> Select I.instance_number from V$instance i;
Instance_number
---------------
1
--View hibernate_sequence.nextval at the first node of RAC
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
1
--View Hibernate_sequence.nextval at the second node of RAC
How much should it be? Is it 2? The answer is no.
Sql> Select I.instance_number from V$instance i;
Instance_number
---------------
2
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
21st
How much should hibernate_sequence.nextval be when switching to the first node of RAC? This time it's 2.
Sequence cache is stored separately in the cache of each instance in the RAC.
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
2
We continue to get hibernate_sequence.nextval on node 1 to see if the Hibernate_sequence.nextval on Node 1 will be 21.
If so, there is a problem with the sequence mechanism in Oracle RAC.
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
3
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
4
... Continuous fetch until the Hibernate_sequence.nextval value is 20 ...
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
20
after reaching 20, the next value for Hibernate_sequence.nextval is not 21, but a.
Why, then? Because 21-40 is in the RAC 2 node cache.
Sql> select Hibernate_sequence.nextval from dual;
Nextval
----------
41