{"canonical_url":"https://engineer.company/glossary/postgresql/","content_markdown":"# PostgreSQL\n\n## What it is\n\nPostgreSQL is a relational database server, free and open source, that keeps\ndata in tables, answers questions written in SQL and makes every transaction\nall-or-nothing. Most people who work with it call it Postgres, and the project\ntreats both names as its own. Asked “what is PostgreSQL?”, a working engineer\nwould put it plainly: it is the general-purpose database a new system starts on\nwhen nobody has a specific reason to choose another.\n\nIt is older than most of the software it now sits underneath. The POSTGRES\nproject began at the University of California at Berkeley under Professor\nMichael Stonebraker, and its implementation started in 1986. Andrew Yu and Jolly\nChen gave it an SQL interpreter in 1994 and released the result as Postgres95.\nTwo years later it was renamed PostgreSQL, and the version numbers restarted at\n6.0 to continue the sequence Berkeley had begun. The project itself describes\nthe system as object-relational: beyond tables and joins, a user can add new\ndata types, functions, operators, aggregates, index methods and procedural\nlanguages, and the server treats them as its own.\n\nArchitecturally it is a client and a server. One server process owns the data\nfiles, and every client connection gets a process of its own, forked for that\nconnection alone. Applications send it SQL over that connection, through a\ndriver for whatever language they are written in. Concurrency rests on\nmultiversion concurrency control: an update writes a new version of a row\nrather than overwriting the old one, so each statement reads a consistent\nsnapshot, readers never wait for writers, and writers never wait for readers.\n\nWhere does it sit among the alternatives? Beside MySQL and MariaDB as the other\nopen-source relational servers, beside Oracle and Microsoft SQL Server as the\ncommercial ones, beside SQLite as the embedded database that lives inside one\nprogram, and against document stores such as MongoDB, which keep records\nwithout a fixed schema.\n\n## Why it matters\n\nChoosing a database is a decision a team lives with for years, because the data\noutlasts the code written against it. PostgreSQL is the low-regret default for\nthree reasons a buyer can check.\n\nThe first is cost and lock-in. It is released under the PostgreSQL License, a\nshort permissive licence in the family of BSD and MIT, so there is no per-core\nfee, no audit and no vendor who can change the terms. Amazon, Microsoft and\nGoogle each sell it as a managed service, and the same database runs on a\nlaptop, which means moving between hosts is a migration of data rather than a\nrewrite of the application.\n\nThe second is breadth. One server covers relational tables, JSON documents in\n`jsonb` columns, full-text search, geospatial queries through the PostGIS\nextension, and scheduled jobs through `pg_cron`. Each of those is a separate\nproduct a team does not have to run, secure, back up and hire for. For most\nproducts, PostgreSQL versus MySQL is decided here: for plain reads and writes\neither serves well, and the difference shows when the work needs richer types,\nstricter constraints or an extension.\n\nThe third is longevity. The project ships one major version a year and supports\neach for five years, so an upgrade can be planned for instead of forced by an\nemergency. PostgreSQL 18, released in September 2025, added asynchronous I/O and\na native function for time-ordered UUIDs, and SQL written for releases a decade\nolder generally runs on it unchanged.\n\nThe trade-offs are real. A process per connection makes connections expensive,\nso a busy application needs a pooler. It grows on one larger machine more\neasily than across several: spreading writes over many servers means\npartitioning, replication or an extension, and each adds operational weight.\nAnd its defaults are tuned for a small machine, so a serious installation has\nto be configured on purpose.\n\n## What it looks like in practice\n\nMany of the projects on this site run on PostgreSQL, and three of them show\nthree different ways to lean on it.\n\nOn one platform the database became the whole data layer.\n[Every read and write goes through one of 1,275 PostgreSQL functions](/portfolio/designed-a-function-first-postgresql-data-layer/)\nacross 34 schemas, and the Go API has no direct access to any table. The role\nthe API logs in as, `mariner`, holds EXECUTE on the functions and USAGE on the\nschemas and nothing else, roughly 4,000 explicit grants. The functions run as\nSECURITY DEFINER under a separate non-login owner with a pinned `search_path`.\nThe access boundary is enforced by Postgres itself; the price is that a new\nfield means a migration and a function change.\n\nOn an application holding tenants, locations and daily electricity readings,\nthe work was tuning rather than design, and the brief was 10x without\noverhauling the architecture. GiST indexes for the spatial data, composite\nindexes on tenant and date range,\n[range partitioning of the electricity table by day and month](/portfolio/accelerated-postgresql-performance-by-10x/),\nand queries rewritten after reading their plans with `EXPLAIN ANALYZE` improved\nquery response times by 10x and cut resource utilization by 40%.\n\nAnd on a platform with slow background work, the job queue lives in the same\ndatabase. [River keeps its queue in PostgreSQL](/portfolio/moved-slow-work-onto-a-river-job-queue/),\nso a job and the rows it touches commit or roll back together. Behind it are 15\nworker modules, 8 scheduled tasks and 20 `pg_cron` jobs that prune partitions,\nrotate salts and refresh aggregates. The page states the limit plainly: a queue\nin Postgres stops being the right answer at some volume, and one less moving\npart was worth more than headroom nobody was going to use.\n\n## Where it goes wrong\n\nPostgreSQL rarely loses data. It does surprise people, and the surprises come in\na few familiar shapes.\n\n**The table grows while the row count stays flat.** An `UPDATE` or `DELETE`\nleaves the old row version behind until `VACUUM` removes it, because another\ntransaction may still be reading it. A transaction left open for hours holds\nthat cleanup back for the whole database, and autovacuum's defaults suit small\ntables. Close idle transactions, tune autovacuum per table for the large ones,\nand partition data that expires so that old months are dropped rather than\ndeleted. Vacuum also does a second job: transaction IDs are 32 bits, every table\nhas to be vacuumed at least once every two billion transactions, and a server\nthat falls too far behind refuses new writes to protect the data.\n\n**Memory runs out at the first traffic spike.** Each connection is a server\nprocess with its own memory, and the default limit is 100 connections. Twenty\napplication instances with a pool of fifty each ask for a thousand processes.\nPut a pooler such as PgBouncer in front, and size each application's pool for\nthe work, which is usually a handful of connections per instance.\n\n**A query that took milliseconds starts taking seconds.** The planner chose a\ndifferent plan as the data grew, often because its statistics went stale or the\nindexes were built for the queries of a year ago. Read the plan before changing\nanything, refresh statistics with `ANALYZE`, and index the predicate the query\nactually filters on:\n\n```sql\nEXPLAIN (ANALYZE, BUFFERS)\nSELECT id, total FROM orders\nWHERE customer_id = 42 AND placed_at \u003e= '2026-01-01';\n```\n\n**Inserts slow down as the table gets large.** Random UUIDs as primary keys land\nall over the B-tree index, so every insert touches a different page and the\nindex fragments. Time-ordered identifiers avoid this:\n[one platform made UUID v7 its default key through PostgreSQL 18's `uuidv7()`](/portfolio/quicker-answers-from-a-better-choice-of-key/),\nand new rows sort into the index instead of scattering across it.\n\n## Further reading\n\n- [What Is PostgreSQL?](https://www.postgresql.org/docs/current/intro-whatis.html)\n  — the project's own definition, with the features and extension points it\n  names.\n- [A Brief History of PostgreSQL](https://www.postgresql.org/docs/current/history.html)\n  — Berkeley, Postgres95 and the rename, from the people who did it.\n- [Concurrency Control: Introduction](https://www.postgresql.org/docs/current/mvcc-intro.html)\n  — how snapshots let reads and writes proceed without blocking each other.\n- [Routine Vacuuming](https://www.postgresql.org/docs/current/routine-vacuuming.html)\n  — dead row versions, autovacuum and transaction ID wraparound in full.\n- [Using EXPLAIN](https://www.postgresql.org/docs/current/using-explain.html)\n  — how to read a query plan, with worked examples.\n- [Versioning Policy](https://www.postgresql.org/support/versioning/) — the\n  yearly major release and the five years of support behind each.\n\n\u003chttps://engineer.company/glossary/postgresql/\u003e\n","date_modified":"2026-10-20T21:59:50Z","description":"What PostgreSQL is, when it is the right default database, what it costs to run well, and the four ways it most often goes wrong in production.","formats":{"gemtext":"https://engineer.company/glossary/postgresql/index.gmi","gopher":"https://engineer.company/glossary/postgresql/gophermap","html":"https://engineer.company/glossary/postgresql/","json":"https://engineer.company/glossary/postgresql/index.json","markdown":"https://engineer.company/glossary/postgresql/index.md","pdf":"https://engineer.company/glossary/postgresql/index.pdf"},"kind":"page","language":"en","title":"What is PostgreSQL?","url":"https://engineer.company/glossary/postgresql/","version":1}