title: Why are there open connections on my Heroku app's PostgreSQL database? How do I close them?
body: <p>My Heroku app is <a href="http://www.inflationtrends.com" rel="nofollow">www.inflationtrends.com</a>. </p>
  
  <p>Usually, when I run "pg:info" in Git Bash to see how many connections there are, that number is zero.</p>
  
  <p>Recently, I've seen a spike in traffic -- not much, only a little over 1,000 in the past 48 hours -- and when I ran "pg:info" this morning (around 11 a.m. Eastern time), the result shows that there are 4 or 5 open connections.</p>
  
  <p>My app is run using the Ruby gem Sinatra. In the Sinatra file, I have the following code:</p>
  
  <pre><code>after do
      DB.disconnect
  end
  </code></pre>
  
  <p>The "after do" loop disconnects from the PostgreSQL database after a page is loaded.</p>
  
  <p>The variable "DB" has the connection info for my PostgreSQL database (username, password, host, port number, SSL mode requirement):</p>
  
  <pre><code>DB = Sequel.postgres(
          db_name,
          :user=&gt;user,
          :password=&gt;password,
          :host=&gt;host,
          :port=&gt;port,
          :sslmode=&gt;sslmode
      )
  </code></pre>
  
  <p>Is there some reason that there are open connections? Are there ways to close these connections? Are there more efficient ways to handle this situation?</p>