docs(inout): DB 생성 명령 — 비밀번호 URL 인코딩·.env 줄 붙음 방지·실제 연결 확인

비밀번호의 @ 등 특수문자가 DSN 을 깨뜨려 /inout/ 이 30초 뒤 500(PoolTimeout)이 된 운영 사례(2026-10-16).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 15:28:26 +09:00
parent e722d8ba1b
commit 65a1fd1991
+10 -4
View File
@@ -266,16 +266,22 @@ docker exec postgres-db psql -U postgres -d project_db -c "SELECT to_regclass('g
## 입출고 관리 DB 생성 (inout_db, 2026-10-16)
새 DB 라 기존 DB·데이터는 건드리지 않는다(초기화 SQL 은 멱등, DROP·TRUNCATE 없음). 비밀번호는 영문·숫자로(DSN 에 그대로 들어감).
새 DB 라 기존 DB·데이터는 건드리지 않는다(초기화 SQL 은 멱등, DROP·TRUNCATE 없음).
**비밀번호를 DSN 에 그대로 넣지 않는다** — `@`·`:`·`/`·`#`·`%` 같은 문자가 있으면 주소가 깨져 앱이 DB 를 못 찾고
(`failed to resolve host '…@postgres-db'`) 화면은 30초 뒤 500(PoolTimeout)이 된다(2026-10-16 실제 발생). 아래처럼 URL 인코딩해서 넣는다.
```bash
cd /opt/www/main && git pull
docker exec postgres-db psql -U postgres -lqt | cut -d| -f1 | grep -w inout_db || echo "inout_db 없음 — 새로 만든다"
read -s -p "inout_app password: " APP_PWD; echo
docker exec -i postgres-db psql -U postgres -v app_password="$APP_PWD" < scripts/sql/inout_db_init.sql
grep -q "^INOUT_DB_URL=" .env || echo "INOUT_DB_URL=postgresql://inout_app:${APP_PWD}@postgres-db:5432/inout_db" >> .env
docker compose up --build -d web
curl -s http://127.0.0.1:<web 포트>/inout/health # {"status":"ok"}
ENC=$(APP_PWD="$APP_PWD" python3 -c "import os,urllib.parse;print(urllib.parse.quote(os.environ['APP_PWD'],safe=''))")
# .env 끝에 줄바꿈이 없으면 앞 줄에 붙으므로 printf 로 새 줄부터, 이미 있으면 그 줄을 바꾼다
grep -q "^INOUT_DB_URL=" .env && sed -i "s|^INOUT_DB_URL=.*|INOUT_DB_URL=postgresql://inout_app:${ENC}@postgres-db:5432/inout_db|" .env \
|| printf '\nINOUT_DB_URL=postgresql://inout_app:%s@postgres-db:5432/inout_db\n' "$ENC" >> .env
docker compose up --build -d --force-recreate web
docker exec dbx-main python -c "import os,psycopg; psycopg.connect(os.environ['INOUT_DB_URL']).execute('select 1 from inout_roles limit 1'); print('DB OK')"
curl -s http://127.0.0.1:8080/inout/health # {"status":"ok"} — DSN 이 있다는 뜻일 뿐, 실제 연결 확인은 위 DB OK
```
그다음 ERP 관리자 화면에서 쓸 사람에게 **입출고 관리** 권한 → 입출고 관리 → 옵션에서 공장·발주 담당·입고 담당 지정.