Database Maintenance Runbook
HeliosDB Database Maintenance Runbook
Use this runbook for routine maintenance, storage hygiene, statistics refresh, and query health checks.
VACUUM Procedure
Run cleanup when dead tuple count, table bloat, or transaction age indicates pressure.
psql -h heliosdb-primary -U admin -d production -c "SELECT schemaname, relname, n_dead_tup, n_live_tupFROM pg_stat_user_tablesORDER BY n_dead_tup DESCLIMIT 20;"Procedure:
- Confirm the table and impact.
- Run nonblocking cleanup first.
- Monitor I/O and replication lag.
- Use stronger maintenance only during approved windows.
VACUUM VERBOSE target_table;VACUUM ANALYZE target_table;ANALYZE Statistics Update
Refresh statistics after large loads, deletes, or skewed query plans.
ANALYZE target_table;ANALYZE;Validate query plans before and after the refresh.
Index Rebuilding (REINDEX)
Rebuild indexes when bloat, corruption, or degraded scan performance is confirmed.
- Identify affected indexes.
- Prefer concurrent rebuilds when supported.
- Rebuild during low traffic for large indexes.
- Validate query plans and index size.
REINDEX INDEX target_index;Table Reorganization
Use table reorganization for severe bloat or layout problems after validating that routine cleanup is insufficient.
- Estimate lock impact and disk requirements.
- Schedule a maintenance window if locks are required.
- Take and verify a fresh backup.
- Reorganize one table at a time.
Query Performance Analysis
Start with active queries and historical slow statements:
SELECT pid, now() - query_start AS duration, state, queryFROM pg_stat_activityWHERE state <> 'idle'ORDER BY duration DESCLIMIT 20;Use EXPLAIN to validate indexes, join strategy, and row estimates.
Storage Management
Monitor:
- Data directory free space.
- WAL growth.
- Temporary file usage.
- Backup staging directories.
- Index bloat and unused indexes.
Keep enough free space for maintenance operations and recovery.