MacOSMontereyでPostgreSQLデータベースサーバーを起動しようとして接続するときにも同じ懸念がありました。
以下のコマンドを実行してPostgreSQLデータベースサーバーを再起動すると、次のようになります。
brew services restart PostgreSQL
再起動しますが、以下のコマンドを使用してPostgreSQLデータベースサーバーのステータスを確認しようとすると、エラーが発生します。
Name Status User File
mysql started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
nginx started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
postgresql error 256 root ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
これが私のために働いたものです:
まず、以下のコマンドを使用して、PostgreSQLデータベースサーバーのログファイルでエラーの原因を確認しました。
cat /usr/local/var/log/postgres.log
また
nano /usr/local/var/log/postgres.log
ログには次のエラーが表示されました。
"root" execution of the PostgreSQL server is not permitted.
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.
2022-01-25 19:01:06.051 WAT [29053] FATAL: database files are incompatible with server
2022-01-25 19:01:06.051 WAT [29053] DETAIL: The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.1.
ルート実行エラーの場合brew services
、次のコマンドを実行して、sudo
コマンドプレフィックスを使用して実行したときに混乱したファイルのアクセス許可を修正する必要がありました。MacOSユーザー名に置き換えyour-username
ます(私の場合、私のユーザー名はpromisepreston
:
# Stop postgresql
sudo brew services stop PostgreSQL
# In case service file is copied to ~/Library/LaunchAgents as well
brew services stop postgresql
# Fix permission of homebrew files
sudo chown -R your-username:admin $(brew --prefix)/*
データベースファイルはサーバーと互換性がないため、次のコマンドを実行して、バージョン13を使用して作成された既存のPostgreSQLデータファイルをコンピューター上の最新のPostgreSQLバージョンである14.1にアップグレードする必要がありました。
brew postgresql-upgrade-database
その後、PostgreSQLデータベースサーバーを再起動しました。
brew services restart PostgreSQL
次に、以下のコマンドを使用してステータスを確認します。
brew services list
次に、すべてが正常に機能していることを示す以下の出力を取得しました。
Name Status User File
mysql started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
nginx started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
postgresql started promisepreston ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
それで全部です。
参考資料: Brew Postgresqlは起動しますが、プロセスが実行されていません