1

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

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Pendelluft
  • 99
  • 9
  • 2
    1) Do `ps ax | grep postgres` and see what shows up? 2) This `psql` is going to try a connection via the local socket. Try `psql -h localhost -p 5432 -U postgres` – Adrian Klaver May 11 '23 at 22:35
  • Thank you for your suggestions. Running `ps ax | grep postgres` puts out the response `500 pts/0 S+ 0:00 grep --color=auto postgres` (I think this is the process just run to look at the processes?). Running `psql -h localhost -p 5432 -U postgres` also gives me the error `psql: error: could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?` Maybe something in the firewall is blocking it? – Pendelluft May 12 '23 at 13:44
  • 1) What do you get when you run `pg_lsclusters` from the command line? 2) Where are you running the `psql` client? **Add answers as update to question**. – Adrian Klaver May 13 '23 at 15:05

1 Answers1

-2

The error could be happening because of a broken host-file.

Check your /etc/hosts/ and put 127.0.0.1 localhost at the top of this file.

  • 1
    Not even close. As the error says `could not bind IPv4 address "127.0.0.1": Address already in use`. So the address is recognized it just already has `5432` bound to it. Come up with a correct answer or delete this one. – Adrian Klaver May 11 '23 at 22:33
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 12 '23 at 06:15