简体   繁体   English

Heroku "psql: FATAL: 剩余的连接槽保留给非复制超级用户连接"

[英]Heroku "psql: FATAL: remaining connection slots are reserved for non-replication superuser connections"

I'm developing an app on Heroku with a Postgresql backend.我正在 Heroku 上开发一个应用程序,后端为 Postgresql。 Periodically, I get this error message when trying to access the database, both from the CLI and from loading a page on the server:在尝试访问数据库时,我会定期从 CLI 和在服务器上加载页面时收到此错误消息:

psql: FATAL: remaining connection slots are reserved for non-replication superuser connections

Anyone seen this before or please help point me in the right direction?有人以前见过这个,或者请帮我指出正确的方向吗?

You either need to increase the max_connections configuration setting or (probably better) use connection pooling to route a large number of user requests through a smaller connection pool.您要么需要增加max_connections配置设置,要么(可能更好) 使用连接池通过较小的连接池路由大量用户请求。

https://wiki.postgresql.org/wiki/Number_Of_Database_Connections https://wiki.postgresql.org/wiki/Number_Of_Database_Connections

当我忘记关闭连接时发生此异常

See Heroku “psql: FATAL: remaining connection slots are reserved for non-replication superuser connections” :请参阅Heroku “psql: FATAL: 剩余连接槽为非复制超级用户连接保留”

Heroku sometimes has a problem with database load balancing. Heroku 有时会遇到数据库负载平衡问题。

André Laszlo , markshiz and me all reported dealing with that in comments on the question. André Laszlomarkshiz和我都在对这个问题的评论中报告了处理这个问题。

To save you the support call, here's the response I got from Heroku Support for a similar issue:为了节省您的支持电话,以下是我从 Heroku 支持部门收到的针对类似问题的回复:

Hello,你好,

One of the limitations of the hobby tier databases is unannounced maintenance.爱好层数据库的限制之一是不通知的维护。 Many hobby databases run on a single shared server, and we will occasionally need to restart that server for hardware maintenance purposes, or migrate databases to another server for load balancing.许多爱好数据库运行在单个共享服务器上,我们偶尔需要重新启动该服务器以进行硬件维护,或者将数据库迁移到另一台服务器以进行负载平衡。 When that happens, you'll see an error in your logs or have problems connecting.发生这种情况时,您会在日志中看到错误或连接出现问题。 If the server is restarting, it might take 15 minutes or more for the database to come back online.如果服务器正在重新启动,则数据库可能需要 15 分钟或更长时间才能重新联机。

Most apps that maintain a connection pool (like ActiveRecord in Rails) can just open a new connection to the database.大多数维护连接池的应用程序(如 Rails 中的 ActiveRecord)只能打开一个到数据库的新连接。 However, in some cases an app won't be able to reconnect.但是,在某些情况下,应用程序将无法重新连接。 If that happens, you can heroku restart your app to bring it back online.如果发生这种情况,您可以 heroku 重新启动您的应用程序以使其重新上线。

This is one of the reasons we recommend against running hobby databases for critical production applications.这是我们建议不要为关键生产应用程序运行爱好数据库的原因之一。 Standard and Premium databases include notifications for downtime events, and are much more performant and stable in general.标准和高级数据库包括停机事件通知,并且通常性能更高且更稳定。 You can use pg:copy to migrate to a standard or premium plan.您可以使用 pg:copy 迁移到标准或高级计划。

If this continues, you can try provisioning a new database (on a different server) with heroku addons:add, then use pg:copy to move the data.如果这种情况继续存在,您可以尝试使用 heroku addons:add 配置一个新数据库(在不同的服务器上),然后使用 pg:copy 移动数据。 Keep in mind that hobby tier rules apply to the $9 basic plan as well as the free database.请记住,爱好等级规则适用于 9 美元的基本计划以及免费数据库。

Thanks, Bradley谢谢,布拉德利

I actually tried to implement connection pooling on the django end using:我实际上尝试使用以下方法在 django 端实现连接池:

https://github.com/gmcguire/django-db-pool https://github.com/gmcguire/django-db-pool

but I still received this error, despite lowering the number of connections available to below the standard development DB quota of 20 open connections.但我仍然收到此错误,尽管将可用连接数降低到低于 20 个打开连接的标准开发数据库配额。

There is an article here about how to move your postgresql database to the free/cheap tier of Amazon RDS.这里有一篇关于如何将您的 postgresql 数据库移动到 Amazon RDS 的免费/廉价层的文章。 This would allow you to set max_connections higher.这将允许您将max_connections设置得更高。 This will also allow you to pool connections at the database level using PGBouncer.这也将允许您使用 PGBouncer 在数据库级别建立连接池。

https://www.lewagon.com/blog/how-to-migrate-heroku-postgres-database-to-amazon-rds https://www.lewagon.com/blog/how-to-migrate-heroku-postgres-database-to-amazon-rds

UPDATE:更新:

