PostgreSQL Interview Questions
Check out 30 of the most common PostgreSQL interview questions and take an AI-powered practice interview
What is PostgreSQL and how does it differ from MySQL?
What is ACID and how does PostgreSQL guarantee it?
Explain MVCC (Multi-Version Concurrency Control) in PostgreSQL.
What are the transaction isolation levels in PostgreSQL?
What's the difference between CHAR, VARCHAR, and TEXT in PostgreSQL?
What is a PRIMARY KEY and how does it differ from a UNIQUE constraint?
What is an index and what types does PostgreSQL support?
What is the difference between WHERE and HAVING?
What is JSONB and how is it different from JSON in PostgreSQL?
What are foreign keys and what does ON DELETE CASCADE do?
What is the difference between INNER JOIN, LEFT JOIN, and FULL JOIN?
What does EXPLAIN do and how do you read its output?
When would you use a partial index versus a full index?
What is a covering index (INCLUDE) and when does it help?
How do GIN and GiST indexes work and when do you choose between them?
What is autovacuum and how do you tune it?
Explain table bloat and how to detect and fix it.
How do you query JSONB efficiently?
What are Common Table Expressions (CTEs) and when should you use them?
What are window functions and how do they differ from GROUP BY?
What is a materialized view and when should you use one?
How do you implement row-level locking with SELECT ... FOR UPDATE?
What is the N+1 query problem and how do you avoid it in Postgres?
What is streaming replication versus logical replication in PostgreSQL?
How do you set up high availability with Patroni?
How do you partition a large table in PostgreSQL and what are the trade-offs?
How do you debug a slow query in production safely?
How would you architect a Postgres cluster for a payments system handling 5,000 TPS?
How do Foreign Data Wrappers (FDW) work and when should you use them?
How do lateral joins work and when are they the right tool?
Frequently Asked Questions
Is PostgreSQL a good choice for new projects in 2026?
Yes — for nearly every transactional workload, Postgres is the default and the safe answer. Its type system, extension ecosystem (PostGIS, pgvector, TimescaleDB), JSONB support, and reliability story make it the standard at Razorpay, Swiggy, Zerodha, Cred and almost every well-funded Indian startup. Reach for an alternative only when you have a clear specialised need: ClickHouse for analytics at petabyte scale, DynamoDB / Cassandra for global key-value with strict latency SLOs, or Redis for caches and queues.
What is the average salary for PostgreSQL developers in India?
₹6-20 LPA in 2026 for backend developers with strong Postgres skills as a differentiator. Dedicated database/DBA roles (replication, performance tuning, large-scale partitioning) pay at the upper end — ₹18-30 LPA at fintechs and unicorns. Cities with the densest demand: Bengaluru, Hyderabad, Pune, Gurugram. Razorpay, Swiggy, Zomato, Zerodha, Cred, Meesho, PhonePe and most YC-backed Indian SaaS companies hire Postgres-strong engineers throughout the year.
Should I learn PostgreSQL or MongoDB first?
Postgres. The ratio of Indian backend job postings in 2026 favors relational SQL skills roughly 4:1 over MongoDB. Postgres's JSONB type covers most use cases where teams reach for Mongo and gives you transactions, joins and constraints for free. Many companies that started on MongoDB in 2018-2022 have migrated significant workloads to Postgres by 2026 — the inverse is rare.
Which PostgreSQL version should I target for interviews?
Postgres 16 and 17 are the relevant versions in 2026. Postgres 17 (released September 2024) shipped a rewritten memory-efficient VACUUM that dramatically lowers maintenance_work_mem usage on big tables, faster B-tree scans for IN-list and range queries, incremental backups via `pg_basebackup -i`, `pg_createsubscriber` to convert a physical standby into a logical subscriber in place for low-downtime upgrades, and SQL/JSON merge plus JSON_TABLE features. Knowing the Postgres 12 line additions (declarative partitioning maturity, generated columns, JSON path queries) and Postgres 15+ features (`MERGE` statement, `NULLS NOT DISTINCT`) is also valuable because many production clusters at older Indian companies are still on 13/14/15 and migrating up. Interviewers test version-awareness implicitly — referring to features like 'we use logical replication for upgrades' tells them you've operated a real cluster, not just read tutorials.
What are the most common PostgreSQL production incidents to know about?
(1) Long-running transactions blocking autovacuum, leading to runaway bloat — fix is to alert on `pg_stat_activity.xact_start` older than 10 minutes and set `idle_in_transaction_session_timeout` to auto-kill idle sessions. (2) Connection exhaustion when an app deploys badly and every replica opens a fresh pool — PgBouncer in transaction pooling prevents it. (3) Missing index on a foreign key column making parent UPDATEs and DELETEs minutes-slow. (4) Bigint vs int overflow when SERIAL hits 2.1 billion rows — always use BIGINT for IDs. (5) `SELECT *` retrieving large unused JSONB / TEXT columns and bloating buffer cache, hurting every query on the cluster. (6) A migration that adds a NOT NULL column without DEFAULT to a billion-row table, taking ACCESS EXCLUSIVE lock for hours. (7) Forgetting `CREATE INDEX CONCURRENTLY` on a hot table and locking writes for the duration of the build. Hiring managers love asking how you'd diagnose and prevent each.
How do PostgreSQL and pgvector fit into the AI / RAG stack in 2026?
pgvector is a Postgres extension that adds a `vector` type and indexes (IVFFlat, HNSW) for similarity search. In 2026, the majority of Indian startups building RAG-backed AI features (legal-tech, ed-tech, customer support) use pgvector instead of a dedicated vector DB — it co-locates embeddings with relational metadata, removes a service to operate, and the recall vs latency story is competitive with Pinecone / Weaviate for sub-100M-vector workloads. Expect questions on HNSW vs IVFFlat trade-offs in AI-adjacent backend interviews.
Introduction
PostgreSQL is the relational database of choice for nearly every serious backend stack in 2026. The latest major release, Postgres 17 (September 2024), brought a rewritten memory-efficient VACUUM, faster B-tree scans for IN-lists, incremental backups, and a much-improved logical replication story for failover. Across India, almost every modern startup of consequence — Razorpay, Swiggy, Zomato, Zerodha, Cred, Meesho — runs heavy Postgres clusters as the system of record.
Interviews in 2026 go well beyond 'what is a primary key'. Hiring managers probe indexing strategy (B-tree vs GIN vs BRIN vs partial vs covering), MVCC and transaction isolation behaviour, JSONB query patterns versus MongoDB, EXPLAIN ANALYZE reading, autovacuum tuning, partitioning, and replication / failover (Patroni). Expect to defend schema decisions, explain why a query is slow, and reason about lock contention under concurrent load.
This guide covers the 30 most-asked PostgreSQL interview questions in 2026, grouped by difficulty. Each answer includes the underlying mechanism, common production gotchas, and a code example where it adds clarity.