1. 程式人生 > >Oracle session active 和 inactive 狀態 說明

Oracle session active 和 inactive 狀態 說明

一. Session 狀態說明

            可以通過v$session 檢視的status列檢視session 的狀態。  關於該檢視的使用,參考聯機文件:

V$SESSION

STATUS

VARCHAR2(8)

Status of the session:

ACTIVE - Session currently executing SQL

INACTIVE

KILLED - Session marked to be killed

CACHED - Session temporarily cached for use by Oracle*XA

SNIPED - Session inactive, waiting on the client

有關狀態的說明:

(1)active 處於此狀態的會話,表示正在執行,處於活動狀態。

            官方文件說明:

            Any session that is connected to the database and is waiting for an event that does not belong to the Idle wait class is considered as an active session.

(2)killed處於此狀態的會話,被標註為刪除,表示出現了錯誤,正在回滾。

            當然,也是佔用系統資源的。還有一點就是,killed的狀態一般會持續較長時間,而且用windows下的工具pl/sql developer來kill掉,是不管用的,要用命令:alter system kill session 'sid,serial#' ;

(3)inactive 處於此狀態的會話表示不是正在執行的

            該狀態處於等待操作(即等待需要執行的SQL語句),通常當DML語句已經完成。 但連線沒有釋放,這個可能是程式中沒有釋放,如果是使用中介軟體來連線的話,也可能是中介軟體的配置或者是bug 導致。

            inactive對資料庫本身沒有什麼影響,但是如果程式沒有及時commit,那麼就會造成佔用過多會話。容易是DB 的session 達到極限值。

            問了幾個朋友,他們的做法是不處理inactive 狀態的session, 如果達到了session 的最大值, 就增加processes 和 sessions 引數。 如果kill inactive session 可能會到中介軟體有影響。 具體中介軟體這塊我也不太熟,等以後弄清楚了,在說。

二. 處理inactive 狀態的session

            在前面說不處理inactive 狀態的session,但是還是有方法來解決的。 有兩種方法。

2.1 在 sqlnet.ora檔案中設定expire_time 引數

官網有關這個引數的說明:

SQLNET.EXPIRE_TIME

Purpose

            Use parameter SQLNET.EXPIRE_TIME to specify a the time interval, in minutes, to send a probe to verify that client/server connections are active.Setting a value greater than 0 ensures that connections are not left open indefinitely, due to an abnormal client termination. If the probe finds a terminated connection, or a connection that is no longer in use, it returns an error, causing the server process to exit. This parameter is primarily intended for the database server, which typically handles multiple connections at any one time.

            sqlnet.expire_time 的原理:Oracle Server 傳送包探測dead connection ,如果連線關閉,或者不再用,則關閉相應的server process.

Limitations on using this terminated connection detection feature are:

(1)It is not allowed on bequeathed connections.

(2)Though very small, a probe packet generates additional traffic that may downgrade network performance.

(3)Depending on which operating system is in use, the server may need to perform additional processing to distinguish the connection probing event from other events that occur. This can also result in degraded network performance.

Default :0

Minimum Value :0

Recommended Value :10

Example

SQLNET.EXPIRE_TIME=10

2.2 設定使用者profile的idle_time 引數

之前整理的一篇有關profile的文章:

            Oracle 使用者 profile 屬性

            注意,要啟用idle_time 要先啟用RESOURCE_LIMIT引數。 該引數預設是False。 官網說明如下:

RESOURCE_LIMIT

Property

Description

Parameter type

Boolean

Default value

false

Modifiable

ALTER SYSTEM

Range of values

true | false

            RESOURCE_LIMIT determines whether resource limits are enforced in database profiles.

Values:

            TRUE: Enables the enforcement of resource limits

            FALSE:Disables the enforcement of resource limits

如下blog 在這塊說的比較清楚,並提供了相關的指令碼:

            sqlnet.expire_time and IDLE_TIME

            IDLE_TIME Specify the permitted periods of continuous inactive time during a session, expressed in minutes. Long-running queries and other operations are not subject to this limit.

            A valid database connection that is idle will respond to the probe packet causing no action on the part of the Server , whereas the resource_limit will snipe the session when idle_time is exceeded. The 'sniped' session will get disconnected when the user(or the user process) tries to communicate with the server again.

            -- 通過idle_time限制session idle 時間。session idle超過設定時間,狀態為sniped (v$session).,然而OS下的process並不會釋放,當session(user process) 再次與server process 通訊,將關閉相應的server process.

