Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql | remaining connection slots are reserved for non-replication superuser connections

I am getting an error "remaining connection slots are reserved for non-replication superuser connections" at one of PostgreSQL instances.

However, when I run below query from superuser to check available connections, I found that enough connections are available. But still getting the same error.

select max_conn,used,res_for_super,max_conn-used-res_for_super 
res_for_normal 
from 
  (select count(*) used from pg_stat_activity) t1,
  (select setting::int res_for_super from pg_settings where 
name='superuser_reserved_connections') t2,
  (select setting::int max_conn from pg_settings where name='max_connections') t3

Output

enter image description here

I searched this error and everyone is suggesting to increase the max connections like below link. Heroku "psql: FATAL: remaining connection slots are reserved for non-replication superuser connections"

EDIT

I restarted the server and after some time used connections were almost 210 but i was able to connect to the server from a normal user.

like image 444
YogeshR Avatar asked Oct 08 '18 07:10

YogeshR


People also ask

How do I fix Postgres remaining connection slots are reserved for non replication superuser connections?

Go to /opt/lce/db/postgresql and edit the postgresql. conf file. Look for max_connections parameter (should be 40 as default). Increase it to 50, reboot the server and try to run list-client again.

How many reserved connections for superuser by default are allowed in PostgreSQL?

Sets the number of connection slots reserved for superusers The default value is three connections.

How many concurrent connections can PostgreSQL handle?

PostgreSQL Connection Limits 15 connections are reserved for the superuser to maintain the state and integrity of your database, and 100 connections are available for you and your applications. If the number of connections to the database exceeds the 100-connection limit, new connections fail and return an error.

What is the default max connections in Postgres?

The default is typically 100 connections, but might be less if your kernel settings will not support it (as determined during initdb).


1 Answers

Might not be a direct solution to your problem, but I recommend using middlewares like pgbouncer. It helps keeping a lower, fixed number of open connections to the db server. Your client would connect to pgbouncer and pgbouncer would internally pick one of its already opened connection to use for your client's queries. If the number of clients exceed the amount of possible connections, clients are queued till one is available, therefore allowing some breathing room in situations of high traffic, while keeping the db server under tolerable load.

like image 184
darioguarascio Avatar answered Nov 05 '22 09:11

darioguarascio