What is PostgreSQL and what makes it popular for backend systems?
PostgreSQL is an open-source object-relational database known for standards compliance, reliability and extensibility. It is a common default for new Java and Spring Boot services and is offered as a managed service everywhere (Cloud SQL, Amazon RDS and Aurora, Azure Database, AlloyDB, Neon, Supabase).
Strengths
- Rich data types:
JSONB(binary JSON with indexing), arrays,UUID, ranges,INTERVAL, network types, enums, full-text search (tsvector), geospatial via PostGIS, vectors via pgvector for AI similarity search. - Advanced SQL: CTEs including recursive ones, window functions,
LATERALjoins,UPSERTwithON CONFLICT,RETURNING,MERGE, partial and expression indexes. - MVCC concurrency: readers never block writers.
- Extensibility: extensions (
pg_stat_statements,pg_trgm,postgis,pgvector,timescaledb), custom types and functions in PL/pgSQL. - Transactional DDL:
CREATE TABLEandALTER TABLEcan be rolled back, which makes migrations (Flyway, Liquibase) safer.
Versions to know
PostgreSQL ships a major version each year and supports each for five years. Recent releases improved logical replication, MERGE, JSON functions (JSON_TABLE in 17) and asynchronous I/O and uuidv7() (18).
Example
CREATE TABLE products (
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
sku TEXT UNIQUE NOT NULL,
name TEXT NOT NULL,
attributes JSONB NOT NULL DEFAULT '{}',
tags TEXT[] NOT NULL DEFAULT '{}',
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Upsert and return the stored row
INSERT INTO products (sku, name, attributes)
VALUES ('TSHIRT-RED-M', 'Red T-shirt', '{"size": "M", "color": "red"}')
ON CONFLICT (sku) DO UPDATE
SET name = EXCLUDED.name, attributes = EXCLUDED.attributes, updated_at = now()
RETURNING id, updated_at;
-- Query inside JSON and arrays
SELECT name FROM products
WHERE attributes ->> 'color' = 'red' AND 'summer' = ANY (tags);Follow-up questions interviewers ask
Try answering each one before you open it.
TIMESTAMP vs TIMESTAMPTZ?
TIMESTAMPTZ stores an absolute instant (converted to UTC internally and displayed in the session time zone); TIMESTAMP stores a wall-clock value with no zone. Use TIMESTAMPTZ for events, and map it to Instant or OffsetDateTime in Java.