資料庫連接的用戶端異常斷開後,其佔有的相應並沒有被釋放,如從v$session視圖中依舊可以看到對應的session處於inactive,且對應的伺服器處理序也沒有釋放,導致資源長時間地被佔用,對於這種情形開該如何處理呢?SQLNET.EXPIRE_TIME對於這個問題我們提供瞭解決方案,專門用於清理那些異常斷開的情形,如網路異常中斷,用戶端異常掉電,異常重啟等。本文描述了設定SQLNET.EXPIRE_TIME參數以及示範死串連以及資源被釋放的情形。
1、理解SQLNET.EXPIRE_TIME參數
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.
通過設定參數為非零值(分鐘)來發送探測包以檢查用戶端的異常斷開。一旦探測包找到了異常的串連將返回錯誤,清除對應的server process
下面是參數使用的一些限制。(預設值為0,最小值0,建議值10。SQLNET.EXPIRE_TIME=10)
Limitations on using this terminated connection detection feature are:
It is not allowed on bequeathed connections.
Though very small, a probe packet generates additional traffic that may downgrade network performance.
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.
2、Dead Connection Detection (DCD)與Inactive Sessions
Dead connections:
These are previously valid connections with the database but the connection between the client and server processes has
terminated abnormally.
Examples of a dead connection:
- A user reboots/turns-off their machine without logging off or disconnecting from the database.
- A network problem prevents communication between the client and the server.
In these cases, the shadow process running on the server and the session in the database may not terminate.
Implemented by
* adding SQLNET.EXPIRE_TIME = <MINUTES> to the sqlnet.ora file
With DCD is enabled, the Server-side process sends a small 10-byte packet to the client process after the duration of
the time interval specified in minutes by the SQLNET.EXPIRE_TIME parameter.
If the client side connection is still connected and responsive, the client sends a response packet back to the database
server, resetting the timer..and another packet will be sent when next interval expires (assuming no other activity on
the connection).
If the client fails to respond to the DCD probe packet
* the Server side process is marked as a dead connection and
* PMON performs the clean up of the database processes / resources
* The client OS processes are terminated
NOTE: SQLNET.RECV_TIMEOUT can be set on the SERVER side sqlnet.ora file. This will set a timeout for the server process
to wait for data from the client process.
Inactive Sessions:
These are sessions that remain connected to the database with a status in v$session of INACTIVE.
Example of an INACTIVE session:
- A user starts a program/session, then leaves it running and idle for an extended period of time.
3、配置SQLNET.EXPIRE_TIME
#對於SQLNET.EXPIRE_TIME的配置,需要修改sqlnet.ora,然後添加SQLNET.EXPIRE_TIME項
[Oracle@orasrv admin]$ more sqlnet.ora
sqlnet.expire_time = 1 #僅僅需要配置此項,後面的各項僅僅是為了產生追蹤記錄檔,可省略
TRACE_LEVEL_SERVER = 16
TRACE_FILE_SERVER = SERVER
TRACE_DIRECTORY_SERVER= /u01/app/oracle/network/trace
TRACE_TIMESTAMP_ SERVER = ON
TRACE_UNIQUE_SERVER = ON
DIAG_ADR_ENABLED=OFF