What does 'SNIPED' status in v$session mean?

            When IDLE_TIME is set in the users' profiles or the default profile. This will kill the sessions in the database (status in v$session now becomes SNIPED) and they will eventually disconnect. It does not always clean up the Unix session (LOCAL=NO sessions).

            At this time all oracle resources are released but the shadow processes remains and OS resources are not released. This shadow process is still counted towards the parameters of init.ora.

            This process is killed and entry from v$session is released only when user again tries to do something. Another way of forcing disconnect (if your users come in via SQL*Net) is to put the file sqlnet.ora on every client machine and include the parameter "SQLNET.EXPIRE_TIME" in it to force the close of the SQL*Net session

sqlnet.expire_time

            sqlnet.expire_time actually works on a different principle and is used to detect dead connections as opposed to disconnecting(actually 'sniping') a session based on idle_time which the profile accomplishes.


            But again, as you mentioned, expire_time works globally while idle_time profile works for that user. You can use both of them to make sure that the client not only gets sniped but also gets disconnected if the user process abnormally terminates.

修改示例:

SQL>alter profile default limit idle_time 10;

--需要重啟下oracle

查詢應用的連線數SQL:

/* Formatted on 2011/6/12 13:06:23 (QP5 v5.163.1008.3004) */

  SELECT b.MACHINE, b.PROGRAM, COUNT (*)

    FROM v$process a, v$session b

   WHERE a.ADDR = b.PADDR AND b.USERNAME IS NOT NULL

GROUP BY b.MACHINE, b.PROGRAM

ORDER BY COUNT (*) DESC;


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

相關推薦

Oracle session active inactive 狀態 說明

一. Session 狀態說明             可以通過v$session 檢視的status列檢視session 的狀態。  關於該檢視的使用,參考聯機文件: V$SESSION STATUS VARCHAR2(8) Status of the se

Oracle session active inactive 狀態 說明(與死連線檢測DCD ,客戶端的聯接仍然是活動的 有關)

一. Session 狀態說明             可以通過v$session 檢視的status列檢視session 的狀態。  關於該檢視的使用,參考聯機文件: V$SESSION STATUS VARCHAR2(8) Status of the session: ACTIVE -

Hadoop2.7.0叢集的NameNode在HA下如何切換activestandby狀態

       1、筆者所在公司的開發環境搭建了一個hadoop叢集,為保證HDFS的高可用,配置了NameNode的HA模式 , 10.17.2.134 為active ,10.17.2.121為standby         2、筆者平時訓練寫的很多mapreduce

Oracle查詢session連線數inactive

伺服器Oracle資料庫出現問題,用不到半天,就會報maxsession(150)的問題,肯定是資料庫的會話超過最大數了。   由於伺服器跑的是檔案傳輸應用,佔用的請求和會話肯定很大,因此使用者數不大就已經讓oracle的會話數達到最大值。   處理方式不外乎兩種:擴大oracle最大session數以及清除

從有狀態應用(Session)到無狀態應用(JWT),以及 SSO OAuth2

從有狀態應用(Session)到無狀態應用(JWT),以及 SSO 和 OAuth2 不管用哪種方式認證使用者,都可能被中間人攻擊竊取 SessionID 或 Token,從而發生 CSRF 攻擊。解決方式就是全站 HTTPS。現在 Let’s Encrypt 已經支援免費的萬用字元 HTT

CookieSession實現儲存登入狀態免登入。

  首先Cookie和Session都是為了狀態管理,HTTP協議是無狀態的,不能儲存每次提交的資訊,即當伺服器返回與請求相對應的應答之後,這次事務的所有資訊就丟掉了。   如果使用者發來一個新的請求,伺服器無法知道它是否與上次的請求有聯絡。   對於

ORACLE資料庫的三種狀態:RESTRICT、QUIESCESUSPEND

