PostgreSQL

PostgreSQL is an open-source object-relational DBMS distributed under the PostgreSQL License (a BSD-style license). It supports a wide range of standard SQL, and extensions can add data types, indexes, and functions. This site's sandbox uses PostgreSQL 17.

Key Specs

ItemValue
Storage unitPage (block), 8KB by default. Set at build time, up to 32KB
Table storageHeap (rows are stored in free space regardless of arrival order). No clustered tables
Table filesOne file per table or index, with a new segment file every 1GB
Buffer poolshared_buffers, 128MB by default
Large value handlingTOAST: compresses large values in rows over about 2KB or moves them to a separate table. Up to 1GB per value
Concurrency controlMVCC. Leaves old row versions in the same table, and VACUUM reclaims them
LogWAL (Write-Ahead Log), 16MB segments by default
Default isolation levelRead Committed
Execution structureOne backend process per connection (process model)
Operating system cacheUsed together. Reads and writes data files with buffered I/O
ReleasesOne major version per year, each supported for 5 years

Process Structure

When the server starts, the postmaster process waits for connections and creates one backend process each time a client connects. All processes share shared_buffers and the WAL buffers in shared memory. Because one connection is one process, thousands of connections raise memory and context-switch costs, and a connection pooler such as PgBouncer is usually placed in front. The full picture of processes and memory areas is in Memory and Process Structure; connections, prepared statements, and cursors are in Connections, Cursors, and the SQL Cache.

Background processWhat it does
checkpointerWrites all dirty pages to disk at a checkpoint
background writerWrites dirty pages ahead of time, a few at a time, between checkpoints
walwriterWrites the WAL buffers to the WAL files
autovacuum launcher / workerRuns VACUUM and ANALYZE on tables that have accumulated dead rows

Row Versions and VACUUM

An UPDATE does not overwrite the same location. It adds a new row version and marks the old version as ended (xmax). VACUUM reclaims the old version after every transaction that could see it has finished. This makes rollback fast and lets reads avoid waiting for writes, but a heavily updated table tends to grow (bloat) because of dead rows. If you leave free space in a table with fillfactor, more HOT updates write the new version inside the same page, which reduces index updates.

Configuration and Checks

SELECT version();
SHOW block_size;                 -- 8192
SHOW shared_buffers;
SELECT name, setting, unit, context FROM pg_settings WHERE name IN ('shared_buffers', 'work_mem', 'max_connections');

Comparison with Other DBMSs

  • Because the table is a heap, secondary indexes point to the row address (ctid). MySQL (InnoDB) stores rows in primary key order, and its secondary indexes point to the primary key value.
  • PostgreSQL is the only one of these DBMSs that keeps old versions inside the table. Oracle and InnoDB keep them in Undo, and SQL Server keeps them in the version store.
  • DDL can also be rolled back inside a transaction.

In the Articles

NOTE Defaults and limits can vary by version.

Related pages