PostgreSQL源码学习--Chapter 2 Process and Memory Architecture

Chapter 2 Process and Memory Architecture

2.1 Process Architecture

  • 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.

相关资源链接

2.1.1 Postgres Server Process
  • It is also called Main Process, it was called Postmaster in the earlier versions.
  • All of other processes concerning database cluster management are the sub-process of it.
  • (负责是整个 data cluster 的总控进程,负责启动和关闭 data cluster。)
  • START IT: By issuing the command pg_ctl
# 启动PostgreSQL服务器
[usera@localhost /]$ pg_ctl -D /pgdata/15.3/poc/data start
  • 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.
processdescriptionreference
background writer()将共享缓存池中的脏页逐渐定期写入一个持久的存储器(例如:HDD硬盘驱动器,SSD闪存) (In version 9.1 or earlier, it was also responsible for checkpoint process.)Section 8.6
checkpointerSection 8.6, Section 9.7
autovacuum launcher自动清空工作进程被调用用于定期清空进程Section 6.5
WAL writer预写日志,Write Ahead Logging,此进程定期地把WAL缓存上的WAL数据写入一个持久的存储器Section 9.9
statistics collector这个进程收集pg_stat_activitypg_stat_database数据信息
logging collector(logger processor)将报错信息写入日志文件
archiver存档日志记录Section 9.10

2.2 Memory Architecture

  • 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-areadescriptionreference
work_memUsing this area for sorting tuples by ORDER BYand DISTINCT operations, and for joining tables by merge-join and hash-join operations. (这一块区域用于接受order bydistinct命令时将元组排序,也用于通过合并联接和散列联接操作联接表。)Chapter 3
maintenance_work_memBy using for some maintenance operations. (用于一些维护性操作,例如:vaccumreindexSection 6.1
temp_buffersFor storing temporary tables. (用于存储临时的表)
2.2.2. Shared Memory Area
  • 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-areadescriptionreference
shared buffer pool(共享内存池)PostgreSQL will load pages (within tables and indexes) from the persistent storage to here, and then operate them directly. (PG会把pages从固存中加载到这一块区域,以便直接操作它们)Chapter 8
WAL buffer(预写日志缓存)This mechanism could ensure that users’ data will not be lost by PG server failures.(WAL机制能确保用户存储在数据库中的数据不会因为PG服务器崩溃而丢失)Chapter 9
commit log((事务)提交日志)Commit Log(CLOC) keeps the states of all transactions for Concurrency Control mechanism.(CLOC保存着所有并发控制机制的事务状态)Section 5.4
各种访问控制机制的子区域Sub-areas for the various access control mechanisms. (e.g., semaphores, lightweight locks, shared and exclusive locks, etc)
给各种后台进程用的区域Sub-areas for the various background processes. (e.g., checkpointer & autovacuum).
给各种事务进程用的区域Sub-areas for transaction processing ( e.g., save-point & two-phase-commit).
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值