本篇文章主要介绍了" Postgres 连接数过多 psql: FATAL: sorry, too many clients already",主要涉及到方面的内容,对于其他数据库感兴趣的同学可以参考一下:
今天开发找到我,说他们的数据库连接不上了,可能是连接数太多,然后我登录到服务器,并且尝试登陆数据库,也是报错:psql: FATAL: sorry, ...
今天开发找到我,说他们的数据库连接不上了,可能是连接数太多,然后我登录到服务器,并且尝试登陆数据库,也是报错:
psql: FATAL: sorry, too many clients already
很明显,是数据库连接满了。于是查看一下数据库连接进程:
[postgres@ec2s-autodenalicontentpoi-01 ~]$ ps -ef |grep postgres
postgres 3406 18212 0 00:35 ? 00:01:00 postgres: denaliadmin region_na 172.16.60.16(51976) idle
postgres 4221 18212 0 01:09 ? 00:00:03 postgres: denaliadmin region_anz 10.66.40.44(61006) idle
postgres 4223 18212 0 01:09 ? 00:00:00 postgres: denaliadmin region_anz 10.66.40.44(61009) idle
postgres 4390 18212 0 01:16 ? 00:00:00 postgres: denaliadmin region_sa 10.66.40.46(63779) idle
postgres 4391 18212 0 01:16 ? 00:00:00 postgres: denaliadmin region_sa 10.66.40.46(63784) idle
postgres 5587 18212 0 02:04 ? 00:00:00 postgres: denaliadmin postgres 172.16.60.16(53018) idle
postgres 5782 18212 2 02:13 ? 00:01:29 postgres: denaliadmin region_sa 10.189.101.98(40704) idle
postgres 5793 18212 1 02:13 ? 00:01:06 postgres: denaliadmin region_sa 10.189.101.98(40705) idle
postgres 5794 18212 1 02:13 ? 00:01:10 postgres: denaliadmin region_sa 10.189.101.98(40706) idle
......
为了能够登录数据库,只有kill掉一些处于idle状态的进程,再使用超级用户登录
$ kill 4223
然后就可以进到数据库中通过select * from pg_stat_activity where state='idle';来查到哪些进程处于空闲,然后批量kill.