postgresql - 无法在 WSL Ubuntu 上启动 postgresql
问题描述
我正在尝试在我的本地机器上启动我的 Postgresql 开发实例。我正在使用 WSL Ubuntu 18.04.4 LTS 运行 Windows 10 Home(内部版本 18363.900)。我尝试了很多事情:
$ 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 $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
我不知道从这里去哪里。
解决方案
为什么不能使用 systemd 的答案很简单:WSL 从第 1 天到现在都不支持它。这是一个已知问题,您可以参考2018 年打开的这个问题和使用 Windows 的类似配置的这个问题和 WSL了解更多信息。
postgresql 的问题是另一个已知问题。它已在 WSL 2 中修复。为了解决 WSL 1 上的这个问题,这篇文章告诉您设置fsync=on
和data_sync_retry=true
. 解决问题的另一种方法是设置fsync=off
. 有关 WSL 中 fsync 问题的更多信息,请参阅此问题。
推荐阅读
- python - Python 神经网络中的形状问题
- nuxt.js - 为什么`nuxt generate`把commons.js文件放到dist/node_modules/
- javascript - 未解析编码查询参数的角度路由
- android - 我们如何将所有应用程序的流量路由到 Android 上的 SOCKS 服务器
- angular - 我可以获得角度材料表的标题单元格的索引吗?
- go - 使用 Go-bindata-assetfs 构建问题:找不到命令
- regexp-replace - Replacing GUID in Kusto
- python - 在 python3 上安装 socketio 模块似乎正在破坏 pip
- asp.net-mvc - 将 ASP.NET MVC 网站部署到 PLESK 时的连接字符串问题
- python-3.x - 使用 psycopg2 连接到 psql docker 容器但无法读取或写入