11

I have installed PostgreSQL. However everytime I try to connect through PGAdmin or through psql it gives me the below error.

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?

I checked the postgresql.conf file and the line: listen_addresses = '*' isn't commented out.

Also this is how my pg_hba.conf file is set:

# IPv4 local connections:
  host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
  host    all             all             ::1/128                 trust

Can anyone please advise on how I can resolve this issue?

Thanks!

1
  • 2
    pg_hba.conf, not pg_hba.conf.txt Commented Mar 14, 2017 at 21:42

6 Answers 6

9

Use services "start -> run -> services.msc" and look for the postgresql-[vers] service.

If it is not running try to start it, if it won't start open the event-viewer (start -> run -> eventvwr) and look for error messages relating to the PostgreSQL service.

Sign up to request clarification or add additional context in comments.

1 Comment

After searching for several answers, this one worked for me! It simply needed to start the application (right click -> start). Then the error is gone!
1

In my case it was postgres.config. The port was somehow changed to 5433 in there and I do not remember doing it myself lol. So make sure your ports are matching up in your project vs postgres.config

1 Comment

This may have happened if you installed a second version of PostgreSQL while another was already installed (maybe while trying to migrate from version X to version Y), as the second version will see that there is already another PostgreSQL installed and using port 5432, so will automatically set its port to 5433 in postgres.conf so that it doesn't conflict with the other PostgreSQL when both servers are running.
0

pg_hba.conf.txt has to be called pg_hba.conf.

Beyond this, when you have en authentication error you will get a message similar to:

psql -U nonexistent
psql: FATAL:  Peer authentication failed for user "nonexistent"

The error you are getting means most likely that PostgreSQL is not started on this server.

You can start PostgreSQL with:

service postgresql start
service postgresql status

1 Comment

psql -U myuser -d mydatabase works fine, I did start the service and statusshows it as active. But I still get that Connection refused error.
0

This worked for me -

In C:\Program Files\PostgreSQL\data\postgresql.conf set listen_addresses ='localhost'

Then try -

pg_ctl -D "C:\Program Files\PostgreSQL\9.5\data" start

if already try restarting using pg_ctl

Comments

0

It works for me. Remember, whatever comes after -D should be the path to where you installed PostgreSQL, to the data folder, which holds the pg_hba.conf and postgresql.conf files.

pg_ctl start -D "C:/Program Files/PostgreSQL/9.6/data"

Comments

0

Maybe you can try this. Open cmd and insert.

"C:\Program Files\PostgreSQL\11\bin\pg_ctl.exe" runservice -N "postgresql-x64-11" -D "C:\Program Files\PostgreSQL\11\data" -w

Hit enter...

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.