title: Connection refused on heroku postgresql db via node
body: <p>I'm running a postgresql database on heroku, via node. I have my server setup to post to '/submit', which calls a database controller to insert the data into the database. Everything works successfully locally, but when I deploy it to heroku and POST, I get the following error in my heroku logs.</p>
  
  <pre><code>2013-01-21T20:23:43+00:00 heroku[router]: at=info method=POST path=/submit host=[MYDOMAIN].herokuapp.com fwd=[IP] dyno=web.1 queue=0 wait=5ms connect=17ms service=35ms status=200 bytes=2
  2013-01-21T20:23:46+00:00 app[web.1]:               ^
  2013-01-21T20:23:46+00:00 app[web.1]: node.js:201
  2013-01-21T20:23:46+00:00 app[web.1]:         throw e; // process.nextTick error, or 'error' event on first tick
  2013-01-21T20:23:46+00:00 app[web.1]: 
  2013-01-21T20:23:46+00:00 app[web.1]:     at Object.afterConnect [as oncomplete] (net.js:637:18)
  2013-01-21T20:23:46+00:00 app[web.1]: Error: connect ECONNREFUSED
  2013-01-21T20:23:46+00:00 app[web.1]:     at errnoException (net.js:646:11)
  2013-01-21T20:23:48+00:00 heroku[web.1]: Process exited with status 1
  </code></pre>
  
  <p>and a 503 in the application.</p>
  
  <p>Here's the relevant controller code (in coffeescript).</p>
  
  <pre><code>LOCAL_DB = "postgres://localhost:#{DBNAME}"
  
  connect = -&gt;
      db = process.env.DATABASE_URL or LOCAL_DB
      client = new pg.Client
      client.connect()
      client
  
  insert = (options) -&gt;
      client = connect()
      query = client.query "INSERT INTO #{TABLE} VALUES($1, $2, $3, $4);",
          [options.uid, options.ls_pref, options.hp_pref, options.date]
      query.on "error", onError
      query.on "end", -&gt; client.end()
  </code></pre>
  
  <p>I did promote my database to DATABASE_URL:</p>
  
  <pre><code>$ heroku config | grep DATABASE_URL
  &gt; DATABASE_URL: postgres://[URL]
  </code></pre>
  
  <p>Why is my connection being refused?</p>