89

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?

6
  • 3
    Is Postgres starting on your PC (which O.S and Postgres version are you using?)? Check that windows firewall isn't blocking the ports. Commented Nov 10, 2016 at 16:25
  • i am using windows 10 and my postgres is 9.6.How to check windows firewall blocking the port?@n34_panda Commented Nov 10, 2016 at 16:34
  • 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. Commented Nov 10, 2016 at 16:36
  • 2
    So, did you start the Postgres (Windows) Service? Commented Nov 11, 2016 at 6:46
  • 1
    Yes,i already start the service Commented Nov 11, 2016 at 7:22

26 Answers 26

147

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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
26

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

3 Comments

On CentOS Linux (7), these files are in /var/lib/pgsql/<version>/data/; update the entries as above, and restart pgsql server sudo systemctl restart postgresql-14
I had to repeat this process on Windows after upgrading my Postgres software version and being unable to reconnect to my local db.
It can't be overstated how many different ways there are to block traffic to your postgres instance. But yes, postgresql.conf and pg_hba.conf are the main ones. Always good to lint/scan them. Example one that can analyze Postgres confs e.g. is github.com/coguardio/coguard-cli
19

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.

2 Comments

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

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.

Comments

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

And re-enter.

1 Comment

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

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

Comments

7

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

Comments

7

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

1 Comment

same to me. I installed two Postgres and need to change port.
5

Summary: There are 2 Solutions:

  1. Open Services and make sure that postgresql-x64-14 is running.

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

1 Comment

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

goto service and start postgresql-x64-10 service

steps

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

Comments

4

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!

Comments

3

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

Comments

2

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

  1. Win+R and type services.msc
  2. Search Postgres service based on the version installed, e.g., "postgresql-x64-13 - PostgreSQL Server 13"
  3. Click stop, start, or restart the service option
  4. 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.

1 Comment

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

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.

Comments

1

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

Comments

1

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:

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

Comments

1

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.

Comments

1

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

Comments

1

For me on windows this worked by changing the configuration file default settings as follows.

In the postgresql.conf file in the C://ProgramFiles/PostgrSQL/<version>/data directory, Under CONNECTION AND AUTHENTICATION, ensure

listening_addresses = '127.0.0.1'

and

port = 5432

then press Win+R and type services.msc, look for PostgreSQL then restart the service.

That should work.

Comments

1

I had installed postgresql@12 using homebrew. These steps worked for me.

rm -rf /opt/homebrew/var/postgresql@12/postmaster.pid                        

brew services restart postgresql@12

Comments

0

Using psql with single quotes fails:

psql -c 'Select version();' 'postgresql://username:[email protected]: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:[email protected]: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)

Comments

0

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

Comments

0

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.

Comments

0

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}

    enter image description here

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

Comments

0

If you are a Mac OS user, run these below two commands on termial,

rm /usr/local/var/postgres/postmaster.pid
brew services restart postgresql

Comments

0

The solution that worked for me:

  1. Open the Services configuration window (you can access it from Windows Control Panel > Administrative Tools or from the Start menu when you type services or simply hold the Windows key + x and select services).
  2. Find your service (in this example: PostgreSQL_For_Odoo) and double-click it to open its properties (or right click it and select Properties).
  3. Go to the Log On tab and then check the Local System account radio button and apply.

I hope it will work for you as well :-)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.