sqlnet.expire_time and IDLE_TIME

本文介绍如何通过设置resource_limit及使用idle_time参数来管理Oracle数据库中的闲置会话(session),并通过sqlnet.expire_time参数来检测并关闭死连接(dead connection)。文中还提供了一种方法来查找和终止处于sniped状态的会话。

当设置了resource_limit=true 。通过idle_time限制session idle 时间。session idle超过设置时间,状态为sniped (v$session).,然而OS下的process并不会释放,当session(user process) 再次与server process 通讯,将关闭相应的server process.

sqlnet.expire_time 的原理不一样,Oracle Server 发送包探测dead connection ,如果连接关闭,或者不再用,则关闭相应的server process.

以上两者组合使用,减少server process,防止process超过init$ORACLE_SID极限值。


#查找长时间不用的session.
SELECT s.username,s.status,s.machine,osuser,spid,
'kill -9 '||spid UNIX_level_kill,
'alter system kill session ' ||''''||s.sid||','||s.serial# || ''';' Oracle_level_kill,
TO_CHAR (logon_time, 'dd/mm/yyyy hh24:mi:ss') logon_time,
last_call_et idle_time,
TO_CHAR (TRUNC (last_call_et / 3600, 0))||' '||' HRS '||TO_CHAR (TRUNC ((last_call_et - TRUNC(last_call_et / 3600, 0) * 3600) / 60, 0)) ||' MINS' idle_time_hour_minute,
module
FROM v$session s, v$process p
WHERE TYPE = 'USER'
AND p.addr = s.paddr
AND status = 'SNIPED'
-- AND SUBSTR (machine, 1, 19) NOT IN ('machine')
AND last_call_et > 60 * 60 * 2
-- session idle time more than 1 hour
ORDER BY last_call_et desc;

##写了一个脚本,kill sniped session
##kill_sniped_session.sh
#! /bin/bash
ORACLE_SID=xxxxprod
export ORACLE_SID
ORACLE_HOME=`cat /var/opt/oracle/oratab|grep ^$ORACLE_SID:|cut -f2 -d':'`
export ORACLE_HOME
SQLPATH=/apps/oracle/sql
export SQLPATH
#
$ORACLE_HOME/bin/sqlplus -s "/ as sysdba"<<!
@sniped_session.sql
exit
!
if [ -s /apps/oracle/sql/kill_sniped_session.lst ]
then
echo "have a list of sniped_session"
grep kill /apps/oracle/sql/kill_sniped_session.lst
grep kill /apps/oracle/sql/kill_sniped_session.lst | awk '{ print $3 }' | xargs kill -9 2>/backup/oracle/kill_sniped_session.log
fi
if [ $? -ne 0 ]
then
cat /backup/oracle/kill_sniped_session.log | mailx -s "xxxxprod kill sniped session failed"
xx@@ss.com
else
sessions_count=`grep kill /apps/oracle/sql/kill_sniped_session.lst | wc -l`
echo "sessions:${sessions_count}" | mailx -s "xxxxprod kill sniped session successful"
xx@@ss.com
touch /backup/oracle/kill_sniped_session.sh
fi


oracle@xxxxprod$ more sniped_session.sql
rem sniped_session.sql
rem DESCRIPTION
rem kill sniped session
rem MODIFIED
set pagesize 1000
set heads off
set verify off
set heading off
set termout off
set echo off
set feedback off
spool on
spool /apps/oracle/sql/kill_sniped_session.lst
select 'kill -9 '||spid UNIX_level_kill
FROM v$session s, v$process p
WHERE TYPE = 'USER'
AND p.addr = s.paddr
AND status = 'SNIPED'
AND last_call_et > 60 * 60 * 3
ORDER BY last_call_et desc;
spool off

 

##btw

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.

Sqlnet.expire_time basically instructs the Server to send a probe packet every set minutes to the client , and if it finds a terminated connection or a connection that is no longer in use, causes the associated server process to terminate on the server.
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.
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.


http://space.itpub.net/10687595/viewspace-420407

首页/大数据 宝塔MySQL8.0.36有时无法访问(大约15秒左右),目前CPU占用1,如何解决? mysql 数据库 java 求社区用户再支个招,感谢! 宝塔MySQL8.0.36每隔 5 分钟左右没有请求时,再次请求必卡 15 s,之后一切正常。当没有数据请求后隔5分钟左右再次请求会出现上述的问题,目前没有部署项目CPU占用1%,内存为50%。 MySQL配置文件 [client] #password = your_password port = 3306 socket = /tmp/mysql.sock [mysqld] binlog_cache_size = 128K thread_stack = 256K join_buffer_size = 2048K max_heap_table_size = 128M port = 3306 socket = /tmp/mysql.sock datadir = /www/server/data default_storage_engine = InnoDB skip-external-locking key_buffer_size = 128M max_allowed_packet = 100G table_open_cache = 384 sort_buffer_size = 1024K net_buffer_length = 4K read_buffer_size = 1024K read_rnd_buffer_size = 768K myisam_sort_buffer_size = 16M thread_cache_size = 128 tmp_table_size = 128M lower_case_table_names = 1 default_authentication_plugin = mysql_native_password sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES explicit_defaults_for_timestamp = true skip-name-resolve max_connections = 300 max_connect_errors = 100 open_files_limit = 65535 log-bin=mysql-bin binlog_format=mixed server-id = 1 binlog_expire_logs_seconds = 600000 slow_query_log=1 slow-query-log-file=/www/server/data/mysql-slow.log long_query_time=3 #log_queries_not_using_indexes=on early-plugin-load = "" wait_timeout = 300 interactive_timeout = 300 innodb_data_home_dir = /www/server/data innodb_data_file_path = ibdata1:10M:autoextend innodb_log_group_home_dir = /www/server/data innodb_buffer_pool_size = 256M innodb_log_file_size = 128M innodb_log_buffer_size = 32M innodb_flush_log_at_trx_commit = 1 innodb_lock_wait_timeout = 50 innodb_max_dirty_pages_pct = 90 innodb_read_io_threads = 4 innodb_write_io_threads = 4 [mysqldump] quick max_allowed_packet = 500M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 64M sort_buffer_size = 1M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout = 600 # bt_mysql_set = None # bt_mem_size = None # bt_query_cache_size = None # bt_mysql_set = None # bt_mem_size = None # bt_query_cache_size = None 轻量云4核4G centOs7 宝塔 MySQL8.0.36 若依springboot项目 已试过 my.cnf、TCP keepalive、wait_timeout、interactive_timeout,均无效,求社区用户支支招 希望能够支支招解决每隔五分钟不使用就会卡的问题
最新发布
10-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值