MacでPostgreSQLがうまく自動起動しなくなった
OSを新しくしたせいなのか、突然PostgreSQLの自動起動でエラーが出るようになりました。 一度直ったのですが、再度、再起動時に同じエラーが出ましたので、メモします。
エラー内容
❯ php artisan serve
Illuminate\Database\QueryException
SQLSTATE[08006] [7] connection to server at "127.0.0.1", port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? (Connection: pgsql, SQL:select * from "settings" limit 1)❯ brew services listName Status User Filemailpit nonemysql nonephp noneredis started dev ~/Library/LaunchAgents/homebrew.mxcl.redis.plist下記のように再起動しても変わらず上記のままです。
brew services stop postgresql@16brew services start postgresql@16plistの内容は下記でした。
❯ cat ~/Library/LaunchAgents/[email protected]<?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>EnvironmentVariables</key> <dict> <key>LC_ALL</key> <string>C</string> </dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>homebrew.mxcl.postgresql@16</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@16/bin/postgres</string> <string>-D</string> <string>/opt/homebrew/var/postgresql@16</string> </array> <key>RunAtLoad</key> <true/> <key>StandardErrorPath</key> <string>/opt/homebrew/var/log/[email protected]</string> <key>StandardOutPath</key> <string>/opt/homebrew/var/log/[email protected]</string> <key>WorkingDirectory</key> <string>/opt/homebrew</string></dict></plist>ログを見てみます。
2024-10-15 11:19:30.964 JST [8382] FATAL: lock file "postmaster.pid" already exists2024-10-15 11:19:30.964 JST [8382] HINT: Is another postmaster (PID 754) running in data directory "/opt/homebrew/var/postgresql@16"?ここに同じエラーについて書かれていました。postgresの二重起動を防止するもので、何らかの原因で残ってしまうものが、よく残るようになってしまったのでしょうか? https://www.fujitsu.com/jp/about/faq/sfw-enterprisepostgres/20163.html — www.fujitsu.com
とりあえず、消してみます。
rm /opt/homebrew/var/postgresql@16/postmaster.pidおー直りました。
❯ brew services listName Status User Filemailpit nonemysql nonephp noneredis started dev ~/Library/LaunchAgents/homebrew.mxcl.redis.plistこれが続くのは嫌ですが、とりあえず、postmaster.pidを削除したら良いのかなと思いました。