Interview Q&A · questions with model answers
PostgreSQL Interview Questions
Part of the study plan for: Data Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked What does VACUUM do, and how does autovacuum work?
VACUUM marks space from dead tuples as reusable, updates the visibility map (enabling index-only scans) and freezes old transaction IDs. Autovacuum runs it automatically when a table's dead tuples…
-
Most asked What index types does PostgreSQL support, and when do you use each?
B-tree (default: equality, ranges, sorting), Hash (equality only), GIN (inverted index for JSONB, arrays, full-text, trigrams), GiST (geometric data, ranges, nearest-neighbour, exclusion…
-
Most asked What isolation levels does PostgreSQL provide, and how do they behave?
READ COMMITTED (the default: each statement sees data committed before it started), REPEATABLE READ (snapshot isolation: the whole transaction sees one snapshot and concurrent updates of the same…
-
Most asked What is a partial index, and when is it useful?
A partial index covers only rows matching a WHERE condition, for example CREATE INDEX ON jobs (created_at) WHERE status = 'queued'. It is small, cheap to maintain, and fast for queries that use the…
-
Most asked What do shared_buffers, work_mem and effective_cache_size control?
shared_buffers is PostgreSQL's own page cache (commonly about 25% of RAM); effective_cache_size is only a planner hint of how much data the OS cache plus shared buffers can hold (often 50-75% of…
-
What is transaction ID wraparound, and how do you prevent it?
Transaction IDs are 32-bit and compared modulo 2^32, so after about 2 billion transactions old rows would appear to be 'in the future'. VACUUM 'freezes' old tuples to mark them visible to everyone.…
-
What are expression indexes?
An index on the result of an expression, such as lower(email) or (payload->>'customer_id'). Queries using exactly that expression can use the index.
-
What are covering indexes and index-only scans in PostgreSQL?
An index-only scan answers a query from the index without visiting the table (heap). It requires that the index contains every needed column, which INCLUDE makes possible without adding the columns…
-
What are advisory locks in PostgreSQL?
Application-defined locks identified by a number (or two), managed by PostgreSQL but with no meaning to it: pg_advisory_lock(key) / pg_try_advisory_lock(key) and their transaction-scoped variants…
-
What are WAL and checkpoints, and why do they matter for performance?
The write-ahead log records every change before data files are modified, so committed work survives crashes and can be replicated. A checkpoint flushes all dirty pages to data files so older WAL is…
-
What is row-level security, and when would you use it?
Row-level security (RLS) lets the database filter rows per user or session with policies: CREATE POLICY tenant_isolation ON orders USING (tenant_id = current_setting('app.tenant_id')::bigint);. Once…
-
What are exclusion constraints? Give an example.
An exclusion constraint guarantees that no two rows satisfy a set of operator comparisons, generalising UNIQUE. The classic example: no two bookings for the same room may overlap in time, enforced…
-
What are materialized views, and how do you refresh them without blocking reads?
A materialized view stores the result of a query physically, so expensive aggregations can be read quickly. It does not update itself; REFRESH MATERIALIZED VIEW recomputes it, and REFRESH ...…
-
What is logical decoding, and how is it used for change data capture?
Logical decoding turns WAL into a stream of row-level changes (inserts, updates, deletes) through a replication slot and an output plugin (pgoutput, wal2json). CDC tools such as Debezium consume it…
-
What is the fastest way to bulk-load data into PostgreSQL?
COPY (or \copy from psql, or the driver's COPY API) streams rows in bulk and is much faster than individual INSERTs. For very large loads, create indexes and foreign keys after loading, raise…
-
What does the RETURNING clause give you?
INSERT, UPDATE, DELETE and MERGE can return values from the affected rows, such as generated IDs, defaults or updated values, in the same statement and round trip.
-
What does synchronous replication guarantee in PostgreSQL?
With synchronous_standby_names set, a commit waits until the configured standbys confirm they have received (and with synchronous_commit = on, flushed) the WAL, so a primary failure loses no…
-
What is TOAST?
TOAST (The Oversized-Attribute Storage Technique) automatically compresses large values and moves them out of the main table into a separate TOAST table when a row exceeds about 2 KB, so large text,…
-
What are LISTEN and NOTIFY used for?
A lightweight publish/subscribe channel inside PostgreSQL: a session runs LISTEN orders, and any transaction can NOTIFY orders, 'payload' (or pg_notify), delivered to listeners when it commits. It…
-
What are HOT updates, and how does fillfactor help?
A heap-only tuple (HOT) update happens when no indexed column changes and the new row version fits on the same page: no index entries are written, and the old version can be pruned without VACUUM.…
-
What are generated columns in PostgreSQL?
GENERATED ALWAYS AS (expression) STORED columns are computed from other columns on every write and stored, so they can be indexed and queried like normal columns. PostgreSQL 18 adds virtual…
-
What are deferrable constraints?
Constraints declared DEFERRABLE can be checked at commit time instead of after each statement (SET CONSTRAINTS ... DEFERRED or INITIALLY DEFERRED). This allows temporarily inconsistent states within…