password authentication failed for user “postgres” with docker
Steps:
-
- 1. run the instruction to create a docker container.
docker run --rm --name test-postgres -p 5432:5432 -e POSTGRES_PASSWORD=pw -d postgres
-
- 2. run the following command in node code to connect to the database:
import pg from 'pg'
const { Pool } = pg
pool = new Pool({
database: 'postgres',
user: 'postgres',
password: 'pw',
port: 5432
})
The following error is thrown:
error: password authentication failed for user “postgres”
Cause analysis
Because Postgres has been installed locally, Postgres is automatically started when the system is started by default. When connecting to the database, the locally installed Postgres service is preferentially connected, so the connection fails.
Solution:
Open Window Task Manager, under Services you will see a postgres service running. Right-click to turn off the postgres service, open the Service window and double-click on the postgres service to set the Startup Type to Manual.
then
Other troubleshooting methods
Open the Terminal of the container
- Enter the following two commands to see if there is a problem with local host permissions.
cd var/lib/postgresql/data
cat pg_hba.conf
- To see if the default user is postgres.
psql -U postgres -x -c "select * from current_user;"
- Check the password expiration date. rolvaliduntil no value means no expiration date.
psql -h 127.0.0.1 -U postgres -d postgres
SELECT * FROM pg_roles WHERE rolname='postgres';
- Try clearing docker’s columns and containers, and restarting docker
Read More:
- Mysql5.7.18.1 Error 1054 (42S22): Unknown Column’password’ In’field List’ When Changing User Password
- Support for password authentication was removed on August 13, 2021
- [Solved] GitHub Error: remote: Support for password authentication was removed on August 13, 2021.
- [Solved] Git push Error: remote: Support for password authentication was removed on August 13, 2021.
- Git push Submit to Remote Error: “remote: Support for password authentication was removed on August 13, 2021.“
- [Solved] Flink jdbc Error: Access Denied for user ‘root‘@‘10.0.0.x‘ (using password: YES)
- Postgres uuid_generate_v1() does not exist [How to Solve]
- [Solved] Error: ER_ACCESS_DENIED_ERROR: Access denied for user ‘root’@‘localhost’ (using password: YES)
- [Solved] Postgres Start Error: Job for postgresql.service failed because the control process exited with error code.
- Mongodb error: authentication failed [How to Solve]
- DB::Exception: test: Authentication failed: [How to Solve]
- Creating test database for alias ‘postgres’… Got an error creating the test database: permission
- Git pull code error fatal: authentication failed fo
- Postgres Multiple data insertion error: The ‘default‘ dialect with current database version settings does not support
- [Solved] Canal 1.1.5 Startup Error: caching_sha2_password Auth failed
- [Solved] SecureCRT error: keyboard-interactive authentication with the ssh2 server failed
- SourceTree Git Error: remote: HTTP Basic: Access denied fatal: Authentication failed
- The application could not be installed: INSTALL_FAILED_USER_RESTRICTED
- [Solved] Installation failed due to: ‘INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: Package com.
- [Solved] C# Access Mongodb Database Error: command find failed: Command find requires authentication