---
title: "Listener refused the connection with the following error: ORA-12519, TNS:no appr"
author: "书安然"
date: "2014-12-13T17:25:30Z"
tags: []
categories: ["企业架构"]
slug: "listener-refused-the-connection-with-the-following-error-ora-12519-tns-no-appr"
draft: false
lastmod: "2014-12-13T17:25:30Z"
id: 2166053
url: "https://amflytogether.iteye.com/blog/2166053"
---

异常：

```java
Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: localhost:1521:orcl 
Hibernate operation: Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [null]; error code [0]; Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: localhost:1521:orcl ; nested exception is java.sql.SQLException: Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: localhost:1521:orcl 

```



> 查询数据库当前进程的连接数： 
> 
> 　select count(*) from v$process;
> 
> 　　查看数据库当前会话的连接数： 
> 
> 　　elect count(*) from v$session;
> 
> 　　查看数据库的并发连接数： 
> 
> 　　select count(*) from v$session where status='ACTIVE'; 
> 
> 　　查看当前数据库建立的会话情况： 
> 
> 　　select sid,serial#,username,program,machine,status from v$session; 
> 
> 　　查询数据库允许的最大连接数： 
> 
> 　　select value from v$parameter where name = 'processes'; 
> 
> 　　或者：show parameter processes; 
> 
> 　　修改数据库允许的最大连接数： 
> 
> 　　alter system set processes = 300 scope = spfile; 
> 
> 　　(需要重启数据库才能实现连接数的修改) 
> 
> 　　重启数据库： 
> 
> 　　shutdown immediate; 
> 
> 　　startup; 
> 
> 　　查看当前有哪些用户正在使用数据： 
> 
> 　　select osuser,a.username,cpu_time/executions/1000000's' ,sql_fulltext,machine 
> 
> 　　from v$session a,v$sqlarea b 
> 
> 　　where a.sql_address = b.address 
> 
> 　　order by cpu_time/executions desc; 
> 
> 　　备注：UNIX 1个用户session对应一个操作系统process，而Windows体现在线程。 
> 
> 　　启动oracle 
> 
> 　　su - oracle 
> 
> 　　sqlplus system/pwd as sysdba //进入sql 
> 
> 　　startup //启动数据库 
> 
> 　　lsnrctl start //启动监听 
> 
> 　　sqlplus "/as sysdba" 
> 
> 　　shutdown immediate; 
> 
> 　　startup mount; 
> 
> 　　alter database open; 
> 
> --
> 
> web应用连接oracle数据库时，经常在查询数据时发生
> 
> Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found The Connection descriptor used by the client was: 127.0.0.1:1521:ORCL
> 
> 这种错误，网上查了很多，都说是ip地址改变之后的问题，要把tnsnames.ora中的实例配置中改为计算机名，我试过之后问题还是不能解决，今天终于找到问题所在了，是数据库连接数量的问题，12519错误为监听不能提供服务，通常为数据库进程达到上限导致。
> 
>       可以先执行下 select count(*) from v$process ，看下现在系统有多少连接数，然后再查询 select value from v$parameter where name = 'processes' ，看下oracle设置中设置了多少连接数，一般一个应用都会使用20个，所以如果你开了几个应用的话（web、pl/sql、……）就会出这个问题了，这时只需要执行下
> 
> alter system set processes = 300 scope = spfile;


就可以了，当然300可以根据实际情况设置。