yoklainterview sim

Database Senior Interview Questions

1595 verified Database Senior interview questions — solve with answers, learn from explanations, test yourself in a real simulation.

Try the real simulation →

Sample questions

Backup RecoveryDifficulty 3
You must move a database to a server running a different major version on a different CPU architecture.
# option A (physical): copy the raw data files
# option B (logical): pg_dump olddb | psql -h newhost newdb

Which is generally the safer choice, and why?
  • aThe physical file copy, since raw data files are always compatible across versions and CPU architectures
  • bNeither works — data moves between servers only by configuring streaming replication first
  • cEither is equivalent here, because the backup format has no bearing on cross-platform portability
  • dThe logical SQL dump, since it is portable and can be reloaded into a different version or platform
Explanation:Physical backups copy engine-internal file formats that can differ between major versions and architectures, so restoring them elsewhere is fragile. A logical dump is engine-readable SQL/data, which is exactly why it is the standard tool for cross-version and cross-platform moves. Replication (b) keeps copies in sync but is not a prerequisite for migration.
Backup RecoveryDifficulty 3
pg_dump proddb > /backups/nightly.sql   # cron job, exits 0 every night

The job has exited successfully every night for a year, but during a real outage the restore fails. What does this classic situation illustrate?
  • aThe dump file eventually grew too large for the restore process to load back in
  • bA green backup job proves the command ran, not that the output is restorable
  • cBackups should never be scheduled through cron; a dedicated backup agent is mandatory
  • dSQL dumps become impossible to restore once they are more than a couple of months old
Explanation:A zero exit code means the dump command ran, not that the output is complete and restorable — a wrong flag, an excluded schema, or a silent truncation stays hidden until you actually restore (e.g. psql newdb < /backups/nightly.sql into a scratch database). Only a real test restore turns 'we have backups' into 'we can recover.' The other options misdiagnose the cause.
Backup RecoveryDifficulty 3
cp -r /var/lib/db/data /backup/data   # the database is live and serving writes

An engineer backs up the data directory with a plain recursive copy while the database keeps accepting writes, with no snapshot or coordination. What is the main risk?
  • aThe copy is always a perfect, fully restorable image of the running database
  • bAll incoming writes are automatically blocked until the recursive copy finishes
  • cThe copy can be internally inconsistent and may not restore to a valid state
  • dThe operating system automatically encrypts the copy as it is being written
Explanation:A live copy reads files over a span of time while data keeps changing, so file A and file B can reflect different moments — a torn, inconsistent image that may refuse to start or contain half-applied transactions. Safe physical backups use a consistent snapshot or the engine's backup mode. The copy is neither blocked (b), guaranteed valid (a), nor encrypted (d).
Backup RecoveryDifficulty 3
CREATE INDEX idx_orders_customer ON orders (customer_id);

On a very large, high-traffic orders table, why can running a plain schema change like this in production be risky?
  • aCreating an index permanently corrupts the rows that are already stored inside the table
  • bSome changes lock the table or run long, blocking writes (and, for some DDL, reads) and causing downtime
  • cA schema change like this one can never be undone once it has started executing
  • dThe entire table must first be loaded into memory before the statement can run
Explanation:On a big, busy table an operation like building an index can hold locks and run long enough to stall queries, so teams schedule it in low-traffic windows or use online/concurrent variants. It does not corrupt data (a), it is reversible with DROP INDEX (c), and it does not require loading the table into RAM (d).
Backup RecoveryDifficulty 3
You take a full backup every Sunday and a differential backup every night Monday–Saturday. To restore the database to its state on Wednesday night, which backups do you need?
  • aEvery backup Sunday through Wednesday: the full plus Monday, Tuesday, and Wednesday differentials
  • bOnly Sunday's full backup together with Wednesday night's differential
  • cOnly Wednesday night's differential backup, used entirely on its own
  • dOnly Sunday's full backup, with none of the differential backups
Explanation:A differential contains everything changed since the last full backup, so each night's differential already includes the previous days' changes — you need just the full plus the one differential for your target night. Applying every differential in the chain (a) describes an incremental strategy; a differential alone (c) has no base, and the full alone (d) misses the week's changes.
Data ModelingDifficulty 3
A table order_items(order_id, product_id, quantity, product_name) has the composite primary key (order_id, product_id), and product_name depends only on product_id. What is the problem and its fix?
  • aIt violates 1NF because product_name repeats; split each value into its own row
  • bIt violates 3NF through a transitive dependency; move quantity into another table
  • cIt violates 2NF: product_name is a partial dependency on part of the key; move it to a products table
  • dIt violates no normal form; a wide order-line table is always an acceptable design
Explanation:2NF requires every non-key column to depend on the whole composite key. product_name depends only on product_id, part of the key — a partial dependency — so it belongs in a products table keyed by product_id. The values are atomic, so it is not a 1NF issue (a), and a partial dependency is distinct from the transitive dependency that 3NF addresses (b).

Test yourself against the 2475-question Database bank.

Start interview