What are the main operational differences between running MySQL (InnoDB) and PostgreSQL?
What the interviewer wants to hear
- MVCC: PostgreSQL keeps old row versions in the table and needs vacuum; InnoDB uses undo logs and purge
- InnoDB clusters tables by primary key; PostgreSQL uses heap tables with separate indexes
- Replication: PostgreSQL streams WAL; MySQL uses binlog with GTIDs
- Default isolation: PostgreSQL READ COMMITTED, InnoDB REPEATABLE READ
- Different tools: pgBackRest and Patroni vs XtraBackup and Orchestrator or Group Replication
Model answer
Both are solid, but they behave differently day to day. PostgreSQL MVCC stores old row versions inside the table, so vacuum and autovacuum tuning, bloat and transaction ID wraparound are big topics. InnoDB keeps old versions in undo logs and cleans them with purge, so long transactions grow the undo history instead. InnoDB stores each table as a clustered index on the primary key, so key choice affects layout and secondary indexes include the primary key; PostgreSQL uses heap tables with separate indexes. PostgreSQL replicates by streaming WAL, while MySQL uses the binlog, usually with GTIDs and row format. Defaults differ too: PostgreSQL uses READ COMMITTED, InnoDB REPEATABLE READ. The tooling also differs: pgBackRest, Patroni and pgBouncer on one side; XtraBackup, Orchestrator or InnoDB Cluster and ProxySQL on the other.
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?
- Developers send you schema changes and new queries to review. What do you look for?