我正在尝试在本地计算机上启动我的Postgresql开发实例。 我正在运行Windows 10家庭版(版本18363.900),带有WSL Ubuntu 18.04.4 LTS。 我已经尝试了很多方法:
$ sudo systemctl start postgresql
System has not been booted with systemd as init system (PID 1). Can't operate.
(与重新启动相同)
$ sudo /etc/init.d/postgresql start
* Starting PostgreSQL 10 database server * Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-10-main.log -s -o -c config_file="/etc/postgresql/10/main/postgresql.conf" exited with status 1:
2020-06-16 20:36:37.334 PDT [8106] LOG: could not bind IPv4 address "127.0.0.1": Permission denied
2020-06-16 20:36:37.334 PDT [8106] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-06-16 20:36:37.335 PDT [8106] WARNING: could not create listen socket for "localhost"
2020-06-16 20:36:37.335 PDT [8106] FATAL: could not create any TCP/IP sockets
2020-06-16 20:36:37.335 PDT [8106] LOG: database system is shut down
pg_ctl: could not start server
Examine the log output.
(同样适用于PostgreSQL)
$ sudo service postgresql start
* Starting PostgreSQL 10 database server * Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgresql/postgresql-10-main.log -s -o -c config_file="/etc/postgresql/10/main/postgresql.conf" exited with status 1:
2020-06-16 20:37:19.907 PDT [8140] LOG: could not bind IPv4 address "127.0.0.1": Permission denied
2020-06-16 20:37:19.907 PDT [8140] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2020-06-16 20:37:19.907 PDT [8140] WARNING: could not create listen socket for "localhost"
2020-06-16 20:37:19.907 PDT [8140] FATAL: could not create any TCP/IP sockets
2020-06-16 20:37:19.908 PDT [8140] LOG: database system is shut down
pg_ctl: could not start server
Examine the log output.
以防万一
$ sudo service postgres start
postgres: unrecognized service
服务对我没有任何帮助。
当然,停止功能按预期工作:
$ sudo service postgresql stop
* Stopping PostgreSQL 10 database server [ OK ]
但是
sudo service postgresql restart
给出的结果与开始相同。
状态还给我一个预期的结果:
$ sudo service postgresql status
10/main (port 5432): down
我的 /etc/hosts 文件内容如下
# This file is automatically generated by WSL based on the Windows hosts file:
# %WINDIR%\System32\drivers\etc\hosts. Modifications to this file will be overwritten.
127.0.0.1 localhost
127.0.1.1 DESKTOP-LKMEB17.localdomain DESKTOP-LKMEB17
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
这让我相信更改/etc/hosts文件不会有所帮助。
我尝试杀死postmaster进程,但每次尝试时其pid都在变化,这让我相信它正在自旋。
$ ps -ef | grep postmaster | awk '{print $2}'
8151
$ ps -ef | grep postmaster | awk '{print $2}'
8154
在黑暗中盲目地杀死进程也行不通,这会让人感到困惑。
$ ps -ef | grep postmaster
me 298 116 0 15:35 tty3 00:00:00 grep postmaster
$ kill -9 300
-bash: kill: (300) - No such process
$ kill -9 298
-bash: kill: (298) - No such process
$ kill -9 299
-bash: kill: (299) - No such process
$ kill -9 301
-bash: kill: (301) - No such process
$ ps -ef | grep postmaster
me 300 116 0 15:36 tty3 00:00:00 grep postmaster
这很奇怪——我杀掉了pid 300。
令人惊讶的是,似乎没有任何东西在监听localhost:5432。
$ curl localhost:5432
curl: (52) Empty reply from server
我不确定接下来该怎么做。