PostgreSql process and memory structure

1. Process and memory architecture

insert image description here

When the PostgreSQL database is running, use the following command to query the database process, which corresponds to the above structure diagram.

[postgres@localhost ~]$ ps -ef|grep post
postgres   8649      1  0 15:05 ?        00:00:00 /app/pg13/bin/postgres -D /data/pg13/data
postgres   8657   8649  0 15:05 ?        00:00:00 postgres: logger
postgres   8659   8649  0 15:05 ?        00:00:00 postgres: checkpointer
postgres   8660   8649  0 15:05 ?        00:00:00 postgres: background writer
postgres   8661   8649  0 15:05 ?        00:00:00 postgres: walwriter
postgres   8662   8649  0 15:05 ?        00:00:00 postgres: autovacuum launcher
postgres   8663   8649  0 15:05 ?        00:00:00 postgres: archiver last was 0000000100000003000000CD
postgres   8664   8649  0 15:05 ?        00:00:00 postgres: stats collector
postgres   8666   8649  0 15:05 ?        00:00:00 postgres: logical replication launcher
postgres  10188   8649  0 16:19 ?        00:00:00 postgres: postgres postgres 192.168.100.1(53966) idle
postgres  10234   8649  0 16:20 ?        00:00:00 postgres: syd postgres [local] idle

[postgres@localhost ~]$ ll /app/pg13/bin/postgres
-rwxr-xr-x 1 postgres postgres 8389568 Jun 30  2022 /app/pg13/bin/postgres
[postgres@localhost ~]$
[postgres@localhost ~]$ ll /app/pg13/bin/postmaster
lrwxrwxrwx 1 postgres postgres 8 Jun 30  2022 /app/pg13/bin/postmaster -> postgres

2. Process Description

  • postmaster process : the main process of the database, as shown above, postmaster is a soft connection, corresponding to the postgres process, compatible with the historical version, still retains the postmaster writing method, this process can be used to start and stop the database (postgres command encapsulated by pg_ctl), create (fork) customers Subprocess for end connections.
  • logger process : log process, only when the parameter logging_collect is set to on, the logger auxiliary process will be started.
  • Checkpointer process : checkpoint process, assists background write to write dirty data blocks in memory, and records the dirty blocks that have been written, so as to ensure that only new dirty blocks will be written next time.
  • background writer process : Data writing process, which writes dirty data blocks in shared memory to disk.
  • walwriter process : wal log writing process, the modified data is recorded in the wal log.
  • autovacuum launcher process : automatic cleaning process, automatically cleans up data marked as deleted (automatically cleans up dead tuples generated by multiple versions of MVCC).
  • archiver process : archiving process, backing up the wal log before overwriting and using it.
  • stats collector process : Statistical data collection process, the main function is the statistical collection of data, such as the number of insert, update and delete operations on a table, the number of reads and writes of disk blocks, the number of reads and writes of rows, and so on.
  • Logical replication launcher process : Logical replication process, the subscriber subscribes to the publisher for the update of the table through the logical replication launcher process and obtains the update.
  • postgres process : the client connection child process created by the postmaster.

3. Memory description

3.1 Shared memory

  After PostgreSQL is started, a piece of shared memory will be generated. The shared memory is mainly used as a buffer for data blocks to improve read and write performance. WAL log buffer and CLOG (CommitLog) buffer also exist in shared memory. In addition, some global information is also stored in shared memory, such as process information, lock information, global statistics, etc. The relevant database parameters are as follows:

  • shared_buffers : A reasonable starting value is 25% of the system memory, and the effect of setting too large may not always be ideal, because PostgreSQL also relies on the high-speed buffer of the operating system, and the default value is 128MB.

3.2 Local memory

  In addition to accessing shared memory, the background service process will also apply for the allocation of some local memory in order to temporarily store some data that does not require global storage. The relevant database parameters are as follows:

  • temp_buffers : Set the maximum memory used for temporary buffers for each database session, local buffers for accessing temporary tables, the default value is 8MB.
  • work_mem : Sets the base maximum memory capacity that each query operation (sort or hash table) can use before writing to a temporary disk file. The default value is 4MB.
  • maintenance_work_mem : Specifies the maximum amount of memory used in maintenance operations (such as VACUUM, CREATE INDEX, and ALTER TABLE ADD FOREIGN KEY). The default value is 64MB.

PostgreSql logical structure: https://xiaosonggong.blog.csdn.net/article/details/131452022
PostgreSql file directory structure: https://xiaosonggong.blog.csdn.net/article/details/120303380

Guess you like

Origin blog.csdn.net/songyundong1993/article/details/132026800