10

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!

MwamiTovi
  • 2,050
  • 14
  • 22
dino9239
  • 101
  • 1
  • 1
  • 3

5 Answers5

7

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.

tayfun Kılıç
  • 884
  • 9
  • 11
  • 1
    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! – Albert Israel Nov 29 '18 at 13:51
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
Gab
  • 3,208
  • 1
  • 8
  • 20
  • 1
    `psql -U myuser -d mydatabase` works fine, I did start the service and `status`shows it as *active*. But I still get that `Connection refused` error. – DarksteelPenguin Oct 16 '17 at 14:49
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

Karthik Sagar
  • 424
  • 4
  • 7
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...

Dharman
  • 26,923
  • 21
  • 73
  • 125
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"
Kairat Koibagarov
  • 1,199
  • 12
  • 7