PostgreSQL is a client/server type relation database management system.
PostgreSQL has multi-process architecture.
PostgreSQL runs on a single host.
PostgreSQL server(PG服务器) — A cluster of multiple processes which cooperatively manage one database cluster.
PostgreSQL server process(PG服务器进程)— A parent of all processes related to a database cluster management. In 2.1.1 of this chapter.(Main process,也就是主进程)
Back-end process(后端进程)— Each back-end process handles all queries and statements(查询与语句) issued by a connected client.(处理所有由与其连接的客户端发布的查询和语句,每有一个客户端与PG服务器建立连接,就会创建一个与之交互的 Back-end Process)In 2.1.2 of this chapter.
background process(后台进程)— perform processes of each feature(每个特征的进程) for database management. For example, VACUUM, CHECKPOINT, WAL, LOG WRITER processes. In 2.1.3 of this chapter.
replication associated processes(与复制相关的进程)— perform the streaming replication(流复制),Chapter 11
background worker process(后台工作进程)— it can perform any processing implemented by users.
After ①starting server, ②OS will allocate a block of shared memory for starting various background processes, (③and starting replication associated process & background worker process IF NECESSARY ), and ④then waiting for the connection request from the clients. Whenever receiving a connection request from a client, it ⑤starts a back-end process.
When we use command line to access the PostgreSQL server, what process play the role of client? bash?
A Postgres server process listens to one network port, the default port is 5432. Although more than one PostgreSQL server can be run on the same host, each server should be set to listen to different port number in each other. (同一台主机中的不同PG服务器应该要使用不同的端口号,不能都用一个默认的5432)
2.1.2 Back-end Processes
A back-end process, which is also called Postgres, is started by the Postgres server process and handles all queries issued by one connected client. (会话服务进程)
Each a client establishes a connection with the PG server, a Back end Process is created to interact with it.
It communicates with the client by a single TCP (Transfer Control Protocol, 传输控制协议) connection.
Too frequently repeat the connection and disconnection with a PostgreSQL server will increase the cost of establishing connections and of creating back-end processes, because PostgreSQL has not implemented a native connection pooling feature. WHAT IS POOLING FEATURE???
2.1.3. Background Processes
Because of these functions of background processes depend on the individual specific features and PostgreSQL internals. Their details will be described in the following chapters.
process
description
reference
background writer()
将共享缓存池中的脏页逐渐定期写入一个持久的存储器(例如:HDD硬盘驱动器,SSD闪存) (In version 9.1 or earlier, it was also responsible for checkpoint process.)
The Memory Architecture in PG can be classified into two broad categories:
①Local memory area — allocated by each back-end process for its own use(分配给每一个*postgres*会话服务进程自身使用)
②Shared memory area — used by all processed of a PostgreSQL server(同一个PG服务器的所有子进程共用)
2.2.1 Local Memory Area
Each back-end process allocates a local memory area for query processing, and each local memory is divided into several sub-areas, and those sub-areas’ sizes are either fixed or variable. (每一个会话服务程序的Local Memory Area 又被分成一些或固定或变化的子区域)Some major sub-areas are shown as follow:
sub-area
description
reference
work_mem
Using this area for sorting tuples by ORDER BYand DISTINCT operations, and for joining tables by merge-join and hash-join operations. (这一块区域用于接受order by和distinct命令时将元组排序,也用于通过合并联接和散列联接操作联接表。)
A shared memory area is allocated by a PostgreSQL server when it starts up. This area is divided into several fixed sized sub-areas.
sub-area
description
reference
shared buffer pool(共享内存池)
PostgreSQL will load pages (within tables and indexes) from the persistent storage to here, and then operate them directly. (PG会把pages从固存中加载到这一块区域,以便直接操作它们)