intermediateTop 30 Scenario-Based Questions
Your PostgreSQL table has 40% dead tuples causing slow queries. How do you fix it with no downtime?
1) Immediate: VACUUM ANALYZE orders — removes dead tuple pointers, updates statistics, no lock. 2) Verify: SELECT n_dead_tup, n_live_tup FROM pg_stat_user_tables WHERE relname='orders' — should drop. 3) Tune autovacuum: ALTER TABLE orders SET (autovacuum_vacuum_scale_factor=0.01, autovacuum_vacuum_threshold=1000). 4) Find long transactions blocking vacuum: SELECT pid, xact_start, state FROM pg_sta
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response