跳转到主要内容

unix_socket_directories

unix_socket_directories 定义创建 Unix 域套接字的目录。
说明

Fact — 官方简述译文:设置创建 Unix 域套接字的目录。

身份

类型 , string
上游 pg_settings 类型
Context , postmaster
修改后需要重启数据库
单位 ,
原始单位
范围 ,
最后在档版本的原始上下限
枚举值 ,
非枚举类型记为 —
分类 , Connections and Authentication / Connection Settings
上游分类
最后 boot 值 , /var/run/postgresql
/var/run/postgresql

生命周期

Fact
首次观测 PG9.3
在档版本 PG9.3–19 Beta 3
移除版本
引入提交 c9b0cbe98bd7 — Support having multiple Unix-domain sockets per postmaster.
提交日期 2012-08-10
Discussion

默认值变迁

PG9.0–19 Beta 3 实测 boot 默认值
版本 原始 boot_val 单位 人类可读值
PG9.3–19 Beta 3 /var/run/postgresql /var/run/postgresql

机制详解

unix_socket_directories:设置创建 Unix 域套接字的目录。PostgreSQL 启动时在每个所列目录创建套接字与锁文件;在支持的系统上,以 @ 开头的值选择抽象命名空间。

unix_socket_directories 属于 POSTMASTER 上下文:PostgreSQL 在服务器启动时读取它,重新加载配置或会话 SET 都不能使新值生效。

Unix 套接字可达性由目录存在性与遍历权限、套接字组和模式、服务器账号及客户端搜索路径共同决定;pg_hba.conf 的 local 记录仍负责认证。

调优建议

提示

Advice。 以下建议是工作负载起点,必须用真实测量验证。

场景 建议
OLTP 把 unix_socket_directories 纳入同一套 Unix 套接字访问策略:选择可信目录、所有者、组成员与权限,并测试本地连接池、监控、备份和管理工具。
OLAP 分析工具采用同一套经评审本地访问边界;只有客户端与操作系统生命周期受管时才新增目录或组。
小规格 保持 unix_socket_directories 简单且最小权限。本地套接字只带来很小的 TCP 开销差异,不应为方便而开放给所有用户。

Pigsty 取值

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

模板 有效值 与上游 boot 比较 源表达式
OLTP /var/run/postgresql, /tmp 不同于 boot 值 '/var/run/postgresql, /tmp'
OLAP /var/run/postgresql, /tmp 不同于 boot 值 '/var/run/postgresql, /tmp'
CRIT /var/run/postgresql, /tmp 不同于 boot 值 '/var/run/postgresql, /tmp'
TINY /var/run/postgresql, /tmp 不同于 boot 值 '/var/run/postgresql, /tmp'
注意

Advice — 待人工复核。 当前 Pigsty 模板投影事实:OLTP: PG9.3–19 Beta 3 = /var/run/postgresql, /tmp (local);OLAP: PG9.3–19 Beta 3 = /var/run/postgresql, /tmp (local);CRIT: PG9.3–19 Beta 3 = /var/run/postgresql, /tmp (local);TINY: PG9.3–19 Beta 3 = /var/run/postgresql, /tmp (local)。 建议(待人工复核)——编辑推断:同时提供发行版运行目录与 /tmp,可兼容本地工具,并保留常规托管套接字路径。

常见坑

  • 期待重新加载或 SET 激活 unix_socket_directories,而它实际需要受控重启服务器。
  • 放宽套接字模式,却忽略目录遍历、组成员与 pg_hba.conf local 认证。
  • 加入易失或不存在目录,导致重启后服务器无法启动或本地客户端找错位置。
  • 没有回滚计划及客户端或运维兼容测试,就全局修改 unix_socket_directories。

listen_addresses · port · max_connections · reserved_connections · superuser_reserved_connections

参考资料