PostgreSQL

On this page 7

PostgreSQL is an open-source object-relational database management system that stores data in tables, queries it with SQL and guarantees ACID transactions through multiversion concurrency control. Among database systems, it is the general-purpose relational engine most valued for standards compliance, data integrity and extensibility, and it runs workloads that range from small web applications to multi-terabyte analytical and transactional databases.

The project descends from the POSTGRES research system and is developed by an independent global community under the permissive PostgreSQL License. A new major version is released about once a year, and each major version receives fixes for five years, which gives operators a predictable upgrade cycle.

How the PostgreSQL architecture works

PostgreSQL uses a process-per-connection model: a supervisor process called the postmaster accepts each client connection and starts a dedicated backend process to serve it. All backends share a common memory area, shared_buffers, that caches data pages read from disk.

Durability comes from the write-ahead log (WAL). Every change is first written to the WAL and flushed at commit, so the data files can be updated lazily by the checkpointer and background writer. After a crash, the server replays the WAL from the last checkpoint to restore a consistent state. The same WAL stream feeds streaming replication and point-in-time recovery.

ComponentRoleOperational note
PostmasterAccepts connections and starts backendsOne process per client connection
Shared buffersCaches table and index pagesOften set to about 25% of RAM
WAL writer and checkpointerPersist the log and flush dirty pagesCheckpoint spacing affects I/O spikes
AutovacuumRemoves dead row versions and updates statisticsMust keep up with write volume
WAL senderStreams the log to replicasOne per connected standby
Main PostgreSQL server components

MVCC and vacuum in PostgreSQL

PostgreSQL implements multiversion concurrency control (MVCC) by keeping old row versions inside the table itself. An UPDATE writes a new tuple and marks the old one as expired, so readers never block writers and writers never block readers; each transaction sees the snapshot that matches its isolation level.

The cost of this design is dead tuples. They occupy space until VACUUM reclaims it, and a table whose cleanup falls behind suffers bloat, slower scans and larger indexes. VACUUM also freezes old transaction IDs, which prevents transaction ID wraparound, a condition that forces the server to stop accepting writes if it is ignored for too long. Tuning autovacuum thresholds for large, busy tables is therefore a routine task for PostgreSQL administrators.

Data types, indexes and extensions

PostgreSQL is distinguished by an unusually rich type system and pluggable index methods. Besides standard numeric, text and temporal types, it offers arrays, ranges, UUID, network addresses, and JSONB, a binary JSON format that can be indexed and queried efficiently.

Index methodBest suited forExample query
B-treeEquality, ranges and sortingWHERE created_at > a date
HashEquality onlyWHERE token = a value
GINJSONB, arrays and full-text searchWHERE tags contain a value
GiSTGeometry, ranges and nearest-neighbor searchOverlapping time ranges
BRINVery large tables ordered by insertionTime-ordered log tables
Index methods available in PostgreSQL

The extension mechanism lets new types, functions, index methods and even storage behavior be added without forking the server. Widely used extensions include PostGIS for geospatial data, pg_stat_statements for query statistics, and pgvector for vector similarity search, which turns PostgreSQL into a multi-model platform.

PostgreSQL compared with other database systems

PostgreSQL competes mainly with MySQL and MariaDB as a general-purpose relational server, while SQLite, MongoDB and Redis serve different shapes of workload. The table summarizes the practical differences that usually drive the choice.

SystemModel and deploymentTypical strength
PostgreSQLObject-relational client-serverComplex SQL, integrity, extensibility
MySQL and MariaDBRelational client-serverSimple read-heavy web workloads, wide hosting support
SQLiteEmbedded library in one fileLocal storage inside applications
MongoDBDocument databaseFlexible schemas and horizontal sharding
RedisIn-memory key-value storeCaching, counters and queues
PostgreSQL and neighboring database systems

Compared with MySQL, PostgreSQL offers transactional DDL, more complete window functions and CTEs, stricter type checking and a more advanced query planner. MySQL with InnoDB often needs less tuning for simple primary-key lookups. Neither system is universally faster; the workload and the team’s operational experience decide.

Configuration and operational pitfalls

A default PostgreSQL installation is configured conservatively and needs adjustment for production hardware. The following settings are the first ones administrators review.

SettingTypical starting valueWhat it affects
shared_buffersAbout 25% of RAMSize of the page cache
effective_cache_size50-75% of RAMPlanner estimate of OS caching
work_mem4-64 MB per operationSorts and hashes before spilling to disk
max_connections100-300Process count and memory use
random_page_cost1.1-1.5 on SSD storagePreference for index scans
Key PostgreSQL settings and typical starting values
  • Too many direct connections waste memory because each is a process; use connection pooling such as PgBouncer.
  • Long-running transactions hold back vacuum and cause bloat across the whole database.
  • Major version upgrades require pg_upgrade or logical replication, not a simple package update.
  • Setting work_mem too high multiplies across concurrent operations and can exhaust memory.

Understanding it simply

PostgreSQL is a program that stores data in neat tables. People ask it questions in a standard language called SQL. It is free to use and very careful about keeping data correct. It can also store maps, documents and searchable text next to ordinary numbers and names.

Think of it as a meticulous archive clerk. The clerk never loses a record and lets many people read and write at once. The clerk also keeps a diary of every change, so nothing is lost if the power fails.

Applied in practice

A logistics company runs its shipment tracking on a single PostgreSQL primary with two streaming replicas. Orders and customers live in normalized tables, each shipment carries a JSONB column with carrier-specific fields, and depot locations use PostGIS to find the nearest warehouse for each delivery address.

As traffic grew to about 2,000 transactions per second, the team saw memory pressure from 600 direct application connections and growing bloat in the shipment events table. They placed PgBouncer in front of the server and reduced backend connections to 80, then lowered the autovacuum scale factor for the events table to 1%. Memory use stabilized, the table stopped growing beyond its live data size, and p95 query latency fell from about 120 ms to about 35 ms without new hardware.