开始服务 postgresql@14 失败

发生在世界各地的观察结果。

$ brew services start postgresql@14

Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/my_pc/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.

维修过程

首先,让我们查看一下/Users/my_pc/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist。

$ cat /Users/my_pc/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>homebrew.mxcl.postgresql@14</string>
	<key>LimitLoadToSessionType</key>
	<array>
		<string>Aqua</string>
		<string>Background</string>
		<string>LoginWindow</string>
		<string>StandardIO</string>
		<string>System</string>
	</array>
	<key>ProgramArguments</key>
	<array>
		<string>/opt/homebrew/opt/postgresql@14/bin/postgres</string>
		<string>-D</string>
		<string>/opt/homebrew/var/postgresql@14</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/opt/homebrew/var/log/postgresql@14.log</string>
	<key>StandardOutPath</key>
	<string>/opt/homebrew/var/log/postgresql@14.log</string>
	<key>WorkingDirectory</key>
	<string>/opt/homebrew</string>
</dict>
</plist>

由于标准错误路径为/opt/homebrew/var/log/postgresql@14.log,因此让我们来查看它。

$ cat /opt/homebrew/var/log/postgresql@14.log

2022-10-31 14:44:29.831 JST [13709] LOG:  database system is shut down
2022-10-31 14:44:39.881 JST [13962] LOG:  starting PostgreSQL 14.5 (Homebrew) on aarch64-apple-darwin21.6.0, compiled by Apple clang version 14.0.0 (clang-1400.0.29.102), 64-bit
2022-10-31 14:44:39.883 JST [13962] LOG:  listening on IPv6 address "::1", port 5432
2022-10-31 14:44:39.883 JST [13962] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2022-10-31 14:44:39.883 JST [13962] FATAL:  could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied

因为似乎发生了查看 /tmp/.s.PGSQL.5432.lock 文件的权限错误,所以尝试使用 sudo 命令来执行。

$ sudo brew services start postgresql@14                                      

Warning: Taking root:admin ownership of some postgresql@14 paths:
  /opt/homebrew/Cellar/postgresql@14/14.8/bin
  /opt/homebrew/Cellar/postgresql@14/14.8/bin/postgres
  /opt/homebrew/opt/postgresql@14
  /opt/homebrew/var/homebrew/linked/postgresql@14
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
Warning: postgresql@14 must be run as non-root to start at user login!
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)

查看brew services时发现它失败了。
重新查看日志后,

$ cat /opt/homebrew/var/log/postgresql@14.log

The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.
"root" execution of the PostgreSQL server is not permitted.

似乎不能使用sudo命令启动postgresql。

一旦我手动删除了/tmp/.s.PGSQL.5432.lock。

$ rm /tmp/.s.PGSQL.5432.lock             

override rw------- postgres/wheel for /tmp/.s.PGSQL.5432.lock? y

这次重新运行的话就成功了。?

$ brew services start postgresql@14     
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
$ brew services                   
Name          Status  User File
postgresql@14 started root 
广告
将在 10 秒后关闭
bannerAds