Oracle数据库 连接数的消耗情况及简单优化

观察各项指标,查看连接消耗情况

--查看会话session:
select * from v$session where username is not null
select username,count(username) from v$session where username is not null group by username

--查看当前连接数
select count(*) from v$process;

--查看最大连接数
select value from v$parameter where name ='processes';

--查看并发连接数
Select count(*) from v$session where status='ACTIVE';

--查询:客户端设备标识、客户端程序、oracle用户名、消耗的连接数量
select  b.MACHINE 机器名, b.PROGRAM 程序名, b.USERNAME 用户名, 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, b.USERNAME 
order by count(*) desc;

--杀死指定的进程
alter system kill session 'sid,serial#' immediate;

可能需要优化的点

1、释放资源

        在sqlnet.ora文件中设置expire_time 参数。
        可以使用EXPIRE_TIME参数间歇检查异常session并释放process。
        官方说明: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.
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.

Recommended Value
10
Example
SQLNET.EXPIRE_TIME=10

这里设置是10分钟,每10分钟Oracle会确认所有session客户端连接是否正常,对于不正常的session,oracle会清理process。

2、扩大连接数,同时Session自动跟着扩大

alter system set processes = 500 scope = spfile;

3、以上优化操作设置完要重启数据库,shutdown的时候要关闭所有连接(采用立即关闭)

SQL>conn /as sysdba
SQL>shutdown immediate
SQL>startup

连接或会话很多的话关闭可能很慢,关不掉的话可以参考:https://www.cnblogs.com/kerrycode/p/3435581.html

connection、process和session的基本知识

上面提到几次连接、进程和会话,这里简单补充一下两者的关系:

    每个sql login称为一个连接(connection),而每个连接,可以产生一个或多个会话,如果数据库运行在专用服务器方式,
一个会话对应一个服务器进程(process),如果数据库运行在共享服务器方式,一个服务器进程可以为多个会话服务。

    Connection并不是直接建立在用户进程和数据库实例之间的。而是在用户进程和Server Process(服务器进程)之间的,
因此有一个Connection就一定会有一个用户进程和一个服务器进程,但不一定会存在Session。
比如,如果需要将东西从A运到B,Connection可以看成是一座“桥”,而卡车把东西从A运到B后并返回A,这就是Session。
所以,只要不断开连接,随时都可以在这个连接上创建出会话。

参考:https://blog.csdn.net/aganliang/article/details/79809775

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值