Oracle 10g中对resumable session的增强
從9i開始,Oracle提供了一種避免因為space Error而導(dǎo)致事務(wù)異常的操作,那就是resumable.通常,DBA在日常工作中,往往忽略了對空間資源上的需求,比如一個大的事務(wù)所需要的temp,undo,data space等等。直到出現(xiàn)了經(jīng)典的ORA-01652才恍然大悟。
下面回顧一下這個特性。
一、回顧9i中的功能(復(fù)習(xí)一下好了) 1)權(quán)限設(shè)置 首先一個用戶要設(shè)置 session,必須具有的權(quán)限。 SQL> select * from system_privilege_map where name=''; PRIVILEGE NAME PROPERTY ---------- ---------------------------------------- ---------- -236 0 SQL> SQL> conn study/study 已連接。 SQL> alter session enable ; ERROR: ORA-01031: 權(quán)限不足 SQL> SQL> conn /as sysdba 已連接。 SQL> grant to study; 授權(quán)成功。 SQL> conn study/study 已連接。 SQL> alter session enable ; 會話已更改。 SQL> 當(dāng)然了,權(quán)限也被包含在其他role里面,比如dba,當(dāng)一個用戶擁有dba role時 ,就自動擁有了 privilege. 2)ENALBE session 在9i中,我們可以通過如下的設(shè)置,讓一個session當(dāng)遇到空間分配不足的時候繼續(xù)。 SQL> alter session enable ; 3)DISABLE session 和enable 相反 SQL> alter session disable ; 4)超時設(shè)置session的默認(rèn)超時時間為7200秒,也就是2小時。 我們可以通過如下的SQL來調(diào)整timeout的時間,比如 SQL> alter session enable timeout 1800; 會話已更改。 SQL> 5)監(jiān)控 我們可以通過dba_和alert日志來監(jiān)控 session的狀態(tài)。 SQL> alter session enable timeout 10; 會話已更改。 SQL> select user_id,SESSION_ID, STATUS, START_TIME, SUSPEND_TIME, 2 SQL_TEXT, ERROR_NUMBER, ERROR_MSG 3 from dba_; USER_ID SESSION_ID STATUS START_TIME SUSPEND_TIME ---------- ---------- --------- ----------------- -------------- 61 49 NORMAL SQL_TEXT ERROR_NUMBER ERROR_MSG ------------- ------------ ------------- 0 SQL> create index inx_res_test on res_test(owner,object_id,object_name) tablespace test; 。。。 SQL> select user_id,SESSION_ID, STATUS, START_TIME, SUSPEND_TIME, 2 SQL_TEXT, ERROR_NUMBER, ERROR_MSG 3 from dba_; USER_ID SESSION_ID STATUS START_TIME SUSPEND_TIME ---------- ---------- --------- -------------------- -------------------- 61 49 SUSPENDED 02/26/07 10:31:20 02/26/07 10:31:20 SQL_TEXT ERROR_NUMBER ------------------------------------------ ------------ create index inx_res_test on res_test 1536 (owner,object_id,object_name) tablespace t ERROR_MSG ---------------------------------------- ORA-01536: 超出表空間 'TEST' 的空間限額 超時以后: SQL> create index inx_res_test on res_test(owner,object_id,object_name) tablespace test; create index inx_res_test on res_test(owner,object_id,object_name) tablespace test * 第 1 行出現(xiàn)錯誤: ORA-30032: 掛起的 (可恢復(fù)) 語句已超時 ORA-01536: 超出表空間 'TEST' 的空間限額 SQL> 同時,當(dāng) session 被掛起時,在alert 日志文件中也會有相應(yīng)的記錄信息 ,如下所示: Mon Feb 26 10:29:37 2007 statement in session 'User STUDY(61), Session 49, Instance 1' was suspended due to ORA-01536: 超出表空間 'TEST' 的空間限額 6)dbms_reumable包 Oracle也提供了一個dbms_ package來設(shè)置獲取或異常終止一個 session的操作。 這個包比較簡單。我簡單的示范一下。有興趣的同志,可以參考Oracle的online doc. SQL> alter session enable ; 會話已更改。 SQL> exec dbms_.set_session_timeout(49,1800); PL/SQL 過程已成功完成。 SQL> select dbms_.get_session_timeout(49) from dual; DBMS_.GET_SESSION_TIM ------------------------------ 1800 SQL> SQL> create index inx_res_test on res_test(owner,object_id,object_name) tablespace test; ... {因為表空間不足,所以被掛起} 打開另外一個session,可以取消上面的操作,而不必等到timeout SQL> exec dbms_.abort(49); PL/SQL procedure successfully completed SQL> 在session id 為49的交互界面將得到如下的返回信息: SQL> create index inx_res_test on res_test(owner,object_id,object_name) tablespace test; create index inx_res_test on res_test(owner,object_id,object_name) tablespace test * 第 1 行出現(xiàn)錯誤: ORA-01013: 用戶請求取消當(dāng)前的操作 SQL> 二、10g中的增強(qiáng) 在10g中,Oracle一樣支持9i的上述方法,同時做了增強(qiáng)。 1)增加了一個_timeout的參數(shù) 該參數(shù)可以在system和session level級均可以修改.對RAC db,每個instance可以單獨(dú)設(shè)置. 而9i中只能在session一級中設(shè)置。比如: SQL> show parameter _timeout; NAME TYPE VALUE ------------------------------------ -------------- ------- _timeout integer 0 SQL> alter system set _timeout=60; 系統(tǒng)已更改。 SQL> create index inx_res_test on res_test(owner,object_id,object_name) tablespace test; create index inx_res_test on res_test(owner,object_id,object_name) tablespace test * 第 1 行出現(xiàn)錯誤: ORA-30032: 掛起的 (可恢復(fù)) 語句已超時 ORA-01652: 無法通過 8 (在表空間 TEST 中) 擴(kuò)展 temp 段 SQL> 2)對分布式事務(wù)的支持 In 9i, users are not allowed to start a distributed transaction in a enabled session. And if a session has a distributed transaction, users are not allowed to enable . These restrictions are removed in 10g. However, in a distributed transaction, if users enable/disable or change _timeout, only the local instances are affected. In a distributed transaction, sessions on remote instances are suspended if has been enabled in the remote instance. 3)增加了一個監(jiān)控的視圖 在10g中,我們也可以通過DBA_OUTSTANDING_ALERTS 來監(jiān)控 session.比如: SQL> create index inx_res_test on res_test(owner,object_id,object_name) tablespace test; create index inx_res_test on res_test(owner,object_id,object_name) tablespace test * 第 1 行出現(xiàn)錯誤: ORA-30032: 掛起的 (可恢復(fù)) 語句已超時 ORA-01652: 無法通過 8 (在表空間 TEST 中) 擴(kuò)展 temp 段 SQL> select object_name,object_type,reason,message_type,message_level 2 from dba_outstanding_alerts 3 where message_group='Space'; OBJECT_NAME OBJECT_TYPE REASON ------------ ------------ ----------------------------------------------- TEST TABLESPACE 對可恢復(fù)會話 User STUDY(61),Session 49,Instance 1 (會話 ID 為 49) 的操作被掛起 MESSAGE_TYPE MESSAGE_LEVEL ------------ ------------- Warning 5 SQL> 三、操作在其他utiliy中的使用 在exp/imp,sql*loader工具,同樣也支持操作,本文不再多加介紹, 大家可以參考Oracle online doc獲取更多的信息。 最后,這個特性還是很有用的。我們可以在臨近下班的時候,開始一個很大的create index的操作,設(shè)置2小時的timeout,然后就可以回家吃飯了,如果中間因為space不 足而掛起,我們也可以及時的收到短信告警[別的朋友可能有其他的監(jiān)控],調(diào)整后, 讓事務(wù)繼續(xù)。多爽!啥也不耽誤 特性以及系統(tǒng)觸發(fā)器中的SUSPEND event測試! 之前一直沒有搞清楚系統(tǒng)觸發(fā)器中的suspend事件什么時候觸發(fā),正好看到一位puber問此問題,搜索一下doc,做了一個簡單的測試。
參考doc:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/schema.htm#sthref2075
session1:
SQL> create tablespace users datafile 'E:ORACLEPRODUCT10.2.0ORADATAORCLUSE
RS.DBF' SIZE 3M;
表空間已創(chuàng)建。
SQL> grant resumable to xys;
授權(quán)成功。
SQL> create or replace trigger trigg_system
2 after suspend on database
3 begin
4 dbms_resumable.set_timeout(10);
5 end;
6 /
警告: 創(chuàng)建的觸發(fā)器帶有編譯錯誤。
SQL> show error
TRIGGER TRIGG_SYSTEM 出現(xiàn)錯誤:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/2 PL/SQL: Statement ignored
2/2 PLS-00201: 必須聲明標(biāo)識符 'DBMS_RESUMABLE'
SQL> create or replace trigger trigg_system
2 after suspend on database
3 begin
4 dbms_resumable.set_timeout(10);
5 end;
6 /
警告: 創(chuàng)建的觸發(fā)器帶有編譯錯誤。
SQL> connect /as sysdba
已連接。
SQL> grant execute on dbms_resumable to xys;
授權(quán)成功。
SQL> connect xys/manager
已連接。
SQL> create or replace trigger trigg_system
2 after suspend on database
3 begin
4 dbms_resumable.set_timeout(10);
5 end;
6 /
觸發(fā)器已創(chuàng)建
session2:
SQL> create table t_resumable tablespace users as select *from dba_objects;
表已創(chuàng)建。
SQL> insert into t_resumable select *from t_resumable;
insert into t_resumable select *from t_resumable
*
第 1 行出現(xiàn)錯誤:
ORA-01653: 表 XYS.T_RESUMABLE 無法通過 128 (在表空間 USERS 中) 擴(kuò)展
SQL> alter session enable resumable;
會話已更改。
--注意這里insert操作會等待10秒,10秒之后出現(xiàn)了錯誤
SQL> insert into t_resumable select *from t_resumable;
insert into t_resumable select *from t_resumable
*
第 1 行出現(xiàn)錯誤:
ORA-30032: 掛起的 (可恢復(fù)) 語句已超時
ORA-01653: 表 XYS.T_RESUMABLE 無法通過 128 (在表空間 USERS 中) 擴(kuò)展
--回到session1修改一下timeout時間(10秒有些短,來不及修改datafile 4的autoextend屬性),單位是秒
SQL> create or replace trigger trigg_system
2 after suspend on database
3 begin
4 dbms_resumable.set_timeout(60);
5 end;
6 /
觸發(fā)器已創(chuàng)建
session2:
--此時下面insert會等待60秒,如果60秒之后發(fā)現(xiàn)空間可用,則繼續(xù)執(zhí)行
SQL> insert into t_resumable select *from t_resumable;
已創(chuàng)建11413行。
--此期間在session1中修改datafile 4使其能自動擴(kuò)展
SQL> alter database datafile 4 autoextend on;
數(shù)據(jù)庫已更改。
轉(zhuǎn)載于:https://www.cnblogs.com/afant/archive/2008/11/03/1325215.html
總結(jié)
以上是生活随笔為你收集整理的Oracle 10g中对resumable session的增强的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JEECG Online Coding
- 下一篇: Java中主线程如何捕获子线程抛出 ..