bash-2.03$ srvctl status db -d testracInstance testrac1 is running on node racnode1Instance testrac2 is running on node racnode2Instance testrac3 is runnin

Oracle index unusableinvisible的差別

rename dex rop split pac 索引 int mar visible 摘錄自11g的官方文檔: UNUSABLE Specify UNUSABLE to mark the index or index partition(s) or ind

oracle中rownumrow_number()

cnblogs 計算 順序分配 每一個 total tom ins 使用 div row_number()over(partition by col1 order by col2)表示根據col1分組,在分組內部根據col2排序,而此函數計算的值就表示每組內部排序後的順序編

Oracle卸載安裝

manage sta 用戶 acl 參考 管理員 禁止 edi 開頭 主要是跟著李興華老師的安裝步驟(http://edu.csdn.net/course/detail/3574/62057?auto_start=1)來的,但是最後一步忘記了口令管理了,所以卸了重新安裝。

oracle sqlplus命令常用函數

width to_char sla 變量替換 init into leading greate 常用函數 常用命令: 連接sqlplus命令行下運行cmd進入,如以sys模式登陸,命令如下:(1).sqlplus "sys/zhb126 as sysdba" (2).sql

oracle 給表字段添加註釋

oracle 註釋 備註comment on column TableName.ColumnName is ‘備註名’;comment on table TableName is ‘備註名‘;oracle 給表和字段添加註釋

Oracle字符時間比較

知識 etime nbsp 間隔 to_date ember 位數 不一致 -m 數據庫中的字段 2017-07-11 13:37:51 類型是char 或者varchar 要進件與 ‘20170625‘ 比較,格式不一致,需要將他轉換成:yyyyMMdd 字符串 1、先

Entity Framework 添加、附加、實體狀態

鍵值 name 五個 能夠 att first 通過 數據集 attach   這篇文章將會覆蓋如何新增和附加實體到上下文以及在 SaveChanges 中Entity Framework 如何處理它們。 Entity Framework 會在實體與上下文連接時追蹤它們的

oracle靜態sql動態sql

收入 性能 varchar 建立 系統 根據 ora imm arch 1.靜態SQL與動態SQLOracle編譯PL/SQL程序塊分為兩個種:  其一為前期聯編(early binding),即SQL語句在程序編譯期間就已經確定,大多數的編譯情況屬於這種類型;  另外一種

Oracle中chr()ascii()函數(附:常用字符與ascii對照表)

關鍵字 回車 pps body api adding com eve amp Oracle中chr()和ascii()函數(附:常用字符與ascii對照表) 關鍵字:chr() chr()函數作用:“特殊”字符特殊處理 在PLSql中可查詢相對應的字碼與特殊符 chr()函

windows 啟動關閉Oracle監聽服務

break stat local 程序啟動 tle -- add network 寫入 經常要用數據庫,讓他自己啟動的話,開機太慢,所以用命令啟動方便點。 1.開啟: 在運行中輸入cmd,進入控制臺,lsnrctl start回車,提示啟動監聽成功後

智能指針前置聲之間的小問題

2.4 anti c++工程 智能 test 無法 sizeof pri inline 對比Go等其他語言的工程,C++工程讓人痛苦的一件事情就是當工程稍微龐大一點,編譯時間就蹭蹭蹭往上爬。一般來說看過Effective C++這本書或者其他類似書籍的人都知道要解決編譯時長

oracle函數存儲過程有什麽區別

以及 插入數據 應該 部分 思維 必須 等級 中一 func oracle函數和存儲過程有什麽區別 1. 返回值的區別,函數有1個返回值,而存儲過程是通過參數返回的,可以有多個或者沒有 2.調用的區別,函數可以在查詢語句中直接調用,而存儲過程必須單獨調用. 函數

Oracle 的備份恢復

改變 方式 冷備份 div 可能 例子 數據庫 速度 外部 Oracle數據庫有三種標準的備份方法,它們分別是導出/導入(EXP/IMP)、熱備份和冷備 份。導出備件是一種邏輯備份,冷備份和熱備份是物理備份。 一、 導出/導入(Export/Import) 利用