1

I installed and started my Postgres database with brew (on my Mac). I also defined an entry in my /etc/hosts file (I tried both with 127.0.0.1 postgres and with postgres).

However, when I try

psql -h postgres -U postgres -p 5432

I cannot connect

psql: could not connect to server: Connection refused.

However, when I try with

psql -h localhost -U postgres -p 5432

I can connect. What is needed to be able to connect with: psql -h postgres -U postgres -p 5432

3
  • Looks like your hosts file is wrong. Can you ping to postgres? Commented Sep 11, 2019 at 13:10
  • I guess this is an OS-related question, not a PSQL-related one. If your system resolves the address postgres to localhost, you should be able to connect in such way. Commented Sep 11, 2019 at 13:11
  • What happens if you run ping postgres? Commented Sep 11, 2019 at 13:34

1 Answer 1

1

Make sure your PostgreSQL server is willing to accept tcp/ip connections on port 5432.

In your PostgreSQL configuration file check these values.

listen_addresses = '*'
port = 5432
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - that enabled me to connect with either postgres or localhost as the hostname.

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.