homebrewでインストールしたpostgreSQLの起動が失敗したので備忘録。
postgreSQLを起動する
postgreSQLはHomebrewでインストール済み。
$ brew services run postgresql@14
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
brew services run
で起動すると、無事に起動したように見えるが
psql
を実行しようとするとエラーになる。
$ psql -d postgres
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?
brew services
を確認するとコケている
$ brew services
Name Status User File
postgresql@14 error 256 nako ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist
ログを確認する
/opt/homebrew/var/log/postgresql@14.log
にログを吐いているようなので、そちらを見てみる。
$ view /opt/homebrew/var/log/postgresql@14.log
〜 略 〜
2023-09-09 21:31:23.054 JST [84735] FATAL: could not create shared memory segment: Cannot allocate memory
2023-09-09 21:31:23.054 JST [84735] DETAIL: Failed system call was shmget(key=5133258, size=56, 03600).
2023-09-09 21:31:23.054 JST [84735] HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMALL parameter. You might need to reconfigure the kernel with larger SHMALL.
The PostgreSQL documentation contains more information about shared memory configuration.
割り当てられているshared memoryが足りないらしい。
共有メモリの値を変更する
/etc/sysctl.conf
ファイルを作成し、設定を記述する。
$ sudo vim /etc/sysctl.conf
kern.sysv.shmmax=536870912
kern.sysv.shmmin=1
kern.sysv.shmmni=4096
kern.sysv.shmseg=1024
kern.sysv.shmall=131072
Macを再起動する
カーネルパラメータを変更したので再起動する。
参考にした記事