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
| Item | Value |
|---|---|
| Storage unit | Page (block), 8KB by default. Set at build time, up to 32KB |
| Table storage | Heap (rows are stored in free space regardless of arrival order). No clustered tables |
| Table files | One file per table or index, with a new segment file every 1GB |
| Buffer pool | shared_buffers, 128MB by default |
| Large value handling | TOAST: compresses large values in rows over about 2KB or moves them to a separate table. Up to 1GB per value |
| Concurrency control | MVCC. Leaves old row versions in the same table, and VACUUM reclaims them |
| Log | WAL (Write-Ahead Log), 16MB segments by default |
| Default isolation level | Read Committed |
| Execution structure | One backend process per connection (process model) |
| Operating system cache | Used together. Reads and writes data files with buffered I/O |
| Releases | One 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 process | What it does |
|---|---|
| checkpointer | Writes all dirty pages to disk at a checkpoint |
| background writer | Writes dirty pages ahead of time, a few at a time, between checkpoints |
| walwriter | Writes the WAL buffers to the WAL files |
| autovacuum launcher / worker | Runs 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
- 1.4 When a Record Is Updated
- 1.6 Buffer Pool Management Rules by Database
- 1.8 Differences Between DBMSs
NOTE Defaults and limits can vary by version.
Related pages
- PostgreSQL Memory and Process Architecture
- PostgreSQL connections, cursors, and SQL cache
- DBMS Architecture at a Glance
- shared_buffers
- TOAST
- PostgreSQL WAL
- full_page_writes
- synchronous_commit
- VACUUM
- PostgreSQL Lock Modes
- PostgreSQL isolation levels and SSI
- Operating system cache and direct I/O
- MySQL (InnoDB)
- Oracle Database
- SQL Server / Azure SQL