关于ORACLE的v$process 和v$session 到达最大连接限制的问题

ORA-12520:TNS:监听程序无法为请求的服务器类型找到可用的处理程序

oracle这个错误的意思是  数据库的连接数达到最大值限制。

一、关于v$process v$session的基本知识
Oracle数据库中Session和Connection的区别。
在Oracle的官方文档上,对Session和Connection是这样解释的:
  Connection: Communicate pathway between a client process and an Oracle database instance.

连接:一个客户端进程和Oracle数据库实例之间的通信链路。

Session: A logical entity in the database instance memory that represnts the state of a current user login to a database. A single connection can have 0, 1 or more sessions established on it.
会话:用于展示当前登录到数据库用户的状态的数据库实例内存中的一个逻辑实体。一个单独的连接可以有0,1,或者更多的会话。

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

二、查看v$process v$session的基本信息
查询资源限制的视图的语法:

select * from v$resource_limit;

select * from v$process;

select * from v$session;

select * from v$session t where t.STATUS=’ACTIVE”;

process和session参数最大值估算方法
select round(sum(pga_used_mem)/1024/1024,0) total_used_M, round(sum(pga_used_mem)/count(1)/1024/1024,0) avg_used_M,
round(sum(pga_alloc_mem)/1024/1024,0) total_alloc_M, round(sum(pga_alloc_mem)/count(1)/1024/1024,0) avg_alloc_M from v$process;

三、释放资源
在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。

同时,扩大最大连接数,同时Session自动跟着扩大。

–修改最大连接数:

alter system set processes = 500 scope = spfile;

重启数据库:

cmd :sqlplus sys/passw@databasename as sysdba

然后输入以下命令

shutdown immediate;——关闭数据库,大概需要一个小时

startup;–重启数据库,大概几分钟。

重启之后:

select count(*) from v$process    ——从298变成132

select count(*) from v$session    ——从104变成38

但是,在ArcGIS Portal 里面打开一个页面,调用了SDE图层,

上面的连接数字都增加,那么就算设置为最大500,也支撑不来多少用户使用的!!!!????

–查看当前有哪些用户正在使用数据

SELECT osuser, a.username,cpu_time/executions/1000000||’s’,b.sql_text,machine

from v$session a, v$sqlarea b

where a.sql_address =b.address order by cpu_time;

——在ArcGIS Portal 里面打开一个页面,调用了SDE图层,通过以上语句,可以看到SDE用户的连接信息。

就算关闭了浏览器,一段时间依然可以看到这些信息,半个小时后,SDE的连接才消失。

——查询数据库有没有死锁,no row selected 说明没有死锁。

select * from v$locked_object