title: Postgresql | remaining connection slots are reserved for non-replication superuser connections
body: <p>I am getting an error "<em>remaining connection slots are reserved for non-replication superuser connections</em>" at one of PostgreSQL instances.</p>
  
  <p>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.</p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p><a href="https://i.stack.imgur.com/wzfif.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/wzfif.jpg" alt="enter image description here"></a></p>
  
  <p>I searched this error and everyone is suggesting to increase the max connections like below link.
  <a href="https://stackoverflow.com/questions/11847144/heroku-psql-fatal-remaining-connection-slots-are-reserved-for-non-replication">Heroku &quot;psql: FATAL: remaining connection slots are reserved for non-replication superuser connections&quot;</a></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>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. </p>