8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Postgresqlに接続できなくなった時の対処法

Posted at

環境

  • macOS Catalina 10.15.6
  • postgres (PostgreSQL) 12.4

内容

postgresqlサーバーに接続しようとしたら次のようなエラーが出てきたので、その時の解決方法を覚え書き
この記事が誰かの助けになれば幸いです

psql: error: could not connect to server: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

解決までのプロセス

次のコマンドでログを確認

$ postgres -D /usr/local/var/postgres

すると次のようなエラーが

FATAL:  could not create lock file "/tmp/.s.PGSQL.5432.lock": Permission denied

権限がないようなので次のコマンドで/tmpに適切な権限を付与

$ chmod 1777 /tmp

再びログを確認したところ次のような内容がありました

FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 3473) running in data directory "/usr/local/var/postgres"?

どうやら起動時に生成されるlock fileがすでに存在しているようなので、それを削除

$ rm /usr/local/var/postgres/postmaster.pid

次のコマンドで動作確認

$ psql -l

無事にデータベース一覧が表示されました!

おそらく、何かしらの理由でpostgresが正しく終了しなかったことが原因ではないかと考えられます

参考記事

https://stackoverflow.com/questions/33942967/unable-to-start-postgres-server-because-of-permission-denied-on-lock-file
https://qiita.com/great084/items/98c83364f246473249c4

8
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?