DEV Community

m_aamir
m_aamir

Posted on

PostgreSQL Process Architecture

PostgreSQL is a powerful open-source relational database management system (RDBMS) used by many organizations and individuals around the world. If you are a developer who uses PostgreSQL frequently, it helps to understand its internal structure. In this article, we will discuss the process architecture of postgres.

Introduction

PostgreSQL has a client/server architecture. The client side is what the developer sees. The server side is made up of what is called a database cluster. A collection of multiple processes work together to manage the cluster, otherwise known as a PostgreSQL server. These processes are:

  • A postgres server process
  • Backend processes to handle queries from the client side
  • Various Background processes for different database management features
  • Replication associated processes for streaming replication
  • Background worker processes

The Postgres Server Process

A PostgreSQL server's postgres server process is the parent of all other processes. It used to be referred to as "postmaster" in older versions.

A postgres server process can be launched by executing the pg_ctl utility with the start option. The process sets aside a portion of shared memory area in memory, launches a number of background processes, launches background worker processes and replication-related processes as needed, and waits for client connection requests. It launches a backend procedure each time a client requests a connection. (All requests sent by the connected client are handled by the running backend process.)

A postgres server process listens to one network port, the default port is 5432.

Backend Processes

The postgres server process starts a backend process, which is also called postgres, that responds to all queries sent by a single connected client. It only uses one TCP connection to communicate with the client, and it terminates when the client disconnects.

You must specify the database you intend to use when connecting to a PostgreSQL server since only one database can be used at a time.

Multiple customers may connect to PostgreSQL at once; the configuration option max_connections restricts the number of clients that may connect at once (the default value is 100).

Due to PostgreSQL's lack of a native connection pooling functionality, expenses associated with establishing connections and developing backend procedures increases when several clients, such as WEB applications, repeatedly connect and disconnect from a PostgreSQL server. Such an event has a detrimental impact on the database server's performance. A pooling middleware (such as pgbouncer or pgpool-II) is typically used to handle such circumstances.

Background Processes

PostgreSQL has a wide variety of background processes. The most commonly used ones are briefly described below:

  1. Background writer: In this process, dirty pages on the shared buffer pool are written to a persistent storage (e.g., HDD, SSD) on a regular basis gradually.

  2. Checkpointer: Checkpoint process is performed.

  3. Autovacuum Launcher: Periodically invokes the vacuum process.

  4. Statistics Collector: Collects information for pg_stat_activity and pg_stat_database.

  5. Logging Collector: Writes error messages into log files.

  6. Archiver: Executes archiving logging.

References:

https://www.interdb.jp/pg/pgsql02.html

Top comments (0)