Issue
I have a laravel App on elastic beanstalk on AWS. And I am using Postgres as the DB. It is an AWS linux 2.
When I try connecting even local to the db I get this error.
I tried modifying the db’s inbound rules, still not working.
Illuminate\Database\QueryException: SQLSTATE[08006] [7] FATAL:
password authentication failed for user "postgres" FATAL: password
authentication failed for user "postgres" (SQL: select count(*) as
aggregate from "user" where "phoneNumber" = +1111111111111111) in file
/var/app/current/vendor/laravel/framework/src/Illuminate/Database/Connection.php
on line 692
Solution
If your DB is a Managed PostgreSQL on AWS RDS
Then you may want to reset password of the postgres
user.
As per RDS manual
To modify the master user password, follow these steps:
- Open the Amazon RDS console.
- Select Databases.
- Select the RDS DB instance, and then choose Modify.
Note: If you use Aurora, expand the cluster, and choose the instance that you want to modify. Then, choose Modify.- Enter the master user password you want to use in the New Master Password field.
Note: The password change is asynchronous, and applies as soon as possible. This change ignores the Apply Immediately setting.- Choose Continue, and then choose Modify DB Instance.
The Status field for your RDS DB instance on the RDS dashboard changes to resetting-master-credentials. When the modification is complete, the Status column changes to Available. You can also modify an RDS DB instance using the Amazon RDS API or the AWS Command Line Interface (AWS CLI).
If your DB is self-deployed to the AWS EC2
instance
Then you may want to enable password-based authentication of the postgres
user. It’s disabled by default for new DB instances.
- Find the
pg_hba.conf
file
To find the pg_hba.conf file on your server, you can look in the PostgreSQL configuration directory.
E.g.:
find /etc/postgresql/ -name pg_hba.conf
- Then open found file in your
${EDITOR}
- To allow md5 password authentication for any connections coming from the local 192.168.0.0/24 network, add a line like this:
# TYPE DATABASE USER ADDRESS METHOD OPTIONS
host all all 192.0.0.0/24 md5
- And then restart PostgreSQL:
sudo pgctl restart
Answered By – Yasen
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0