This paper mainly describes several main processes of PG, and the core architecture of PG. Process and architecture See:
As can be seen from the architecture diagram above, PG uses the classic C/s architecture, the process architecture. There are a large number of main processes, service processes, child processes, shared memory, and file storage on the server side, with a detailed account of a few parts of the server segment:
1. Postmaster Master process and service process
When the PG database is started, the postmaster Master process is started first. This process is the total control process for the PG database and is responsible for starting and shutting down the database instance. The postmaster process is actually a link to the Postgres command, as follows:
[ [email protected] ~ ] $ ll / opt/ Postgresql/ Bin/ postmaster lrwxrwxrwx. 1 Postgres dba 8 7 23 : / opt/ Postgresql/ Bin/ postmaster -> postgres
When the user and the PG database establish a connection to the postmaster process, the client process sends an authentication message to the postmaster master process, postmaster the main process is authenticated based on the message, The postmaster Master process will fork out a session service process to connect the service to this user. The PID of the service process can be viewed through the Pg_stat_activity table, as follows:
Test=Select from pg_stat_activity; PID | usename | | -------+----------+-------------+-------------26402| | | - 1 (1 Row)
2. Bgwriter (background Write) process
The bgwriter process is a process that writes dirty pages in shared memory to disk. It has two functions: one is to periodically brush the dirty data from the memory buffer to the disk, reduce the blocking of the query, and the other is that the PG needs to write out all the dirty pages to disk in a regular checkpoint, and write some dirty pages beforehand by bgwriter, which can reduce the set checkpoint (CheckPoint, Database recovery technology, the IO operation to make the system's IO load tend to smooth. Bgwriter is a new feature after PostgreSQL 8.0, and its mechanism can be controlled by the configuration parameters in the postgresql.conf file with "Bgwriter_":
#-Background Writer-#bgwriter_delay=200MS #Ten-10000msbetweenRounds
#bgwriter_lru_maxpages= -#0- + MaxBuffers written/round#bgwriter_lru_multiplier= 2.0#0-10.0Multiplier onBuffers scanned/round#bgwriter_flush_after=512kB # measuredinchPages,0Disables
Bgwriter_delay:
The interval between the time that the Backgroud writer process flush data twice in a row. The default value is 200, in milliseconds.
bgwriter_lru_maxpages:
backgroud writer Process writes the maximum amount of data per write, the default value is 100, unit buffers. If the amount of dirty data is less than this value, the write operation is all done by the Backgroud writer process, whereas the larger part will have the server process process complete when the value is greater than. Setting this value to 0 disables the Backgroud writer write process, which is complete with the server process, and 1 indicates that all dirty data is done by Backgroud writer. (This does not include the checkpoint operation)
bgwriter_lru_multiplier:
bgwriter maximum data volume calculation:
1000/bgwriter_delay*bgwriter_lru_maxpages*8k= maximum amount of data
bgwriter_flush_after:
The bgwriter is triggered when the data page size reaches Bgwriter_flush_after, and the default is 512KB.
"PostgreSQL" Process and architecture