PostgreSQL Explained: The Database You Default To
Introduction
Ask experienced developers which database to pick for a new project, and one answer comes up more than any other: PostgreSQL, usually called Postgres. It is free, open source, battle-tested for decades, and now the most loved database in developer surveys. If the SQL joins post taught you how to ask questions of data, this one explains where that data should live.
Tables, rows, and relationships
Postgres is a relational database: data lives in tables of rows and columns, and tables relate to each other by keys. A blog has users, posts, and comments — three tables, linked by IDs:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL
);
CREATE TABLE posts (
id SERIAL PRIMARY KEY,
author_id INTEGER REFERENCES users(id),
title TEXT NOT NULL,
body TEXT
);
PRIMARY KEY uniquely identifies each row, REFERENCES users(id) says a post's author must be a real user, and UNIQUE prevents duplicate emails. These constraints are the database enforcing your rules even when application code forgets — which is exactly the safety net you want.
ACID: the promise that matters
Postgres is famous for ACID guarantees: Atomicity, Consistency, Isolation, Durability. In plain terms: a transfer that debits one account and credits another either completes fully or not at all, never halfway; the data is always left in a valid state; concurrent users don't corrupt each other's work; and once the database confirms a write, it survives a crash. For anything involving money, orders, or user accounts, ACID is not a luxury — it is the reason to choose a relational database in the first place.
Not just rows: JSON too
Modern Postgres also handles JSON data inside columns, so you don't need a second database for flexible, document-like data:
CREATE TABLE products (
id SERIAL PRIMARY KEY,
details JSONB
);
INSERT INTO products (details)
VALUES ('{"name": "Keyboard", "price": 49, "tags": ["mechanical", "wireless"]}');
SELECT details->>'name' FROM products WHERE details @> '{"price": 49}';
JSONB stores JSON efficiently and queryably — you can search inside it, index it, and combine it with normal columns in the same query. That flexibility is why many teams now use Postgres for everything, instead of one database per data shape.
Takeaway
Tables with enforced relationships, ACID guarantees for data you cannot afford to lose, and JSON support when you need flexibility. That combination is why Postgres is the default answer — and why "just use Postgres" is genuinely good advice for most new projects.
Comments
Post a Comment