LoginSignup
4
0

More than 1 year has passed since last update.

PostgreSQL接続時に「psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed:」エラーが出た時の解消

Last updated at Posted at 2023-02-08

出力されたエラーは下記の2つ

  1. psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL: role "ユーザー名" does not exist
  2. 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?

久々にPostgreSQLを使用することがあって、下記で接続しようとすると、上記の1番目のエラーが出力されてしまった。。。

psql -U ユーザー名

DB一覧を確認しようとしたところ、上記の2番目のエラーが出力されてしまった。。。

psql -l

一旦Postgresがインストールされているか確認すると、インストールされている

~ $ psql --version
psql (PostgreSQL) 14.6 (Homebrew)

起動できるかを確認すると起動できる

~ $ brew services start postgresql
Warning: Use postgresql@14 instead of deprecated postgresql
==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)

と思ったら起動できていない。。。

~ $ brew services list
postgresql@14 error

cd /usr/local/var/log/postgresql@14.logでログ内容を確認

Reason: tried: '/usr/local/opt/icu4c/lib/libicui18n.72.dylib' (no such file)

以下のコマンドでicu4cのバージョンを確認したところ69系になっていた

brew info icu4c

icu4c72系にするためにHomebrewをアップグレードしてみる

brew upgrade icu4c

再度、icu4cのバージョンを確認すると72系に変更されていた

brew info icu4c

再度、DB一覧を確認したところ確認できた(※一覧はサンプルです)

~ $ psql -l
                                          List of databases
      Name       |      Owner      | Encoding | Collate | Ctype |          Access privileges
-----------------+-----------------+----------+---------+-------+-------------------------------------
 postgres        | postgres        | UTF8     | C       | C     |
(7 rows)

ユーザー名で接続してみる(※上記の「Owner」名で接続)と、接続できた

~ $ psql -U postgres
psql (14.6 (Homebrew))
Type "help" for help.

postgres=#

Roleの一覧を確認すると登録しているロール名を確認できた

postgres=# \du
                                      List of roles
    Role name    |                         Attributes                         | Member of
-----------------+------------------------------------------------------------+-----------
 postgres        | Superuser, Create role, Create DB                          | {}
 

もっとスマートなやり方あると思いますが、自分はこれで解決しました。
精進します。。。

参考:

4
0
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
4
0