无法在 WSL 上启动 postgresql Ubuntu
Can't start postgresql on WSL Ubuntu
我正在尝试在我的本地机器上启动我的 Postgresql 开发实例。我是 运行 Windows 10 Home(内部版本 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.
(postgres 相同)
$ 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 }'
8151
$ ps -ef | grep postmaster | awk '{print }'
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
我不知道从这里到哪里去。
服务停止只是告诉你服务停止了。不是说它停止了服务。
当您尝试查找 postmaster PID 时,您正在查找自己试图查找 postmaster PID 的 PID:
$ ps -ef | grep postmaster
me 300 116 0 15:36 tty3 00:00:00 grep postmaster
当您使用 curl 检查端口 5432 时,它告诉您它得到一个空回复。这意味着某些东西正在侦听端口 5432。您想要看到的是“连接失败”消息。
您是 运行 主机 Windows 机器上端口 5432 上的 postgresql 服务器吗?如果是这样,那将阻止您的 运行 进入 WSL 内部,并且您将无法从那里看到该过程。
请尝试将您的端口更改为 WSL 端的 5433。
为什么你不能使用 systemd 的答案很简单:WSL 从第一天开始就不支持它,直到 now.This 是一个已知问题,你可以参考 this issue opened in 2018 and this issue using a similar configuration of Windows and WSL 了解更多信息。
postgresql的问题是另一个已知问题。它已在 WSL 2 中修复。要在 WSL 1 上解决此问题, tells you to set fsync=on
and data_sync_retry=true
. An alternative way to solve the problem is to set fsync=off
. Refer to this issue 以获取有关 WSL 中 fsync 问题的更多信息。
我正在尝试在我的本地机器上启动我的 Postgresql 开发实例。我是 运行 Windows 10 Home(内部版本 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.
(postgres 相同)
$ 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 }'
8151
$ ps -ef | grep postmaster | awk '{print }'
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
我不知道从这里到哪里去。
服务停止只是告诉你服务停止了。不是说它停止了服务。
当您尝试查找 postmaster PID 时,您正在查找自己试图查找 postmaster PID 的 PID:
$ ps -ef | grep postmaster
me 300 116 0 15:36 tty3 00:00:00 grep postmaster
当您使用 curl 检查端口 5432 时,它告诉您它得到一个空回复。这意味着某些东西正在侦听端口 5432。您想要看到的是“连接失败”消息。
您是 运行 主机 Windows 机器上端口 5432 上的 postgresql 服务器吗?如果是这样,那将阻止您的 运行 进入 WSL 内部,并且您将无法从那里看到该过程。
请尝试将您的端口更改为 WSL 端的 5433。
为什么你不能使用 systemd 的答案很简单:WSL 从第一天开始就不支持它,直到 now.This 是一个已知问题,你可以参考 this issue opened in 2018 and this issue using a similar configuration of Windows and WSL 了解更多信息。
postgresql的问题是另一个已知问题。它已在 WSL 2 中修复。要在 WSL 1 上解决此问题,fsync=on
and data_sync_retry=true
. An alternative way to solve the problem is to set fsync=off
. Refer to this issue 以获取有关 WSL 中 fsync 问题的更多信息。