docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.19k stars 1.14k forks source link

Error FATAL: password authentication failed for user "postgres" #679

Closed ghost closed 4 years ago

ghost commented 4 years ago

Clean system - running postgres without volume or anything defined.

2020-02-14 17:26:38.505 UTC [62] FATAL:  password authentication failed for user "postgres"
2020-02-14 17:26:38.505 UTC [62] DETAIL:  Password does not match for user "postgres".
        Connection matched pg_hba.conf line 95: "host all all all md5"
docker run --rm -e POSTGRES_USERNAME=postgres -e POSTGRES_PASSWORD=postgres --name postgres -p 5432:5432 postgres

The files belonging to this database system will be owned by user "postgres". This user must also own the server process.

The database cluster will be initialized with locale "en_US.utf8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english".

Data page checksums are disabled.

fixing permissions on existing directory /var/lib/postgresql/data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Etc/UTC creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok

Success. You can now start the database server using:

pg_ctl -D /var/lib/postgresql/data -l logfile start

initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. waiting for server to start....2020-02-14 17:26:34.092 UTC [46] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit 2020-02-14 17:26:34.094 UTC [46] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2020-02-14 17:26:34.105 UTC [47] LOG: database system was shut down at 2020-02-14 17:26:33 UTC 2020-02-14 17:26:34.109 UTC [46] LOG: database system is ready to accept connections done server started

/usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

waiting for server to shut down...2020-02-14 17:26:34.191 UTC [46] LOG: received fast shutdown request .2020-02-14 17:26:34.193 UTC [46] LOG: aborting any active transactions 2020-02-14 17:26:34.196 UTC [46] LOG: background worker "logical replication launcher" (PID 53) exited with exit code 1 2020-02-14 17:26:34.196 UTC [48] LOG: shutting down 2020-02-14 17:26:34.209 UTC [46] LOG: database system is shut down done server stopped

PostgreSQL init process complete; ready for start up.

2020-02-14 17:26:34.309 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit 2020-02-14 17:26:34.309 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2020-02-14 17:26:34.309 UTC [1] LOG: listening on IPv6 address "::", port 5432 2020-02-14 17:26:34.312 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2020-02-14 17:26:34.325 UTC [55] LOG: database system was shut down at 2020-02-14 17:26:34 UTC 2020-02-14 17:26:34.328 UTC [1] LOG: database system is ready to accept connections 2020-02-14 17:26:38.505 UTC [62] FATAL: password authentication failed for user "postgres" 2020-02-14 17:26:38.505 UTC [62] DETAIL: Password does not match for user "postgres". Connection matched pg_hba.conf line 95: "host all all all md5" 2020-02-14 17:26:39.293 UTC [63] FATAL: password authentication failed for user "postgres" 2020-02-14 17:26:39.293 UTC [63] DETAIL: Password does not match for user "postgres". Connection matched pg_hba.conf line 95: "host all all all md5" 2020-02-14 17:26:39.436 UTC [64] FATAL: password authentication failed for user "postgres" 2020-02-14 17:26:39.436 UTC [64] DETAIL: Password does not match for user "postgres". Connection matched pg_hba.conf line 95: "host all all all md5" 2020-02-14 17:26:41.104 UTC [65] FATAL: password authentication failed for user "postgres" 2020-02-14 17:26:41.104 UTC [65] DETAIL: Password does not match for user "postgres". Connection matched pg_hba.conf line 95: "host all all all md5" ^C2020-02-14 17:26:44.327 UTC [1] LOG: received fast shutdown request 2020-02-14 17:26:44.328 UTC [1] LOG: aborting any active transactions 2020-02-14 17:26:44.329 UTC [1] LOG: background worker "logical replication launcher" (PID 61) exited with exit code 1 2020-02-14 17:26:44.330 UTC [56] LOG: shutting down 2020-02-14 17:26:44.341 UTC [1] LOG: database system is shut down

wglambert commented 4 years ago

Your POSTGRES_USERNAME is the wrong variable name but it doesn't matter, POSTGRES_USER defaults to postgres which if it's the superuser doesn't require a password for local connections

I can't reproduce the issue, I attached it to the network net so it can be connected to from another container

