1
0

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] psql: 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"? エラーが発生した

Posted at

環境

Amazon linux2
postgre 11.5

起きたエラー

postgreにログインしようとしたところ以下のようなエラーが発生

$ psql -U postgres
psql: 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"?

解決策を探る

エラーを検索してみたところサーバーが起動していないことが原因の場合があるらしい、以下のコマンドで起動する

$ sudo /etc/init.d/postgresql start

そしてまたログインを実行
しかし、ログインできず、、

次にこっちのコマンドで起動してみました。
するとエラー内容が表示!

$ sudo -u postgres postgres -D /var/lib/pgsql/data
 LOG:  skipping missing configuration file "/var/lib/pgsql/data/postgresql.auto.conf"
2021-04-23 07:29:45.763 UTC [10472] FATAL:  データベースファイルがサーバと互換性がありません
2021-04-23 07:29:45.763 UTC [10472] 詳細:  データディレクトリはPostgreSQLバージョン9.2で初期化されましたが、これはバージョン11.5とは互換性がありません

なるほど、理解した!
実は最初に入っていたversionが9.2でその時にpostgresを初期化してしまいその後11.5にアップデートしました。
9.2で作ったサーバーでは11.5では動かせないってことだったんですね。
ここまで解れば大丈夫です

/var/lib/pgsql/dataフォルダを削除して初期化します。

$ sudo rm -fr /var/lib/pgsql/data
$ sudo postgresql-setup --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

初期化完了!
postgresにログインします。

$ sudo su - postgres
$ -bash-4.2$ 

ログイン成功!

結論

PostgreSQLバージョン9.2は古すぎて、それ以降のversionと互換性がない。
この場合は一旦/var/lib/pgsql/dataフォルダを削除して、最新バージョンで初期化しなければならない。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?