# replication_timeout

> replication_timeout：设置等待 WAL 复制活动的最长时间。实测在档范围为 PG9.1–9.2；最后在档的 PG9.2 启动默认值为 1 min，context 为 sighup。它在 PG9.3 被移除。
---

> [!NOTE]
> **Fact — 官方简述译文**：设置等待 WAL 复制活动的最长时间。

## 身份 {#identity}

| 字段 | 值 | 含义 |
| --- | --- | --- |
| 类型 | `integer` | 上游 pg_settings 类型 |
| Context | `sighup` | 配置 reload 后生效 |
| 单位 | `ms` | 原始单位 |
| 范围 | `0` – `2147483647` | 最后在档版本的原始上下限 |
| 枚举值 | — | 非枚举类型记为 — |
| 分类 | Replication / Sending Servers | 上游分类 |
| 最后 boot 值 | `60000` | 1 min |
{.fields meta="-"}

## 生命周期 {#lifecycle}

| Fact | 值 |
| --- | --- |
| 首次观测 | PG9.1 |
| 在档版本 | PG9.1–9.2 |
| 移除版本 | PG9.3 |
| 引入提交 | [`754baa21f723`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=754baa21f723255272c24dc5f9ab456858e361e3) — Automatically terminate replication connections that are idle for more than replication_timeout (a new GUC) milliseconds. The TCP timeout is often too long, you want the master to notice a dead connection much sooner. People complained about that in 9.0 too, but with synchronous replication it's even more important to notice dead connections promptly. |
| 提交日期 | 2011-03-30 |
| Discussion | — |

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

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

## 机制详解 {#mechanism}

replication_timeout：设置等待 WAL 复制活动的最长时间。重新加载配置即可让服务器采用新值，无需完整重启。 本站在 PG9.1–9.2 实测到它；boot_val 是编译或初始化基线，并不能证明某个运行集群的当前有效值。

这是早期流复制中由发送端终止不活跃连接的超时。PG9.3 将其改名为 wal_sender_timeout；接收端故障检测由 wal_receiver_timeout 独立控制，迁移时必须分清计时器属于连接哪一端。

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

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

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

| 场景 | 建议 |
| --- | --- |
| OLTP | 不要把这个已退出的名称加入现代 OLTP 配置。应把原意迁移到文档给出的后继参数，在连接与写并发下验证，并清理仍会输出旧名称的自动化。 |
| OLAP | 升级分析型环境前应盘点所有生成配置，把旧控制映射到后继项，并比较执行计划、吞吐、WAL 或日志行为；不能假设旧数值可直接搬用。 |
| 小规格 | 记录旧覆盖存在的原因后将其删除。小节点应先采用后继参数默认值，实测后再调整；未知的启动参数可能直接阻止服务器启动。 |
{.full-width}

## Pigsty 取值 {#pigsty}

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

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

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

## 常见坑 {#common-pitfalls}

- 把 replication_timeout 的实测 boot_val 当成初始化后或托管集群当前有效值的证明。
- 忽略 pg_settings 报告的 sighup context，误以为修改会立即生效。
- 孤立修改该参数，没有检查关联上限、可观测性和回滚路径。
- 把已移除名称复制到现代 postgresql.conf，而没有迁移到文档给出的后继参数。

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

[`wal_sender_timeout`](/zh/parameters/wal-sender-timeout/) · [`wal_receiver_timeout`](/zh/parameters/wal-receiver-timeout/) · [`wal_receiver_status_interval`](/zh/parameters/wal-receiver-status-interval/) · [`max_wal_senders`](/zh/parameters/max-wal-senders/)

## 参考资料 {#references}

- [机器可读 GUC 全量导出](/data/guc.jsonl)
