Search code examples
ruby-on-railspostgresqlpg-dump

Trying to do a PG dump from an active rails server and getting password authentication failed


I am trying to run this command

ssh -p <PORT> <user@server> 'PGPASSWORD=\"<production_password>\" pg_dump -U database_user #<production_database> -h 127.0.0.1 -F t' > <location>

and I am getting

pg_dump: [archiver (db)] connection to database "database_name" failed: FATAL: password authentication failed for user "database_user"

The credentials must be right since deploys work fine.

This is a RoR app on CentOS running live, and I was trying to follow other stack overflow answers and realized I do not have directories var/lib/postgres nor do I have /etc/postgresql. I was looking for /etc/postgresql/9.4/main/pg_hba.conf

I do not imagine postgres was not installed, since we are actively running a postgres database.

All I want is to dump the rails pg production database to my local computer!

Any leads would be super helpful.

-------Adding my database.yml config--------

adapter: postgresql
  encoding: utf8
  host: 127.0.0.1
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  reconnect: true
  timeout: 5000

Another note to add to the puzzle, we have 2 or 3 PG databases on this same server.

AND using this_is_a_fake_db_name still threw me the same error. So it definitely is not connecting to the database I'm requesting.


Solution

  • I think I was blocked from connecting to my database and that is why I could not pass authentication.

    In the end I backed it up as sudo on the server: (su postgres -c 'pg_dump -U postgres <db-name>') > <backupNAME>.sql

    Then copied it down with SCP

    scp -P <port> user@server:/path/to/<backupNAME>.sql <local/path/to/save>

    Thanks @lackoftactics for your help!