Sequence caching in RAC
Hi All,
Production server configuration is 4 node RAC. Version is 11.2.0.3. Linux Platform. We are using sequences in DB.
I was reading some blogs on sequence working on RAC env. I came to know a sequence with cache noorder will improve the performance.But i have not seen how can we cache a sequence properly in RAC.Can you please let me know your suggestions for the below questions?
When we create any sequence, how can we cache a sequence properly on 4 instances?
How can we calculate the cache for each instance?
How shall we know whether sequence is using or not?
Thanks,
Mani
Production server configuration is 4 node RAC. Version is 11.2.0.3. Linux Platform. We are using sequences in DB.
I was reading some blogs on sequence working on RAC env. I came to know a sequence with cache noorder will improve the performance.But i have not seen how can we cache a sequence properly in RAC.Can you please let me know your suggestions for the below questions?
When we create any sequence, how can we cache a sequence properly on 4 instances?
How can we calculate the cache for each instance?
How shall we know whether sequence is using or not?
The 'user' doesn't cache the sequence, Oracle does. Just specify the CACHE value when you create the sequence.
Oracle will use the SAME cache value for each instance. So if the cache value is 20 one instance might cache 1-20, the next instance cache 21-40 and so on. When an instance needs more values it will get the next set of 20 values that are available for that sequence.
Which 'cache' gets used depends on which instance a query runs on. A query that executes on instance #2 will use the cache on instance #2.
Similar Messages
-
if there is a sequence with CACHE 20, are numbers that are allocated from the cache going to be ordered?. So if I have values 61..80 in the sequence cache, is the next NEXTVAL call GUARANTEED to get 61, or will it get any random value from the cache
thanksIn a RAC environment, by default, sequence values can be returned out of order. There is an ORDER attribute that can be added to he DDL to create a sequence to force sequence values to be returned in order (though I'd wager this has a decent performance cost).
In a single instance database, sequence values will be returned sequentially whether the sequence is created as ORDER or NOORDER.
Of course, even if sequences come in order, it's possible that when you have concurrent transactions, the one with the later sequence value manages to commit before the one with the earlier sequence value. This may or may not be a concern in your environment.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Sequence caching with toplink and oracle caching
Hi,
In my application, I use toplink as a JPA provider. For performance reasons, I defined an allocationSize on sequence generator for some persistence objects. I read some documentation to understand how it works, the result of my research is that the allocationSize of sequence generator must match with the increment value of the sequence in database.
So if I want to cache 1000 of values, I must define on my sequence generator allocationSize of 1000 and create a sequence like this : create sequence myseq increment by 1000. Am I right ?
Second question, what if my sequence define a cache in the database. For example, create sequence myseq increment by 1000 cache 20.
Does it mean that 20 values will be cached or 1000*20 values will be cached ? Is the cache size defined per session or for all the sessions of the database ?
Thanks.
Will.Thank you for your response.
I used the default parameter of toplink (increment by 50) and I left a cache size of 20 on database side.
But I noticed that whenever the server restarts, I "lost" between 900 and 1000 ids (nearly 20*50). So even if sequence cache on oracle size is non transactional, I think there is a kind of prefetch somewhere on the server side. I must not lost more than 50 ids when a server restarts.
If I remove the cache on database side, then the behavior is correct (the expected one to be more precise).
Is there any kind of sequence caching in oracle jdbc drivers ?
Thanks.
Will. -
Oracle 10g sequence cache aging
I have been reading some about how sequences work and why you can end up with gaps in the sequence numbers. It is my understanding that you could 'lose' certain sequence numbers when the library cache ages/expires. What I can't find is where this cache is configured. Where do you define when the cache will expire and thus clear out? Seems like it's happening very quickly in one of our databases, but much more slowly in another. Don't know where to look for this setting. Can anyone help point me in the right direction? Thanks!
- The size of the sequence cache is driven by the CACHE parameter (default 20) when you create the sequence
- Oracle manages the library cache automatically-- there are no parameters to set here for the timeout. When a particular object is aged out is going to depend on, among other things, the size of the library cache, the frequency a particular object is used, and the number of other objects competing for space in the library cache. If one sequence is constantly being used, it will stay in the library cache much longer than the cache for a less frequently used sequence. If one database's library cache is under pressure because you're constantly loading new objects, cached objects will be aged out far more quickly than in a database where the library cache is not under pressure.
Justin -
제품 : ORACLE SERVER
작성날짜 : 2003-08-04
Sequence Cache
오라클 sequence를 사용할 때에 cache라는 옵션을 가지고 있다.
이러한 옵션을 사용할때 가끔 수자가 이어지지 않고 끊어지는 경우가 발생할 수
있는데 여기서는 어떤 상황에서 수자가 없어지며 이러한 상황을 최소화할수 있는
방법을 찾아보고자 한다.
non-cache mode 인 경우에 'nextval' 을 요구하게 되면 current value에서 increment
만큼의 값이 증가될 것이다. 예를 들어 current value는 0이고 increment는 1이며
cache가 아닐 때 'nextval'을 요구하게 되면 1이 return 될 것이다.
cache option과 같이 사용될 때 sequence에 대해서 'nextval'을 요구하게 되면
cache 되는 만큼의 값에서부터 차례대로 next 값을 가져오게 되며 cache된 값을
모두 사용하고 난 다음은 다음 caching 을 하게 된다.
만약 다음과 같이 sequence가 선언되었다고 하자.
create sequence seq increment by 1 cache 5;
NUMBER SEQUENCE CACHE
RETURNED CURRENT CURRENT
start none 0 none
1st access 1 5 1
2nd access 2 5 2
3rd access 3 5 3
4th access 4 5 4
5th access 5 5 5
6th access 6 10 6
7th access 7 10 7
cache되어 있는 값들이 절대로 없어지지 않는다고 가정하면 출력되는 결과 값들은
non-cache 의 그것과 다를 것이 없을 것이다.
그러나 sequence cache도 역시 다른 cached information과 같이 shared pool 에 저장된다.
이것은 다른 shared pool에 있는 procedure처럼 자주 access 되지 않으면 age out될 수
있음을 의미하기도 한다. 또한 shutdown 시에는 cache에 있는 모든 것을 잃어버리게
된다. 여기서 주로 shutdown에 의해 sequence의 번호가 skip 될수 있으므로 skip되어서는
안되는 번호를 가진 응용프로그램에서는 non-cached sequence 를 사용해야 한다.
다음에는 cache age out과 shutdown이후에 sequence number의 변화를 예를 들어 설명한다.
NUMBER SEQUENCE CACHE
RETURNED CURRENT CURRENT
start none 0 none
1st access 1 5 1
2nd access 2 5 2
cache aged out
3rd access 5 10 5
4th access 6 10 6
shutdown
5th access 10 15 10
6th access 11 15 11
7th access 12 15 12
aging 문제를 해결하기 위해서 7.3 이후에서 부터는 dbms_shared_pool 이라는 package 를
이용해서 shared pool내에 다음과 같이 고정시켜 놓을수 있다.
dbms_shared_pool.keep('seq','Q');
Reference Documents
<Note:62002.1>제품 : ORACLE SERVER
작성날짜 : 2003-08-04
Sequence Cache
오라클 sequence를 사용할 때에 cache라는 옵션을 가지고 있다.
이러한 옵션을 사용할때 가끔 수자가 이어지지 않고 끊어지는 경우가 발생할 수
있는데 여기서는 어떤 상황에서 수자가 없어지며 이러한 상황을 최소화할수 있는
방법을 찾아보고자 한다.
non-cache mode 인 경우에 'nextval' 을 요구하게 되면 current value에서 increment
만큼의 값이 증가될 것이다. 예를 들어 current value는 0이고 increment는 1이며
cache가 아닐 때 'nextval'을 요구하게 되면 1이 return 될 것이다.
cache option과 같이 사용될 때 sequence에 대해서 'nextval'을 요구하게 되면
cache 되는 만큼의 값에서부터 차례대로 next 값을 가져오게 되며 cache된 값을
모두 사용하고 난 다음은 다음 caching 을 하게 된다.
만약 다음과 같이 sequence가 선언되었다고 하자.
create sequence seq increment by 1 cache 5;
NUMBER SEQUENCE CACHE
RETURNED CURRENT CURRENT
start none 0 none
1st access 1 5 1
2nd access 2 5 2
3rd access 3 5 3
4th access 4 5 4
5th access 5 5 5
6th access 6 10 6
7th access 7 10 7
cache되어 있는 값들이 절대로 없어지지 않는다고 가정하면 출력되는 결과 값들은
non-cache 의 그것과 다를 것이 없을 것이다.
그러나 sequence cache도 역시 다른 cached information과 같이 shared pool 에 저장된다.
이것은 다른 shared pool에 있는 procedure처럼 자주 access 되지 않으면 age out될 수
있음을 의미하기도 한다. 또한 shutdown 시에는 cache에 있는 모든 것을 잃어버리게
된다. 여기서 주로 shutdown에 의해 sequence의 번호가 skip 될수 있으므로 skip되어서는
안되는 번호를 가진 응용프로그램에서는 non-cached sequence 를 사용해야 한다.
다음에는 cache age out과 shutdown이후에 sequence number의 변화를 예를 들어 설명한다.
NUMBER SEQUENCE CACHE
RETURNED CURRENT CURRENT
start none 0 none
1st access 1 5 1
2nd access 2 5 2
cache aged out
3rd access 5 10 5
4th access 6 10 6
shutdown
5th access 10 15 10
6th access 11 15 11
7th access 12 15 12
aging 문제를 해결하기 위해서 7.3 이후에서 부터는 dbms_shared_pool 이라는 package 를
이용해서 shared pool내에 다음과 같이 고정시켜 놓을수 있다.
dbms_shared_pool.keep('seq','Q');
Reference Documents
<Note:62002.1> -
From the oracle documentation, http://docs.oracle.com/cd/E11882_01/server.112/e10701/original_export.htm#BABJHCDH
it says that sequence numbers that have been allocated are available for use in the current database.
I have a table Test which has a column test_id having a sequence test_sequence.
Max value in the test_id is 20 and assume if test_sequence is cached for 20 in a 2 RAC node with each node caching numbers from 20-30 and 30-40.
If I do an export and import the sequences to a new database, will my next sequence number in the new database be 41 ?
If so, what will be the LAST_NUMBER in the dba_Sequences table in the source database.
Thanks in advance.Hi,
if you set CACHE 20 in a RAC environment each node will cache 20 number. In your case - cached numbers will be 21-40 and 41-60 and the dba_sequences.last_number=60.
If you do export/import all the cached numbers will be lost and your first number will be last_number+1. -
Increase sequence cache - DWH Environment
Hello everyone,
I am writing to ask a question on the sequences.
We work on a RAC with two nodes.
We have some sequences, highly used by several job.
The cache of these sequences is set with the default value.
We would increase the performance of access to the sequences.
Is it worth it?
How can we make an estimate on the correct or most plausible value of the cache?
Thanks
Greetings
SandroHi,
It all depends on how are you using the sequences. You need to think about two main points: ordering and caching. Do the sequences MUST be ordered? If that's true than those sequences have to be created using ORDER and NOCACHE clauses but this will lead to poor performance on a RAC environment because you will increase the overhead to maintain consistency about the sequence. If the sequences don't need to be ordered and you can have different numbers accross the instances, than you should use NORDER and CACHE for best performance.
Take a look at the doc in MOS Doc 853652.1 (RAC and Sequences)
Regards. -
Hi All,
I am getting contention problem on SEQ$ table becuase of sequence numbers are generated in huge amount for some sequences everyday. Below I mentioned the figures. I am planning to cache the more sequence number instead of default 20.
I want to know, Is there any drowback to cache more sequence number? Is there any formula or calculation or thumbrule that we can figure out how many number should we cache?
Please also suggest me if any good documnet available on that.
Thanks in advance.
Here is the sequence statistics.
Sequence Maxval (21/06/07) Maxval(22/06/07) Diff(F-E)
Seq-1 967989200 975861637 7872437
Seq-2 95990500 96766097 775597
Seq-3 73371394 73944908 573514
Seq-4 47959122 48336988 377866
Seq-5 33055165 33327676 272511
Seq-6 10407032 10488940 81908
Seq-7 8027641 8108770 81129
Seq-8 8031524 8109764 78240
Seq-9 8311000 8379200 68200
Seq-10 7204295 7256597 52302
Seq-11 5511145 5546865 35720
Seq-12 1594791 1617743 22952
Seq-13 1375542 1385085 9543
Seq-14 1802450 1808251 5801
Seq-15 240624 242455 1831
Seq-16 152600 153843 1243
Seq-17 157491 158605 1114
Seq-18 28701 28840 139
Seq-19 43367 43501 134
Seq-20 28459 28584 125In a very busy environment cache default 20 to my mind definitely is too low. We had an app on RAC (which means each serialization point hit even harder) and increasing cache really made faster inserts especially bigger loads. Depending on the types of tables (i.e. how much inserts) we increased cache even till 10K. I personally don't know about any drawbacks except that you'll loose more values in case of db restart. But for example for number(15) even if you loose 10K values each second your sequence will work for 999999999999999/10000/60/60/24/365 ~=~ 3171 years. That should be enough even for the most exigent future planner on the earth :)
Gints Plivna
http://www.gplivna.eu -
I created my sequence to increment by 1 with a default cache size of 20. This works fine as long as all my entries are done in the same session ( n + 1, n + 1... and so on). However, when I exit/return to my app the new sequence begins like: Last n + 20, n + 1, n + 1. . . and so on. Is it possible to reduce the cache size of a sequence?
Leo,
Please see this post:
Sequence problem
Particularly, Tom Kyte's explanation here:
http://asktom.oracle.com/pls/ask/f?p=4950:8:::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:530735152441
Thanks,
- Scott - -
Hi,
In my application, I use toplink as a JPA provider. For performance reasons, I defined an allocationSize on sequence generator for some persistence objects. I read some documentation to understand how it works, the result of my research is that the allocationSize of sequence generator must match with the increment value of the sequence in database.
So here is my question, what if my sequence define a cache in the database ? For a cache of 1000 values on the application (or server) side, I can create a sequence like this : sequence myseq increment by 1000 cache 20.
Does it mean that 20 values will be cached or 1000*20 values will be cached ? Is the cache size defined per session or for all the sessions of the database ?
Thanks.
Will.ok.... so if my sequence starts with 10000 and has a cache of 5, values from 11000 to 15000 will be cached, not values from 10000 to 100020 ?"5" values will be cached. You will find the following example to be helpful.
[cache]
SQL> create sequence myseq start with 10000 cache 5;
Sequence created.
SQL> select increment_by, cache_size, last_number from user_sequences where sequence_name = 'MYSEQ';
INCREMENT_BY CACHE_SIZE LAST_NUMBER
1 5 10000
SQL> select myseq.nextval from dual;
NEXTVAL
10000
SQL> /
NEXTVAL
10001
SQL> /
NEXTVAL
10002
SQL> /
NEXTVAL
10003
SQL> /
NEXTVAL
10004
SQL> select increment_by, cache_size, last_number from user_sequences where sequence_name = 'MYSEQ';
INCREMENT_BY CACHE_SIZE LAST_NUMBER
1 5 10005
SQL> select myseq.nextval from dual;
NEXTVAL
10005
SQL> select increment_by, cache_size, last_number from user_sequences where sequence_name = 'MYSEQ';
INCREMENT_BY CACHE_SIZE LAST_NUMBER
1 5 10010
SQL>
Asif Momen
http://momendba.blogspot.com -
Log sequence difference among RAC Instances
RDBMS Version : 11.2
Platform : Solaris 10
In our RAC DB, we have 6 redo logs.
SQL> select * from v$logfile order by 1,2;
GROUP# STATUS TYPE MEMBER IS_
1 ONLINE +ORCL_ARCH01/ORCL_ARCH/orcl_log01.dbf NO
2 ONLINE +ORCL_ARCH01/ORCL_ARCH/orcl_log02.dbf NO
3 ONLINE +ORCL_ARCH01/ORCL_ARCH/orcl_log03.dbf NO
4 ONLINE +ORCL_ARCH01/ORCL_ARCH/orcl_log04.dbf NO
5 ONLINE +ORCL_ARCH01/ORCL_ARCH/orcl_log05.dbf NO
6 ONLINE +ORCL_ARCH01/ORCL_ARCH/orcl_log06.dbf NO
6 rows selected.
Logically or shall I say 'internally' , 3 redo logs are allocated per thread. But they all belong to one database.
SQL> select group#,thread#,members from v$log order by 1,2;
GROUP# THREAD# MEMBERS
1 1 1
2 1 1
3 1 1
4 2 1
5 2 1
6 2 1
6 rows selected.
SQL> exit;If all these 6 redo log files belong to one database, then why do they have different max (sequence#) ?
ie. The 'Oldest online log sequence' in Node1 shows 3432 and
''Oldest online log sequence' in Node2 shows 3188 (a difference of 244 )
-- Instance1 in Node1
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +ORCL_ARCH01/ORCL_ARCH
Oldest online log sequence 3432 ------------------------->
Next log sequence to archive 3434
Current log sequence 3434
-- Instance 2 in Node2
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +ORCL_ARCH01/ORCL_ARCH
Oldest online log sequence 3188 ------------------------> ( 3432 - 3188 = 244)
Next log sequence to archive 3190
Current log sequence 3190So, this means Node1 is more loaded than Node2 ?
So, in a properly configured RAC set both instances should show almost similar number for 'Oldest online log sequence' ? (ignoring the manual switches) -
I am CONFUSED SEQUENCE CACHE BUG OR NOT
I HAVE CONFUSED, I HAVE CREATE ONE SEQUENCE AND I HAVE TEST BELOW PRACTICAL OF SEQUENCE
STEP 1 --
CREATE SEQUENCE SEQ_TEST
START WITH 1
MAXVALUE 999999
CACHE 20 ;
STEP 2 --
CREATE TABLE TEST_SEQUENCE (NO NUMBER) ;
STEP-3 --
INSERT INTO TEST_SEQUENCE VALUES(SEQ_TEST.NEXTVAL);
STEP-4 --
SELECT * FROM TEST_SEQUENCE;
STEP --5
CREATE SEQUENCE SEQ_TEST
START WITH 1
MAXVALUE 999999
CACHE 20 ;
ORA-00955: NAME IS ALREADY USED BY AN EXISTING OBJECT
STEP-6 --
INSERT INTO TEST_SEQUENCE VALUES(SEQ_TEST.NEXTVAL);
STEP-7 --
SELECT * FROM TEST_SEQUENCE;
I AM NOT SURE, SO PLEASE SUGGESTIONHi gunjan ,
I copied all your code and executed ,its working file there is nothing wrong .
But the problem is, as you are using cache ,some times it will skip 20 nos .
visit the beloiw link for further explanation
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:530735152441
Plz mark answered .
Regards
Timir -
Sequence cache (can it cause lock when.....)
it is set to 0?
We have a sequence that is used as a key in a table. If many users try to select next val from it at once and the cache is 0, can this cause the application to lock?
(I know this sounds far fitch but the only question not ask is a stupid question)I would also ask why you were setting a sequence to
NOCACHE if there is the potential for many users to
access it simultaneously. Frequently used sequences
ought to have appropriately sized caches.
Folks that set sequences to NOCACHE are frequently
trying to prevent gaps in their sequences. While
setting a sequence to NOCACHE will tend to decrease
the probability of gaps, it will not eliminate them.
If your application absolutely requires a gap-free
e sequence, you cannot use Oracle sequences and you
have to deal with the (significant) performance
penalty of serializing all transactions on the next
sequence value.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
It was not the idea of the dba here, but the application programmers (we should be shot for allowing them to tell us this). They did not believe us when we told them that the sequences would not roll back... I reset the cache to a number other than 0...
Thanks all for the feedback -
Hi
I am new for RAC environment
My new database will create in RAC environment
In my database table,we are using sequence in many place
so what are the step i want to take when i create sequence
Please any one help me
Regards
MakeshHi,
Check this sample questions explanation on oracle site.
Sequences and Oracle RAC
The use of sequences in Oracle Real Application Clusters (Oracle RAC) is much the same as it is for single-instance Oracle databases, but there are certain Oracle RAC-specific issues. With two or more database instances, sequences may require coordination to guarantee that the sequence numbers are allocated in the correct order.
Which of the following are always true regarding the use of sequences in an Oracle 10g RAC database? (Pick two.)
A. It is not possible to use the CACHE option, because each database has a row cache.
B. Sequence numbers may be out of order if multiple instances run the application program that uses the sequence.
C. Sequences add no extra overhead to traffic over the interconnect.
D. Using the CACHE and NOORDER options together results in the best performance for a sequence.
The correct answers are B and D.
Answer B is correct because if the CACHE option is used without the ORDER option, each instance caches a separate range of numbers and sequence numbers may be assigned out of order by the different instances. Answer D is correct because the CACHE option causes each instance to cache its own range of numbers, thus reducing I/O to the Oracle Data Dictionary, and the NOORDER option eliminates message traffic over the interconnect to coordinate the sequential allocation of numbers across all instances of the database.
Answer A is incorrect because even though each instance has a row cache, it is still possible to use the CACHE option with sequences. In such a case, each instance may cache numbers for that sequence in its row cache. Answer C is incorrect because if the CACHE and ORDER options are used together, all instances must allocate numbers in order by coordinating the assignment of the next value, using messages over the interconnect, thereby increasing interconnect traffic in proportion to the frequency of new-number assignment.
Hope it explains -
Hi, I have some sequences in cache and i'm losing the cache with the instance "ON".
I'm using 10g.
The sequence's cache uses LRU list? What can I do?
Thanks.The sequence cache is in the library cache.
You will loose sequences by bouncing the instance amongst other.
This is not a problem, as sequences are used for surrogate keys, and as surrogate keys don't have a meaning (except for bean counters), you can have a surrogate key with holes.
If you want to minimize the impact create your sequences with the nocache clause.
If you want a surrogate without holes, revert to the sequence table. Remember this 'solution' scales badly.
Sybrand Bakker
Senior Oracle DBA
Maybe you are looking for
-
Creating XML file from ABAP internal table data....
Hello, I am fethcing data froma custom table and I have to write data in XMl format. Following is the XML format in which I want data. Is there any function module iN SAP which will help me in writing data from internal table to XML file ? <batch>
-
Calculations in Update rules/Start routine/End Routine
Hi Friends, I have loaded data to a DSO and i have three fields in to it. Lets say Filed1, Filed2 and Field3. Field1 and Field2 are being populated through an update rule in transformation. Aggregation type for these two fields are "Summation". Now,
-
I have an iPod shuffle. On the Apple Help it says that the iPod can be used with more than one library. Is this true? I have a laptop with a library on it and a desktop with another library.
-
Can anyone tell when is the amber update cmng fr lumia 720????
-
Ok, I am sure thi shas been asked before, but here I go... What is the oldest Mac can I use for the 5.5. I do know you need one of the latest G5's. I am looking at a Mac from 2009~2010. Also I see from the Apple's site that the graphic boards that t