Developers send you schema changes and new queries to review. What do you look for?
What the interviewer wants to hear
- Correct data types, constraints, primary and foreign keys
- Indexes that match the query patterns, and no unneeded duplicates
- Locking impact of the migration on large tables and a safe rollout plan
- Query plans on realistic data volumes, avoiding N+1 patterns and unbounded queries
- Backward compatibility with the running application version
Model answer
For schema changes I first check modelling: sensible data types such as timestamptz and numeric for money, a primary key, foreign keys and NOT NULL or CHECK constraints so bad data cannot get in. Then I look at how the change will be applied on a big live table: does it take a long ACCESS EXCLUSIVE lock or rewrite the table, does it need CREATE INDEX CONCURRENTLY, a lock_timeout, or batched backfills. It must be backward compatible with the app version still running, so renames happen in expand and contract steps. For queries I ask for the access pattern and run EXPLAIN on realistic data, check that indexes match the WHERE, JOIN and ORDER BY, and look for N+1 loops, SELECT star on wide tables and queries without LIMIT. I also make sure there is a rollback plan.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Database Administrator questions
- A query that ran in 50 ms yesterday now takes 20 seconds. Nothing in the code changed. How do you investigate?
- Explain the SQL isolation levels and the anomalies each one allows.
- How do you set up and monitor replication, and what do you do when replica lag grows?
- How would you add a column and an index to a 500 million row table without downtime?
- A busy PostgreSQL table keeps getting bloated. How do you tune autovacuum?
- Walk me through how you read an EXPLAIN ANALYZE plan to find why a query is slow.
- How would you tune the main PostgreSQL memory settings on a new server?
- Which metrics and alerts would you set up for a production PostgreSQL or MySQL database?
- What are the main operational differences between running MySQL (InnoDB) and PostgreSQL?