I've been struggling with an error while trying to log into PostgreSQL:
psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "postgres"
Despite changing the postgres password, the error persisted. After investigating, I found the solution and wanted to share it for anyone facing a similar issue:
- Check PostgreSQL Configuration: I checked the PostgreSQL configuration file to verify the port number:
sudo nano /etc/postgresql/16/main/postgresql.conf
- Port Number Issue: I discovered that PostgreSQL 16 was set to run on port 5433 instead of the default port 5432:
port = 5433
- Connect Using the Correct Port: To connect to PostgreSQL, I specified the port explicitly in my connection command:
psql -h localhost -U postgres -p 5433
After making this adjustment, I was able to log in successfully.
I hope this helps anyone encountering the same issue! If anyone has further insights or suggestions, please feel free to share.
pg_lsclusters
to see it. You need to determine which one you actually want to connect to.