Score:0

WSL Ubuntu: Sometimes postgresql won't start but the next day it would start again

mx flag
JS3

This is my wsl -l -v

  NAME      STATE           VERSION
* Ubuntu    Stopped         2

lsb_release -a output:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       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-bit
2023-03-17 21:08:03.103 CST [1028] LOG:  could not bind IPv4 address "127.0.0.1": Address already in use
2023-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 sockets
2023-03-17 21:08:03.106 CST [1028] LOG:  database system is shut down
pg_ctl: could not start server
Examine 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 use
2023-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 sockets
2023-03-18 17:18:34.723 CST [337] LOG:  database system is shut down
pg_ctl: could not start server
Examine 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 name
udp        0      0 127.0.0.1:323           0.0.0.0:*                           -
udp6       0      0 ::1:323                 :::*

pg_hba.conf enter image description here

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

in flag
Welcome to AskUbuntu. The section of the log that you posted is over three weeks old. Has PostgreSQL started since February 24th? If so, then some more recent error logs will be needed
JS3 avatar
mx flag
JS3
@matigo no, that's the only log that shows up. No recent error logs. And it's weird considering that postgresql is working and only after updating the Windows 11 just a few days ago, the problem occured. I tried to start the postgresql earlier and it just started the database server and no errors occurs. I wanted to figure out what's happening to prevent it from happening again.
JS3 avatar
mx flag
JS3
@matigo I had to go and close the computer. After a few hours, I opened it again, and the same problems occurs. I swear when I opened it earlier, I was able to start the postgresql database server with no problems
JS3 avatar
mx flag
JS3
@matigo My bad, I had to scroll down to check the latest recent logs. However, when I checked it, it has the same error output when I do the `sudo service postgresel start`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.