unable to connect to server for Postgres

Postgresql

Postgresql Problem Overview


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?

Postgresql Solutions


Solution 1 - Postgresql

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.

Solution 2 - Postgresql

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

Solution 3 - Postgresql

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.

Solution 4 - Postgresql

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.

Solution 5 - Postgresql

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

Solution 6 - Postgresql

  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.

Solution 7 - Postgresql

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

Solution 8 - Postgresql

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.

Solution 9 - Postgresql

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

Solution 10 - Postgresql

goto service and start postgresql-x64-10 service

> steps

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

Solution 11 - Postgresql

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.

Solution 12 - Postgresql

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.

Solution 13 - Postgresql

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

Solution 14 - Postgresql

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.

Solution 15 - Postgresql

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.

Solution 16 - Postgresql

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)

Solution 17 - Postgresql

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

Solution 18 - Postgresql

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.

Solution 19 - Postgresql

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.

Solution 20 - Postgresql

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

Solution 21 - Postgresql

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSySyByView Question on Stackoverflow
Solution 1 - Postgresqlgagan chhabraView Answer on Stackoverflow
Solution 2 - PostgresqlFranc DrobničView Answer on Stackoverflow
Solution 3 - PostgresqlAndreas AlamanosView Answer on Stackoverflow
Solution 4 - PostgresqlVADHANView Answer on Stackoverflow
Solution 5 - PostgresqlTim UzlovView Answer on Stackoverflow
Solution 6 - PostgresqlНикита МельниковView Answer on Stackoverflow
Solution 7 - Postgresqldevyan91View Answer on Stackoverflow
Solution 8 - PostgresqlNitin NainView Answer on Stackoverflow
Solution 9 - PostgresqlDamilare OyediranView Answer on Stackoverflow
Solution 10 - PostgresqlB GView Answer on Stackoverflow
Solution 11 - PostgresqlManoj SwamiView Answer on Stackoverflow
Solution 12 - PostgresqlKanjooMView Answer on Stackoverflow
Solution 13 - PostgresqluosjeadView Answer on Stackoverflow
Solution 14 - PostgresqlNirmalView Answer on Stackoverflow
Solution 15 - PostgresqlCharlycrisView Answer on Stackoverflow
Solution 16 - PostgresqlJeremy ThompsonView Answer on Stackoverflow
Solution 17 - PostgresqlAshok MehtaView Answer on Stackoverflow
Solution 18 - Postgresqlsanket WalunjView Answer on Stackoverflow
Solution 19 - PostgresqlMaceView Answer on Stackoverflow
Solution 20 - PostgresqlDINA TAKLITView Answer on Stackoverflow
Solution 21 - PostgresqlHarvey DentView Answer on Stackoverflow