[英]psql: FATAL: remaining connection slots are reserved for non-replication superuser connections
I want to understand when this error occurs and how to resolve it.我想了解此错误何时发生以及如何解决。 I checked
pg_stat_activity
and pg_locks
but couldnt figure out which process is exhausing the connections我检查了
pg_stat_activity
和pg_locks
但无法弄清楚哪个进程正在耗尽连接
We are using sqlalchemy to connect to database as below我们正在使用 sqlalchemy 连接到数据库,如下所示
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine_url = f'{dbms}://{username}:{password}@{hostname}:{port}/{database}'
engine = create_engine(engine_url, pool_size=20, max_overflow=10)
Session = sessionmaker(bind=engine)
db_session = Session()
This is an extension of Heroku "psql: FATAL: remaining connection slots are reserved for non-replication superuser connections"这是Heroku的扩展“psql:致命:剩余的连接槽是为非复制超级用户连接保留的”
I am adding the client process id in application name of sqlalchemy engine url.我正在 sqlalchemy 引擎 url 的应用程序名称中添加客户端进程 ID。 This will be stored under
application_name
in pg_stat_activity
and it will be helpful to debug from where did this connection was opened.这将被存储在
application_name
中pg_stat_activity
,这将是有帮助的,从没有就此被打开了哪里调试。
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
client_hostname = os.environ.get('HOSTNAME', 'UNKNOWN')
client_pid = os.getpid()
engine_url = f'{dbms}://{username}:{password}@{hostname}:{port}/{database}?application_name={client_hostname}_{client_pid}'
engine = create_engine(engine_url, pool_size=20, max_overflow=10)
Session = sessionmaker(bind=engine)
db_session = Session()
This shows where the connection was originated from and the application name has a limit of 64 chars , so we can include any custom information that you want to pass on to db stats这显示了连接的来源,并且应用程序名称限制为64 个字符,因此我们可以包含您想要传递给 db stats 的任何自定义信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.