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.

Postgresのデータベース作成時のエラー対処

Posted at

概要

  • 下記のコマンドを実行すると、エラーが出てしまう。
$ docker-compose exec workspace psql -U default -h postgres
psql: error: could not translate host name "postgres" to address: Name or service not known
  • docker-compose upでコンテナを作成している。
  • しかし、docker-compose psするとpostgresの部分の「State」が「Exit 1」となっている。
$ docker-compose up -d workspace php-fpm nginx postgres
Creating network "laravel-app_default" with the default driver
Creating laravel-app_workspace_1 ... done
Creating laravel-app_php-fpm_1   ... done
Creating laravel-app_nginx_1     ... done
Creating laravel-app_postgres_1  ... done
$ docker-compose ps
Name                        Command               State                     Ports                  
------------------------------------------------------------------------------------------------------------
laravel-app_nginx_1       /docker-entrypoint.sh ngin ...   Up       0.0.0.0:80->80/tcp,:::80->80/tcp        
laravel-app_php-fpm_1     docker-php-entrypoint php-fpm    Up       0.0.0.0:9001->9000/tcp,:::9001->9000/tcp
laravel-app_postgres_1    docker-entrypoint.sh postgres    Exit 1                                           
laravel-app_workspace_1   docker-php-entrypoint php-fpm    Up       9000/tcp

原因

下記のログで「pg_tblspc」、「pg_replslot」がないので開けないと言われておりますが、正直わかってないです。引き続き調査しておりますが、分かり次第更新したいと思っております。。

解決法(※暫定処置)

docker-compose logsでエラーの内容を確認する。

$ docker-compose logs
postgres_1   |
postgres_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres_1   |
postgres_1   | 2022-02-27 05:31:40.430 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1   | 2022-02-27 05:31:40.430 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1   | 2022-02-27 05:31:40.433 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres_1   | 2022-02-27 05:31:40.460 UTC [1] LOG:  could not open directory "pg_tblspc": No such file or directory
postgres_1   | 2022-02-27 05:31:40.468 UTC [23] LOG:  database system shutdown was interrupted; last known up at 2022-02-23 11:11:08 UTC
postgres_1   | 2022-02-27 05:31:42.871 UTC [23] LOG:  could not open directory "pg_tblspc": No such file or directory
postgres_1   | 2022-02-27 05:31:42.881 UTC [23] LOG:  could not open directory "pg_tblspc": No such file or directory
postgres_1   | 2022-02-27 05:31:42.882 UTC [23] FATAL:  could not open directory "pg_replslot": No such file or directory
postgres_1   | 2022-02-27 05:31:42.883 UTC [1] LOG:  startup process (PID 23) exited with exit code 1
postgres_1   | 2022-02-27 05:31:42.883 UTC [1] LOG:  aborting startup due to startup process failure
postgres_1   | 2022-02-27 05:31:42.888 UTC [1] LOG:  database system is shut down
  1. プロジェクト配下のlaravel-app/dataディレクトリ を削除する。
  2. docker-compose down --rmi all --volumes --remove-orphansコマンドでコンテナを一掃する。
  3. 再度docker-compose up -d workspace php-fpm nginx postgresを実行でコンテナを再作成する。
  4. docker-compose psで再度「State」を確認する。
$ docker-compose ps
Name                        Command               State                    Ports                  
-----------------------------------------------------------------------------------------------------------
laravel-app_nginx_1       /docker-entrypoint.sh ngin ...   Up      0.0.0.0:80->80/tcp,:::80->80/tcp        
laravel-app_php-fpm_1     docker-php-entrypoint php-fpm    Up      0.0.0.0:9001->9000/tcp,:::9001->9000/tcp
laravel-app_postgres_1    docker-entrypoint.sh postgres    Up      0.0.0.0:5432->5432/tcp,:::5432->5432/tcp
laravel-app_workspace_1   docker-php-entrypoint php-fpm    Up      9000/tcp
  • docker-compose exec workspace psql -U default -h postgresを再度実行で作成できた。
1
0
1

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?