ChatGPT解决这个技术问题 Extra ChatGPT

unable to connect to server for Postgres

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?

Is Postgres starting on your PC (which O.S and Postgres version are you using?)? Check that windows firewall isn't blocking the ports.
i am using windows 10 and my postgres is 9.6.How to check windows firewall blocking the port?@n34_panda
Open Up "Control Panel", select "System and Security" and choose "Windows Firewall" or simply search for "Windows Firewall" then you'll see some radio buttons. Easiest quick test is to switch them all off and see if the service works and you can connect.
So, did you start the Postgres (Windows) Service?
Yes,i already start the service

g
gagan chhabra

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.


What if I can't find the postgresql-X64 service anywhere in my services? Why is it not there?
@MatthewWolman in this post: 'How to run PostgreSQL as a service in Windows' is elaborated how you can start the service. Another solution is to reinstall postgresql as explained in 'Connection refused in local postgresql' . Hope this will help.
This was exactly what happened to me. Thanks so much.
if the start button is disabled. then goto properties and select manual and then click on start
F
Franc Drobnič

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/.


A
Andreas Alamanos

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.


This worked for me. My Postgres port was 5432 but pgAdmin was connecting to 5433.
This worked for me on Windows 10, simply just changing the port in the Properties of the server to what was in postgresql.conf solved this issue.
V
VADHAN

First press win key+R Search for services.msc A window will open in that find postgresql-x64-13 and open that, in that tab click start option For me its works perfectly.


work like a charm
T
Tim Uzlov

Faced this problem immediately after installing on Windows. At startup the pgAdmin gave this error which means that the server is not running. For me the solution was: Start -> Control panel -> Administration -> Services -> postgresql-x64-12 - start or restart


Н
Никита Мельников

Go to PgAdmin Right click on PostgreSQL 3.Choose properties At the top, select connection Try changing the port from 5433 to 5432 or vice versa.

And re-enter.


currently my postgres v14 is running on port 5433, and I deleted v13 completely which was running on port 5432... and I am not able to use psql command... don't know why :(.. what should I do any idea ? And on changing port from pgAdmin I am not able to connect.. giving that same error..
d
devyan91

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.

worked for me


N
Nitin Nain

This happened because I installed two versions of Postgres (v12 and v13). Psql 12 was installed later so got the port 5433. I needed to use Postgres 12. To fix this particular case:

Go to Program Files/Postgres//data Open the postgresql.conf file Search for Port and change the port number to 5432.

Open Windows Services (Press Cmd + R then type services.msc)

Stop the service for the version you don't want (You can stop it permanentally from the Right Click > Properties menu.)

Start the service for the version you want.


H
Harsha Biyani

I think the problem is with your server listening to default public IP address. For example in the PostgreSQL package, your sever is set to listen to localhost as default public address which when you launch/ run database, the address might be something like '127.0.0.1'

To fix you can try change localhost to '' as in "listen_addresses = ''".

As seen as "listen_addresses = 'localhost'" under "Connection Settings" in the postgresql.conf file.

Also to access your postgresql.conf file, go to:

On Windows, the file is in /Program Files/PostgreSQL/<version>/share/. On Ubuntu, these files are in /etc/postgresql/<version>/main/.

P.S: Changing the defaults 'localhost'; to '*' will let your server listen to any public database address either "localhost, 127.0.0.1 etc.

I know you might have fix this, just for others that might run into the same issue in the future. Hope it was helpful


B
B G

goto service and start postgresql-x64-10 service

steps

run -> services.msc -> find postgresql-x64-10 -> start the service

services image


M
Manoj Swami

This is a note for a normal user. If using an official installer, it should have a built-in service,

Win+R and type services.msc Search Postgres service based on the version installed, e.g., "postgresql-x64-13 - PostgreSQL Server 13" Click stop, start, or restart the service option If you don't see start/stop or if these buttons are disabled, then double-click on the PostgreSQL and change startup type to automatic and click on start. This will start the PostgreSQL every time automatically whenever you start your system.


works for anyone who killed the process of postgresql service from the Task-manager for whatever reason
o
ouflak

