DEV Community

Raja Rakshak
Raja Rakshak

Posted on • Updated on

Internals of PostgreSQL: Chapter 02: Process and Memory Architecture

The process architecture of PostgreSQL is explained at the beginning of the chapter. It outlines the various steps involved in running a PostgreSQL server, including:

1) Postgres Server Process: This parent process, formerly referred to as the postmaster in earlier iterations, is in charge of overseeing the whole PostgreSQL server. Prior to starting background processes, replication processes, and background worker processes, shared memory is allocated. It runs backend processes to respond to client requests and watches for requests for client connections.

2) Backend Processes: Backend processes are created by the postmaster to respond to requests from linked clients. Through a TCP connection, each backend process connects to a single client and runs until the client disconnects. Depending on the chosen maximum number of connections, numerous clients may connect at once to each backend process's single database.

3) Background Processes: PostgreSQL has a number of background processes that carry out different database management functions. These procedures include, among others:

  • Background Writer: Dirty pages from the shared buffer pool are written to persistent storage by the background writer.
  • Checkpointer: Performs checkpoint operations to guarantee data consistency and recovery.
  • AutoVacuum Launcher: Launches the processes used by the autovacuum workers to perform routine vacuuming.
  • WAL Writer: Records information from Write-Ahead Logs (WAL) in persistent storage.
  • Statistics Collector: Database activity statistics are gathered by the statistics collector.
  • Logging Collector (Logger) : Writing error messages to log files is done by the logging collector (logger).Executes archiving logging operations.

The following section of the chapter covers PostgreSQL's memory architecture, which can be divided into local memory and shared memory areas:

Local Memory Area: For the purpose of processing queries, each backend process allocates a separate local memory area. Sorting, maintenance tasks, and temporary tables are just a few examples of the specialized uses for which this area is divided into fixed or variable-sized sub-areas.

Shared Memory Area: The PostgreSQL server allots a portion of memory for shared use by all server processes when it first starts up. It consists of a number of sub-areas, including the commit log for keeping track of transaction statuses, the WAL buffer for buffering WAL data before writing it to storage, and the shared buffer pool for loading and using table and index pages.

Top comments (0)