Unable to connect to server: PgAdmin 4
Asked Answered
A

18

53

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 ?

Awesome answered 19/7, 2019 at 9:27 Comment(6)
Did you configure your Postgres server to actually run on localhost, port 5432?Applique
Do you have a postgres server running locally on your machine?Varicocele
@MattSeymour No, I checked in services.msc but there is no active connectionAwesome
@Applique How do I do that ?Awesome
If you have installed it correctly, then the default port is 5432. If that is fine, then this error suggest that your server is not running locally. Run your server from sql shell. Then pgAdmin will connect it.Mismanage
Matt Seymour's comment resolved my issue: I had a postgres server running locally. Once I stopped it and connected to the docker image it all worked out.Mireillemireles
A
9

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.

Applique answered 19/7, 2019 at 9:44 Comment(2)
I have done that but as soon as I click on save "Unable to connect to server" pops upAwesome
Did you start your Postgres server either directly on your machine or through docker? Pgadmin4 is a client that connects to a running Postgres server.Applique
V
65

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

Vernon answered 12/6, 2022 at 19:50 Comment(6)
how can I do something similar, but with the postgres instance not running in a docker container? sudo netstat -plunt |grep postgres returns that my postgres is running on 0.0.0.0:5432 I cannot connect that even though I edited my configs to allow itMutilate
@Pfinnn, first of all I didn't try to do that, so I cant recommend a solution to that, but did you try to add localhost in the host field or simply 127.0.0.1Vernon
yes I tried that aswell... It still refused the connection. I also have configured UFW... i have no more ideas left...Mutilate
This worked. But why couldn't I use localhost in host field?Governor
Thanks. It works, but may I ask why does localhost does not work, since we've already exposed the ports while creating the container.Smelly
When running in containers, localhost will refer to the container and not your local machine. This is configuring the network relative to the internal docker network and not your local machineHyperpituitarism
D
28

You may need to installing PostgreSQL Server first.


You can verify if the folder is created in the below folder, C:\Program Files\PostgreSQL (for Windows) or /etc/postgresql/{version}/main (for Linux / MacOS).

Devito answered 25/8, 2020 at 4:0 Comment(1)
Solved it for me.Emptor
D
22

Execute the container with the data Eg:

docker run --name postgresdb -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -e POSTGRES_DB=mydb -p 5432:5432 --restart always -d postgres

Then in the PGAdmin client in the Host Name/Address use:

host.docker.internal

Image Conn PGAdmin

Disject answered 9/1, 2023 at 3:8 Comment(3)
Its worked!!! when I try to connect db on supabase local dev on localhost:54322Deakin
I was not authenticated to SOF, and I did just to thank you! Haha..Pleat
Oh by the way, is there any doc for that? because really I wouldn't be able to guess it by myself. Thank youPleat
A
9

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.

Applique answered 19/7, 2019 at 9:44 Comment(2)
I have done that but as soon as I click on save "Unable to connect to server" pops upAwesome
Did you start your Postgres server either directly on your machine or through docker? Pgadmin4 is a client that connects to a running Postgres server.Applique
M
4

In my case was I got both pgadmin and postgresql services running in separate docker containers and I was trying to connect to localhost(127.0.0.1), which is cause of unable to connect to server error.

enter image description here

Note: 5438 port on my computer (host machine) was mapped to 5432 port of postgresql container.

so practically there are two solutions (if you have these services in separate containers and you have mapped postgresql port to your host machine ):

1-find out your local IP (mine is 192.168.1.106) and put it in the Host field.

enter image description here

2- you can put two containers(pgadmin and postgres) in one network (docker network) and instead of your local IP, put postgres container IP in the Host field.

-Another tip that may help: what I've recently find out was if you are linux user and have ufw enabled, you should allow the port.

e.g. on my computer postgres is running on 5438 port, so I performed below command (so I could connect from pgadmin container to 5438 port of host wich postgres is running)

ufw allow 5438
Missive answered 15/9, 2022 at 10:1 Comment(0)
T
3

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.

Thermistor answered 7/11, 2019 at 9:41 Comment(0)
J
2

I was running postgress and pgadmin both using docker container.

sudo docker ps

sudo docker inspect <postgress_container_id>

