This is my wsl -l -v
NAME STATE VERSION* Ubuntu Stopped 2
lsb_release -a
output:
No LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 22.04.1 LTSRelease: 22.04Codename: jammy
pg_config --version
output:
PostgreSQL 14.6 (Ubuntu 14.6-0ubuntu0.22.04.1)
I had this problem the day before where I cannot start or restart postgresql and would output this:
sudo service postgresql start
and sudo service postgresql restart
output:
* Starting PostgreSQL 14 database server * Error: /usr/lib/postgresql/14/bin/pg_ctl /usr/lib/postgresql/14/bin/pg_ctl start -D /var/lib/postgresql/14/main -l /var/log/postgresql/postgresql-14-main.log -s -o -c config_file="/etc/postgresql/14/main/postgresql.conf" exited with status 1:2023-03-17 21:08:03.100 CST [1028] LOG: starting PostgreSQL 14.6 (Ubuntu 14.6-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0, 64-bit2023-03-17 21:08:03.103 CST [1028] LOG: could not bind IPv4 address "127.0.0.1": Address already in use2023-03-17 21:08:03.103 CST [1028] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.2023-03-17 21:08:03.103 CST [1028] WARNING: could not create listen socket for "localhost"2023-03-17 21:08:03.103 CST [1028] FATAL: could not create any TCP/IP sockets2023-03-17 21:08:03.106 CST [1028] LOG: database system is shut downpg_ctl: could not start serverExamine the log output.
I check the log outputs and this is what it shows:
2023-03-18 17:18:34.718 CST [337] LOG: starting PostgreSQL 14.6 (Ubuntu 14.6-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu,>2023-03-18 17:18:34.721 CST [337] LOG: could not bind IPv4 address "127.0.0.1": Address already in use2023-03-18 17:18:34.721 CST [337] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds>2023-03-18 17:18:34.721 CST [337] WARNING: could not create listen socket for "localhost"2023-03-18 17:18:34.721 CST [337] FATAL: could not create any TCP/IP sockets2023-03-18 17:18:34.723 CST [337] LOG: database system is shut downpg_ctl: could not start serverExamine the log output.
I tried this: sudo service postgresql status
but it would show that the host is down.and sudo service postgresql stop
would also stop the server.
ps -ef | grep postgres
output:
ann 211 60 0 20:27 pts/0 00:00:00 grep --color=auto postgres
I also already changed the localhost from this file sudo nano /etc/postgresql/14/main/postgresql.conf
:
from: listen_addresses: localhost
to: listen_addresses = '*'
I have already checked that it is listening on Port: 5432
. I even tried restarting the computer, and no luck. I started getting these errors after I updated Windows 11.
This already happened the day before, however, after a few tries on just exiting Ubuntu terminal from the Powershell it would just start the postgresql. Yesterday, when I tried it, all of those errors appeared. And now, when I tried starting the postgresql with sudo service postgresql start
, the postgresql database server did not have any problem starting it on the main port 5432. I am using this to develop a Ruby on Rails application.
sudo netstat -tulpn
output:
Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nameudp 0 0 127.0.0.1:323 0.0.0.0:* -udp6 0 0 ::1:323 :::*
This question is also available at Stackoverflow: https://stackoverflow.com/questions/75773133/sometimes-postgresql-would-not-start-but-the-next-day-it-would-start-again