Q1
How does PostgreSQL's MVCC (Multi-Version Concurrency Control) prevent readers from blocking writers—and why does failing to VACUUM cause table bloat & Transaction ID Wraparound?
PostgreSQL updates write new row tuples rather than overwriting old ones in-place so concurrent snapshots stay non-blocking. Dead tuples remain until VACUUM marks space reusable; neglected autovacuum causes giant bloat and threatens Transaction ID wraparound shutdowns.
Q2
When indexing a PostgreSQL JSONB column, why do GIN indexes (jsonb_path_ops) speed up @> containment queries yet fail on ->> text lookups without expression indexes?
Default GIN indexes support @> key-value containment and ? existence operators, whereas WHERE payload->>'email' = 'a@b.com' uses B-tree equality—speed that up with a B-tree expression index ON table ((payload->>'email')).
Q3
Why is BRIN (Block Range Index) 100x smaller than B-tree on append-only time-series tables in PostgreSQL?
Instead of indexing every single row key, BRIN stores only min/max summaries per 128-page physical block—taking kilobytes instead of gigabytes on chronologically ordered logs.
Q4
What does CREATE INDEX CONCURRENTLY prevent—and what happens if it fails halfway?
Regular CREATE INDEX blocks INSERT/UPDATE/DELETE writes for the whole build. CONCURRENTLY allows concurrent writes at the cost of two table scans; if interrupted (e.g. unique violation), it leaves an INVALID index behind that must be dropped and rebuilt.
Q5
How does PostgreSQL's INSERT ... ON CONFLICT (id) DO UPDATE SET ... (UPSERT) avoid race conditions safely?
Checking SELECT then INSERT fails under concurrent load. ON CONFLICT locks the conflicting index key atomically inside PostgreSQL, avoiding duplicate-key exceptions cleanly.
Q6
Why does SELECT * FROM items ORDER BY price LIMIT 10 on PostgreSQL sometimes become non-deterministic on tied prices?
Under MVCC updates or parallel scans, physical tuple order shifts constantly. Without a unique tie-breaker (ORDER BY price ASC, id ASC), rows with identical prices can jump between page 1 and page 2 during pagination!
Q7
How do Partial Indexes (CREATE INDEX ... WHERE deleted_at IS NULL) shrink index size and speed up soft-delete apps?
If 90% of historical rows are archived/soft-deleted, indexing only active WHERE deleted_at IS NULL keeps the active working B-tree tiny in shared buffers RAM.
Q8
What is the key difference between EXPLAIN and EXPLAIN ANALYZE in PostgreSQL?
EXPLAIN prints only planner estimates without executing the query; EXPLAIN (ANALYZE, BUFFERS) *actually runs the query* (so wrap DELETE/UPDATE in BEGIN; ... ROLLBACK;!) and reveals exact execution timing, row misestimates, and buffer hits/reads.
Q9
Why does PostgreSQL's CTE (WITH) behavior change in PostgreSQL 12+ unless MATERIALIZED is specified?
Prior to PG 12, CTEs acted as optimization fences evaluated once before outer filters. PG 12+ inlines non-recursive CTEs automatically so outer WHERE clauses push into indexes unless AS MATERIALIZED is explicitly requested.
Q10
Why should you prefer TIMESTAMPTZ (timestamp with time zone) over TIMESTAMP in global PostgreSQL applications?
TIMESTAMPTZ normalizes every timestamp to UTC internally and renders cleanly per client session timezone, whereas plain TIMESTAMP drops offset metadata—causing subtle daylight-saving and regional bugs.