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.
4
Answers
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 usingNote: 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
You are currently using the
-U
flag for specifying the username, but you have not provided the actual username. To resolve this, you can try using the following command:Please replace the
<username>
placeholder with your system’s username and<database>
with (defaultpostgres
)Before running the command, make sure that the server is already started using the
pg_ctl
command.Note that you can use a simpler statement for connecting to the PostgreSQL database without explicitly using the
-h
,-p
, and-U
flags. This is because, by default, the connection will be made tolocalhost:5432
, and the username will be your system’s default username. You can try using the following statement: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.
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.