-1

To run Apache AGE, I built postgres 12 from source with the --debug flag enabled and followed the instructions given. Upon it being succesfully built (in ubuntu on wsl2), I tried running it with the psql command, but it kept giving an error.

I tried running

psql -U postgres

but that gave me the following error

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket?

However, if I run

psql -h localhost -p 5432 -U postgres

I am able to connect to the server. I've googled for hours but I am not sure what the problem is.

tokamak32
  • 27
  • 7

3 Answers3

1

This can happen due to a number of reasons. Aside from the other answers, you can try checking what WSL2 is using for the TCP connections.

I experienced the same issue running without a VPN but as soon as I connected to the same VPN (in the specific location I was connected to) at the time of install it magically worked.

https://gist.github.com/machuu/7663aa653828d81efbc2aaad6e3b1431

Describes the issue I had the produced same error message on WSL2.

RU-D
  • 224
  • 8
-1

It is because you are not connected to the database server yet. After you have created a database cluster using bin/initdb <db_cluster>. You can connect to database server using

bin/pg_ctl -D <db_cluster> -l logfile start

Note: For running these commands, you need to be inside the directory where you downloaded postgreSQL (that directory has many other subdirectories like bin, contrib, src, doc, <db_cluster> etc). Then you can launch psql command line to interact with database postgres

bin/psql postgres
Zainab Saad
  • 728
  • 1
  • 2
  • 8
  • The database instance (aka cluster) was correctly installed, initialized and started (otherwise using `psql -h localhost` wouldn't work). It simply doesn't accept socket connections. –  Mar 23 '23 at 12:34
-1

You have to start the server before running psql. You can start the server by running the following command.

pg_ctl -D 'dbname' -l logfile start

After starting server, you can run psql.

This was the main problem why you were getting an error. The server was not started before running psql.