From eefc803d5f3423982c24d3f095e2387f1fa6ee54 Mon Sep 17 00:00:00 2001 From: windyboy Date: Tue, 22 Sep 2026 08:49:40 +0800 Subject: [PATCH] =?UTF-8?q?VPS-78:=20pgdb-health=20=E6=A0=87=E4=B8=BA=209?= =?UTF-8?q?=20=E9=A1=B9=E5=B9=B6=E6=9B=B4=E6=96=B0=20last=20reviewed?= =?UTF-8?q?=EF=BC=9Bpgdb.md=20Runbooks=20=E8=A1=8C=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - runbooks/pgdb-health.md: Last reviewed 2026-08-29 → 2026-09-22;Related systems 加入 scribe.csg_history 永久归档(job 1010/1011 维护) - hosts/pgdb.md: Runbooks 行注明 9 项(第 9 项 CSG 归档新鲜度) --- hosts/pgdb.md | 2 +- runbooks/pgdb-health.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hosts/pgdb.md b/hosts/pgdb.md index e1ec6fe..3a1255c 100644 --- a/hosts/pgdb.md +++ b/hosts/pgdb.md @@ -38,7 +38,7 @@ - **开机自愈**(2026-08-30):新增 systemd oneshot `pgdb-compose.service`(enabled,源码在仓库 `compose/pgdb/pgdb-compose.service`):`After=network-online.target docker.service`,开机后幂等执行 `docker compose up -d`,重试直到 `192.168.55.15:5432` 监听,重试耗尽 `--force-recreate` 兜底(数据在 bind mount,无损)。原因:2026-08-30 开机竞态——docker 恢复容器时 VM IP 尚未可绑(EADDRNOTAVAIL),timescaledb/pgweb 启动失败且 docker 不重试。手动重跑:`sudo systemctl restart pgdb-compose.service`。 - 本机无防火墙(ufw/nft/iptables 均未装)——待办:如要彻底隔离可加 ufw 白名单 192.168.55.11。 - `/opt/database/backups/` 根下残留 `*-2026-08-29_1359.dump`(compose 化之前旧备份机制产物)与 `backup.log`——健康检查只看 `daily/`,残留可清理。 -- **Runbooks**:[pgdb-health](../runbooks/pgdb-health.md)(只读健康检查)、[pgdb-restore](../runbooks/pgdb-restore.md)(pg_restore 还原)、[pgdb-update](../runbooks/pgdb-update.md)(镜像/compose 升级)。 +- **Runbooks**:[pgdb-health](../runbooks/pgdb-health.md)(只读健康检查,**9 项**;第 9 项为 CSG 归档新鲜度,2026-09-22 新增)、[pgdb-restore](../runbooks/pgdb-restore.md)(pg_restore 还原)、[pgdb-update](../runbooks/pgdb-update.md)(镜像/compose 升级)。 - **CSG 长期归档(2026-08-29, W1N-243)**:`csg_history` 表(`period date / kind('day'|'month') / usage_kwh / cost / ladder / balance / updated_at`,PK(period,kind),`GRANT SELECT TO hass`)保存南方电网有价值数据:day = 逐日(昨日用电/费用/阶梯/余额,2026-07-01 起),month = 当月累计(用电/费用,2025-01 起)。由 TimescaleDB 每日任务 **1010**(2026-09-21 起;原 1008)`csg_daily_snapshot()`(**14:30 UTC = 22:30 Asia/Shanghai**;**TS job 非 pg_cron**,本库未装 pg_cron)upsert 维护;计费用 `csg_ladder_cost(kwh, month)` 助手(归档侧唯一计价来源)。回填来源:集成 attributes `history_data`(59 天)+ `by_month`(19 月)——08-29 前唯一残存历史。回滚:`DROP TABLE csg_history` + 删任务(另有迁移前快照表 `csg_history_bak_20260921`)。详见下方 Known issues 2026-09-21。**2026-09-22 v5 补两件事**:① **断档自愈** job **1011** `csg_backfill_missing_days()`(**15:10 UTC = 23:10 Asia/Shanghai**,排在 1010 之后)——只 `INSERT` 缺失日期、`ON CONFLICT DO NOTHING`,**绝不覆盖既有行**,数据源是 `states_raw` 里 `latest_day_kwh` 的 (`latest_day_date`, `value`) 观测对;② day 行费用改为 `csg_ladder_cost_raw` 的**累积边际差分 + 单次 `round(...,2)`**(与 v3 回填同口径),快照表 `csg_history_bak_20260922`,脚本 `compose/pgdb/csg-snapshot-v5.sql`。详见下方 Known issues 2026-09-22。 ## Known issues diff --git a/runbooks/pgdb-health.md b/runbooks/pgdb-health.md index 523581c..7b01cf3 100644 --- a/runbooks/pgdb-health.md +++ b/runbooks/pgdb-health.md @@ -13,8 +13,8 @@ Read-only health check of the pgdb TimescaleDB compose stack (PG18 + pgweb GUI + ## Ownership - Owner: personal ops (Windy) -- Last reviewed: 2026-08-29 -- Related systems: pgdb (`/opt/database`, TimescaleDB 18.6 / TS 2.29.2), HA `192.168.55.11` (hass/scribe clients) +- Last reviewed: 2026-09-22(新增 check 9:CSG 归档新鲜度) +- Related systems: pgdb (`/opt/database`, TimescaleDB 18.6 / TS 2.29.2), HA `192.168.55.11` (hass/scribe clients), `scribe.csg_history` 永久归档(南方电网逐日/逐月,由 job 1010/1011 维护) ## Access