From ac8d6dcf452ac555eb344f76caf6965c2ea42a97 Mon Sep 17 00:00:00 2001 From: wangbo Date: Sun, 2 Aug 2026 00:10:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(postgres):=20=E6=94=BE=E5=AE=BD=E8=B7=A8?= =?UTF-8?q?=E5=9C=B0=E5=9F=9F=20WAL=20=E8=BF=9E=E6=8E=A5=E6=8A=96=E5=8A=A8?= =?UTF-8?q?=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将生产 WAL sender/receiver timeout 从 CNPG 隐式 5 秒显式调整为 30 秒,避免短时控制面或 Pod 网络停顿反复拆除复制流并触发异步降级。保留 preferred 同步策略,防止副本不可达时冻结全部写入。\n\n影响:仅修改生产 CNPG 参数、发布门禁和运维说明,不改变应用镜像和迁移。仍需通过同步复制、六向链路与验收硬门禁。\n\n验证:kubectl kustomize、bash -n、ShellCheck、manual-release-test。 --- deploy/kubernetes/production/database.yaml | 7 +++++++ docs/operations/k3s-ha-runbook.md | 2 +- tests/release/manual-release-test.sh | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deploy/kubernetes/production/database.yaml b/deploy/kubernetes/production/database.yaml index 99e831e..8dd6c38 100644 --- a/deploy/kubernetes/production/database.yaml +++ b/deploy/kubernetes/production/database.yaml @@ -128,6 +128,13 @@ spec: shared_buffers: 512MB wal_compression: "on" wal_keep_size: 1GB + # CNPG defaults these cross-region liveness timers to 5 seconds. A short + # control-plane or pod-network stall can otherwise tear down a healthy + # WAL stream and make preferred synchronous replication fall back to + # async. Keep failure detection bounded without amplifying a transient + # multi-second stall into repeated reconnects. + wal_sender_timeout: 30s + wal_receiver_timeout: 30s monitoring: enablePodMonitor: false projectedVolumeTemplate: diff --git a/docs/operations/k3s-ha-runbook.md b/docs/operations/k3s-ha-runbook.md index aed8df7..e65fcbb 100644 --- a/docs/operations/k3s-ha-runbook.md +++ b/docs/operations/k3s-ha-runbook.md @@ -41,7 +41,7 @@ NodePort 公网入口。节点防火墙继续由原有 UFW 管理,接入脚本 [生产同构验收模式与高媒体压力测试](production-acceptance.md)。 - 健康双库:同步复制,RPO=0。 -- 单库降级:`dataDurability: preferred` 保持写入,`archive_timeout=5min`,灾难 RPO 目标不超过 5 分钟。生产 WAL 段为 16 MiB;禁止把该值降到 60 秒,否则仅空闲切段就要求跨地域链路持续承载至少 2.24 Mbit/s,会使同步副本在当前带宽下永久追不平。 +- 单库降级:`dataDurability: preferred` 保持写入,`archive_timeout=5min`,灾难 RPO 目标不超过 5 分钟。生产 WAL 段为 16 MiB;禁止把该值降到 60 秒,否则仅空闲切段就要求跨地域链路持续承载至少 2.24 Mbit/s,会使同步副本在当前带宽下永久追不平。生产同时显式设置 `wal_sender_timeout=30s` 和 `wal_receiver_timeout=30s`,避免 5 秒级控制面或 Pod 网络抖动反复拆除 WAL 流;该配置只降低瞬时抖动放大,不替代同步复制、六向链路和复制日志门禁。 - 数据库故障 RTO:不超过 5 分钟。 - 应用发布:香港验收后再滚动宁波,计划内零停机。 - 公网入口:双 NGINX 加人工 AliDNS 切换。接入带健康检查的 GTM 前,不宣称公网入口自动高可用。 diff --git a/tests/release/manual-release-test.sh b/tests/release/manual-release-test.sh index b5a7e13..d92448c 100755 --- a/tests/release/manual-release-test.sh +++ b/tests/release/manual-release-test.sh @@ -305,6 +305,8 @@ if grep -Fq 'archive_timeout: 60s' "$root/deploy/kubernetes/production/database. echo 'production archive timeout would exceed the certified cross-region bandwidth floor' >&2 exit 1 fi +grep -Fq 'wal_sender_timeout: 30s' "$root/deploy/kubernetes/production/database.yaml" +grep -Fq 'wal_receiver_timeout: 30s' "$root/deploy/kubernetes/production/database.yaml" "$root/tests/release/cluster-release-helper-test.sh" >/dev/null "$root/tests/release/production-acceptance-script-test.sh" >/dev/null