title: pg_dump: [archiver (db)] connection to database failed: could not connect to server: Connection refused
body: <p>I'm running a Rails app using Dokku on DigitalOcean and using Rails <a href="https://github.com/backup/backup" rel="nofollow">backup</a> gem to regularly take DB backup. Recently I moved the app from one droplet to another (changed the region) and then the backup is failing to connect to the DB.</p>
  
  <p>Backup model (<code>/root/Backup/models/oktob_database_backup.rb</code>)</p>
  
  <pre><code>Model.new(:oktob_database_backup, 'Oktob Production Database Backup') do
  
    ##
    # PostgreSQL [Database]
    #
    database PostgreSQL do |db|
      db.name               = ENV['DATABASE_NAME']
      db.username           = ENV['DATABASE_USERNAME']
      db.password           = ENV['DATABASE_PASSWORD']
      db.host               = ENV['DATABASE_HOST']
      db.port               = ENV['DATABASE_PORT']
    end
  
    ##
    # Amazon Simple Storage Service [Storage]
    #
    store_with S3 do |s3|
      # AWS Credentials
      s3.access_key_id     = ENV['AWS_ACCESS_KEY_ID']
      s3.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
      s3.region            = "us-west-2"
      s3.bucket            = ENV['AWS_DATABASE_BACKUP_BUCKET_NAME']
      s3.path              = "/"
    end
  
    ##
    # Gzip [Compressor]
    #
    compress_with Gzip
  
    ##
    # Mail [Notifier]
    #
    # The default delivery method for Mail Notifiers is 'SMTP'.
    # See the documentation for other delivery options.
    #
    notify_by Mail do |mail|
      mail.on_success           = true
      mail.on_warning           = true
      mail.on_failure           = true
  
      mail.from                 = ENV['EMAIL_ADDRESS']
      mail.to                   = ENV['EMAIL_ADDRESS']
      mail.address              = "smtp.gmail.com"
      mail.port                 = 587
      mail.domain               = "oktob.io"
      mail.user_name            = ENV['SMTP_USERNAME']
      mail.password             = ENV['SMTP_PASSWORD']
      mail.authentication       = "plain"
      mail.encryption           = :starttls
    end
  end
  </code></pre>
  
  <p>The configurations are stored in <code>/etc/environment</code></p>
  
  <pre><code>## Database
  export DATABASE_NAME=''
  export DATABASE_USERNAME=''
  export DATABASE_PASSWORD=''
  export DATABASE_HOST=''
  export DATABASE_PORT=''
  
  ## Amazon S3
  export AWS_ACCESS_KEY_ID=''
  export AWS_SECRET_ACCESS_KEY=''
  export AWS_DATABASE_BACKUP_BUCKET_NAME=''
  
  ## Email
  export EMAIL_ADDRESS=''
  export SMTP_USERNAME=''
  export SMTP_PASSWORD=''
  </code></pre>
  
  <p>Error message:</p>
  
  <pre><code>2016/08/19 11:04:34][info] Performing Backup for 'Oktob Production Database Backup (oktob_database_backup)'!
  [2016/08/19 11:04:34][info] [ backup 4.2.2 : ruby 2.0.0p647 (2015-08-18 revision 51631) [x86_64-linux] ]
  [2016/08/19 11:04:34][warn] Cleaner::Error: Cleanup Warning
  [2016/08/19 11:04:34][warn]   The temporary packaging folder still exists!
  [2016/08/19 11:04:34][warn]   '/root/Backup/.tmp/oktob_database_backup'
  [2016/08/19 11:04:34][warn]   It will now be removed.
  [2016/08/19 11:04:34][warn]
  [2016/08/19 11:04:34][warn]   Please check the log for messages and/or your notifications
  [2016/08/19 11:04:34][warn]   concerning this backup: 'Oktob Production Database Backup (oktob_database_backup)'
  [2016/08/19 11:04:34][warn]   The temporary files which had to be removed should not have existed.
  [2016/08/19 11:04:34][info] Database::PostgreSQL Started...
  [2016/08/19 11:04:34][info] Using Compressor::Gzip for compression.
  [2016/08/19 11:04:34][info]   Command: '/bin/gzip'
  [2016/08/19 11:04:34][info]   Ext: '.gz'
  [2016/08/19 11:04:34][error] Model::Error: Backup for Oktob Production Database Backup (oktob_database_backup) Failed!
  [2016/08/19 11:04:34][error] --- Wrapped Exception ---
  [2016/08/19 11:04:34][error] Database::PostgreSQL::Error: Dump Failed!
  [2016/08/19 11:04:34][error]   Pipeline STDERR Messages:
  [2016/08/19 11:04:34][error]   (Note: may be interleaved if multiple commands returned error messages)
  [2016/08/19 11:04:34][error]
  [2016/08/19 11:04:34][error]   pg_dump: [archiver (db)] connection to database "oktob" failed: could not connect to server: Connection refused
  [2016/08/19 11:04:34][error]    Is the server running on host "172.17.0.1" and accepting
  [2016/08/19 11:04:34][error]    TCP/IP connections on port 5432?
  [2016/08/19 11:04:34][error]   The following system errors were returned:
  [2016/08/19 11:04:34][error]   Errno::EPERM: Operation not permitted - 'pg_dump' returned exit code: 1
  [2016/08/19 11:04:34][error]
  [2016/08/19 11:04:34][error] Backtrace:
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/lib/backup/database/postgresql.rb:72:in `perform!'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/lib/backup/model.rb:269:in `each'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/lib/backup/model.rb:269:in `block in perform!'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/lib/backup/model.rb:268:in `each'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/lib/backup/model.rb:268:in `perform!'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/lib/backup/cli.rb:156:in `perform'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/gems/backup-4.2.2/bin/backup:5:in `&lt;top (required)&gt;'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/bin/backup:23:in `load'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/bin/backup:23:in `&lt;main&gt;'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/bin/ruby_executable_hooks:15:in `eval'
  [2016/08/19 11:04:34][error]   /usr/local/rvm/gems/ruby-2.0.0-p647/bin/ruby_executable_hooks:15:in `&lt;main&gt;'
  [2016/08/19 11:04:34][warn] Cleaner::Error: Cleanup Warning
  [2016/08/19 11:04:34][warn]   The temporary packaging folder still exists!
  [2016/08/19 11:04:34][warn]   '/root/Backup/.tmp/oktob_database_backup'
  [2016/08/19 11:04:34][warn]   This folder may contain completed Archives and/or Database backups.
  [2016/08/19 11:04:34][warn]
  [2016/08/19 11:04:34][warn]   Make sure you check these files before the next scheduled backup for
  [2016/08/19 11:04:34][warn]   'Oktob Production Database Backup (oktob_database_backup)'
  [2016/08/19 11:04:34][warn]   These files will be removed at that time!
  [2016/08/19 11:04:34][info] Sending notification using Notifier::Mail...
  </code></pre>
  
  <p>The app is working properly, but not sure what happened for the backup after the move. I tried to restart the DB container and the man app, but something is missing.</p>