Skip to content
RED SAGSkills
mediumDatabase Administrator interview question

How would you add a column and an index to a 500 million row table without downtime?

What the interviewer wants to hear

  • Understand which DDL takes heavy locks
  • Add nullable columns or columns with constant defaults, which are fast in modern versions
  • Use CREATE INDEX CONCURRENTLY or online DDL
  • Use lock_timeout and retries
  • Backfill in small batches
  • Tools like gh-ost or pt-online-schema-change for MySQL

Model answer

First I check what locks each step takes. In PostgreSQL 11 and later, adding a nullable column or one with a constant default is a quick metadata change, but it still needs a brief ACCESS EXCLUSIVE lock, so I set lock_timeout to a few seconds and retry, so it does not queue behind a long query and block everyone. For the index I use CREATE INDEX CONCURRENTLY, which does not block writes, and I check afterwards that it is valid. If existing rows need values, I backfill in small batches with pauses to limit replication lag. In MySQL I use InnoDB online DDL with ALGORITHM=INSTANT or INPLACE where possible, or gh-ost for bigger changes. I follow an expand and contract approach so old and new app versions both work during rollout.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium Database Administrator questions