Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to server: PgAdmin 4

I have installed pgadmin on a new windows laptop and when I try to create a new server, it says:

enter image description here

When I try to run my django app in pycharm it is giving me the same error

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?

How to solve this ?

like image 231
Rahul Sharma Avatar asked Jul 19 '19 09:07

Rahul Sharma


People also ask

Why pgAdmin Cannot connect to server?

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.

Can't connect to postgres server?

“Could not connect to server: Connection refused” To be sure that PostgreSQL is running, you can also restart it with systemctl restart postgresql. If this does not fix the problem, the most likely cause of this error is that PostgreSQL is not configured to allow TCP/IP connections.


Video Answer


4 Answers

You may need to installing PostgreSQL Server first.


You can verify if the folder is created in the below folder, C:\Program Files\PostgreSQL

like image 113
Jeberdson Abraham Avatar answered Oct 07 '22 14:10

Jeberdson Abraham


You can configurate your newly created server to run on localhost and port 5432.

First select the “Connection” tab in the “Create-Server” window. Then, configure the connection as follows:

  • Enter your server’s IP address in the “Hostname/ Address” field. Default is localhost.

  • Specify the “Port” as “5432”.

  • Enter the name of the database in the “Database Maintenance” field.

  • Enter your username as postgres and password (use the same password you used when previously configuring the server to accept remote connections) for the database.

  • Click “Save” to apply the configuration.

NOTE You first have to install PostgreSQL on your machine and run it or run it with docker.

like image 43
Stevy Avatar answered Oct 07 '22 12:10

Stevy


In case someone is running the pgadmin-4 in docker, and not able to connect to postgres container, like me. The solution is to first find the ip at which the docker image is running.

Step-1, make sure the postgres container is running.

Step-2 write command- PS C:\docker> docker ps Should result as below or similar,

enter image description here

Step3- in order to find the ip address running the postgres use part of container ID and analyze like below command

PS C:\docker> docker inspect fc834 enter image description here Note: Here I have only used part of container id that is fc834..

This should result the following or similar, Step4-

Use this ip address in the connection as below with your correct username and password

enter image description here enter image description here

like image 18
Kjk Avatar answered Oct 07 '22 13:10

Kjk


I had the same issue. But in my case I had installed pgadmin in version 9. But also installed version 12 at the same time.

When I now uninstalled version 9, the port was already set in the config of version 12 and not given free.

So my solution was to change the port of version 12 in the postgresql.conf file. Or even simplier, change the port in the server creation from 5432 to 5433. Now you are able to create a server again.

like image 3
kwoxer Avatar answered Oct 07 '22 12:10

kwoxer