Restart Heroku Postgres Dev DB

The error mesage you have there isn't a reason to restart the database; it isn't a database problem. Your application is holding too many connections, probably because you forgot to set up its connection pool. That isn't a DB server problem and you can fix it without restarting the DB server.

If you stop your Play application or reconfigure its connection pool the problem will go away.

Another option is to put your Heroku instance in maintenance mode then take it out again.

Since heroku doesn't allow you to connect as a superuser (for good reasons) you can't use that reserved superuser slot to connect and manage connections like you would with normal PostgreSQL.

See also:

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

http://wiki.postgresql.org/wiki/Number_Of_Database_Connections

If you're a non-heroku user who found this:

With normal PostgreSQL you can disconnect your client from the server end end using a PostgreSQL connection to your server. See how it says there's a slot reserved for "superuser connections" ? Connect to Pg as a superuser (postgres user by default) using PgAdmin-III or psql.

Once you're connected you can see other clients with:

SELECT * FROM pg_stat_activity;

If you want to terminate every connection except your own you can run:

SELECT procpid, pg_terminate_backend(procpid) 
FROM pg_stat_activity WHERE procpid <> pg_backend_pid();

Add AND datname = current_database and/or AND usename = <target-user-name> as appropriate.


I think I should have just added this in reply to the previous answer, but I couldn't figure out how to do that, so...

As an update to Liron Yahdav's comment in the accepted answer's thread: the "non-heroku users who found this" solution worked for me on a Heroku PostgreSQL dev database, but with a slight modification to the query Liron provided. Here is my modified query: SELECT pid, pg_terminate_backend(pid) FROM pg_stat_activity WHERE pid <> pg_backend_pid() AND usename='<your_username>';

It seems that procpid has changed to pid.


There is no way to restart the whole database. Though, heroku offers a simple way to stop all connections which solves the problem in the majority of cases:

heroku pg:killall