Django django.db.utils.OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections

Django django.db.utils.OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections

  File "/usr/local/lib/python3.7/dist-packages/psycopg2/__init__.py", line 126, in connect    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATAL:  remaining connection slots are reserved for non-replication superuser connections

根据 Postgres 文档,当 Django 与 Postgres 数据库建立的连接数超过默认连接限制时,就会发生此错误。

#settings.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'xxxxx',
        'USER': 'xxxxx',
        'PASSWORD':'xxxxx',
        'HOST':'localhost',
        'PORT':'5432',
    }

我相信这是在 Django 框架不进行数据库池化的情况下发生的。查看 Django 文档 (https://docs.djangoproject.com/en/3.2/ref/databases/#transaction-pooling-and-server-side-cursors) i could find a sugestion to user pgBouncer (http://www.pgbouncer.org/) 来解决这个问题。