1

I am not a programmer, I do my best, but I need help. I created and managed postgressql DB for my department needs on localhost, Windows. I set required ip to listens in postgresql.conf and configured pg_hba.conf. And it worked fine for 3 months.

But today I came to work, tried to connect to Postgresql server. And see this:

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?

I checked configs - there are no changes. I tested settings with listened_ip='*'. Still not working. And I see that message when i try to create new server.

What happened? How to fix all this?

Archirk
  • 427
  • 7
  • 25

3 Answers3

1

Assuming you have not alteres pg_hba.conf file, you can start your postgres from windows cmd.exe using

net start postgresql-9.8

instead of 9.8, you use your postgres version number. Other way round you can look for your services from (start -> run -> services.msc)

lat long
  • 920
  • 6
  • 16
  • I know that I use Postgresql 11. however it can not find this service. i write "NET START postgresql-11". I cannot not get more information about a version, because i can't write sql query in PgAdmin. It's locked, cause server not working... – Archirk Sep 02 '19 at 10:28
  • write services.msc in cmd.exe. And from there find the exact service name that has postgres text in it. If not found there, it means your pg service is uninstalled somehow. – lat long Sep 02 '19 at 10:59
  • I found: postgresql-x64-11. However when i try to execute NET START postgresql-x64-11 it writes: System Error 5. Access denied (or close to it. It's in my native language, not in English). I am not an administrator. But DB worked before even without administrator's rights. – Archirk Sep 02 '19 at 11:11
  • May be only Administrator user have the permissions to start service. – lat long Sep 02 '19 at 11:26
  • Well, I manage to get administrator right from our admin. I started postgresql server through terminal. Now it doesn't show old error, but still can't connect and can't create server. And says: "Unable to connect to server: " – Archirk Sep 02 '19 at 13:18
  • 1
    Strange. check this. may be you still need to allow addresses. https://stackoverflow.com/questions/32439167/psql-could-not-connect-to-server-connection-refused-error-when-connecting-to – lat long Sep 03 '19 at 06:17
1

The general thought/assumptions:

It looks like it is pgAdmin (probably version 4) or your admin rights or one of the files mentioned above (postgresql.conf and/or pg_hba.conf).

I had the same error and even a password error (for the correct password) after being a step further by some todo's and fixes that helped other people in previous versions;

But none of them worked for postgresql version 12.3 and/or postgresql version 11.8

Solution versions:

The only thing that helped after two hours was: As explained in this post: 'PostgreSQL Install fail on Windows 10 (icalcs error/acces denied)' on the superuser forum of StackExchange:

  • Uninstall en reinstall postgresql. The official version provided by EDB through this link: postgresql.org/download; Or try a different version if you are sure this one doesn't work for you. Therefor head to the 'File Browser'of Postgresql: here
  • After reinstall, start pgAdmin from the Start Menu (scroll for the folder and the correct related pgAdmin; an older version could still hang around in the shortcuts and won't start).

Note: You can keep your data map so nothing is lost!

In my case e.g.: I removed the /data folder from the (Windows 10) [Drive]/Program Files/PostgreSQL/11 and as soon as I uninstalled version 11.2 and reinstalled (earlier removed 12) version 12: when I started pgAdmin4 my former servers ([nameA] and [PostgreSQL 11] and databases ánd the new server [PostgreSQL 12] were there! And the connection was reestablished

Tried:

Earlier tried solutions that did not work in my case:

sophievda
  • 334
  • 6
  • 18
1

if you've installed the official postgreSQL on Windows accepting all default settings, maybe you need to manually start the service (Run cmd.exe as admin and enter this command) each time you start querying:

pg_ctl -D "C:\Program Files\PostgreSQL\[YOUR_POSTGRESQL_VERSION]\data" start

in my case is:

pg_ctl -D "C:\Program Files\PostgreSQL\12\data" start
Yu Gao
  • 11
  • 2