PostgreSQL问题解决--连接数过多
I am trying to connect to a Postgresql database, I am getting the following Error:
Error:org.postgresql.util.PSQLException: FATAL: sorry, too many clients already
What does the error mean and how do I fix it?
My server.properties
file is following:
serverPortData=9042
serverPortCommand=9078
trackConnectionURL=jdbc:postgresql://127.0.0.1:5432/vTrack?user=postgres password=postgres
dst=1
DatabaseName=vTrack
ServerName=127.0.0.1
User=postgres
Password=admin
MaxConnections=90
InitialConnections=80
PoolSize=100
MaxPoolSize=100
KeepAliveTime=100
TrackPoolSize=120
TrackMaxPoolSize=120
TrackKeepAliveTime=100
PortNumber=5432
Logging=1
An explanation of the following error:
org.postgresql.util.PSQLException: FATAL: sorry, too many clients already.
Summary:
You opened up more than the allowed limit of connections to the database. You ran something like this: Connection conn = myconn.Open();
inside of a loop, and forgot to run conn.close();
. Just because your class is destroyed and garbage collected does not release the connection to the database. The quickest fix to this is to make sure you have the following code with whatever class that creates a connection:
protected void finalize() throws Throwable
{
try { your_connection.close(); }
catch (SQLException e) {
e.printStackTrace();
}
super.finalize();
}
Place that code in any class where you create a Connection. Then when your class is garbage collected, your connection will be released.
Run this SQL to see postgresql max connections allowed:
show max_connections;
The default is 100. PostgreSQL on good hardware can support a few hundred connections at a time. If you want to have thousands, you should consider using connection pooling software to reduce the connection overhead.
Take a look at exactly who/what/when/where is holding open your connections:
SELECT * FROM pg_stat_activity;
The number of connections currently used is:
SELECT COUNT(*) from pg_stat_activity;
Debugging strategy
You could give different usernames/passwords to the programs that might not be releasing the connections to find out which one it is, and then look in pg_stat_activity to find out which one is not cleaning up after itself.
Do a full exception stack trace when the connections could not be created and follow the code back up to where you create a new
Connection
, make sure every code line where you create a connection ends with aconnection.close();
How to set the max_connections higher:
max_connections in the postgresql.conf sets the maximum number of concurrent connections to the database server.
- First find your postgresql.conf file
- If you don't know where it is, query the database with the sql:
SHOW config_file;
- Mine is in:
/var/lib/pgsql/data/postgresql.conf
- Login as root and edit that file.
- Search for the string: "max_connections".
- You'll see a line that says
max_connections=100
. - Set that number bigger, check the limit for your postgresql version.
- Restart the postgresql database for the changes to take effect.
What's the maximum max_connections?
Use this query:
select min_val, max_val from pg_settings where name='max_connections';
PostgreSQL问题解决--连接数过多的更多相关文章
- 《oracle每日一练》Oracle DBLink连接数过多的问题(Ora-02020)
本文转自Oracle DBLink连接数过多的问题(Ora-02020) 今天在处理资料同步问题,需要将其它几个DB Server的资料同步到一个目地资料库,采用的方式是:DBLink+Job ,然而 ...
- Oracle连接数过多释放机制
Oracle连接数过多释放机制 sqlplus /nolog 打开sqlplus connect /as sysdba 使用具有dba权限得用户登陆oracle ...
- VB php JAVA关于数据库连接数过多的解决方法
这里讲解一个关于数据库连接多多的解决办法 一般都会在方法中进行数据库的开,利用和关 不过如果在一个循环里面使用的时候 这样数据库的连接数就会过多,如果是1万次的话,数据库服务器可能就会当机 PHP 中 ...
- 科学地增加postgresql最大连接数
PG配置文件路径 /etc/postgresql/9.3/main/postgresql.conf 首先如何查看最大连接数 This SQL will help you select max_conn ...
- postgresql 最大连接数相关
PG中有一张表记录着当前有多少连接 表名:pg_stat_activity 查询当前连接数: select count(1) from pg_stat_activity; 查询最大连接数 show m ...
- linux下postgresql的连接数配置
1.查询当前连接数: select count(*) from pg_stat_activity; 2.查询最大连接数 show max_connections; 3.修改最大连接数 SHOW con ...
- 【问题处理】mysql sleep 连接数过多
睡眠连接过多,会对mysql服务器造成什么影响?严重消耗mysql服务器资源(主要是cpu, 内存),并可能导致mysql崩溃.造成睡眠连接过多的原因?1. 使用了太多持久连接(个人觉得,在高并发系统 ...
- linux连接数过多,导致ping包丢包的问题解析
1.首先要明确,无论是tcp, udp, raw等这些都要占用socket, 那么就涉及到连接数的问题. 所以,linux连接数的问题,不仅仅是tcp连接数. 2.查看当前系统中所有的socket 连 ...
- Confluence 6 PostgreSQL 问题解决
如果 Confluence 提示没有 class 文件,你可能将你的 JDBC 驱动放置到了错误的文件夹. 如果你不能从你从 Confluence 中连接到 PostgreSQL ,并且这 2 个服务 ...
随机推荐
- 使用Docker在服务器上部署Ubuntu,本地传文件到docker
使用Docker在服务器上部署Ubuntu,本地传文件到docker 作者:王佳乐 目录 安装Docker 安装Docker 全部安装流程: 登录服务器 ssh username@ip 检查是否已经安 ...
- c++11新特性学习2
noexcept 替代 throw.优点是更安全, 如果noexcept 修饰的函数抛出了异常,编辑器可以直接选择终止程序. C++ 11中析构函数默认为noexcept(true),从而阻止异常的扩 ...
- 实时查询系统架构:spark流式处理+HBase+solr/ES查询
最近要做一个实时查询系统,初步协商后系统的框架 1.流式计算:数据都给spark 计算后放回HBase 2.查询:查询采用HBase+Solr/ES
- 【收集+】DDR5 vs DDR4
Advantages of Migrating to DDR5 DDR5 is the next evolution in DRAM, bringing a robust list of new fe ...
- ArcGIS和ENVI最新软件下载
浏览的时候发现一位博主分享了很多版本很新的软件 在这里分享一下下载界面链接 https://www.ixxin.cn/software.html
- scrapy的使用--Rcrapy-Redis
Scrapy-Redis分布式爬虫组件 Scrapy是一个框架,他本身是不支持分布式的.如果我们想要做分布式的爬虫.就需要借助一个组件叫做Scrapy-Redis.这个组件正式利用了Redis可以分布 ...
- Mybatis 使用Mapper接口的Sql动态代码方式进行CURD和分页查询
1.Maven的pom.xml 2.配置文件 2.1.db.properties 2.2.mybatis.xml 2.3.log4j.xml 3.MybatisUtil工具类 4.Mapper映射文件 ...
- 关于SQL server2017无法连接远程服务器的问题
安装了SQL server2017,能连接上本地数据库,但是连接远程数据库则老报错,什么实例错误之类的,百度找了也是什么打开sql server 服务,什么修改端口1433,什么TCP协议之类的,全部 ...
- 关于Excel的ctrl+方向键失效的解决方法
在Excel中按方向键,出现了类似滚动条的效果,即按下,表格就往下滚了一格.正常的情况应该是选中的单元格往下移动一格.其实这是一个很正常的情况,只要按一下Scroll Lock键就可以了,对于没有Sc ...
- 数据库MySQL--基础查询
1.查询字段 查询表某字段:select 字段名 from 表名: 查询表内所有字段:select * from 表名: (当字段和关键字重名是用( ` )着重号区分 ) 2.查询常量值 select ...