open devices error "remaining connection slots are reserved for non-replication superuser connections" #3178

Closed
opened 2025-12-29 18:26:22 +01:00 by adam · 1 comment
Owner

Originally created by @bybai on GitHub (Jan 17, 2020).

Environment

  • Python version: 3.6
  • NetBox version: 2.7.1

Steps to Reproduce

  1. Add Rack
  2. Add device types, add 2 interfaces for this type
  3. add 2 devices, add these devices to rack, I got the following error under devices page:

<class 'django.db.utils.OperationalError'>

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

The background:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 83, in dispatch
if not self.has_permission():
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 80, in has_permission
return self.request.user.has_perms(perms)
File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 256, in inner
self._setup()
File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 392, in _setup
self._wrapped = self._setupfunc()
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/middleware.py", line 24, in
request.user = SimpleLazyObject(lambda: get_user(request))
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/middleware.py", line 12, in get_user
request._cached_user = auth.get_user(request)
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/init.py", line 182, in get_user
user_id = _get_user_session_key(request)
File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/init.py", line 59, in _get_user_session_key
return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY])
File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py", line 54, in getitem
return self._session[key]
File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py", line 194, in _get_session
self._session_cache = self.load()
File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 43, in load
s = self._get_session_from_db()
File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 34, in _get_session_from_db
expire_date__gt=timezone.now()
File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/cacheops/query.py", line 390, in get
return qs._no_monkey.get(qs, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 402, in get
num = len(clone)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 256, in len
self._fetch_all()
File "/usr/local/lib/python3.6/site-packages/cacheops/query.py", line 303, in _fetch_all
return self._no_monkey._fetch_all(self)
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 55, in iter
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1131, in execute_sql
cursor = self.connection.cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor
return self._cursor()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor
self.ensure_connection()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection
self.connect()
File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
connection = Database.connect(**conn_params)
File "/usr/local/lib64/python3.6/site-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

[17/Jan/2020 12:34:40] "GET /dcim/devices/ HTTP/1.1" 500 1820

Expected Behavior

Get right device list

Observed Behavior

Originally created by @bybai on GitHub (Jan 17, 2020). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6 <!-- Example: 3.5.4 --> * NetBox version: 2.7.1 <!-- Example: 2.5.2 --> <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox (or the current beta release where applicable). Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a wrapper like pynetbox. --> ### Steps to Reproduce 1. Add Rack 2. Add device types, add 2 interfaces for this type 3. add 2 devices, add these devices to rack, I got the following error under devices page: <class 'django.db.utils.OperationalError'> FATAL: remaining connection slots are reserved for non-replication superuser connections The background: The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 83, in dispatch if not self.has_permission(): File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 80, in has_permission return self.request.user.has_perms(perms) File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 256, in inner self._setup() File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 392, in _setup self._wrapped = self._setupfunc() File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/middleware.py", line 24, in <lambda> request.user = SimpleLazyObject(lambda: get_user(request)) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/middleware.py", line 12, in get_user request._cached_user = auth.get_user(request) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 182, in get_user user_id = _get_user_session_key(request) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py", line 59, in _get_user_session_key return get_user_model()._meta.pk.to_python(request.session[SESSION_KEY]) File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py", line 54, in __getitem__ return self._session[key] File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/base.py", line 194, in _get_session self._session_cache = self.load() File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 43, in load s = self._get_session_from_db() File "/usr/local/lib/python3.6/site-packages/django/contrib/sessions/backends/db.py", line 34, in _get_session_from_db expire_date__gt=timezone.now() File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/cacheops/query.py", line 390, in get return qs._no_monkey.get(qs, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 402, in get num = len(clone) File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 256, in __len__ self._fetch_all() File "/usr/local/lib/python3.6/site-packages/cacheops/query.py", line 303, in _fetch_all return self._no_monkey._fetch_all(self) File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 1242, in _fetch_all self._result_cache = list(self._iterable_class(self)) File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 55, in __iter__ results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size) File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1131, in execute_sql cursor = self.connection.cursor() File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 256, in cursor return self._cursor() File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 233, in _cursor self.ensure_connection() File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection self.connect() File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__ raise dj_exc_value.with_traceback(traceback) from exc_value File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 217, in ensure_connection self.connect() File "/usr/local/lib/python3.6/site-packages/django/db/backends/base/base.py", line 195, in connect self.connection = self.get_new_connection(conn_params) File "/usr/local/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection connection = Database.connect(**conn_params) File "/usr/local/lib64/python3.6/site-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 [17/Jan/2020 12:34:40] "GET /dcim/devices/ HTTP/1.1" 500 1820 <!-- What did you expect to happen? --> ### Expected Behavior Get right device list <!-- What happened instead? --> ### Observed Behavior
adam closed this issue 2025-12-29 18:26:22 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jan 17, 2020):

It would appear you have too many connections to your PostgreSQL database. You'll need to inspect its configuration and the number of concurrent sessions. This is outside the scope of what NetBox can control.

@jeremystretch commented on GitHub (Jan 17, 2020): It would appear you have too many connections to your PostgreSQL database. You'll need to inspect its configuration and the number of concurrent sessions. This is outside the scope of what NetBox can control.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3178