这是我的wsl -l -v
NAME STATE VERSION
* Ubuntu Stopped 2
lsb_release -a
输出:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS
Release: 22.04
Codename: jammy
pg_config --version
输出:
PostgreSQL 14.6 (Ubuntu 14.6-0ubuntu0.22.04.1)
前一天我遇到了这个问题,我无法启动或重新启动 postgresql,并且会输出以下内容:
sudo service postgresql start
并sudo service postgresql restart
输出:
* 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.
我检查日志输出并显示以下内容:
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.
我尝试过这个:sudo service postgresql status
但它会显示主机已关闭。并且sudo service postgresql stop
还会停止服务器。
ps -ef | grep postgres
输出:
ann 211 60 0 20:27 pts/0 00:00:00 grep --color=auto postgres
我也已经从此文件更改了本地主机sudo nano /etc/postgresql/14/main/postgresql.conf
:
从listen_addresses: localhost
到:listen_addresses = '*'
我已经检查过它是否正在监听Port: 5432
。我甚至尝试过重启电脑,但还是不行。我在更新 Windows 11 后开始收到这些错误。
前一天已经发生过这种情况,但是,经过几次尝试后,只需从 Powershell 退出 Ubuntu 终端,它就会启动 postgresql。昨天,当我尝试时,所有这些错误都出现了。现在,当我尝试使用启动 postgresql 时sudo service postgresql start
,postgresql 数据库服务器在主端口 5432 上启动它没有任何问题。我正在使用它来开发 Ruby on Rails 应用程序。
sudo netstat -tulpn
输出:
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 :::*
Stackoverflow 上也有这个问题:https://stackoverflow.com/questions/75773133/sometimes-postgresql-would-not-start-but-the-next-day-it-would-start-again