title: Kill all database connections on heroku when max connections have been reached
body: <p>My instance has a maximum number of connections of 16. As soon as I realized that I had <strong>19</strong> connections, I hurried to kill one, which turns out to open a standard connection with the same priority and limitations.</p>
  
  <p>I have now reached the absolute maximum number of connection, which is <strong>20</strong>, and cannot even do a <code>pg:ps</code> or a <code>pg:killall</code>.</p>
  
  <p>How can I kill all connections, or do anything to lower the number of connections now? The query which seems to be blocking is extremely long (seems like a <code>select *</code> from a table which has 410k entries).</p>
  
  <pre><code>$ heroku pg:info -a XYZ
  === HEROKU_POSTGRESQL_COBALT_URL (DATABASE_URL)
  Plan:        Basic
  Status:      Available
  Connections: 19
  PG Version:  9.1.11
  Created:     2013-03-12 15:11 UTC
  Data Size:   7.16 GB
  Tables:      103
  Fork/Follow: Unsupported
  Rollback:    Unsupported
  $ heroku pg:ps -a XYZ
   procpid | source |   running_for   | waiting | (...)
  $ heroku pg:kill 12593 -a XYZ
   pg_cancel_backend 
  -------------------
   t
  (1 row)
  
  $ heroku pg:ps -a XYZ
  psql: FATAL:  too many connections for role "abc"
   !    Heroku client internal error.
   !    Search for help at: https://help.heroku.com
   !    Or report a bug at: https://github.com/heroku/heroku/issues/new
  
      Error:       undefined method `[]' for nil:NilClass (NoMethodError)
      Backtrace:   /home/chris/.heroku/client/lib/heroku/command/pg.rb:442:in `version'
                   /home/chris/.heroku/client/lib/heroku/command/pg.rb:447:in `nine_two?'
                   /home/chris/.heroku/client/lib/heroku/command/pg.rb:451:in `pid_column'
                   /home/chris/.heroku/client/lib/heroku/command/pg.rb:226:in `ps'
                   /home/chris/.heroku/client/lib/heroku/command.rb:218:in `run'
                   /home/chris/.heroku/client/lib/heroku/cli.rb:37:in `start'
                   /usr/local/heroku/bin/heroku:24:in `&lt;main&gt;'
  
      Command:     heroku pg:ps -a XYZ
      Version:     heroku-toolbelt/3.9.6 (x86_64-linux) ruby/2.0.0
  $ heroku pg:killall -a XYZ
  psql: FATAL:  too many connections for role "abc"
   !    Heroku client internal error.
   !    Search for help at: https://help.heroku.com
   !    Or report a bug at: https://github.com/heroku/heroku/issues/new
  
      Error:       undefined method `[]' for nil:NilClass (NoMethodError)
      Backtrace:   /home/chris/.heroku/client/lib/heroku/command/pg.rb:442:in `version'
                   /home/chris/.heroku/client/lib/heroku/command/pg.rb:447:in `nine_two?'
                   /home/chris/.heroku/client/lib/heroku/command/pg.rb:451:in `pid_column'
                   /home/chris/.heroku/client/lib/heroku/command/pg.rb:272:in `killall'
                   /home/chris/.heroku/client/lib/heroku/command.rb:218:in `run'
                   /home/chris/.heroku/client/lib/heroku/cli.rb:37:in `start'
                   /usr/local/heroku/bin/heroku:24:in `&lt;main&gt;'
  
      Command:     heroku pg:killall -a XYZ
      Version:     heroku-toolbelt/3.9.6 (x86_64-linux) ruby/2.0.0
  $ heroku pg:info -a XYZ
  === HEROKU_POSTGRESQL_COBALT_URL (DATABASE_URL)
  Plan:        Basic
  Status:      Available
  Connections: 20
  PG Version:  9.1.11
  Created:     2013-03-12 15:11 UTC
  Data Size:   8.24 GB
  Tables:      103
  Fork/Follow: Unsupported
  Rollback:    Unsupported
  </code></pre>