0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQLの裏側を学びたい(Step2:マスターサーバプロセスを学ぶ)

0
Posted at

はじめに

前回の続きです!
今回はマスターサーバプロセスについて学びます。

マスターサーバプロセスとは

マスターサーバプロセスとは、PostgreSQLの親玉です。これがないと何もできないようです。
それ以上のことはよくわかっていないので、下記はChatGPTの解説です。

ChatGPTの解説

PostgreSQL のマスターサーバプロセス(Postmaster)を理解する

PostgreSQL の動作の中心にあるのが Postmaster(マスターサーバプロセス) です。
これは PostgreSQL 全体を管理する「親玉」であり、すべてのプロセスの親となる存在です。


🧠 Postmaster とは

Postmaster は PostgreSQL が起動したときに最初に立ち上がるプロセスで、
サーバ全体の管理・接続の受付・プロセスの生成・停止制御 を担っています。

主な役割

役割 説明
1️⃣ サーバ起動 PostgreSQL の各種プロセス・共有メモリ領域を初期化する。
2️⃣ 接続受付 クライアント(psql やアプリ)からの接続要求を待ち受け、子プロセス(バックエンド)を fork して処理を任せる。
3️⃣ プロセス管理 子プロセス(バックエンド・バックグラウンド)を監視し、異常終了したら再起動。
4️⃣ 停止制御 サーバ停止命令を受け取ると、安全に全プロセスを停止させる。

📘 公式定義(PostgreSQL ドキュメントより)

The postmaster process is the parent of all other server processes.
It handles startup, shutdown, and client connection requests.


🧩 プロセス構成のイメージ

さぁ、実際に手を動かして学んでいきましょう!

Hands-on

Postgresを手元に準備し、何がなんなのかを整理していこうと思います!
下記にソースコードを置いているので、学びたい人はご自由にどうぞ!

マスターサーバプロセスを見る。
root@3f83029523db:/# ps aux | grep '[p]ostgres'
postgres     1  0.0  0.1 217732 27664 ?        Ss   07:10   0:00 postgres ←これがマスターサーバープロセス
postgres    28  0.0  0.0 217864  8556 ?        Ss   07:10   0:00 postgres: checkpointer 
postgres    29  0.0  0.0 217888  7376 ?        Ss   07:10   0:00 postgres: background writer 
postgres    31  0.0  0.0 217732 10304 ?        Ss   07:10   0:00 postgres: walwriter 
postgres    32  0.0  0.0 219328  8128 ?        Ss   07:10   0:00 postgres: autovacuum launcher 
postgres    33  0.0  0.0 219312  8492 ?        Ss   07:10   0:00 postgres: logical replication launcher 

一番上のやつが、マスターサーバプロセスみたいです。ふーんって感じですね。

親子関係をツリーで可視化してみましょう。

親子関係をツリーで可視化
root@3f83029523db:/# apt update && apt install -y psmisc
root@3f83029523db:/# pstree -p postgres
postgres(1)─┬─postgres(28)
            ├─postgres(29)
            ├─postgres(31)
            ├─postgres(32)
            └─postgres(33)

→確かに、マスターサーバプロセスが親であることがわかりますね。ただ、ふーんって感じですね。🙁

さいごに

今回はマスターサーバプロセスについて学びました。postgresの親玉のようです。
初回起動時に色々やってくれている親だまなんだなくらいでいい気がします!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?