Maintenance Commands
SQL
-- Analyze — collect table statistics for the query optimizer
ANALYZE table;
ANALYZE; -- Analyze all tables
-- Vacuum — reclaim storage from deleted rows
VACUUM table;
VACUUM FULL table; -- Full table rewrite (locks table briefly)
-- Explain — show query execution plan
EXPLAIN SELECT * FROM users WHERE age > 30;
EXPLAIN ANALYZE SELECT * FROM users WHERE age > 30; -- Also execute and time it
-- Prepared statements (parameter binding)
PREPARE stmt AS SELECT * FROM users WHERE id = $1;
EXECUTE stmt(42);
DEALLOCATE stmt;
-- Index management
REINDEX TABLE users;
REINDEX INDEX idx_users_email;