LoginSignup
8
11

More than 3 years have passed since last update.

Postgresqlに接続できない時の対処法

Last updated at Posted at 2020-02-12

開発環境

  • ubuntu(WSL)
  • Postgresql

解決策

サーバを起動させるために下記のコマンドを実行します。

sudo /etc/init.d/postgresql start

エラー内容

rails sしたら、以下のようになった。

PG::ConnectionBad (could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

pg_lsclustersで現状確認。
やっぱり、downしてる。

10  main    5432 down   postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log

下記のコマンドでクラスターを起動させる。
pg_ctlcluster 10 main start

install: cannot change owner and permissions of ‘/var/run/postgresql’: No such file or directory
Error: Could not create /var/run/postgresql/10-main.pg_stat_tmp: No such file or directory

サーバが起動していないことが原因だあるらしいので、下記のコマンドを実行させる。

sudo /etc/init.d/postgresql start

これで動きました。

参考文献

8
11
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
11