我使用 Postgres 和 Sequelize 作为 ORM/查询接口。最近我们开始遇到一些错误:
SequelizeConnectionError: remaining connection slots are reserved for non-replication superuser connections
调查一下,问题似乎与 Postgres 设置的连接限制有关,但我在弄清楚如何将客户端池设置与 Postgres 设置关联起来时遇到了一些麻烦:
在我的 postgres 9.4 数据库(在 Amazon RDS 上)上,我的
max_connections
默认为 26:
SELECT name, setting FROM pg_settings WHERE name='max_connections';
+-----------------+---------+
| name | setting |
+-----------------+---------+
| max_connections | 26 |
+-----------------+---------+
在 Sequelize 中,我将池设置为:
pool: {
max: 10,
min: 0,
idle: 10000
},
一些问题:
max_connections
有何关系?max_connections
中占用 1 个计数?max_connections
?下面的查询将帮助您找出为什么您有如此多的联系
SELECT * FROM pg_stat_activity
一般来说,池与 max_connections 有何关系?
池中的最大值表示您在池中设置的连接数。在 postgresql 中,
max_connections
是您在数据库服务器中设置的连接数。因此,池中的每个连接都会从 max_connections
中获取 1 个值
将
max_connections
设置为26相当低,我建议您增加设置值。
池中的每个连接是否从 max_connections 中占用 1 个计数?
是的,每个连接占用 1 个计数。
这是否意味着池 max 必须始终小于 max_connections?
是的,池最大值必须始终小于 max_connections
降低池上的空闲超时是否有助于更快地释放连接?
是的,这确实有帮助,但在这种情况下并不是完美的解决方案。
可能的原因!!
还有,你检查过
superuser_reserved_connections
变量值了吗,请看这个post,这可能对你有帮助!!
您使用 Heroku 进行连接池吗?
在我的例子中,最大连接数是 1000,使用的连接数是 40。我仍然收到错误连接池已满。 我正在使用 pgagroal 和 postgresql