Top 100+ Database Questions for Senior Engineers
PostgreSQL Focus
Answers live in Senior Engineer Database Answers — question numbers match one-to-one.
1. FUNDAMENTAL CONCEPTS (15 questions)
-
PostgreSQL stores tables as heaps and every index is non-clustered. What follows from that, and how does it differ from a clustered-index engine like InnoDB?
-
Explain the difference between a primary key and a unique constraint. When would you use one over the other?
-
What is the B-tree data structure and why is it the most common index structure in databases?
-
Describe the differences between OLTP and OLAP workloads and how database design differs for each.
-
What is normalization and what are the first three normal forms? Why might you denormalize intentionally?
-
Explain the concept of query cardinality and how it affects query optimization.
-
What is the difference between vertical and horizontal partitioning/sharding?
-
How does a query optimizer work? What information does it use to make decisions?
-
What is a histogram in database statistics and why is it important for query optimization?
-
Explain the difference between optimistic and pessimistic locking strategies.
-
What is a phantom read and how does it differ from a dirty read and non-repeatable read?
-
Describe the purpose and trade-offs of connection pooling.
-
What is write amplification and how is it relevant to database performance?
-
Explain the concept of "working set" in the context of database performance.
-
What is the difference between a full scan and an index scan, and when would each be preferred?
2. INDEXING & QUERY OPTIMIZATION (19 questions)
-
What is a composite (multi-column) index and what is the significance of column order?
-
Explain the concept of index selectivity and how it affects whether an index will be used.
-
What is an index skip scan (PostgreSQL) and when does it occur?
-
Describe the difference between an inclusive index and a covering index.
-
What is a partial index and provide a real-world use case.
-
How do you identify and fix slow queries? Walk through your diagnostic approach.
-
Explain what EXPLAIN and EXPLAIN ANALYZE show you, and how to read their output.
-
What is index bloat in PostgreSQL, and how do you detect and remediate it?
-
Describe the different join algorithms (Nested Loop, Hash Join, Merge Join) and when each is used.
-
What is a filter condition vs a join condition, and why does this distinction matter for performance?
-
Explain the concept of "index-only scans" (PostgreSQL) and the visibility map.
-
What is the N+1 query problem and how do you identify and prevent it?
-
How do you optimize queries with OR conditions?
-
Explain why adding more indexes doesn't always improve performance.
-
How would you optimize a query with multiple DISTINCT operations?
-
Explain the difference between functional indexes and expression indexes.
-
What is a deferred index build and why might you use it?
-
How do you handle query optimization for very large LIKE patterns?
-
Describe the performance implications of using functions in WHERE clauses.
3. CONCURRENCY & LOCKING (15 questions)
-
Explain the different row lock modes in PostgreSQL (FOR UPDATE, FOR SHARE, etc.).
-
What is lock escalation, why does PostgreSQL never do it, and what does it take at table level instead?
-
Describe deadlock scenarios and how to prevent them.
-
What is a blocking query and how do you identify and resolve it?
-
Explain the differences between shared locks and exclusive locks.
-
What is the purpose of sequence numbers and how are they handled concurrently?
-
PostgreSQL has no gap locks. How does it prevent write-side phantoms, and what does that require of your application?
-
How does PostgreSQL store row locks, and why does locking millions of rows still cost you something?
-
How does PostgreSQL's MVCC (Multi-Version Concurrency Control) work?
-
Explain the concept of transaction isolation levels and their trade-offs.
-
What is a lock wait timeout and how do you configure it?
-
Describe the difference between optimistic and pessimistic locking with examples.
-
What are "phantom rows" and how do different isolation levels handle them?
-
How do you detect and monitor lock contention?
-
Explain the purpose of advisory locks in PostgreSQL.
4. TRANSACTIONS & ACID (12 questions)
-
Explain the ACID properties and why they matter.
-
What is a dirty read, non-repeatable read, and phantom read? How do isolation levels prevent each?
-
Describe the four SQL isolation levels (READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE).
-
What is the difference between snapshot isolation and serializable snapshot isolation?
-
Explain savepoints and how you would use them in a transaction.
-
What is an implicit transaction vs explicit transaction?
-
Describe what happens when a transaction is rolled back. What are the implications?
-
How do long-running transactions impact database performance?
-
What is transaction log (WAL in PostgreSQL) and why is it critical?
-
Explain the concept of "consistency" in ACID. Why is it different from isolation?
-
What is a distributed transaction and what challenges does it present?
-
Describe the purpose and gotchas of autocommit mode.
5. REPLICATION & HIGH AVAILABILITY (11 questions)
-
Explain the difference between synchronous and asynchronous replication.
-
What is a read replica and what are the use cases?
-
Describe the causes and implications of replication lag.
-
How does PostgreSQL's streaming replication work?
-
What is logical replication and how does it differ from physical replication?
-
Explain the concept of "split brain" in a replication setup and how to prevent it.
-
What is a failover, failback, and switchover?
-
Describe the architecture of a semi-synchronous replication setup.
-
How do you identify and resolve replication conflicts?
-
What is WAL archiving and how is it used for backup and recovery?
-
How does PostgreSQL track a replica's position (LSN, timelines), and what does
pg_rewindrequire to reattach a diverged primary?
6. MAINTENANCE & ADMINISTRATION (14 questions)
-
Explain the importance of VACUUM in PostgreSQL and how it works.
-
What is autovacuum and how do you tune it for different workloads?
-
How do you perform an online schema migration on a large table without downtime?
-
Describe the process and trade-offs of reorganizing a table.
-
What is bloat in PostgreSQL and how do you detect/reduce it?
-
How do you safely drop a column in a large table?
-
Explain the difference between a full backup, incremental backup, and differential backup.
-
What is point-in-time recovery (PITR) and how do you implement it?
-
How do you monitor database health and set up appropriate alerts?
-
Describe the purpose and configuration of slow query logs.
-
What is an upgrade path for major/minor version changes?
-
How do you estimate table and index sizes, and what do you do if they're growing unexpectedly?
-
Explain the process of analyzing table statistics and rebuilding statistics.
-
Describe the process of creating and maintaining a comprehensive backup strategy.
7. PERFORMANCE TUNING (10 questions)
-
What are the key PostgreSQL configuration parameters and how do you tune them for different hardware?
-
Explain shared_buffers, effective_cache_size, work_mem, and maintenance_work_mem.
-
What is the relationship between database performance and disk I/O patterns?
-
How do you identify whether a performance issue is CPU-bound, memory-bound, or I/O-bound?
-
Describe the performance implications of different data types (VARCHAR vs CHAR, INT vs BIGINT).
-
What is checkpoint frequency and how does it impact performance?
-
How do you optimize for SSD vs HDD storage?
-
Explain the performance impact of foreign keys and when to use them.
-
What is query result caching and what are the trade-offs?
-
How do you approach performance optimization for queries aggregating billions of rows?
8. EDGE CASES & GOTCHAS (9 questions)
-
Describe the difference between COUNT(*) and COUNT(column) when column can be NULL.
-
What happens with data consistency when you have cascading foreign keys and deletes?
-
Explain the gotchas of using OFFSET for pagination on large result sets.
-
What is the "off by one" problem in database design and how do you avoid it?
-
Describe scenarios where DISTINCT can silently hide data issues.
-
What are the implications of using UNIQUE constraints on nullable columns?
-
Explain the behavior of IN vs EXISTS in different scenarios.
-
What is the "Halloween Problem" in databases and how is it addressed?
-
Describe the differences between NATURAL JOIN and explicit INNER JOIN.
9. POSTGRESQL-SPECIFIC (11 questions)
-
Explain the TOAST (The Oversized-Attribute Storage Technique) mechanism in PostgreSQL.
-
What are extensions in PostgreSQL and give examples of critical ones (e.g., pg_stat_statements, pgvector).
-
Describe the differences between DELETE and TRUNCATE in PostgreSQL.
-
What is tablespace in PostgreSQL and why would you use it?
-
Explain Window Functions and provide a use case where they outperform alternatives.
-
What is a CTE (Common Table Expression) and when is it better than a subquery?
-
Describe the role of the transaction ID (XID) in PostgreSQL and XID wraparound.
-
What is the pg_stat_statements extension and how do you use it for performance analysis?
-
Explain native JSON support in PostgreSQL and its performance implications.
-
What is prepared statements and how do they prevent SQL injection?
-
What are generated columns in PostgreSQL (12+), and what are their limitations?
10. DATA TYPES & STORAGE (10 questions)
-
What are the storage and performance implications of VARCHAR(max) columns?
-
Explain the differences between DATE, DATETIME, and TIMESTAMP data types.
-
What is the difference between DECIMAL and FLOAT/DOUBLE in databases?
-
Describe the implications of using ENUM data types.
-
What are JSON data types and what are their performance considerations?
-
Explain the difference between TEXT and VARCHAR storage.
-
What are implications of using UUID as a primary key vs auto-incrementing INT?
-
Describe the storage implications of nullable vs non-nullable columns.
-
PostgreSQL has no unsigned integer types. What are your options when a counter approaches the INTEGER ceiling?
-
How do you handle bit flags efficiently in a database?
11. SECURITY (5 questions)
-
Explain SQL injection and how parameterized queries prevent it.
-
What is the principle of least privilege and how do you apply it to database users?
-
Describe encryption at rest vs encryption in transit for databases.
-
What is row-level security and how do you implement it in PostgreSQL?
-
Explain the security implications of default database configurations.
12. PRACTICAL SCENARIOS (10 questions)
-
You have a query that runs in 2 seconds but needs to run in 200ms. Walk through your optimization approach.
-
How would you redesign a table that has grown to 500GB and is slowing down?
-
A production database is experiencing high replication lag. What are your diagnostic steps?
-
You need to add a NOT NULL column to a table with 100M rows without downtime. How?
-
Describe how you would handle data migration between two different database systems.
-
A reporting query aggregates 10 billion rows and takes 30 minutes. How do you optimize it?
-
How would you implement real-time data analytics on top of a transactional database without impacting OLTP performance?
-
Describe your approach to load testing a database migration.
-
How do you handle bitemporal data (valid time and transaction time)?
-
Design a caching strategy for a high-traffic read-heavy application with a large dataset.
STUDY TIPS FOR SENIOR ENGINEERS
-
Go deep, not wide: For each question, understand not just the answer but the "why" and the trade-offs.
-
Hands-on practice: Run a local PostgreSQL. Use
EXPLAIN (ANALYZE, BUFFERS), create indexes, watch plans change. -
Read documentation: The official docs are often better than blogs. Understand the nuances.
-
Follow a scenario approach: Don't just memorize answers. Think about real-world situations where these concepts apply.
-
Understand trade-offs: Every database decision involves trade-offs. Senior engineers make informed choices, not dogmatic ones.
-
Learn from incidents: Study post-mortems and failure scenarios to understand edge cases.
-
Keep current: Follow database blogs, GitHub issues, and research papers to stay updated with best practices.
-
Teaching is learning: Try explaining these concepts to others or writing about them. It exposes gaps in your understanding.
FURTHER READING RECOMMENDATIONS
- PostgreSQL Official Documentation: https://www.postgresql.org/docs/
- "PostgreSQL 16 Internals" by Egor Rogov — free online, the deepest free resource on PG internals
- "PostgreSQL Query Performance Insights" by Gülnihan Çalış
- Depesz's PostgreSQL Blog: https://www.depesz.com/
- PlanetPostgreSQL: https://planet.postgresql.org/
- pgMustard's EXPLAIN glossary: https://www.pgmustard.com/docs/explain
Last Updated: May 2026