Skip to content
IT glossary
DatabasesUpdated December 3, 2026

PostgreSQL

An open-source database system that stores information in related tables. Applications use SQL to read and change the data, while the server enforces rules such as whether an order refers to a real customer.

Also known as: Postgres, постгрес

What is PostgreSQL?

PostgreSQL, often called Postgres, is an open-source relational database system. A booking app might keep rooms and reservations in separate tables. A primary key identifies each room, and a foreign key on the reservation makes sure it refers to a room that exists. The database enforces that rule whether the reservation comes from the app, an import script, or a developer running SQL directly. SQL is the language; PostgreSQL is the server that stores the data and runs the statements.

What happens when you run a query?

An application connects through a database driver and sends a SQL statement. PostgreSQL's planner considers different ways to run it, such as scanning a table or using an index. It uses statistics to estimate how many rows will match and picks a plan based on estimated cost. That is why the same query can get a different plan in development and production.

Transactions group changes so they can be committed or rolled back together. To handle concurrent work, PostgreSQL uses multiversion concurrency control (MVCC). An update creates a new row version, and each query works with a snapshot that determines which versions it can see. Plain reads and writes generally don't block each other, but two updates to the same row can still contend for a lock. PostgreSQL's autovacuum service runs routine cleanup so space occupied by obsolete row versions can be reused once no transaction needs them.

Example: upcoming reservations for a room

CREATE INDEX reservations_room_start_idx
    ON reservations (room_id, starts_at);

SELECT id, starts_at
FROM reservations
WHERE room_id = 7 AND starts_at >= CURRENT_TIMESTAMP
ORDER BY starts_at
LIMIT 5;

This B-tree index groups entries by room and orders them by start time within each room. PostgreSQL can seek to the first upcoming reservation for room 7, then read the next few entries in order instead of sorting the result. An index makes that plan possible, not mandatory. Use EXPLAIN to see what the planner picked. EXPLAIN ANALYZE actually runs the statement and reports measured timings and row counts, so take care when using it with statements that change data.

Where it fits and what to watch for

PostgreSQL is often the primary database for applications that need transactions, constraints, and joins. It also supports jsonb for attributes that vary across records. That doesn't mean stable fields such as room IDs should live inside JSON: regular columns make it straightforward to enforce types and declare foreign keys. Likewise, index the queries that matter rather than every column. Indexes take up space and add work when data changes.

How it comes up in interviews

Expect to reason through a query plan or a transaction running in two sessions. For a plan, explain how many rows the query is likely to return before deciding whether an index should help. For a transaction, distinguish what each session can see from what it can update without waiting.

“PostgreSQL” questions from real interviews

Asked at 317 companies

All Python questions