docker run ```console $ docker run --rm --network=net -e POSTGRES_USERNAME=postgres -e POSTGRES_PASSWORD=postgres --name postgres -p 5432:5432 postgres The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.utf8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /var/lib/postgresql/data ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting default time zone ... Etc/UTC creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok Success. You can now start the database server using: pg_ctl -D /var/lib/postgresql/data -l logfile start initdb: warning: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. waiting for server to start....2020-02-14 18:05:08.148 UTC [46] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit 2020-02-14 18:05:08.217 UTC [46] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2020-02-14 18:05:08.485 UTC [47] LOG: database system was shut down at 2020-02-14 18:05:00 UTC 2020-02-14 18:05:08.561 UTC [46] LOG: database system is ready to accept connections done server started /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/* waiting for server to shut down....2020-02-14 18:05:08.623 UTC [46] LOG: received fast shutdown request 2020-02-14 18:05:09.015 UTC [46] LOG: aborting any active transactions 2020-02-14 18:05:09.020 UTC [46] LOG: background worker "logical replication launcher" (PID 53) exited with exit code 1 2020-02-14 18:05:09.021 UTC [48] LOG: shutting down .2020-02-14 18:05:09.819 UTC [46] LOG: database system is shut down done server stopped PostgreSQL init process complete; ready for start up. 2020-02-14 18:05:10.412 UTC [1] LOG: starting PostgreSQL 12.1 (Debian 12.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit 2020-02-14 18:05:10.412 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 2020-02-14 18:05:10.412 UTC [1] LOG: listening on IPv6 address "::", port 5432 2020-02-14 18:05:10.920 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" 2020-02-14 18:05:11.057 UTC [55] LOG: database system was shut down at 2020-02-14 18:05:09 UTC 2020-02-14 18:05:11.092 UTC [1] LOG: database system is ready to accept connections ```

Without password (since it's local)

$ docker exec -it postgres psql -U postgres
psql (12.1 (Debian 12.1-1.pgdg100+1))
Type "help" for help.

postgres=# exit

From another container, testing the password auth

$ docker run -it --network=net --rm postgres bash

root@4eabdf38d548:/# psql -h postgres -U postgres
Password for user postgres: 
psql (12.1 (Debian 12.1-1.pgdg100+1))
Type "help" for help.

postgres=# exit

root@4eabdf38d548:/# psql -h postgres -U postgres
Password for user postgres:                                                                                                                                   
psql: error: could not connect to server: FATAL:  password authentication failed for user "postgres"
ghost commented 4 years ago

Thanks for investigating - Friday afternoon issue - I tried but couldn’t replicate it today. Thanks for the pointer POSTGRES_USER I missed that at least.

ghost commented 4 years ago

Thanks Willian, I haven't seen the issue since, only presented itself on Github actions build system.

On Fri, 2 Oct 2020 at 09:07, ✳️ Willian Krueger notifications@github.com wrote:

Hi, I had similar strange problems too, not on same docker recipe (was on the postgis one). It would bring the same error when starting the server for the last time (su

  • postgres -c "...")

Not certain, I THINK the issue was some wrong character in pg_hba.conf.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/docker-library/postgres/issues/679#issuecomment-702589329, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHUCR5VHVN5NBEYJHGGO7ZTSIWC4HANCNFSM4KVMQE6Q .

-- ............................................... (PGP) 0x87E3B94D7B2BEEEF (Keybase) bryan.hunt@erlang-solutions.com (Github) bryanhuntesl ...............................................

--

ElixirConf EU Virtual https://www2.erlang-solutions.com/conferences/ECEUV-oct/2020/emailsig: 7-8 October 2020

Code Mesh V https://www2.erlang-solutions.com/conferences/code-mesh-v/2020/emailsig: 5-6 November 2020 Code BEAM STO https://www2.codesync.global/code-sync/code-beam-sto-2021: 27-28 May 2021

Erlang Solutions cares about your data and privacy; please find all details about the basis for communicating with you and the way we process your data in our Privacy Policy https://www.erlang-solutions.com/privacy-policy.html. You can update your email preferences or opt-out from receiving Marketing emails here https://www2.erlang-solutions.com/email-preference?epc_hash=JtO6C7Q2rJwCdZxBx3Ad8jI2D4TJum7XcUWcgfjZ8YY.

MatthieuRochette commented 3 years ago

Hello,

I'm having the same error here,

The error occurs when I try to connect from my NodeJS app, but it works fine when I connect from a BeeKeeper Studio client. Of course, I made sure I use the same password in both.

Therefore my thinking goes to this error originating from an invisible character or something similar, not from PostgreSQL itself.

EDIT: just found the origin of the error on my side: I was loading the password from a .env file, and it somehow did not parse correctly.

pedromihael commented 3 years ago

@MatthieuRochette how did you solve it?

MatthieuRochette commented 3 years ago

I rewrote the .env file manually (it was quite little), my guess is that there was an invisible character that I couldn't get rid of via my text editor. But the error did not originate from the Postgres instance, that is for sure.

apeengggg commented 1 year ago

https://stackoverflow.com/questions/76506878/password-authentication-failed-for-user-root-on-running-container-with-docker

i have issue like this, how to fix the issue ??