正如上一篇文章PostgreSQL的核心架構所講,PostgresSQL的主進程是Postmaster,當我們啓動PostgresSQL後,會在PostgreSQL中的數據文件夾下生產一個postmaster.pid
的文件,那麼這個文件記錄了什麼信息呢,我通過查閱源代碼以及相關文檔,對此文件進行內容進行說明:
postmaster內容
使用cat -n 命令可以查看postmaster.pid
文件內容:
)
根據每一行進行解釋,並給出對應的源代碼說明
13795: 代表Postgres主進程的PID
/usr/local/pgsql/data: 代表數據目錄
1529235109: 代表postmaster文件的創建時間。
5432: 代表數據庫監聽端口,在postgresql.conf中對應
port = 5432
來自源代碼說明:
/* The socket number we are listening for connections on */ int PostPortNumber;
/tmp: 代表是unix socket的監聽目錄,在postgresql.conf中對應
unix_socket_directory = '/tmp'
來自源代碼說明:
/* The directory names for Unix socket(s) */ char *Unix_socket_directories;
* : 代表數據庫監聽地址,對應postgresql.conf的
listen_addresses = '\* '
來自源代碼說明:
/* The TCP listen address(es) */ char *ListenAddresses;
5432001 163840:代表的是共享內存的地址(shared memory segments中的key和shmid)。
輸入
ipcs
可以查看:注: postmaster.pid顯示的是key轉成10進制後的數字。
ready 代表主進程狀態
typedef enum
{
PM_INIT, /* postmaster starting */
PM_STARTUP, /* waiting for startup subprocess */
PM_RECOVERY, /* in archive recovery mode */
PM_HOT_STANDBY, /* in hot standby mode */
PM_RUN, /* normal "database is alive" state */
PM_WAIT_BACKUP, /* waiting for online backup mode to end */
PM_WAIT_READONLY, /* waiting for read only backends to exit */
PM_WAIT_BACKENDS, /* waiting for live backends to exit */
PM_SHUTDOWN, /* waiting for checkpointer to do shutdown
* ckpt */
PM_SHUTDOWN_2, /* waiting for archiver and walsenders to
* finish */
PM_WAIT_DEAD_END, /* waiting for dead_end children to exit */
PM_NO_CHILDREN /* all important children have exited */
} PMState;