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 个服务 ...
随机推荐
- ionic:temple
ylbtech-ionic:temple 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylb ...
- class12_pack_grid_place 放置位置
其中的部分运行效果图(程序见序号1): #!/usr/bin/env python# -*- coding:utf-8 -*-# ----------------------------------- ...
- Harbor任意管理员注册漏洞复现CVE-2019-16097
注册时抓包 添加poc "has_admin_role":true 管理员权限 POC POST /api/users HTTP/1.1 Host: 127.0.0.1 Conte ...
- 20130318 word2013 mathtype
1.word2013 下如何安装mathtype 1.word2013已经装好 2.下载mathtype6.9 3. 公式编辑器Mathtype安装后无法加载到word的解决办法http://w5 ...
- java通过传送地址获取坐标
package com.action; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputS ...
- 【POJ】1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 题意:n个城镇,m条路上能承载的最大重量.现在问你从1到n的最大承重量. 题解:spfa的变体. 假设当前1->当前点的承 ...
- c++ socket 出现绑定失败的一个特殊原因。Bind failed Error:10049
这个问题,客户那边出现这种情况已经将近一年时间, 一直都得不到很好的解决,我提供出去的动态库可以确保没有问题,因为除了这家公司,其他有好几家公司都在用的,都是很正常的,但是这家公司很奇怪,不,应该说这 ...
- css布局-瀑布流的实现
一.基本思路 1.先看最终的效果图: 2.实现原理:通过position:absolute(绝对定位)来定位每一个元素的位置,并且将当前列的高度记录下来方便下一个dom位置的计算 二.代码实现 1.版 ...
- Git查看历史记录的几种方法
- 【笔记篇】单调队列优化dp学习笔记&&luogu2569_bzoj1855股票交♂易
DP颂 DP之神 圣洁美丽 算法光芒照大地 我们怀着 崇高敬意 跪倒在DP神殿里 你的复杂 能让蒟蒻 试图入门却放弃 在你光辉 照耀下面 AC真心不容易 dp大概是最经久不衰 亘古不化的算法了吧. 而 ...