2
votes

I had a problem that I could not solve a few days ago, I try to connect with my Postgres bd which is on a server, I work with laravel but it has highlighted an error when I connect to my Postgres bd, this error appears

PDOException in Connector.php line 55: SQLSTATE[08006] [7] could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?

error image:

enter image description here

I would like to know if it has happened the same and how to solve it, Thanks!

2
share your .env file code here - Udhav Sarvaiya

2 Answers

0
votes

Hard to tell without your environment file. This error might occur because you are already connecting to postgres,

To check, make sure this line is in your .env file:

DB_PORT=5432

Or, you can remove the line from the .env and let Laravel choose the default according to the connection:

'port' => env('DB_PORT', '5432'),

Another cause for failed connection due to auth is that the env file is looking for 127.0.0.1. Sometimes changing this to localhost will help.

0
votes

Change in your .env setup like this:

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1  //If you want to use only in localhost or otherwise change according to host server
DB_PORT=5432
DB_DATABASE=your_database_name
DB_USERNAME=your_username
DB_PASSWORD=your_password

After changes of .env edit please enter this command in your terminal for clear cache:php artisan config:cache