简体   繁体   English

psql: FATAL: 剩余的连接槽是为非复制超级用户连接保留的

[英]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_activitypg_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_namepg_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.

相关问题 甚至从哪里开始调查导致数据库崩溃的问题:剩余的连接槽保留用于非复制超级用户连接 - Where to even begin investigating issue causing database crash: remaining connection slots are reserved for non-replication superuser connections 拥有单独的复制槽有什么意义? - What's the point of having individual replication slots? 正在关闭连接,但仍然出现异常:null.Message:FATAL:角色“ me”的连接过多 - Closing connection but still getting Exception: null.Message:FATAL: too many connections for role “me” 具有单个连接的连接池 - Connection pool with single connections 是否可以在 bash 中建立持久的 psql 连接? - Is it possible to have a persistent psql connection in bash? psql:严重:尝试访问psql时由于用户错误而导致密码身份验证失败 - psql: FATAL: password authentication failed for user error while trying to access psql 使用非超级用户帐户获取大对象的实际数据 - Get the actual data of the large object using non-superuser account Grails连接池 - 连接未关闭? - Grails connection pool - connections not closing? 连接池不重用空闲连接 - Connection pooling is not reusing idle connections psql中的ip选项的postgresql-server连接密码失败 - postgresql-server connection password fail for ip option in psql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM