消失的postmaster进程

本文探讨了 PostgreSQL 中 postmaster 进程的概念及其实现方式,指出在 PG9.5 及以上版本中 postmaster 实际上是 postgres 进程的一个别名,并详细解释了如何在系统中定位此核心进程。
,
之前看<<PostgreSQL数据库内核分析>>这本书,提到了postmaster进程,
于是在我安装的PG 9.6.0中,ps -ef了一把,结果没找到,如下:
[postgres@rhel73 global]$ pwd
/usr/local/pgsql/data/global
[postgres@rhel73 global]$ ps -ef | grep -i  post
root      2220     1  0 03:43 ?        00:00:00 /usr/libexec/postfix/master -w
postfix   2222  2220  0 03:43 ?        00:00:00 qmgr -l -t unix -u
root      2549  2501  0 03:48 pts/0    00:00:00 su - postgres
postgres  2550  2549  0 03:48 pts/0    00:00:00 -bash
postgres  2632     1  0 03:51 pts/0    00:00:00 /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data--->>>只有这个.
postgres  2634  2632  0 03:51 ?        00:00:00 postgres: checkpointer process   
postgres  2635  2632  0 03:51 ?        00:00:00 postgres: writer process   
postgres  2636  2632  0 03:51 ?        00:00:00 postgres: wal writer process   
postgres  2637  2632  0 03:51 ?        00:00:00 postgres: autovacuum launcher process   
postgres  2638  2632  0 03:51 ?        00:00:00 postgres: stats collector process   
postgres  7255  2550  0 12:03 pts/0    00:00:00 ps -ef
postgres  7256  2550  0 12:03 pts/0    00:00:00 grep --color=auto -i post
[postgres@rhel73 global]$ ps -ef | grep mast
root      2220     1  0 03:43 ?        00:00:00 /usr/libexec/postfix/master -w
postgres  7638  2550  0 12:46 pts/0    00:00:00 grep --color=auto mast
[postgres@rhel73 global]$ ps -ef | grep master
root      2220     1  0 03:43 ?        00:00:00 /usr/libexec/postfix/master -w
postgres  7640  2550  0 12:46 pts/0    00:00:00 grep --color=auto master
[postgres@rhel73 global]$ 
[postgres@rhel73 global]$ 
[postgres@rhel73 global]$ 
[postgres@rhel73 global]$ which postmaster
/usr/local/pgsql/bin/postmaster
[postgres@rhel73 global]$ 
[postgres@rhel73 global]$ 
[postgres@rhel73 global]$ cd ..
[postgres@rhel73 data]$ ls -lrt
total 56
-rw-------. 1 postgres postgres     4 Feb 28 07:57 PG_VERSION
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_twophase
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_tblspc
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_stat
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_snapshots
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_serial
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_replslot
drwx------. 4 postgres postgres    36 Feb 28 07:57 pg_multixact
drwx------. 4 postgres postgres    39 Feb 28 07:57 pg_logical
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_dynshmem
drwx------. 2 postgres postgres     6 Feb 28 07:57 pg_commit_ts
-rw-------. 1 postgres postgres 22282 Feb 28 07:57 postgresql.conf
-rw-------. 1 postgres postgres    88 Feb 28 07:57 postgresql.auto.conf
-rw-------. 1 postgres postgres  1636 Feb 28 07:57 pg_ident.conf
-rw-------. 1 postgres postgres  4468 Feb 28 07:57 pg_hba.conf
drwx------. 3 postgres postgres    60 Feb 28 07:57 pg_xlog
drwx------. 2 postgres postgres    18 Feb 28 07:57 pg_subtrans
drwx------. 2 postgres postgres    18 Feb 28 07:57 pg_clog
drwx------. 6 postgres postgres    54 Feb 28 08:02 base
-rw-------. 1 postgres postgres    78 Mar  2 03:51 postmaster.pid
drwx------. 2 postgres postgres    18 Mar  2 03:51 pg_notify
-rw-------. 1 postgres postgres    59 Mar  2 03:51 postmaster.opts
drwx------. 2 postgres postgres  4096 Mar  2 03:51 global
drwx------. 2 postgres postgres    25 Mar  2 12:56 pg_stat_tmp
[postgres@rhel73 data]$ pwd
/usr/local/pgsql/data
[postgres@rhel73 data]$ cat postmaster.pid
2632
/usr/local/pgsql/data
1488444664
5432
/tmp
localhost
  5432001         0
[postgres@rhel73 data]$ ps -ef | grep 5432
postgres  7746  2550  0 12:57 pts/0    00:00:00 grep --color=auto 5432
[postgres@rhel73 data]$ 
[postgres@rhel73 data]$ 
[postgres@rhel73 data]$ 
[postgres@rhel73 data]$ cat postmaster.opts
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data"
[postgres@rhel73 data]$ pwd
/usr/local/pgsql/data
[postgres@rhel73 data]$ 


问了问公司的技术总监,结果是这样的:
postmaster is a deprecated alias of postgres.
如上来自:
https://www.postgresql.org/docs/9.5/static/app-postmaster.html


结论是这样的:
PG9.5之前的postmaster进程实际上就是PG9.5及其以后版本中第一个启动的postgres进程,该进程的ospid(操作系统进程的进程号)在$PGDATA/下的postmaster.pid中有记录.
<think>好的,我现在要处理用户关于PostgreSQLpostmaster进程的询问。首先,我需要仔细阅读用户提供的引用内容,确保准确理解每个引用中的信息,以便能够正确回答用户的问题。 用户的问题是关于postmaster进程的功能、启动和管理。根据提供的引用,我需要整合不同引用中的信息,确保覆盖所有关键点。引用[1]提到postmasterPostgreSQL最重要的进程,负责初始化系统、管理连接和后台进程。引用[2]进一步说明postmaster和postgres进程的关系,以及postmaster监听连接并分配服务进程。引用[4]详细描述了postmaster作为总控进程,处理客户端连接时的身份验证,并fork子进程。引用[3]和[5]补充了启动方式和管理流程。 接下来,我需要组织这些信息,按照功能、启动和管理三个方面来结构化回答。首先,功能方面要包括初始化系统、连接管理、进程管理、关闭数据库。启动部分需要说明如何通过命令启动,比如使用pg_ctl或者直接运行postgres。管理方面要涉及配置文件的加载、信号处理和监控工具的使用。 另外,用户可能希望了解如何操作这些功能,比如如何启动或停止postmaster,如何配置监听地址等。需要确保回答中包含具体的命令示例,如pg_ctl start -D /data,或者修改postgresql.conf中的listen_addresses。 还要检查是否有遗漏的信息,比如子进程的类型(如后台工作进程、服务进程等),以及postmaster与其他进程的关系。同时,注意引用标注的正确性,每个关键点后面都要加上对应的引用标记,如[^1][^4]等。 最后,生成相关问题时要围绕postmaster的功能扩展,例如启动失败处理、与子进程的交互、配置参数、监控方法以及安全性相关的身份验证机制。确保问题具有针对性,能够引导用户进一步学习相关主题。</think>### PostgreSQL postmaster 进程功能与管理的分步说明 #### 一、核心功能解析 1. **系统初始化与资源分配** postmaster是数据库实例的总控进程,负责初始化共享内存、预加载常用数据结构和后台进程池。启动时会执行以下操作: ```bash # 典型启动命令(通过pg_ctl间接调用) pg_ctl start -D /data/postgresql ``` 该进程会创建共享缓冲区、WAL日志缓冲区和锁管理器等核心组件[^2][^5]。 2. **连接管理与进程派生** 监听`postgresql.conf`中定义的端口(默认5432),采用"每连接一进程"模型。当客户端发起连接时: ```sql SELECT * FROM pg_stat_activity; -- 查看当前活跃进程 ``` 通过身份验证后,postmaster会调用`fork()`创建专属的postgres子进程[^4]。该设计保证了会话隔离性,但高并发时需注意资源消耗。 3. **进程生命周期管理** 维护进程树结构,监控所有子进程状态。当检测到子进程异常终止时,会自动进行清理并记录日志。通过信号机制实现控制: ```bash kill -SIGTERM `head -1 /data/postgresql/postmaster.pid` # 优雅关闭 ``` #### 二、启动过程深度解析 1. **多阶段启动流程** 通过`PostmasterMain()`函数执行分层初始化: ```c /* 伪代码示例 */ void PostmasterMain() { read_configurations(); // 解析配置文件 setup_shared_memory(); // 分配共享内存 start_auxiliary_processes(); // 启动后台进程 enter_main_loop(); // 进入事件循环 } ``` 该过程会依次启动checkpointer、background writer等关键后台进程[^3][^5]。 2. **配置参数影响** 关键启动参数示例: ```ini listen_addresses = '*' # 监听所有IP max_connections = 100 # 最大连接数 autovacuum_max_workers = 3 # 自动清理进程数 ``` 修改配置后需执行`pg_ctl reload`通知postmaster重新加载。 #### 三、高级管理技巧 1. **多实例管理** 通过不同数据目录运行多个postmaster实例: ```bash initdb -D /data/pg_instance2 postgres -D /data/pg_instance2 -p 5433 ``` 2. **故障排查工具** 使用`strace`跟踪系统调用: ```bash strace -f -p $(head -1 postmaster.pid) # 跟踪主进程及子进程 ``` 3. **内存优化实践** 调整共享缓冲区大小(建议为总内存的25%): ```ini shared_buffers = 4GB ``` #### 四、性能指标监控 关键监控项及其SQL查询: ```sql SELECT (SELECT count(*) FROM pg_stat_activity) as active_connections, (SELECT checkpoints_timed FROM pg_stat_bgwriter) as regular_checkpoints, pg_size_pretty(pg_database_size(current_database())) as db_size; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值