# instinct: shadow本番のpostgresスーパーユーザPWローテーションはアプリ無影響で安全。アプリはubuntuソケット(peer)接続でpostgresPWを使わない。pg_hbaは127.0.0.1 trust
shadow本番の **postgres スーパーユーザPWローテーションはアプリに無影響で安全**に実行できる(2026-06-07 実証・#248 SEC-01)。
**Why:** アプリ(vvv-api/scheduler-tick/全ボット)のDB接続は **`ubuntu` ユーザのUnixソケット接続**(`host=/var/run/postgresql dbname=vvv_prod user=ubuntu`・パスワードなし)。postgresスーパーユーザのPWはアプリ認証に**一切使われていない**。バックアップcronも `pg_dump -U ubuntu`(PW不要)。だからpostgres PWを変えてもアプリは落ちない。
**How to apply(ローテーション手順):**
1. 影響範囲確認: `pg_hba.conf`(`local all postgres peer` / `host postgres all 127.0.0.1/32 trust`)・各.envのDATABASE_URL(vvvはubuntuソケットでpostgres:PW行はコメントアウト)・cron(`pg_dump -U ubuntu`)
2. `ubuntu` は非スーパーユーザ(usesuper=f)なので `ALTER USER postgres` 不可 → **`sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '...'"`** で実行(peer認証)
3. 新PWは `python3 -c "import secrets,string; print(''.join(secrets.choice(string.ascii_letters+string.digits) for _ in range(32)))"`(URL安全な記号なし32文字)
4. `.env.master`(権限600)・`.env.arcana` の `postgres:OLD@` を新値に置換。一時保存PWは `shred -u` で削除
5. 確認: `psql "host=/var/run/postgresql dbname=vvv_prod user=ubuntu"` でアプリ接続維持・vvv/anime 200・PM2 online
**⚠️ pg_hba の `host postgres all 127.0.0.1/32 trust`** は127.0.0.1からPW不問でpostgres接続を許す緩い設定。主防御線はpeer/socketだが、最小権限なら scram-sha-256 化を検討(本番影響を慎重評価のうえ)。
関連: vvv-bots#248(SEC-01 Critical・解決済) / [[instinct_env_symlink_rm_danger]]
---
(migrated from local memory/instinct_postgres_pw_rotation_socket_safe.md)
instinct: shadow本番のpostgresスーパーユーザPWローテーションはアプリ無影響で安全。アプリはubuntuソケット(peer)接続でpostgresPWを使わない。pg_hbaは127.0.0.1 trust