PostgreSQL server Connection error: could not connect to server - postgresql

I am using pgAdmin4 and developing a node.js app.I had an abrupt shutdown of the computer and I can no longer connect to the postgresql server.
The error I get when trying to connect is :
psql: 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 tried to run postgres -D /usr/local/var/postgres/ as suggested in this SO answer. However it gave me the following error :
postgres: could not access directory "usr/loval/var/postgres": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
So I just manually deleted the postmaster.pid file inside the PostgreSQL/.../data folder. But I still cannot connect to the database server.
I have checked the postgresql.conf file, and
the listen addresses is already set as listen_addresses = '*', and the port is set to 5432.
I also tried deleting the pgAdmin file in the AppData/Roaming folder.But it gave me an error:
The application server could not be contacted
and then afterwards the same problem of not being able to connect to the server happens.

Funny enough, it was a matter of just deleting the pdAdmin file in AppData/Roaming folder, and then restarting the computer and restarting the pgAdmin4. That solved it for me.

Meet the same challenge while settings up PostgreSQL to work with a Python/Django project.And i resolved the issue here, after reading the official PostgreSQL-9.6.16 documentation.

Related

The database cluster initialization failed - error while installing PostgreSQL

While installing PostgreSQL on Windows 11 I get the error:
the database cluster initialization failed
then SQL Shell gives me an error
psql: 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? Press any key to continue . . .
There's even no Postgres in Services and the data folder is empty. So I uninstalled it and got this error while doing so:
error stopping service PostgreSQL-x64-13
After this, I've tried many different ways of reinstalling Postgres, including running it as Admin, creating a separate user named postgres with Admin rights, etc. In fact, this comprehensive article offers a lot of different ways to deal with this issue: https://forums.holdemmanager.com/general-support/150771-solved-postgresql-database-cluster-initialisation-failed.html
However, none of them worked for me. It seems that I exhausted all possible solutions. Any ideas on what I can try now?

Cannot connect postgreSQL server to pgAdmin 4

I know there are a lot of similar questions on this site, but so far I've been unable to find any answers. I have a postgres 13 server running on a WSL distro, ubuntu 20.04. I am trying to connect a gui to the server. I've tried Postbird and pgAdmin 4, both give me a similar 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?'
Steps I have tried:
I can connect to the server inside of ubuntu by running psql.
I have changed the postgresql.conf file to include listen_addresses = '*'
I have modified the pg_hba.conf file to look like:
pg_hba.conf
I have confirmed that the server is indeed running on port 5432.
Thanks for reading. Any advice would be greatly appreciated.
Ok! So my issue was indeed the pg_hba.conf file. I had to add a line at the bottom
host all all 0.0.0.0/0 trust
Once I did that, I restarted my server and was able to connect.

Postico & Postgres error - could not connect to server: Connection refused

I'm using the latest macOS Catalina.
I've looked into other threads but not sure how to solve mine because I have two errors on both Postgres and Postico.
Postgres says I have a Stale postmaster.pid file
Postico says
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I went on Youtube for a solution to address the stale postmaster.pid file, and deleted it using the terminal... but the error still persists..
Should I uninstall, and reinstall Postgres and Postico?
Using the terminal to delete postmaster.pid didn't do it for some reason. I had to do it via Finder manually.
Problem solved :)
I had the same error on Postico.
I just reinstalled Postgres.app and initialize again my data base on the app, and after go back on Postico.

How to connect pgadmin 4 to an external server?

I just created a server (droplets) in digital ocean, install postgresql, up there well, it works on the console. My problem is when I try to connect through pgadmin.
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "165.22.184.123" and accepting
TCP/IP connections on port 5432?
Look for information and modify the file
/etc/postgresql/10/main/postgresql.conf
where says listen_addresses='localhost' by listen_addresses='*'.
Also add a line to host all all 0.0.0.0/0 md5 to the file /etc/postgresql/10/main/pg_hba.conf and I still have the same problem. Do I have to do some additional configuration?

Can't connect to the default server of pgAdmin 4

I have just installed the pgAdmin-4, and trying to connect to the default server installed with it (PostgreSQL 9.5). It asks for the password (Which I assume by default it's "postgres"), however, I keep receiving the following message:
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 am working on Windows 7.
Any ideas on how to fix this problem?
The first thing is to remove pgadmin from the problem. Try to connect with the command line using psql - if you get the same message you know that the problem is not with pgadmin. If the problem continues with psql then probably your configuration of postgresql is not complete. The issue might be in the file pg_hba.conf - this file controls who is allowed to connect to the backend. You might also check that the server application is running, using an appropriate Windows utility.