DEV Community

Abdullah Bin Omer Zia
Abdullah Bin Omer Zia

Posted on

PostgreSQL - Process and Memory Architecture

PostgreSQL is a popular open-source client/server relational database management system with a multi-process architecture that runs on a single host. The system consists of multiple processes that cooperatively manage one database cluster, which is typically referred to as a 'PostgreSQL server.' The server contains several types of processes, including the postgres server process, backend processes, various background processes, replication-associated processes, and background worker processes.

The postgres server process is the parent of all processes related to a PostgreSQL server. It allocates a shared memory area in memory, starts various background processes, starts replication-associated processes and background worker processes if necessary, and waits for connection requests from clients. Whenever it receives a connection request from a client, it starts a backend process to handle all queries and statements issued by the client.

A backend process is started by the postgres server process and handles all queries issued by one connected client. It communicates with the client by a single TCP connection and terminates when the client gets disconnected. PostgreSQL allows multiple clients to connect simultaneously, and the configuration parameter max_connections controls the maximum number of clients (default is 100).

PostgreSQL has two broad categories of memory architecture: local memory area and shared memory area. The local memory area is allocated by each backend process for its own use and is divided into several sub-areas of fixed or variable sizes. The shared memory area is allocated by a PostgreSQL server when it starts up and is used by all processes of a PostgreSQL server. It is also divided into several fixed-size sub-areas.

In summary, PostgreSQL's process architecture consists of multiple processes that cooperatively manage one database cluster, and its memory architecture consists of a local memory area and a shared memory area. Understanding these architecture components is crucial to understanding how PostgreSQL operates and how to optimize its performance.

References

[1]: Suzuki, H. (n.d.). Internals of PostgreSQL. Retrieved from https://www.interdb.jp/pg/index.html

API Trace View

Struggling with slow API calls?

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay