feat(status): 启用 pg_stat_statements,运行状态页显示最慢 / 最频繁语句与各表死元组;PG 调低 random_page_cost
- docker-compose.yml 的 postgres 加 shared_preload_libraries=pg_stat_statements、pg_stat_statements.track=top; 要重建 postgres 容器才生效(docs/runbook/storage.md) - GET /system/storage 的 db.statements:平均最慢(调用 ≥ 10 次)与调用最多各 5 条;没装扩展 / 没预加载时 enabled=false 并说明原因 - 运行状态页「存储」:体积最大的表加死元组列,新增「数据库语句统计」 - random_page_cost 4 → 1.1(PG_RANDOM_PAGE_COST):库整个在内存里,缺省值高估随机读 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
8c8b252667
commit
63bbcf3cdb
5 files changed
+163
-1
No files matched your search
@@ -556,6 +556,16 @@ export const StorageBudgetUsage = z.object({
|
||||
});
|
||||
export type StorageBudgetUsage = z.infer<typeof StorageBudgetUsage>;
|
||||
|
||||
/** 一条语句的累计统计(pg_stat_statements,参数已归一化为 $n) */
|
||||
export const StatementStat = z.object({
|
||||
query: z.string(),
|
||||
calls: NonNegInt,
|
||||
totalMs: z.number().nonnegative(),
|
||||
meanMs: z.number().nonnegative(),
|
||||
rows: NonNegInt,
|
||||
});
|
||||
export type StatementStat = z.infer<typeof StatementStat>;
|
||||
|
||||
export const SystemStorage = z.object({
|
||||
/** 各项最差档(unknown 不参与) */
|
||||
level: HealthLevel,
|
||||
@@ -578,6 +588,17 @@ export const SystemStorage = z.object({
|
||||
lastAnalyzeAt: Timestamp.nullable(),
|
||||
}),
|
||||
),
|
||||
/**
|
||||
* 语句统计(pg_stat_statements):enabled=false 时 note 说明原因(没装扩展 / postgres 没预加载);
|
||||
* slowest 按平均耗时(调用 ≥ 10 次),frequent 按调用次数,各前 5;since 为统计起点(上次重置)
|
||||
*/
|
||||
statements: z.object({
|
||||
enabled: z.boolean(),
|
||||
note: z.string().nullable(),
|
||||
since: Timestamp.nullable(),
|
||||
slowest: z.array(StatementStat),
|
||||
frequent: z.array(StatementStat),
|
||||
}),
|
||||
}),
|
||||
/** PG kv_cache 各 region(条数含未清理的过期行) */
|
||||
kvCache: z.array(z.object({ region: z.string(), entries: NonNegInt, expired: NonNegInt, bytes: NonNegInt })),
|
||||
|
||||
Reference in new issue
Block a user