I'm trying to open the Postgresql shell so that I can check the data tables and add a default admin username/password to an application. I am using WSL2 and psql --version is 12.14.
When I try:
psql
I receive the error:
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
In response, I tried to just start the service:
sudo service postgresql start
* Starting PostgreSQL 12 database server * Error: /usr/lib/postgresql/12/bin/pg_ctl /usr/lib/postgresql/12/bin/pg_ctl start -D /var/lib/postgresql/12/main -l /var/log/postgresql/postgresql-12-main.log -s -o -c config_file="/etc/postgresql/12/main/postgresql.conf" exited with status 1:
2023-05-11 15:31:28.195 EDT [1195] LOG: starting PostgreSQL 12.14 (Ubuntu 12.14-0ubuntu0.20.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
2023-05-11 15:31:28.196 EDT [1195] LOG: could not bind IPv4 address "127.0.0.1": Address already in use
2023-05-11 15:31:28.196 EDT [1195] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2023-05-11 15:31:28.196 EDT [1195] WARNING: could not create listen socket for "localhost"
2023-05-11 15:31:28.196 EDT [1195] FATAL: could not create any TCP/IP sockets
2023-05-11 15:31:28.196 EDT [1195] LOG: database system is shut down
pg_ctl: could not start server
Examine the log output.
Looking at the log gives me this response:
2023-05-11 15:31:28.195 EDT [1195] LOG: starting PostgreSQL 12.14 (Ubuntu 12.14-0ubuntu0.20.04.1) on x86_64-pc-linux-g>2023-05-11 15:31:28.196 EDT [1195] LOG: could not bind IPv4 address "127.0.0.1": Address already in use
2023-05-11 15:31:28.196 EDT [1195] HINT: Is another postmaster already running on port 5432? If not, wait a few second>2023-05-11 15:31:28.196 EDT [1195] WARNING: could not create listen socket for "localhost"
2023-05-11 15:31:28.196 EDT [1195] FATAL: could not create any TCP/IP sockets
2023-05-11 15:31:28.196 EDT [1195] LOG: database system is shut down
pg_ctl: could not start server
Examine the log output.
So something is probably running on that port. Checking...
root@2300-JMFC9K3:/home/artemisia/concordia# netstat -a -p -n
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::5432 :::* LISTEN -
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] SEQPACKET LISTENING 17496 - /run/WSL/7_interop
etc.
I don't really understand what's blocking this--it looks like something's running on that socket, but it's not giving me a pid. Suggestions? I also had a look at another StackOverFlow Thread on issues with connecting to the psql server. this: PostgreSQL: Why psql can't connect to server? It suggests 'If you can't find the socket, but see that the service is running, Verify that the pg_hba.conf file allows local sockets.' However, I can't find the pg_hba.conf in the PGDATA section. This StackOverFlow thread has recommendations for finding it, but I can't just query my database for it since psql isn't working, and trying ps aux | grep 'postgres *-D' gives no results.
Any assistance would be greatly appreciated, and thank you all for your time and energy.
ADDED:
Running pg_lsclusters gives the result:
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
I'm running this command from the commandline of WSL inside a project directory cloned from this open-source project: https://github.com/LibraryOfCongress/concordia