1. <strike id="owqwq"><menu id="owqwq"></menu></strike>
              <tfoot id="owqwq"></tfoot>
              <fieldset id="owqwq"></fieldset>
            • 小程序員之歌
              java先(我應該為它寫點什么了?。?/div>

              (轉)Oracle Sequence Cache 參數說明

              Oracle Sequence Cache 參數說明 收藏
               

                     公司上線一套RAC 系統。 Aston對Sequence 的 Cache 參數表示關注,建議并發大的系統對Cache設置大一點。 這樣可以提高性能。 和Aston 討論了一下。 又從網上查了一下。

               

              RACLE SEQUENCE 介紹
              http://blog.csdn.net/tianlesoftware/archive/2009/10/30/4745039.aspx

               

              之前整理的一篇文章。 剛才看了一下,也是從網上轉的。 那是還是寫blog初期的作品。 2009年10月份的。 轉眼一年,寫Blog 也比以前成熟了很多。
               

              一. 理論知識先看一個創建Sequence的語句:
              SQL> create sequence seq_tmp

                2  increment by 1

                3  start with 1

                4  nomaxvalue

                5  nocycle

                6  ;

              序列已創建。
               

              相關參數說明:
                    INCREMENT BY 1 -- 每次加幾個

                    START WITH 1 -- 從1開始計數

                    NOMAXvalue -- 不設置最大值

                    NOCYCLE -- 一直累加,不循環

                    CACHE 10;  --設置緩存cache個序列

                    CURRVAL=返回 sequence的當前值

                    NEXTVAL=增加sequence的值,然后返回 sequence 值

               

              更多信息,參考Oracle 聯機文檔:
              CREATE SEQUENCE

              http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_6015.htm#SQLRF01314

               

               

              這里對Cache 參數做一個說明:
                    如果指定CACHE值,ORACLE就可以預先在內存里面放置一些sequence,這樣存取的快些。cache里面的取完后,oracle自動再取一組到cache。 使用cache或許會跳號, 比如我們在創建序列時指定Cache 為100. 在某一個時刻,序列使用到了80. 而在這個時刻,數據庫突然不正常down掉(shutdown abort),cache中的sequence就會丟失.  在下次啟動分配cache時,數據庫會從101 開始,在分配100個緩存。即101--200. 而之前分配100個中的80-100這20個因為意外宕機而丟失。 這種情況下就會出現跳號的現象。我們可以在create sequence的時候用nocache防止這種情況。 但是nocache 的性能較差。 如果指定cache而沒有設定cache值,默認cache是20個。 這個默認值對于大多數情況下都是夠用的。 除非那種每秒上萬次的select。 所以具體情況要具體對待。 對于哪些大并發的系統,最好設置在100以上。像移動的BOSS系統,以1000為單位。

               

              CACHE Specify how many values of the sequence the database preallocates and keeps in memory for faster access. This integer value can have 28 or fewer digits. The minimum value for this parameter is 2. For sequences that cycle, this value must be less than the number of values in the cycle. You cannot cache more values than will fit in a given cycle of sequence numbers. Therefore, the maximum value allowed for CACHE must be less than the value determined by the following formula:

              (CEIL (MAXVALUE - MINVALUE)) / ABS (INCREMENT)

              If a system failure occurs, then all cached sequence values that have not been used in committed DML statements are lost. The potential number of lost values is equal to the value of the CACHE parameter.

              Note:

              Oracle recommends using the CACHE setting to enhance performance if you are using sequences in an Oracle Real Application Clusters environment.

              NOCACHE  Specify NOCACHE to indicate that values of the sequence are not preallocated. If you omit both CACHE and NOCACHE, then the database caches 20 sequence numbers by default.

               

               

              關于Order 參數的說明:
               

                     序參數:oracle默認是NOORDER,如果設置為ORDER;在單實例環境沒有影響,在RAC環境此時,多實例實際緩存相同的序列,此時在多個實例并發取該序列的時候,會有短暫的資源競爭來在多實例之間進行同步。因次性能相比noorder要差,所以RAC環境非必須的情況下不要使用ORDER,尤其要避免NOCACHE   ORDER組合。

               

              ORDER Specify ORDER to guarantee that sequence numbers are generated in order of request. This clause is useful if you are using the sequence numbers as timestamps. Guaranteeing order is usually not important for sequences used to generate primary keys.

              ORDER is necessary only to guarantee ordered generation if you are using Oracle Real Application Clusters. If you are using exclusive mode, then sequence numbers are always generated in order.

              NOORDER  Specify NOORDER if you do not want to guarantee sequence numbers are generated in order of request. This is the default.

               

               

              查看user_sequences 表的結構:
              SQL> desc user_sequences;

               名稱                                      是否為空? 類型
               ----------------------------------------- -------- ---------------

               SEQUENCE_NAME                             NOT NULL VARCHAR2(30)

               MIN_VALUE                                          NUMBER

               MAX_VALUE                                          NUMBER

               INCREMENT_BY                              NOT NULL NUMBER

               CYCLE_FLAG                                         VARCHAR2(1)

               ORDER_FLAG                                         VARCHAR2(1)

               CACHE_SIZE                                NOT NULL NUMBER

               LAST_NUMBER                               NOT NULL NUMBER

               

               

              查看剛才創建的序列seq_tmp 的值:
              SQL> select * from user_sequences where sequence_name='SEQ_TMP';

              SEQUENCE_N  MIN_VALUE MAX_VALUE INCREMENT_BY C O CACHE_SIZE LAST_NUMBER

              ---------- ---------- ---------- ------------ - - ---------- -----------

              SEQ_TMP             1 1.0000E+28            1 N N         20          21

               

              這里有個CACHE_SIZE的值。 我們在創建sequence的時候,啟用了cache,但是沒有給它值。 所以這里的cache_size 就是系統的模式值。 即20個。

               

               

              取下一個sequence的值:
              SQL> select seq_tmp.nextval from dual;

                 NEXTVAL

              ----------

                       1

              SQL> select seq_tmp.nextval from dual;

                 NEXTVAL

              ----------

                       2

               

               

              查看當前sequence的值:
              SQL> select seq_tmp.currval from dual;

               

                 CURRVAL

              ----------

               

              二. 實驗一個網友RAC 系統上的測試時結果:
              nocache:               2100s

              cache =1000:          55s

              差別很明顯。

               

               

              測試一:
              SQL> create sequence seq_1 nocache;

              序列已創建。

              SQL> set timing on;

              SQL> declare

                2  x number;

                3  begin

                4  for i in 1 .. 10000 loop

                5  select seq_1.nextval into x from dual;

                6  end loop;

                7  end;

                8  /

              PL/SQL 過程已成功完成。

               

              已用時間:  00: 00: 02.26

               

              測試二:
              SQL> create sequence seq_2 cache 20;

              序列已創建。

              已用時間:  00: 00: 00.01

              SQL> declare

                2  x number;

                3  begin

                4  for i in 1 .. 10000 loop

                5  select seq_2.nextval into x from dual;

                6  end loop;

                7  end;

                8  /

              PL/SQL 過程已成功完成。

               

              已用時間:  00: 00: 00.46

               

              測試三:
              SQL> create sequence seq_3 cache 100;

               

              序列已創建。

               

              已用時間:  00: 00: 00.05

              SQL> declare

                2  x number;

                3  begin

                4  for i in 1 .. 10000 loop

                5  select seq_3.nextval into x from dual;

                6  end loop;

                7  end;

                8  /

               

              PL/SQL 過程已成功完成。

               

              已用時間:  00: 00: 00.37

               

               

              測試四:
              SQL> create sequence seq_4 cache 1000;

              序列已創建。

              已用時間:  00: 00: 00.04

              SQL> declare

                2  x number;

                3  begin

                4  for i in 1 .. 40000 loop

                5  select seq_4.nextval into x from dual;

                6  end loop;

                7  end;

                8  /

               

              PL/SQL 過程已成功完成。

               

              已用時間:  00: 00: 01.31

              SQL> declare

                2  x number;

                3  begin

                4  for i in 1 .. 40000 loop

                5  select seq_1.nextval into x from dual;

                6  end loop;

                7  end;

                8  /

               

              PL/SQL 過程已成功完成。

               

              已用時間:  00: 00: 09.33

              SQL>

               

               

               

              小結:

               

              在自己的本本上測試的,Oracle 11gR2.  單Instance數據庫單會話循環不間斷取1-4萬個值。

              nocache:             2.26s          10000   

              cache:20              0.46s          10000

              cache:100             0.37s          10000

              cache:1000            1.31s          40000

              nocache:             9.33s         40000

               

              基本上cache 大于20的時候性能基本可以接受,nocache的時候性能確實很差.

               

              本文來自CSDN博客,轉載請標明出處:http://blog.csdn.net/tianlesoftware/archive/2010/11/08/5995051.aspx

              posted on 2011-01-31 11:49 liujg 閱讀(1823) 評論(0)  編輯  收藏 所屬分類: 數據庫

              新用戶注冊  刷新評論列表  

              只有注冊用戶登錄后才能發表評論。


              網站導航:
              博客園   IT新聞   Chat2DB   C++博客   博問   管理
              相關文章:
              • (轉)pl/sql developer 中文字段顯示亂碼
              • (轉)Oracle Sequence Cache 參數說明
              • (轉)
              • (轉)表空間不足的問題
              • oracle 取子串(轉)
              • PL/SQL中用光標查詢多條記錄
              • 漫 談oracle 中 的 空 值(轉)
              • PowerDesigner 使用 (轉載)
              • SQL 查找重復記錄(轉)
               

              Powered by:
              BlogJava
              Copyright © liujg

              <2025年7月>
              日一二三四五六
              293012345
              6789101112
              13141516171819
              20212223242526
              272829303112
              3456789

              導航

              • BlogJava
              • 首頁
              • 新隨筆
              • 聯系
              • 聚合
              • 管理

              統計

              • 隨筆 - 10
              • 文章 - 40
              • 評論 - 6
              • 引用 - 0

              常用鏈接

              • 我的隨筆
              • 我的評論
              • 我的參與
              • 最新評論

              留言簿(1)

              • 給我留言
              • 查看公開留言
              • 查看私人留言

              隨筆分類

              • js (rss)
              • linux(1) (rss)
              • strus2 (rss)
              • Struts2 Tag語法(轉) (rss)

              隨筆檔案

              • 2014年12月 (1)
              • 2011年9月 (1)
              • 2011年5月 (2)
              • 2011年1月 (1)
              • 2007年11月 (1)
              • 2007年10月 (1)
              • 2007年5月 (1)
              • 2006年12月 (1)

              文章分類

              • Java基礎(10) (rss)
              • JDBC(1) (rss)
              • js(1) (rss)
              • portlet(1) (rss)
              • Tapestry(1) (rss)
              • 數據庫(9) (rss)
              • 算法(1) (rss)

              文章檔案

              • 2011年10月 (1)
              • 2011年5月 (2)
              • 2011年1月 (1)
              • 2010年12月 (1)
              • 2010年8月 (1)
              • 2010年7月 (1)
              • 2010年5月 (2)
              • 2010年4月 (1)
              • 2009年7月 (1)
              • 2009年4月 (1)
              • 2009年3月 (2)
              • 2009年1月 (2)
              • 2008年12月 (1)
              • 2008年11月 (1)
              • 2008年7月 (3)
              • 2008年4月 (2)
              • 2008年3月 (2)
              • 2008年1月 (2)
              • 2007年11月 (3)
              • 2007年7月 (1)
              • 2007年6月 (4)
              • 2007年1月 (1)
              • 2006年7月 (4)

              相冊

              • me

              收藏夾

              • rmi(5) (rss)

              boddiy

              • boddi's blog

              搜索

              •  

              最新評論

              • 1.?re: oracle 取子串(轉)
              • @aaa
                別處轉來的,具體的不懂。
              • --liujg
              • 2.?re: oracle 取子串(轉)[未登錄]
              • 樓主,你說的substring是在oracle哪個版本的???能用嗎???
                charindex又是哪里的函數,能用嗎????搞笑
              • --aaa
              • 3.?re: oracle 取子串(轉)[未登錄]
              • kao
              • --aaa
              • 4.?re: prototype詳解(轉)
              • 郁悶,.NET的!,JAVA里面有MemberwiseClone這個方法么。怎么用JAVA搞原型模式呢?
              • --hehei
              • 5.?re: 轉載一篇jms的文章
              • Thanks for you kind to share the article~~
              • --lingruoxu

              閱讀排行榜

              • 1.?java程序員的5個好習慣()(809)
              • 2.?java 關閉IE(588)
              • 3.?OERR: ORA-12519(567)
              • 4.?doGet()和doPost()的區別(轉)(485)
              • 5.?看了下java核心技術中的代理,還是很暈(400)

              評論排行榜

              • 1.?執行./startup.sh,或者./shutdown.sh的時候,爆出了Permission denied(0)
              • 2.?submit()和onsubmit()的區別(轉)(0)
              • 3.?doGet()和doPost()的區別(轉)(0)
              • 4.?轉載 Vim 基本用法(0)
              • 5.?OERR: ORA-12519(0)
              狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频
              主站蜘蛛池模板: 海伦市| 洪湖市| 同心县| 崇信县| 射阳县| 南溪县| 三台县| 文水县| 隆子县| 如皋市| 九江市| 道孚县| 邮箱| 宁南县| 澄迈县| 融水| 济南市| 万荣县| 离岛区| 垦利县| 芜湖市| 阿拉善右旗| 高尔夫| 百色市| 安吉县| 酒泉市| 定陶县| 睢宁县| 密云县| 巴南区| 郴州市| 阿尔山市| 涞水县| 吴忠市| 凭祥市| 五河县| 贡觉县| 徐水县| 法库县| 阜新| 定南县|
              <del id="g6uqk"></del>
              <strike id="g6uqk"></strike>
                <tfoot id="g6uqk"><input id="g6uqk"></input></tfoot><strike id="g6uqk"><input id="g6uqk"></input></strike>
                <ul id="g6uqk"></ul>