I had the same issue, so, I uninstalled postgres. And during reinstallation I noticed the error:
"Failed to load SQL modules into the database cluster"
And:
"Problem running post installation step.Installition may not complete correctly. Error reading file C:/Program Files/PostgreSQL/14/data/postgresql.conf".

I cancelled the installation and then tried again, but with a plain-text password this time, and it worked. It turned out that the special characters in my password were the problem.


u
uosjead

I got this error message when I moved my database to another computer.

I also got some error messages when starting the server first with

pg_ctl -D /wherever/your/database/is start

which were

pg_ctl: another server might be running; trying to start server anyway server starting DETAIL: File "/wherever/your/database/is/PG_VERSION" does not contain valid data. HINT: You might need to initdb.

In my case rather than running initdb this command actually fixed the issue

pg_ctl -D /wherever/your/database/is restart

N
Nirmal

You might have changed the permissions of the 'PostgreSQL 12' in 'services.msc'. Or maybe it is not started and you are trying to start the server when Postgre 12 is not running.

Try these:

Try to start the 'PostgreSQL 12' in 'services.msc' manually. Try restarting your PC If nothing helps, try reinstalling PostgreSQL (pgAdmin 4) from the scratch.


T
Tony Joseph

Go to C:\Program Files\PostgreSQL\13\data, edit postgresql.conf with notepad.

Change:

#port = 54XX

To:

port = 54XX

(change requires restart)

restart service at "service system" on window.


M
Mace

Solutions:

Open Services and make sure that postgresql-x64-14 is running. Go to C:\Program Files\PostgreSQL\14\data and open postgresql.conf with notepad, find and change port to e.g 5432 and after that open Services and restart postgresql-x64-14.


There are twenty existing answers to this question, including a top-voted answer with nearly one hundred votes. Are you certain your solution hasn't already been given? If not, why do you believe your approach improves upon the existing proposals, which have been validated by the community? Offering an explanation is always useful on Stack Overflow, but it's especially important where the question has been resolved to the satisfaction of both the OP and the community. Help readers out by explaining what your answer does different and when it might be preferred.
J
Jeremy Thompson

Using psql with single quotes fails:

psql -c 'Select version();' 'postgresql://username:password@db.abcdefghi.ap-southeast-2.rds.amazonaws.com:8080/the_db'

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?

Using double quotes works:

psql -c "Select version();" "postgresql://username:password@db.abcdefghi.ap-southeast-2.rds.amazonaws.com:8080/the_db"

PostgreSQL 10.14 on x86_64-pc-linux-gnu, compiled by x86_64-unknown-linux-gnu-gcc (GCC) 4.9.4, 64-bit (1 row)


A
Ashok Mehta

After a wasting 3-4 hrs i find the solution something like this

First set path in enviroment variable.And then make port and psql connecting same i.e 5432 or 5433


A
Anurag A S

If you newly installed the pgAdmin, and you did not remember to install PostgreSQL at that time, you get that error. Make sure you install both pgAdmin And PostgreSQL.


D
DINA TAKLIT

For me I was getting this error and unable to open the server in PgAdmin is because I very often forgot to start the server, one for the way you can start the server with is by running this commands on cmd, make sure you provide the right path

cd "C:\Program Files\PostgreSQL\14\bin"
pg_ctl -D "C:\Program Files\PostgreSQL\14\data" start

J
James Karino Simel

When I run psql, it gave me the same error, and it was because I changed the port while setting Postgres in the installation process.

I had to change back to the default port 5432 in PostgreSQL.conf (which can be found in the data directory) i.e

C:\Program Files\PostgreSQL\14\data>

The problem is no more!


H
Harvey Dent

And so for the new arrivals. If you are using pgAdmin and a Windows operating system, do some research to resolve the issue.

Make sure you have Postgresql installed or active

To do this, go to windows services (press Cmd + R and run the services.msc command)

Look in the list for a service called postgresql-x{BIT}-{Version}-PostgreSQL Server {Version}

Solution 1: If you don't find the service, then PostgreSQL is not installed or has been uninstalled, install it again.

Solution 2: If you find the service, but you still can't log in, then most likely the service is not active for some reason, select the service and click the Start or Restart button


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now