AI Hints
Home›PostgreSQL Tutorial›Interview Questions and Quiz
PostgreSQL · Lesson 116 of 120

Interview Questions, Part 2

Performance and safety.

⏱ 2 min read▶ Video at 1:45:01🎓 Free
Watch this lesson in the PostgreSQL courseWatch on YouTube ↗Full PostgreSQL course

Part two covers performance and safety, the questions senior interviews love.

  • Indexes
  • Transactions
  • Scaling

Performance questions

How do you find a slow query? Pg stat statements, then explain analyze. When isn't an index used? When the column is wrapped in a function, or the table is tiny. What's a GIN index for? Arrays, JSONB and full text.

QuestionShort answer
Find slow queries?pg_stat_statements, EXPLAIN ANALYZE
Index not used?function on column, tiny table
GIN for?arrays, jsonb, full-text

Safety questions

How do you prevent overselling? Lock the row with for update, inside a transaction. How do you avoid SQL injection? Parameters. How do workers share a job table? Skip locked. How do you scale reads? Replicas and a connection pool.

QuestionShort answer
Overselling?FOR UPDATE in a transaction
SQL injection?parameters
Job queue?SKIP LOCKED
Scale reads?replicas + pooling

Summary

Measure before fixing, lock what must be exclusive, and always use parameters. Next, a quick quiz.

Key takeaways
  • EXPLAIN
  • FOR UPDATE
  • Parameters
Next up: Quick Quiz — test yourself