PostgreSQL Database Interview Master
100+ PostgreSQL interview questions covering MVCC concurrency, VACUUM tuning, GIN/GiST/BRIN indexes, CTEs, Window Functions, and Partitioning.
Difficulty Filters
Tools & Options
What is PostgreSQL?
PostgreSQL is a powerful, open-source object-relational database system (ORDBMS) with over 35 years of active development. It is known for its reliability, feature robustness, and performance. It supports both SQL and JSON querying and is highly extensible.
What are the key features of PostgreSQL?
Key features include:
1. **ACID Compliance**: Ensures reliable transactions.
2. **Conjoined Scalability**: Support for complex queries and large data volumes.
3. **Extensibility**: Custom types, functions, and operators.
4. **Advanced Data Types**: JSONB, HSTORE, Arrays, Ranges.
5. **MVCC**: Multi-Version Concurrency Control for high performance.
What is the difference between PostgreSQL and MySQL?
- **MySQL**: Traditional RDBMS, focused on speed and simplicity, traditionally better for read-heavy web apps.
- **PostgreSQL**: ORDBMS, focused on compliance and advanced features, better for complex queries, high concurrency, and technical data types like JSONB.
What is a Schema in PostgreSQL?
How do you create a table in PostgreSQL?
What is the SERIAL data type?
How do you insert a row into a table?
What is the purpose of the 'psql' utility?
How do you list all tables in 'psql'?
How do you see the structure of a table in 'psql'?
What is a Primary Key?
What is a Foreign Key?
Explain the 'LIMIT' and 'OFFSET' clauses.
How do you update data in a table?
How do you delete data from a table?
What is the 'TRUNCATE' command?
What is a View in PostgreSQL?
What is an Index?
What is the 'WHERE' clause used for?
What is the 'GROUP BY' clause?
Explain 'INNER JOIN' vs 'LEFT JOIN'.
What is the 'COALESCE' function?
What is the purpose of 'VACUUM'?
What is 'COPY' command for?
What is the default port for PostgreSQL?
What is a Window Function in PostgreSQL?
What is a CTE (Common Table Expression)?
Explain the 'EXPLAIN' and 'EXPLAIN ANALYZE' commands.
What is MVCC (Multi-Version Concurrency Control)?
What are the differences between JSON and JSONB?
What is a GIN Index?
What is a Partial Index?
How do you perform a recursive query in PostgreSQL?
What is the 'UPSERT' (INSERT ON CONFLICT) operation?
What are the different isolation levels in PostgreSQL?
What is an extension in PostgreSQL?
Explain the 'RETURNING' clause in PostgreSQL.
What is a Materialized View?
How do you generate a UUID in PostgreSQL?
What is 'ILIKE'?
Explain the 'OVER' clause.
What are Savepoints in a transaction?
What is a Sequence in PostgreSQL?
What is the difference between 'VARCHAR' and 'TEXT'?
What is 'hstore'?
How do you handle character encoding in PostgreSQL?
What is the 'DISTINCT ON' clause?
What is a TRIGGER in PostgreSQL?
Explain 'CAST' and the '::' shorthand.
What is the 'pg_stat_activity' view?
Explain PostgreSQL Partitioning.
What is BRIN (Block Range Index)?
Explain GIST (Generalized Search Tree) vs GIN.
What is Table Inheritance?
What are Logical and Physical Replication?
Explain 'Vacuum Full' vs 'Vacuum'.
What are Foreign Data Wrappers (FDW)?
Explain the 'WAL' (Write-Ahead Logging).
What is an Advisory Lock?
What is JIT (Just-In-Time) compilation in Postgres?
How do you handle Deadlocks in PostgreSQL?
What is 'Streaming Replication'?
Explain 'Work Mem' and 'Maintenance Work Mem'.
What is a Bloom Index?
Explain 'HOT' (Heap Only Tuple) updates.
What is 'pg_dump' vs 'pg_dumpall'?
How to find slow queries in PostgreSQL?
What is 'Postgis'?
Explain 'Declarative Partitioning'.
What is 'Index Scan' vs 'Bitmap Index Scan' vs 'Sequential Scan'?
What is 'Checkpointer' process?
What is 'Schema Search Path'?
How to optimize queries with JSONB data?
Explain 'LISTEN' and 'NOTIFY'.
What is 'Parallel Query' execution?
Scenario: How to find the second highest salary without using LIMIT?
Scenario: How to delete duplicate rows from a table while keeping the one with the lowest ID?
Scenario: How to find the average salary by department, and only show departments with an average > 50000?
Scenario: How to perform a case-insensitive search for a username?
Scenario: How to query a JSONB column to find rows where a specific key exists?
Scenario: How to query a JSONB column to find rows where a key has a specific value?
Scenario: How to combine first_name and last_name with a space in between?
Scenario: How to get the first 5 characters of a string?
Scenario: How to prevent a division by zero error in a query?
Scenario: How to find the nth most recent login for each user?
Scenario: How to update multiple rows with different values in a single query?
Scenario: How to copy only the structure of a table without any data?
Scenario: How to find rows where a column's value is between 10 and 20 (inclusive)?
Scenario: How to handle auto-incrementing IDs for a table created from a CSV with existing IDs?
Scenario: How to find the current database name?
Scenario: How to get the size of a database?
Scenario: How to find which processes are currently blocking a specific table?
Scenario: How to kill a slow-running query process?
Scenario: How to generate a range of numbers (1 to 10)?
Scenario: How to convert a comma-separated string into rows?
Scenario: How to get the difference between two timestamps in hours?
Scenario: How to find all columns in a specific table using SQL?
Scenario: How to find the running total of sales over time?
Scenario: You need to store multiple IP addresses in a single column and query them efficiently. Solution?
How to export a table to a CSV file?
Technical Interview Mastery Blueprint
Proven methodologies and frameworks to succeed in technical and architecture rounds.
1. The Engineering STAR Technique
When responding to architectural or situational questions, structure your answer using Situation, Technical Constraint, Action, and Measurable Result. Rather than jumping straight to syntax, articulate the business problem, why certain patterns (e.g. caching, queuing, immutability) were selected over alternatives, and what latency or throughput improvements were achieved.
2. Defending Architectural Trade-Offs
Senior interviewers evaluate how you weigh trade-offs. Always explain why you chose an approach: e.g., memory overhead vs CPU cycle speed, consistency vs availability (CAP theorem), or normalized schemas vs denormalized fast reads. Stating the drawbacks of your own proposal demonstrates maturity and production experience.
3. Clean Code & Edge-Case Proactivity
In live-coding rounds, communicate your thinking aloud before typing. State edge cases explicitly: null or undefined inputs, extreme boundary values, concurrency races, and network timeouts. Writing modular, well-named functions with deterministic unit tests separates junior candidates from staff-level engineers.
4. Antipatterns to Avoid
Avoid reciting memorized definitions without practical context. Never dismiss non-functional requirements such as security (CSRF, injection, token rotation), observability (logging, metrics), and accessibility (ARIA, semantic standards). Always ask clarifying scope questions before writing complex implementations.
Explore Related Tools
Hand-picked utilities and calculators related to this tool.