Heroku responded to my open ticket and stated that my database was improperly load balanced in their network. Heroku 回应了我的开放请求,并表示我的数据库在他们的网络中负载平衡不当。 They said that improvements to their system should prevent similar problems in the future.他们说对他们的系统的改进应该可以防止将来出现类似的问题。 Nonetheless, support manually relocated my database and performance is noticeably improved.尽管如此,支持手动重新定位我的数据库并且性能显着提高。

按照以下命令重新启动postgres数据库:

postgres -D /usr/local/var/postgres

To reproduce same issue in Linux:在 Linux 中重现相同的问题:

for i in {1..300}; do
     PGPASSWORD=MY_PASSWORD gnome-terminal -e  $'/usr/bin/psql -h \'127.0.0.1\' -p 5432 -U MY_USERNAME' 
done

In a dotnet client you can read:在 dotnet 客户端中,您可以阅读:

 System.InvalidOperationException: An exception has been raised that is likely due to a transient failure. ---> Npgsql.PostgresException (0x80004005): 53300: sorry, too many clients already

I had a lot of idle connections in my case, so I had to reuse idle connections before creating new ones,在我的案例中有很多空闲连接,所以我必须在创建新连接之前重用空闲连接,

The error message means that the app has used up all available connections.错误消息意味着该应用程序已用完所有可用连接。

While using postgres in aws with knex and typescript to do some query and update job, the problem pops up when it finishes 390 database operations, for which a mistake prevents the normal knex.destroy() operation.在带有 knex 和 typescript 的 aws 中使用 postgres 执行一些查询和更新作业时,当它完成 390 个数据库操作时会弹出问题,为此错误会阻止正常的 knex.destroy() 操作。 The error message is:错误信息是:

(node:66236) UnhandledPromiseRejectionWarning: error: remaining connection slots are reserved for non-replication superuser connections (节点:66236)UnhandledPromiseRejectionWarning:错误:剩余的连接槽保留用于非复制超级用户连接

When knex.destroy() goes to the right place the error is gone.当 knex.destroy() 到达正确的位置时,错误就消失了。

There seems no questions asking this issue with the context of .NET world..NET世界的背景下,似乎没有问题问这个问题。

For me, this is caused by async void , and this method passed to a Action delegate, Action<TMessage> action , and there are multiple threads trying to call this Persist method at the same time.对我来说,这是由async void引起的,此方法传递给 Action 委托Action<TMessage> action ,并且有多个线程试图同时调用此 Persist 方法。

private async void Persist(WhateverData data)
{
    await _repository.InsertAsync(data);
}

the solution is, remove async and await, and just use it synchronously解决方案是,删除 async 和 await,并同步使用它

private void Persist(PriceInfo price)
{
    _repository.InsertAsync().WaitAndUnwrapException();
}

set the maximum active size for tomcat-jdbc, set this property in your.properties or.yml file:设置 tomcat-jdbc 的最大活动大小,在您的 .properties 或 .yml 文件中设置此属性:

spring.datasource.maxActive=5 spring.datasource.maxActive=5

or要么

spring.datasource.max-active=5 spring.datasource.max-active=5

as below:如下:

spring: datasource: driverClassName: password: url: username: max-active: 5 spring:数据源:driverClassName:密码:url:用户名:max-active:5

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 psql: FATAL: 剩余的连接槽是为非复制超级用户连接保留的 - psql: FATAL: remaining connection slots are reserved for non-replication superuser connections Heroku Postgres严重:剩余的连接插槽保留用于非复制超级用户连接 - Heroku Postgres FATAL: remaining connection slots are reserved for non-replication superuser connections 剩余的连接插槽保留用于非复制超级用户连接 - remaining connection slots are reserved for non-replication superuser connections PostgreSQL | 剩余的连接槽保留用于非复制超级用户连接 - Postgresql | remaining connection slots are reserved for non-replication superuser connections SequelizeConnectionError:致命:剩余的连接插槽保留用于非复制超级用户连接 - SequelizeConnectionError: FATAL: remaining connection slots are reserved for non-replication superuser connections 引起:org.postgresql.util.PSQLException:致命:剩余的连接槽是为非复制超级用户连接保留的 - Caused by: org.postgresql.util.PSQLException: FATAL: remaining connection slots are reserved for non-replication superuser connections Django django.db.utils.OperationalError: FATAL: 剩余的连接槽保留用于非复制超级用户连接 - Django django.db.utils.OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections AWS RDS PostgreSQL 错误“剩余连接槽为非复制超级用户连接保留” - AWS RDS PostgreSQL error “remaining connection slots are reserved for non-replication superuser connections” 甚至从哪里开始调查导致数据库崩溃的问题:剩余的连接槽保留用于非复制超级用户连接 - Where to even begin investigating issue causing database crash: remaining connection slots are reserved for non-replication superuser connections FastAPI + Postgres + SQLAlchemy - 致命:保留剩余连接槽 - FastAPI + Postgres + SQLAlchemy - Fatal: remaining connection slots are reserved
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM