# debug_print_raw_parse

> debug_print_raw_parse：把每条查询的原始解析树写入日志。实测在档范围为 PG19 Beta 3；最后在档的 PG19 Beta 3 启动默认值为 off，context 为 user。这是测试版快照事实，PostgreSQL 19 正式发布前仍可能变化。
---

> [!NOTE]
> **Fact — 官方简述译文**：把每条查询的原始解析树写入日志。

## 身份 {#identity}

| 字段 | 值 | 含义 |
| --- | --- | --- |
| 类型 | `bool` | 上游 pg_settings 类型 |
| Context | `user` | 普通用户可在运行时修改 |
| 单位 | — | 原始单位 |
| 范围 | — | 最后在档版本的原始上下限 |
| 枚举值 | — | 非枚举类型记为 — |
| 分类 | Reporting and Logging / What to Log | 上游分类 |
| 最后 boot 值 | `off` | off |
{.fields meta="-"}

## 生命周期 {#lifecycle}

| Fact | 值 |
| --- | --- |
| 首次观测 | PG19 Beta 3 |
| 在档版本 | PG19 Beta 3 |
| 移除版本 | 否 |
| 引入提交 | [`06473f5a344d`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=06473f5a344df8c9594ead90a609b86f6724cff8) — Allow to log raw parse tree. |
| 提交日期 | 2025-09-06 |
| Discussion | [讨论 1](https://postgr.es/m/CAEoWx2mcO0Gpo4vd8kPMAFWeJLSp0MeUUnaLdE1x0tSVd-VzUw%40mail.gmail.com) |

## 默认值变迁 {#default-history}

| 版本 | 原始 `boot_val` | 单位 | 人类可读值 |
| --- | --- | --- | --- |
| PG19 Beta 3 | `off` | — | off |
{.full-width caption="PG9.0–19 Beta 3 实测 boot 默认值"}

## 机制详解 {#mechanism}

debug_print_raw_parse：把每条查询的原始解析树写入日志。它可以按会话修改，便于在不影响全部负载的前提下比较计划或行为。 本站在 PG19 Beta 3 实测到它；boot_val 是编译或初始化基线，并不能证明某个运行集群的当前有效值。

原始解析树在语义分析、重写、规划与执行之前输出。消息级别为 LOG；debug_pretty_print 控制格式，而 client_min_messages 与 log_min_messages 决定输出位置。内容可能非常庞大，也可能暴露查询结构。

应与 debug_print_parse、debug_print_rewritten、debug_print_plan、debug_pretty_print 一起理解。请在目标服务器检查 SHOW 与 pg_settings，确认 source 和 pending_restart，并在修改前后对比真实负载、日志和资源指标。

## 调优建议 {#tuning-advice}

> [!TIP]
> **Advice。** 以下建议是工作负载起点，必须用真实测量验证。

| 场景 | 建议 |
| --- | --- |
| OLTP | 在出现可复现的运维需求前保持上游默认；应在代表性并发下测试，并在全局修改前检查日志、延迟与关联参数。 |
| OLAP | 结合有代表性的长查询和批处理评估，比较整个任务的总耗时、资源、日志量与失败行为，而不是孤立操作。 |
| 小规格 | 尽量减少覆盖并记录回滚。小系统容纳额外日志、worker、内存或保留 WAL 的余量更小，必须用明确资源上限验证。 |
{.full-width}

## Pigsty 取值 {#pigsty}

以下值来自固定 8 核、32 GiB、100 GiB SSD 夹具，并按 PG19 Beta 3 渲染当前 Pigsty 模板；这不表示 Pigsty 当前支持该历史或测试版本。

| 模板 | 有效值 | 与上游 boot 比较 | 源表达式 |
| --- | --- | --- | --- |
| OLTP | 未修改 | — | — |
| OLAP | 未修改 | — | — |
| CRIT | 未修改 | — | — |
| TINY | 未修改 | — | — |
{.full-width}

> [!CAUTION]
> **Advice — 待人工复核。** 当前 Pigsty 模板投影事实：OLTP: PG19 Beta 3 未修改；OLAP: PG19 Beta 3 未修改；CRIT: PG19 Beta 3 未修改；TINY: PG19 Beta 3 未修改。 未发现覆盖值，因此不推断 Pigsty 专属理由。

## 常见坑 {#common-pitfalls}

- 把 debug_print_raw_parse 的实测 boot_val 当成初始化后或托管集群当前有效值的证明。
- 忽略 pg_settings 报告的 user context，误以为修改会立即生效。
- 孤立修改该参数，没有检查关联上限、可观测性和回滚路径。
- 在生产中依赖测试版行为，却没有在 PostgreSQL 19 正式版发布后重新验证。

## 关联参数 {#related-parameters}

[`debug_print_parse`](/zh/parameters/debug-print-parse/) · [`debug_print_rewritten`](/zh/parameters/debug-print-rewritten/) · [`debug_print_plan`](/zh/parameters/debug-print-plan/) · [`debug_pretty_print`](/zh/parameters/debug-pretty-print/) · [`log_min_messages`](/zh/parameters/log-min-messages/)

## 参考资料 {#references}

- [PostgreSQL 19 Beta 3 — debug_print_raw_parse](https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-DEBUG-PRINT-RAW-PARSE)
- [PostgreSQL 19 发行说明](https://www.postgresql.org/docs/19/release-19.html)
- [机器可读 GUC 全量导出](/data/guc.jsonl)
