Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to connect to server for Postgres

Tags:

postgresql

I have a problem to connect server for Postgres after I updated my windows.Before I update there is no problem to open the database. My database in Postgres also gone. When I want to create my new database it show this error:

Unable to connect to server: 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?

like image 815
SySyBy Avatar asked Nov 10 '16 16:11

SySyBy


People also ask

Can't connect to postgres server Windows?

First, double check that the Postgres process is running where you expect it to be. If you are trying to connect to a Postgres instance on the same host as your terminal, you can run lsof -p :5432 which will show which, if any, processes are listening on that port. The postgres process should be connected there.

Can't connect to server connection timed out postgres?

A Connection Timed Out error occurs when the database's firewall won't allow you to connect to the database from your local machine or resource. If you are getting this error, check that you have added the machine or resource you are connecting from to the database's list of trusted sources.

Can't connect to server connection refused pgAdmin?

If pgAdmin displays this message, there are two possible reasons for this: the database server isn't running - simply start it. the server isn't configured to accept TCP/IP requests on the address shown.


3 Answers

On windows, Just go to the 'Services'. Start/Restart the postgresql-X64 service. It worked for me as my service was in stopped state somehow.

like image 86
gagan chhabra Avatar answered Sep 21 '22 07:09

gagan chhabra


There are two items to configure if your server isn't on localhost:

  • find your postgresql.conf and add your server's public IP address to the end of the setting listen_addresses (separate multiple entries by commas); uncomment the line if it is commented out (e.g. with '#')
  • add a line to pg_hba.conf containing your client's IP address - you may copy the line containing 127.0.0.1 and change only the IP address

On Ubuntu, these files are in /etc/postgresql/<version>/main/.

like image 26
Franc Drobnič Avatar answered Sep 20 '22 07:09

Franc Drobnič


In my case I couldnt' open the pgAdmin4, for some reason. I use Postgresql 10 and pgAdmin4

The port in the postgresql.conf was not the same as in the pgAdmin4 --> postgreSQL 10 --> properties --> Connection --> port.

I fixed it and it worked. Check if those 2 are in line.

like image 22
Andreas Alamanos Avatar answered Sep 21 '22 07:09

Andreas Alamanos