Select Hibernate_sequence.nextval from dual

Source: Internet
Author: User



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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.