Rails 5 in prod: PG::ConnectionBad: FATAL: password authentication failed for user "postgres" with Docker

DaniG2k

I am seeing the following error on my Linode server (Ubuntu 17.04) when starting up my Rails app:

PG::ConnectionBad: FATAL:  password authentication failed for user "postgres"

The odd thing is that this is only happening on my remote server. Locally (on my Mac), it's working fine. I have the following docker-compose.yml file:

version: "2"
services:
  postgres:
    image: postgres:9.6
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: "${DATABASE_NAME}"
      POSTGRES_PASSWORD: "${DATABASE_PASSWORD}"
    volumes:
      - postgres-data:/var/lib/postgresql/data
  redis:
    image: redis:latest
    ports:
      - "6379:6379"
volumes:
  postgres-data:
    driver: local

which should bind Postgres to port 5432 on localhost and set the password to the DATABASE_PASSWORD environment variable. If I run ps aux | grep 5432 on the server I can see the Docker process is running correctly:

root     29550  0.0  0.2  34472  2888 ?        Sl   01:34   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5432 -container-ip 172.18.0.3 -container-port 5432

So I cannot figure out why I'm getting a password authentication failed error message.

My config/database.yml file:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  host: localhost
  username: postgres

...

production:
  <<: *default
  database: <%= ENV['DATABASE_NAME'] %>
  password: <%= ENV['DATABASE_PASSWORD'] %>

The variables are set in my environment and I am able to echo them properly from the shell.

Any help would be much appreciated! Thanks

DaniG2k

After much head-bashing I solved the problem. Not sure exactly how but the following seemed to work:

Installed ntp just to make sure time settings were ok

$ sudo timedatectl set-ntp no
$ sudo apt-get install ntp
$ sudo ntpq -p

specified a Redis image version

redis:
  image: redis:4.0
    ports:
      - "6379:6379"

then tried destroying all the Docker images

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
docker volume rm $(docker volume ls -qf dangling=true)

and finally tried to restart Docker

docker-compose up -d

Seems to be working as intended now.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

PG::ConnectionBad: FATAL: password authentication failed for user "alphauser"

From Dev

PG::ConnectionBad: FATAL: Ident authentication failed for user "rails_dev"

From Dev

FATAL: password authentication failed for user "postgres"

From Dev

PostgreSQL: MD5 Authentication in pg_hba.conf gives me FATAL: Peer authentication failed for user "postgres"

From Java

FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4)

From Dev

FATAL: password authentication failed for user "postgres" Ubuntu v20.10

From Dev

FATAL: Peer authentication failed for user "rails"

From Java

Postgresql: password authentication failed for user "postgres"

From Dev

PSQL - password authentication failed for user "postgres"

From Dev

jitterbit-password authentication failed for user "postgres"

From Dev

PostgreSQL SSPI authentication - FATAL: 2801: password authentication failed for user "xxx"

From Dev

psql: FATAL: password authentication failed for user windows 8

From Dev

Redshift connection issue: FATAL: password authentication failed for user

From Dev

Fatal! Authentication for user postgres failed, multiples OS, nothing work

From Dev

capistrano, rails, PG::ConnectionBad: fe_sendauth: no password supplied

From Dev

capistrano, rails, PG::ConnectionBad: fe_sendauth: no password supplied

From Dev

Docker - PG::ConnectionBad

From Dev

Rails - Postgres - could not connect to server: Connection refused (PG::ConnectionBad)

From Dev

Java Springboot application returning password authentication failed for user "postgres"

From Dev

heroku pg:pull password authentication failed

From Dev

remote: Invalid username or password, fatal: Authentication failed for

From Dev

psql: FATAL: password authentication failed for user error while trying to access psql

From Dev

PG::ConnectionBad FATAL: role "Myname" does not exist

From Dev

PG::ConnectionBad FATAL: role "Myname" does not exist

From Dev

Rails: fe_sendauth: no password supplied (PG::ConnectionBad) from Ruby, but ok in Rails

From Dev

PostgreSQL password authentication failed for user "postgres", not the same user as specified in my app config

From Java

psql: FATAL: Peer authentication failed for user "dev"

From Dev

psql: FATAL: PAM authentication failed for user

From Dev

FATAL: Peer authentication failed for user "shop"

Related Related

  1. 1

    PG::ConnectionBad: FATAL: password authentication failed for user "alphauser"

  2. 2

    PG::ConnectionBad: FATAL: Ident authentication failed for user "rails_dev"

  3. 3

    FATAL: password authentication failed for user "postgres"

  4. 4

    PostgreSQL: MD5 Authentication in pg_hba.conf gives me FATAL: Peer authentication failed for user "postgres"

  5. 5

    FATAL: password authentication failed for user "postgres" (postgresql 11 with pgAdmin 4)

  6. 6

    FATAL: password authentication failed for user "postgres" Ubuntu v20.10

  7. 7

    FATAL: Peer authentication failed for user "rails"

  8. 8

    Postgresql: password authentication failed for user "postgres"

  9. 9

    PSQL - password authentication failed for user "postgres"

  10. 10

    jitterbit-password authentication failed for user "postgres"

  11. 11

    PostgreSQL SSPI authentication - FATAL: 2801: password authentication failed for user "xxx"

  12. 12

    psql: FATAL: password authentication failed for user windows 8

  13. 13

    Redshift connection issue: FATAL: password authentication failed for user

  14. 14

    Fatal! Authentication for user postgres failed, multiples OS, nothing work

  15. 15

    capistrano, rails, PG::ConnectionBad: fe_sendauth: no password supplied

  16. 16

    capistrano, rails, PG::ConnectionBad: fe_sendauth: no password supplied

  17. 17

    Docker - PG::ConnectionBad

  18. 18

    Rails - Postgres - could not connect to server: Connection refused (PG::ConnectionBad)

  19. 19

    Java Springboot application returning password authentication failed for user "postgres"

  20. 20

    heroku pg:pull password authentication failed

  21. 21

    remote: Invalid username or password, fatal: Authentication failed for

  22. 22

    psql: FATAL: password authentication failed for user error while trying to access psql

  23. 23

    PG::ConnectionBad FATAL: role "Myname" does not exist

  24. 24

    PG::ConnectionBad FATAL: role "Myname" does not exist

  25. 25

    Rails: fe_sendauth: no password supplied (PG::ConnectionBad) from Ruby, but ok in Rails

  26. 26

    PostgreSQL password authentication failed for user "postgres", not the same user as specified in my app config

  27. 27

    psql: FATAL: Peer authentication failed for user "dev"

  28. 28

    psql: FATAL: PAM authentication failed for user

  29. 29

    FATAL: Peer authentication failed for user "shop"

HotTag

Archive