Output:

   "Networks": {
        "work_file_default": {
            "IPAMConfig": null,
            "Links": null,
            "Aliases": [
                "postgres",
                "578a7a1050d1"
            ],
            "NetworkID": "49dbe9d7280b55e36afc4308469c1b55e051d7eea8f1c03f08728e652cf22b5b",
            "EndpointID": "c30a642c5a0f2970147c9734cadfbe1e8d7c29fcba8a83a628b7c2b3db114716",
            "Gateway": "172.18.0.1",
            **"IPAddress": "172.18.0.4",**
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "MacAddress": "02:42:ac:12:00:04",
            "DriverOpts": null
        }

Instead of localhost put the IP obtained from above command (172.18.0.4)

Jural answered 14/12, 2022 at 18:40 Comment(1)
Is this an answer to the original question?Yam
C
2

how I solved this problem in ubuntu 22.04

  1. I didn't have a password set in Postgres, that's why the error occurred 'unable to connect server 127.0.0.0 port 5432

  2. Open the terminal in ubuntu and enter this command; sudo -u postgres psql

  3. Run the statement to add new password. ALTER USER Postgres PASSWORD 'AddNewPasswordHere'; in '' you should enter your new password

Example:

1)sudo -u postgres psql

2)ALTER USER postgres PASSWORD 'mynewpassword'

3)sudo service postgresql restart

4)Then you can create a server in pgadmin

Campman answered 26/12, 2022 at 0:13 Comment(2)
This worked for me. Just an information: don't forget to put the password in single quotes. Otherwise, it'll not update. On successful transaction, you will see the following output: ALTER ROLEHomburg
Thanks Severus, this worked for me and can confirm what Avik says, if you don't single quote the password it won't recognize it. You will get the "ALTER ROLE" response if the password change was successful. After this I was able to create the new serverOpportunity
C
2

In the Host name/address field, don't use localhost or 127.0.0.1 If you are using Windows OS, open cmd, and type ipconfig Using IPv4 address from Wireless LAN adapter Wi-Fi, eg: 192.168.0.13 instead of localhost or 127.0.0.1 It should work well.

Cropper answered 7/11, 2023 at 0:25 Comment(1)
This was not exactly my issue but it led me to what it was: I needed to enter 127.0.0.1 instead of localhost - go figure! This is on Mac with pgAdmin 8.6 (but it was also happening with 8.3).Hasidism
P
1

You should uninstall Postgres and pgAdmin from your PC. Then install postgres, note that you have the option of installing pgAdmin together with Postgres, so you don't have to download pgAdmin separately. Allow the installation to complete then restart you PC. Hopefully you should be able to create your server/database

Paramnesia answered 21/8, 2021 at 7:48 Comment(0)
M
0

I was trying to install PostgreSQL and pgAdmin with an installer that is given here https://www.postgresql.org/download/windows/. This installer includes the PostgreSQL server, pgAdmin; I was facing an error while starting pgAdmin: "The pgAdmin 4 server could not be contacted". I tried different solutions but did not work.

Then I uninstalled both of them, deleted the temp folder C:\Users\%USERNAME%\AppData\Roaming\pgAdmin and delete those ones too %temp%.

Then I installed the pgAdmin separately from this link https://www.pgadmin.org/download/ and it works. If you need to connect it with your local server I think you should install the PostgreSQL server first and then pgAdmin separately.

Maighdlin answered 18/5, 2021 at 11:57 Comment(0)
D
0

I faced the same problem. So I uninstalled pgAdmin through control panel. after that deleted the folder where pgAdmin was located. Then I went to this link and installed pgadmin whole package from there and now it works fine.

Deadline answered 17/2, 2022 at 15:45 Comment(0)
F
0

I was getting this error when I was running pgadmin in a docker container on my machine, which meant that localhost:5432 was not accessible.

I worked around this by using the native version of pgadmin.

Fae answered 21/5, 2022 at 1:18 Comment(0)
W
0

If you are running PostgreSQL in a docker container, set the host name in pgAdmin to postgres not the mapped address or localhost.

Whitecap answered 16/9, 2022 at 17:12 Comment(0)
P
0

press win key+R then Search for services.msc A window will open in that find postgresql-x64-13 right click, in that tab click start option For me its works perfectly. Check out this stackoverflow link

unable to connect to server for Postgres

Paramnesia answered 11/12, 2022 at 5:50 Comment(0)
S
0

If you already tried with “127.0.0.1” and it didn’t work then use “localhost”

Sharpie answered 18/1, 2023 at 16:34 Comment(0)
B
0

You don't have to look into the container to get the IP address, use the container name as the hostname will do, and docker will resolve it for you.

Brassica answered 16/7, 2024 at 22:38 Comment(0)
F
-3

After two years i think this would be of good help to so many people.

You don't have to uninstall postgresql or PGADMIN from your system.

What you need to do i input the username and password for a particular user created on postgresql into the server input box.

And that all you need.

i hope this helps anyone

Furfuran answered 28/5, 2022 at 17:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.