title: Can't connect to PostgreSQL database on Heroku using Ruby - could not translate host name
body: <p>I'm using Ruby (not Rails) and connecting a PostgreSQL database. I've been trying to get set up on Heroku, but I'm having problems starting the application. Running the application locally works fine.</p>
  
  <p>My local .env looks like:</p>
  
  <pre><code>postgres://DATABASE_URL=localhost
  </code></pre>
  
  <p>And the Ruby connect to connect to the database looks like:</p>
  
  <pre><code>@@db = PGconn.open(:hostaddr =&gt; ENV['DATABASE_URL'], :dbname =&gt; '(dbname)', :password =&gt; '(password)')
  </code></pre>
  
  <p>When I push to Heroku the app crashes on that line, and writes this error to the logs:</p>
  
  <pre><code>could not translate host name "postgres://(my heroku db address)" to address: Name or service not known (PG::Error)
  </code></pre>
  
  <p>The database address there matches the <code>DATABASE_URL</code> in my <code>heroku:config</code>. I'm using a shared database.</p>
  
  <p>I tried using <code>:host =&gt; ENV['DATABASE_URL']</code> (as opposed to <code>:hostaddr</code>) but had the same result. I'm guessing there's something simple I'm missing but I haven't had any good ideas.</p>