mental-appointment PG16 Clone リハーサル手順書(Global 削除経路の素振り)
本番 mental-appointment(Aurora Global Database・単一リージョン・us-east-1)の PG16 化に先立ち、本番クラスタの Clone(copy-on-write) に対して「Global 化 → Global 削除 → 標準 Blue/Green」の本番と同じ経路を素振りするテスト手順。本体
mental-appointmentは一切操作しない(Clone のみ)。
- 本番手順書(正本・固有値):
preflight.md(§0 アーキ/§6 CPG 設計/§9 検証)/汎用:procedure-clone-rehearsal.md- 役割分担: 本書=Global 削除経路+BG 作成+Switchover 書込断の実測(staging は非-Global で素振り不可なため Clone で担保)。アプリ互換 E2E は
staging.md(#17391・別途作成予定) が担当。- 実施 issue: #17390(手順書)/ #17282(リハ実施)/親 #17280
前提・対象
- profile
production-admin/ region us-east-1 / acct 967691968827(本番と同一アカウント。Clone も本番アカウント内に作る) - source(無操作): cluster
mental-appointment(Aurora PG 13.23・Globalmental-appointment・Writermental-appointment-0+Readermental-appointment-1・db.r7g.large ×2・約 2.5GB)- subnet group
mental-appointment-subnet/ DB SGsg-02088474cf99248f4/ 現 CPGdefault.aurora-postgresql13
- subnet group
- Clone 名(
CL):mental-appointment-bgtest-blue/ 使い捨て Global:g-mental-appointment-bgtest/ BG 名:mental-appointment-bgtest - target engine: 16.14(
preflight.md§9-A・実施直前にdescribe-db-engine-versionsで再確認) - ★ 破壊的操作はすべて Clone(
mental-appointment-bgtest-*)に対してのみ。本体mental-appointment/mental-appointment-0/-1には打たない(identifier を都度目視確認)。
事前ゲート(このリハの本当の前提)
- [ ] source PG13 custom CPG(
logical_replication=1) が作成済み(mental-appointment-pg13-bg。現状 default のため必須)。→ #17388/#17389・preflight.md§6 - [ ] target PG16 CPG(
mental-appointment-pg16・pgaudit 等を source と整合)が作成済み。eligibility 用 CPG を流用しない(BG 作成がINVALID_CONFIGURATIONで失敗する・#13732 の教訓)。 - [ ] 外部論理レプリケーション無し(
publications=0を preflight で確認済=BG のexternal replication失敗リスク無し。dr-work-record #13732 の型を回避できる)。
Writer/Reader の向きに注意:mental-appointment は
-0=Writer /-1=Reader(dr-work-record とは逆)。以下の instance 作成順・再起動順はこれに合わせている。
手順(Clone で「Global 化 → 削除 → 標準 BG」)
export AWS_PROFILE=production-admin ; R=us-east-1
CL=mental-appointment-bgtest-blue # リハで操作する clone
GTEST=g-mental-appointment-bgtest # 本番の Global 構成を再現する使い捨て global
# (1) Clone 作成(copy-on-write)+ Writer/Reader 作成(本体 mental-appointment は無操作)
# ※ restore-...-to-point-in-time は --engine 不可(source から継承)。SG/subnet は source と同一。
aws rds restore-db-cluster-to-point-in-time --region $R \
--source-db-cluster-identifier mental-appointment \
--db-cluster-identifier $CL \
--restore-type copy-on-write --use-latest-restorable-time \
--db-subnet-group-name mental-appointment-subnet \
--vpc-security-group-ids sg-02088474cf99248f4
aws rds wait db-cluster-available --region $R --db-cluster-identifier $CL
# 本番相当に Writer+Reader の2台(class は source と同じ db.r7g.large)。★-0 を先に作る=Writer
aws rds create-db-instance --region $R --db-instance-identifier ${CL}-0 \
--db-cluster-identifier $CL --engine aurora-postgresql --db-instance-class db.r7g.large # Writer
aws rds wait db-instance-available --region $R --db-instance-identifier ${CL}-0
aws rds create-db-instance --region $R --db-instance-identifier ${CL}-1 \
--db-cluster-identifier $CL --engine aurora-postgresql --db-instance-class db.r7g.large # Reader
aws rds wait db-instance-available --region $R --db-instance-identifier ${CL}-1
# ※ 手順素振りだけなら db.t3.medium でも可(所要/性能を本番相当にするなら r7g.large 維持)
# (2) Clone を Global 化(本番の "Global メンバー" 状態を再現)
CL_ARN=$(aws rds describe-db-clusters --region $R --db-cluster-identifier $CL --query 'DBClusters[0].DBClusterArn' --output text)
aws rds create-global-cluster --region $R --global-cluster-identifier $GTEST --source-db-cluster-identifier "$CL_ARN"
# (3) ★Global 削除で standalone 化(本番と同じ経路)
aws rds remove-from-global-cluster --region $R --global-cluster-identifier $GTEST --db-cluster-identifier "$CL_ARN"
aws rds wait db-cluster-available --region $R --db-cluster-identifier $CL
aws rds delete-global-cluster --region $R --global-cluster-identifier $GTEST
# (4) source(PG13) custom Cluster PG(logical=1) を clone に付替 → Reader→Writer 再起動
aws rds modify-db-cluster --region $R --db-cluster-identifier $CL \
--db-cluster-parameter-group-name mental-appointment-pg13-bg --apply-immediately
aws rds wait db-cluster-available --region $R --db-cluster-identifier $CL
# logical_replication は static → 反映に再起動が必要。Reader→Writer の順で1台ずつ(AWS推奨・安全側)
aws rds reboot-db-instance --region $R --db-instance-identifier ${CL}-1 # Reader を先に
aws rds wait db-instance-available --region $R --db-instance-identifier ${CL}-1
aws rds reboot-db-instance --region $R --db-instance-identifier ${CL}-0 # Writer(瞬断)
aws rds wait db-instance-available --region $R --db-instance-identifier ${CL}-0
# 踏み台(i-09384db1d690bcfd0) psql で SHOW rds.logical_replication;=on / SHOW wal_sender_timeout;=0 を確認
# (4.5) ★BG 作成前に blue(clone) で pg_stat_statements 拡張を作成(Green は同期中 read-only で後から不可)
# 本番 source は default CPG(pg_stat_statements 未 preload)のため clone にも拡張が無い可能性大。
# (4) で pg13-bg(shared_preload_libraries=pgaudit,pg_stat_statements) 付替+reboot 済 → 踏み台 psql:
# CREATE EXTENSION IF NOT EXISTS pg_stat_statements; -- \dx で installed 確認(pgaudit は preload のみで拡張不要)
# BG 作成前チェック(clone に対して): available / global=null / CPG in-sync /
# SHOW rds.logical_replication=on / 長時間tx=0 / SHOW default_transaction_read_only=off
# (5) 標準 BG 作成(非-Global・standalone クラスタに対して・target PG16 は cluster/instance 両方指定)
aws rds create-blue-green-deployment --region $R \
--blue-green-deployment-name mental-appointment-bgtest \
--source "$CL_ARN" \
--target-engine-version 16.14 \
--target-db-cluster-parameter-group-name mental-appointment-pg16 \
--target-db-parameter-group-name mental-appointment-pg16
# (6) Green 検証(generic 手順 6)→ ★Switchover 前ゲート(下記 GO/NO-GO)→ Switchover(手順 7)→ 事後(手順 8)
# (7) 後始末(全削除・課金停止): BG レコード削除 → instance → cluster 削除(global は (3) で削除済)★Switchover 前ゲート(GO/NO-GO・clone でも本番同手順を素振り)
BG describe だけで済ませず green に実接続して検証する(本番 production.md / dr-work-record staging §F-4-Gate と統一):
- [ ] BG
Status=AVAILABLE/StatusDetails=null(Replication degraded でない) - [ ]
SwitchoverDetailsの各リソースが AVAILABLE(cluster・instance とも) - [ ] green member CPG が
in-sync(DBClusterParameterGroupStatus。pending-reboot なら green を reboot) - [ ] replica lag ≈ 0(
OldestReplicationSlotLag/AuroraReplicaLag) - [ ] 長時間トランザクション = 0(blue で
pg_stat_activity…state<>'idle' AND xact_start IS NOT NULL) - [ ] ★Green 接続検証(green cluster endpoint へ踏み台 psql):
SHOW server_version=16.14 / 主要テーブル件数が blue と一致(appointments/patients/appointment_patient_histories等)/default_transaction_read_only=on(同期中は正常)/SHOW shared_preload_librariesに pgaudit が含まれる - [ ] ★必須:green で
SET default_transaction_read_only=off;セッションから 全テーブルANALYZE VERBOSE;(Switchover 前・切替直後の性能事故防止)。※2026-08-17 clone 実測=全16テーブル 27.2秒で完了。 - [ ] (clone では任意)手動スナップショットの素振り:
aws rds create-db-cluster-snapshot(本番はロールバック保険として必須・production.md)
※ clone は使い捨てのため Terraform 整合(tfvars の engine_version 更新)は不要(本番/staging のみの事後作業)。事後は Switchover→
ALTER EXTENSION pg_stat_statements UPDATE;の確認まで。
検証チェックリスト(リハで確認すること)
- [ ]
remove-from-global-clusterが無停止(クラスタ稼働継続)で通るか(single-region・secondary 無しで低リスク想定) - [ ]
delete-global-cluster後、standalone として BG 作成できるか - [ ] BG 作成前に blue で
CREATE EXTENSION pg_stat_statements((4.5)・Green は同期中 read-only で後付け不可) - [ ] BG 作成が CPG 不整合 / 外部レプリで失敗しないか(
mental-appointment-pg16が source と整合・publications=0) - [ ] Green が PG16(16.14)・論理レプリ同期しているか(generic 手順 6)
- [ ] Switchover 前ゲート(GO/NO-GO)を全て満たす(上記チェックリスト・green 実接続検証込み)
- [ ] Switchover 書込断の実測(★本 clone 実測 2026-08-17:約70秒。下記「実測所要時間」参照)/rename・endpoint 据え置き・アプリ再接続
- [ ] DB 前後チェック(フル verify #17412 は不要。
pg16-preflightスキルを read-only で BG 前と昇格後に1回ずつ回し、件数・拡張・invalid・sequence 等を突合) - [ ] 所要時間(clone 作成 / BG AVAILABLE / switchover 書込断)を計測し #17282 / #17390 に記録
★実測所要時間(2026-08-17 本番 us-east-1 clone 実施・#17282)
| Stage | 所要(実測) |
|---|---|
| clone 作成(器・copy-on-write) | 即時 |
| インスタンス ×2 起動(db.r7g.large) | 〜10-15分 |
| Global 化 → Global 削除(standalone化・無停止・endpoint 不変) | 数秒 + 〜1-2分 |
| CPG 付替 → reboot(Reader→Writer 各 〜63秒) | 〜2分 |
| 標準 BG 作成(→AVAILABLE・target 16.14) | 約40分 |
| Switchover(★書込停止時間) | 約70秒(21:38:46→21:39:56) |
事後(ALTER EXTENSION pg_stat_statements UPDATE 1.8→1.10) | 即時 |
| teardown(instance→cluster 削除) | 〜10分 |
検証: 全16テーブル件数 blue=green 完全一致・昇格後 16.14 writable・endpoint 据え置き。本番/staging の当日枠見積りはこの実測(BG 約40分+書込停止 約70秒)を基準にする。
⚠️ 本番転用: リハの (2) は不要(本番は既に Global)。本番は ① Global 削除 → ② CPG 付替+再起動(瞬断)→ ③ 標準 BG(〜約40分・実測)→ ④ Switchover(書込停止 約70秒・実測)→ 事後 の順(
preflight.md・production.md(#17392・別途作成予定))。Global 復元は方針上は任意(単一リージョンなら通常不要)。 ⚠️ clone にアプリは繋がらない(ECS は本番 endpoint を参照)。よって consumer 疎通 / deep-health / UI E2E はこのリハでは検証不可=staging(staging.md(#17391・別途作成予定))で担当。clone で見るのは「手順成立・BG 作成可否・書込断時間・DB オブジェクト健全性」。
後始末(全削除・課金停止)
# BG レコード削除 → clone の instance/cluster を全削除(--skip-final-snapshot)。global は (3) で削除済
aws rds delete-blue-green-deployment --region $R --blue-green-deployment-identifier <bgd-xxxx>
for id in ${CL}-0 ${CL}-1 ${CL}-0-old1 ${CL}-1-old1; do
aws rds delete-db-instance --region $R --db-instance-identifier $id --skip-final-snapshot 2>/dev/null || true
done
# cluster 削除(green/old も)→ describe で mental-appointment-bgtest-* が 0 になるまで確認
aws rds describe-db-clusters --region $R --query "DBClusters[?starts_with(DBClusterIdentifier,'mental-appointment-bgtest')].DBClusterIdentifier" --output text- [ ]
mental-appointment-bgtest-*のインスタンス/クラスタ/BG が全て 0(課金停止) - [ ] 本体
mental-appointment(Global・Writer-0/Reader-1)が無変更で健在