Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL unable to connect to localhost (Windows 10)

I am trying to connect to localHost on PG Admin but after entering all my server connection information, the window opened again and says:

Connection to DataBase failed

I already reinstall PostgreSQL 6 times with differents versions. I checked that the user Postgres exist, I modified pg_hba.conf by putting trust to the Postgres user. But it's still not working.

I am on Windows 10.
Using the version 9.4.5

like image 599
yoyani Avatar asked Sep 13 '25 12:09

yoyani


2 Answers

Debug this like this:

  1. Is PostgreSQL running? Check the Services! If not, start it. If there is no service, reinstall Postgres and check the appropriate options. If it is still not there, the installer is not Windows 10 ready. Create the service manually after reading the docs. Update: If you get a permission error when starting the service, a reason might be that the user created for the PostgreSQL service doesn't have the "Log on as a service" permission. You can grant it like described in this Microsoft Technet article.

  2. Is the PostgreSQL port (default = 5432) open (Use netstat to check)? If not, check the postgresql.conf for the port. By default PostgreSQL listens only on localhost, not your external IP. Use "*" as the listen-IP in the PostgreSQL config, restart PostgreSQL.

  3. If the port is open the error message should not appear. If it still does, check the logfiles. Use "trust" everywhere in your pg_hba temporarily to ensure this file is not the root of your problems.

like image 79
Daniel Avatar answered Sep 16 '25 01:09

Daniel


SET path in environment variables [postgres bin]

set environment variable PGDATA <path_of_pgdata_folder> <== create it in postgres main folder

initdb.exe -D "C:\Users\<username>\Softwares\postgresql-9.6.14-1-windows-x64-binaries\pgsql\pgdata"

"pg_ctl" -D "C:\Users\<username>\Softwares\postgresql-9.6.14-1-windows-x64-binaries\pgsql\pgdata" -l logfile start

createuser -r postgres

now Open pgAdmin and connect to your database see image

like image 33
Narayana Avatar answered Sep 16 '25 01:09

Narayana