2

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 Commented Feb 3, 2019 at 5:47
  • Hola este mi .env ibb.co/6XgSmhB Commented Feb 3, 2019 at 6:04

3 Answers 3

2

Changing the DB_HOST to postgres, helped me to solve mine.

DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=your-database-name
DB_USERNAME=user-name
DB_PASSWORD=your-password
Sign up to request clarification or add additional context in comments.

1 Comment

I should add that this led me to a solution with Docker-compose. When specifying the host I was using 127.0.0.1 this was giving an error. The solution was to substitute the name of the service, or its container_name parameter. In my case, the container name was container_name: PostgreSQL, hence the .env is set as DB_HOST=PostgreSQL.
1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.