title: Occasional Postgres error on Heroku: could not translate host name "<pg URL>" to address: Name or service not known (PG::Error)
body: <p>I'm using the shared postgres (dev / free) plan right now on Heroku and I see this error in my logs a decent amount.  Connecting to the PG database does usually work though, so I'm not sure if this is something that's within my control.  The Heroku Status page does not list any downtime for the shared databases when these occur.</p>
  
  <p>Using Rails 3.1.1 and <a href="http://unicorn.bogomips.org/" rel="noreferrer">the Unicorn web server</a>.</p>
  
  <p><strong>Error:</strong>
  could not translate host name "pg60.sharedpg.heroku.com (<a href="http://pg60.sharedpg.heroku.com" rel="noreferrer">http://pg60.sharedpg.heroku.com</a>)" to address: Name or service not known (PG::Error)</p>
  
  <p>My <a href="http://unicorn.bogomips.org/" rel="noreferrer">Unicorn</a> config file (after looking around at the recommended settings for Unicorn in Heroku):</p>
  
  <pre><code>worker_processes 3 # amount of unicorn workers to spin up
  timeout 30         # restarts workers that hang for 30 seconds
  preload_app true
  
  before_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
      ActiveRecord::Base.connection_handler.clear_all_connections!
      ActiveRecord::Base.connection.disconnect!
      Rails.logger.info('Disconnected from ActiveRecord')
    end
  
    # If you are using Redis but not Resque, change this
    if defined?(Resque)
      Resque.redis.quit
      Rails.logger.info('Disconnected from Redis')
    end
  end
  
  after_fork do |server, worker|
    # Replace with MongoDB or whatever
    if defined?(ActiveRecord::Base)
      ActiveRecord::Base.establish_connection
      ActiveRecord::Base.connection_handler.verify_active_connections!
      Rails.logger.info('Connected to ActiveRecord')
    end
  
    # If you are using Redis but not Resque, change this
    if defined?(Resque)
      Resque.redis = ENV['REDIS_URI']
      Rails.logger.info('Connected to Redis')
    end
  end
  </code></pre>
  
  <p><strong>Trace:</strong></p>
  
  <pre><code> 328 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1032:in `initialize': could not translate host name "pg60.sharedpg.heroku.com (http://pg60.sharedpg.heroku.com)" to address: Name or service not known (PG::Error)
  219 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1032:in `new'
  223 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1032:in `connect'
  225 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:301:in `initialize'
  217 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
  235 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
  
  328 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1032:in `initialize': could not translate host name "pg60.sharedpg.heroku.com (http://pg60.sharedpg.heroku.com)" to address: Name or service not known (PG::Error)
  219 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1032:in `new'
  223 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:1032:in `connect'
  225 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:301:in `initialize'
  217 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `new'
  235 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:28:in `postgresql_connection'
  235 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:304:in `new_connection'
  244 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:323:in `checkout_new_connection'
  249 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block (2 levels) in checkout'
  225 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `loop'
  238 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:261:in `block in checkout'
  153 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
  229 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:260:in `checkout'
  231 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:162:in `connection'
  240 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
  249 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
  239 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
  194 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.1.1/lib/active_record/base.rb:703:in `table_exists?'
  128 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/app.rb:38:in `&lt;top (required)&gt;'
  116 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from config.ru:9 (http://config.ru:9):in `require'
  124 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from config.ru:9 (http://config.ru:9):in `block in &lt;main&gt;'
  179 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
  176 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
  112 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from config.ru:1 (http://config.ru:1):in `new'
  115 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from config.ru:1 (http://config.ru:1):in `&lt;main&gt;'
  168 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn.rb:44:in `eval'
  180 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn.rb:44:in `block in builder'
  181 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:691:in `call'
  187 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:691:in `build_app!'
  182 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:136:in `start'
  178 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/gems/unicorn-4.2.0/bin/unicorn:121:in `&lt;top (required)&gt;'
  146 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/bin/unicorn:19:in `load'
  148 &lt;13&gt;1 2012-08-27T21:36:37+00:00 d.4122435c-cb44-421a-9a7d-a68bb10457d6 app web.1 (http://web.1) - - from /app/vendor/bundle/ruby/1.9.1/bin/unicorn:19:in `&lt;main&gt;' 
  </code></pre>