make docker-postgres fails on first run: "the database system is shutting down"

オープン 初心者向け
#1,242 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
bash, docker, postgresql
領域
devops

調査の方向性

競合状態は Makefile の docker-postgres ターゲット、62行目付近で発生しています。ここでは cre-postgres コンテナ内で pg_isready -U cre -d cre が実行されています。issue が引用している docker-entrypoint.sh の動作を読み、新しいコンテナを起動して準備状態をポーリングすることで再現してください。-h 127.0.0.1 をこのチェックに追加し、実際の TCP サーバーが起動した後にのみ成功するようにし、新しいコンテナでの繰り返し実行が psql の段階で失敗しなくなることを確認すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Problem

I cloned the repo and ran make install for the first time (staging branch, commit d9514e52).
It failed at the Postgres step:

psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  the database system is shutting down
make[1]: *** [Makefile:36: docker-postgres] Error 2
[admin-local] ERROR: make docker-postgres failed
make: *** [Makefile:184: install] Error 1

When I ran make install again, it worked.

Cause

When the Postgres container starts for the first time, it does this:

  1. Starts a temporary server (only on the Unix socket, not TCP)
  2. Creates the user and database
  3. Stops the temporary server
  4. Starts the real server

The docker-postgres target checks with pg_isready -U cre -d cre. This checks the Unix socket, so it can say "ready" during step 1.
Then psql runs during step 3 and fails.

From docker-entrypoint.sh in the pgvector/pgvector:pg16 image:

# does not listen on external TCP/IP and waits until start finishes
set -- "$@" -c listen_addresses='' -p "${PGPORT:-5432}"

Steps to reproduce

I used a separate test container (cre-pg-test) so my real database was not affected.
Each run starts a fresh container and does the same check + psql command as the Makefile.

Check Runs Failed
pg_isready -U cre -d cre (current) 20 1
pg_isready -h 127.0.0.1 -U cre -d cre 20 0

The failed run gave the same error as above. It depends on timing, so it does not fail every time.

Test script
#!/bin/bash
# Usage: ./pg_race_test.sh old|fix [runs]
MODE="$1"; RUNS="${2:-5}"; fails=0
for run in $(seq 1 "$RUNS"); do
  docker rm -f cre-pg-test >/dev/null 2>&1
  docker run -d --name cre-pg-test -e POSTGRES_PASSWORD=password -e POSTGRES_USER=cre -e POSTGRES_DB=cre pgvector/pgvector:pg16 >/dev/null
  for i in $(seq 1 30); do
    if [ "$MODE" = "fix" ]; then
      docker exec cre-pg-test pg_isready -h 127.0.0.1 -U cre -d cre >/dev/null 2>&1 && break
    else
      docker exec cre-pg-test pg_isready -U cre -d cre >/dev/null 2>&1 && break
    fi
    sleep 1
  done
  if out=$(docker exec cre-pg-test psql -U cre -d cre -c "CREATE EXTENSION IF NOT EXISTS vector;" 2>&1); then
    echo "run $run: OK"
  else
    echo "run $run: FAILED -> $(echo "$out" | tail -1)"; fails=$((fails+1))
  fi
done
docker rm -f cre-pg-test >/dev/null 2>&1
echo "== mode=$MODE : $fails / $RUNS failed =="

Suggested fix

Add -h 127.0.0.1 to the pg_isready check (Makefile line 62, same on main and staging):

-		if docker exec cre-postgres pg_isready -U cre -d cre >/dev/null 2>&1; then ready=1; break; fi; \
+		if docker exec cre-postgres pg_isready -h 127.0.0.1 -U cre -d cre >/dev/null 2>&1; then ready=1; break; fi; \

The temporary server does not listen on TCP, so this check only passes when the real server is up.

Environment

  • Windows 11 + WSL2 (Ubuntu 24.04)
  • Docker Desktop 28.4.0
  • pgvector/pgvector:pg16

I can open a PR for this. Should it target main or staging?

主要言語
Python
スター
216
フォーク
173
平均マージ
1日 21時間
マージ済み PR(30日)
21

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

OWASP/OpenCRE のほかの issue

OWASP/OpenCRE の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。