<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Patroni 配置 on PIG.CENTER</title><link>https://pig.center/zh/docs/patroni/config/</link><description>Recent content in Patroni 配置 on PIG.CENTER</description><generator>Hugo</generator><language>zh-CN</language><lastBuildDate>Tue, 08 Sep 2026 21:29:01 +0800</lastBuildDate><atom:link href="https://pig.center/zh/docs/patroni/config/index.xml" rel="self" type="application/rss+xml"/><item><title>动态配置</title><link>https://pig.center/zh/docs/patroni/config/dynamic/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pig.center/zh/docs/patroni/config/dynamic/</guid><description>&lt;p&gt;&lt;a id="dynamic"&gt;&lt;/a&gt;&#10;动态配置存储在 DCS（分布式配置存储）中，并应用于集群的所有节点。&lt;/p&gt;&#10;&lt;p&gt;如需修改动态配置，可使用 &lt;a href="https://pig.center/zh/docs/patroni/patronictl/#patronictl_edit_config"&gt;&lt;code&gt;patronictl edit-config&lt;/code&gt;&lt;/a&gt;&#10; 工具或 Patroni &lt;a href="https://pig.center/zh/docs/patroni/rest_api/#rest_api"&gt;&lt;strong&gt;REST API&lt;/strong&gt;&lt;/a&gt;&#10;。&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;loop_wait&lt;/code&gt;&lt;/strong&gt;：主循环每轮的休眠秒数。默认值：10，最小值：1。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;ttl&lt;/code&gt;&lt;/strong&gt;：获取领导者锁的 TTL（秒）。可以理解为触发自动故障转移前的等待时长。默认值：30，最小值：20。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;retry_timeout&lt;/code&gt;&lt;/strong&gt;：DCS 和 PostgreSQL 操作的重试超时时间（秒）。若 DCS 或网络故障时长短于此值，Patroni 不会对主库执行降级。默认值：10，最小值：3。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="td-callout td-callout--warning" role="note"&gt;&#10; &lt;div class="td-callout__title"&gt;&lt;i class="td-callout__icon fa-solid fa-triangle-exclamation" aria-hidden="true"&gt;&lt;/i&gt;&lt;span class="td-callout__label"&gt;警告&lt;/span&gt;&lt;/div&gt;&#10; &lt;div class="td-callout__body"&gt;&#10;&lt;p&gt;修改 &lt;strong&gt;&lt;code&gt;loop_wait&lt;/code&gt;&lt;/strong&gt;、&lt;strong&gt;&lt;code&gt;retry_timeout&lt;/code&gt;&lt;/strong&gt; 或 &lt;strong&gt;&lt;code&gt;ttl&lt;/code&gt;&lt;/strong&gt; 时，必须遵守以下约束：&lt;/p&gt;</description></item><item><title>YAML 配置参数</title><link>https://pig.center/zh/docs/patroni/config/yaml/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pig.center/zh/docs/patroni/config/yaml/</guid><description>&lt;p&gt;&lt;a id="yaml"&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="全局通用"&gt;全局/通用&#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;name&lt;/code&gt;&lt;/strong&gt;：主机名称，在集群中必须唯一。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;namespace&lt;/code&gt;&lt;/strong&gt;：Patroni 在配置存储中保存集群信息的路径，默认值为 &lt;strong&gt;&lt;code&gt;/service&lt;/code&gt;&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;scope&lt;/code&gt;&lt;/strong&gt;：集群名称。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;&lt;a id="log_settings"&gt;&lt;/a&gt;&lt;/p&gt;</description></item><item><title>环境变量</title><link>https://pig.center/zh/docs/patroni/config/env/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://pig.center/zh/docs/patroni/config/env/</guid><description>&lt;p&gt;&lt;a id="env"&gt;&lt;/a&gt;&#10;可以使用系统环境变量覆盖 Patroni 配置文件中定义的部分配置参数。本文档列出了 Patroni 处理的所有环境变量。通过环境变量设置的值始终优先于配置文件中的值。&lt;/p&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="全局通用"&gt;全局/通用&#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_CONFIGURATION&lt;/code&gt;&lt;/strong&gt;：可通过 &lt;a href="https://pig.center/zh/docs/patroni/config/#config"&gt;&lt;code&gt;PATRONI_CONFIGURATION&lt;/code&gt;&lt;/a&gt;&#10; 环境变量为 Patroni 提供完整配置。设置此变量后，其他所有环境变量将被忽略！&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_NAME&lt;/code&gt;&lt;/strong&gt;：运行当前 Patroni 实例的节点名称，在集群内必须唯一。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_NAMESPACE&lt;/code&gt;&lt;/strong&gt;：Patroni 在配置存储中保存集群信息的路径。默认值：&amp;quot;/service&amp;quot;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_SCOPE&lt;/code&gt;&lt;/strong&gt;：集群名称。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;hr&gt;&#10;&lt;h2 id="日志"&gt;日志&#10;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_TYPE&lt;/code&gt;&lt;/strong&gt;：日志格式，可为 &lt;strong&gt;&lt;code&gt;plain&lt;/code&gt;&lt;/strong&gt; 或 &lt;strong&gt;&lt;code&gt;json&lt;/code&gt;&lt;/strong&gt;。使用 &lt;strong&gt;&lt;code&gt;json&lt;/code&gt;&lt;/strong&gt; 格式需要安装 &lt;a href="https://pig.center/zh/docs/patroni/installation/#extras"&gt;&lt;code&gt;jsonlogger&lt;/code&gt;&lt;/a&gt;&#10;。默认值为 &lt;strong&gt;&lt;code&gt;plain&lt;/code&gt;&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_LEVEL&lt;/code&gt;&lt;/strong&gt;：全局日志级别。默认值为 &lt;strong&gt;&lt;code&gt;INFO&lt;/code&gt;&lt;/strong&gt;（参见 &lt;a href="https://docs.python.org/3.6/library/logging.html#levels"&gt;Python logging 文档&lt;/a&gt;&#10;）。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_TRACEBACK_LEVEL&lt;/code&gt;&lt;/strong&gt;：显示 traceback 的日志级别。默认值为 &lt;strong&gt;&lt;code&gt;ERROR&lt;/code&gt;&lt;/strong&gt;。若希望仅在 &lt;strong&gt;&lt;code&gt;PATRONI_LOG_LEVEL=DEBUG&lt;/code&gt;&lt;/strong&gt; 时才显示 traceback，可将其设置为 &lt;strong&gt;&lt;code&gt;DEBUG&lt;/code&gt;&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_FORMAT&lt;/code&gt;&lt;/strong&gt;：日志格式化字符串。若日志类型为 &lt;strong&gt;&lt;code&gt;plain&lt;/code&gt;&lt;/strong&gt;，格式应为字符串，可用属性参见 &lt;a href="https://docs.python.org/3.6/library/logging.html#logrecord-attributes"&gt;LogRecord 属性文档&lt;/a&gt;&#10;。若日志类型为 &lt;strong&gt;&lt;code&gt;json&lt;/code&gt;&lt;/strong&gt;，格式除字符串外还可以是列表，每个列表项对应一个 LogRecord 属性，只需填写字段名，省略 &lt;strong&gt;&lt;code&gt;%(&lt;/code&gt;&lt;/strong&gt; 和 &lt;strong&gt;&lt;code&gt;)&lt;/code&gt;&lt;/strong&gt;。若希望以不同键名输出某个字段，可使用字典，键为日志字段名，值为希望在日志中显示的字段名。默认值为 &lt;strong&gt;%(asctime)s %(levelname)s: %(message)s&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_DATEFORMAT&lt;/code&gt;&lt;/strong&gt;：日期时间格式化字符串（参见 &lt;a href="https://docs.python.org/3.6/library/logging.html#logging.Formatter.formatTime"&gt;formatTime() 文档&lt;/a&gt;&#10;）。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_STATIC_FIELDS&lt;/code&gt;&lt;/strong&gt;：为日志添加额外字段，仅在日志类型为 &lt;strong&gt;&lt;code&gt;json&lt;/code&gt;&lt;/strong&gt; 时可用。示例：&lt;strong&gt;&lt;code&gt;PATRONI_LOG_STATIC_FIELDS=&amp;quot;{app: patroni}&amp;quot;&lt;/code&gt;&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_MAX_QUEUE_SIZE&lt;/code&gt;&lt;/strong&gt;：Patroni 采用两步日志记录机制。日志记录先写入内存队列，由独立线程从队列中取出后写入 stderr 或文件。内存队列容量默认限制为 &lt;strong&gt;&lt;code&gt;1000&lt;/code&gt;&lt;/strong&gt; 条，足以保留过去约 1 小时 20 分钟的日志。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_DIR&lt;/code&gt;&lt;/strong&gt;：应用程序日志的写入目录。该目录必须已存在且对运行 Patroni 的用户可写。设置此变量后，默认保留 4 个 25MB 的日志文件，可通过 &lt;strong&gt;&lt;code&gt;PATRONI_LOG_FILE_NUM&lt;/code&gt;&lt;/strong&gt; 和 &lt;strong&gt;&lt;code&gt;PATRONI_LOG_FILE_SIZE&lt;/code&gt;&lt;/strong&gt; 调整（见下文）。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_MODE&lt;/code&gt;&lt;/strong&gt;：日志文件权限（例如 &lt;strong&gt;&lt;code&gt;0644&lt;/code&gt;&lt;/strong&gt;）。若未指定，将基于当前 umask 值设置。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_FILE_NUM&lt;/code&gt;&lt;/strong&gt;：保留的应用程序日志文件数量。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_FILE_SIZE&lt;/code&gt;&lt;/strong&gt;：触发日志滚动的 patroni.log 文件大小（字节）。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_LOGGERS&lt;/code&gt;&lt;/strong&gt;：按 Python 模块重新定义日志级别。示例：&lt;strong&gt;&lt;code&gt;PATRONI_LOG_LOGGERS=&amp;quot;{patroni.postmaster: WARNING, urllib3: DEBUG}&amp;quot;&lt;/code&gt;&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;&lt;code&gt;PATRONI_LOG_DEDUPLICATE_HEARTBEAT_LOGS&lt;/code&gt;&lt;/strong&gt;：设置为 &lt;strong&gt;&lt;code&gt;true&lt;/code&gt;&lt;/strong&gt; 时，连续且内容相同的心跳日志不再重复输出。默认值为 &lt;strong&gt;&lt;code&gt;false&lt;/code&gt;&lt;/strong&gt;。&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;div class="td-callout td-callout--warning" role="note"&gt;&#10; &lt;div class="td-callout__title"&gt;&lt;i class="td-callout__icon fa-solid fa-triangle-exclamation" aria-hidden="true"&gt;&lt;/i&gt;&lt;span class="td-callout__label"&gt;警告&lt;/span&gt;&lt;/div&gt;&#10; &lt;div class="td-callout__body"&gt;&#10;&lt;p&gt;HA 循环的执行时间是诊断资源耗尽等问题所致故障转移的重要信息。将 &lt;strong&gt;&lt;code&gt;PATRONI_LOG_DEDUPLICATE_HEARTBEAT_LOGS&lt;/code&gt;&lt;/strong&gt; 设置为 &lt;strong&gt;&lt;code&gt;true&lt;/code&gt;&lt;/strong&gt; 后，HA 循环执行将不产生日志（除非领导者发生变化），导致这些潜在有用的信息无法从日志中获取。&lt;/p&gt;</description></item></channel></rss>