问题背景: - PostgreSQL pg_wal 目录从 80MB 膨胀到 60.4GB,导致磁盘使用率达到 96% - 根因: wallet/planting/referral 三个数据库的业务表长期无写入 - 虽然 Debezium 有 heartbeat 配置,但未配置 heartbeat.action.query - 导致 replication slot 的 restart_lsn 无法推进,WAL 文件无法被清理 解决方案: 1. 在 wallet/planting/referral 三个服务中添加 debezium_heartbeat 表 2. 配置 Debezium connector 的 heartbeat.action.query 3. 每 60 秒自动执行 UPDATE 语句推进 restart_lsn 修改内容: - wallet-service/prisma/schema.prisma: 添加 DebeziumHeartbeat model - planting-service/prisma/schema.prisma: 添加 DebeziumHeartbeat model - referral-service/prisma/schema.prisma: 添加 DebeziumHeartbeat model - scripts/debezium/wallet-connector.json: 添加 heartbeat.action.query 配置 - scripts/debezium/planting-connector.json: 添加 heartbeat.action.query 配置 - scripts/debezium/referral-connector.json: 添加 heartbeat.action.query 配置 - 新增三个服务的 Prisma migration 文件 效果: - pg_wal 从 60.4GB 降至 80.2MB - 磁盘使用率从 96% 降至 40% - replication slot lag 从 51-60GB 降至 KB 级别 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| debezium | ||
| accounts.json | ||
| batch-register.js | ||
| check-databases.sh | ||
| init-databases.sh | ||