postmaster.pid 是由 postmaster 进程写入的 pidfile。除了 postmaster 的 PID 外,它还包含有关运行实例的其他信息。
postmaster.pid 在 PostgreSQL 7.0 中添加。
用法
postmaster.pid 在启动时由 postmaster 进程自动写入到数据目录,并在正常关闭后被删除。
如果设置了 external_pid_file,则会在指定位置额外写入一份文件副本,供操作系统(例如 systemd)使用,其中仅包含 PID。
目录
| 项目 | 示例 | 来源 | 备注 | 
|---|---|---|---|
| PID | 17454 | PostgreSQL 7.0 | |
| 数据目录 | /var/lib/pgsql/data | PostgreSQL 7.1 | |
| postmaster 启动时间戳 | 1603954420 | PostgreSQL 9.1 | Unix 纪元 | 
| 端口号 | 5432 | PostgreSQL 9.1 | |
| 第一个 Unix 套接字目录路径 | /tmp | PostgreSQL 9.1 | 如果没有则为空 | 
| 第一个 [listen_addresses|[listen_address]] | 127.0.0.1 | PostgreSQL 9.1 | IP 地址或 "*"; 如果没有 TCP 端口则为空 | 
| 共享内存密钥 | 5432001 9437184 | PostgreSQL 7.1 | Windows 上为空 | 
| postmaster 状态 | ready | PostgreSQL 10 | starting、stopping、ready、standby中的一个 | 
请注意,行数和它们的顺序可能会在不同的 PostgreSQL 版本之间发生变化。
源代码
文件名在 src/backend/utils/init/miscinit.c 中定义
#define DIRECTORY_LOCK_FILE "postmaster.pid"
文件本身由函数 CreateLockFile() 创建,该函数由 CreateDataDirLockFile() 调用,也位于 src/backend/utils/init/miscinit.c 中。
相关声明包含在以下文件中
- src/include/utils/pidfile.h (适用于 PostgreSQL 10 及更高版本)
- src/include/miscadmin.h (适用于 PostgreSQL 9.6 及更早版本)
变更历史
- PostgreSQL 10
- 添加了带有 postmaster 状态的附加行 (commit f13ea95f)
 
- PostgreSQL 9.1
- 添加了带有端口号和套接字目录的行 (commit 075354ad)
- 添加了带有第一个 listen_address 和启动时间的行 (commit 30aeda43)
 
- PostgreSQL 7.1
- PostgreSQL 7.0
- 添加 (commit dde36bfb)
 
示例
$ cat /var/lib/pgsql/data/postmaster.pid 17454 /var/lib/pgsql/data 1603954420 5432 /tmp 127.0.0.1 5432001 9437184 ready
有用链接
- Postgres Postmaster File Explained - 2024 年 1 月 Greg Sabino Mullane / Crunchy Data 的博客文章
分类
另请参阅
external_pid_file, postmaster
