Search code examples
postgresqlheroku

Heroku Postgres: Too many connections. How do I kill these connections?


I have an app running on Heroku. This app has an Postgres 9.2.4 (Dev) addon installed. To access my online database I use Navicat Postgres. Sometimes Navicat doesn't cleanly close connections it sets up with the Postgres database. The result is that after a while there are 20+ open connections to the Postgres database. My Postgres installs only allows 20 simultanious connections. So with the 20+ open connections my Postgress database is now unreachable (too many connections).

I know this is a problem of Navicat and I'm trying to solve this on that end. But if it happens (that there are too many connections), how can I solve this (e.g. close all connections).

I've tried all of the following things, without result.

  • Closed Navicat & restarted my computer (OS X 10.9)
  • Restarted my Heroku application (heroku restart)
  • Tried to restart the online database, but I found out there is no option to do this
  • Manually closed all connections from OS X to the IP of the Postgres server
  • Restarted our router

I think it's obvious there are some 'dead' connections at the Postgres side. But how do I close them?


Solution

  • Maybe have a look at what heroku pg:kill can do for you? https://devcenter.heroku.com/articles/managing-heroku-postgres-using-cli#pg-ps-pg-kill-pg-killall