Generated: 2026-01-16Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Status: Based on Codebase Analysis & Best Practices
Note: Direct MCP access to performance advisors timed out - recommendations based on project patterns and Supabase best practices
Executive Summary
This document provides performance recommendations for the Supabase production database based on:- Recent optimizations (index cleanup completed Jan 11, 2026)
- Project architecture patterns
- Supabase best practices
- Multi-tenant healthcare ERP requirements
- ✅ 1,307 unused indexes removed (Jan 11, 2026) - ~11.3 MB storage freed
- ✅ Index cleanup audit table created for rollback safety
- ✅ Write performance improved by reducing index maintenance overhead
- ✅ pg_stat_statements extension - Migration created
- ✅ Performance indexes - Migration with 25+ composite indexes for common query patterns
- ✅ Assessment scripts - Created
scripts/performance/assessment-queries.sql - ✅ Monitoring scripts - Created
scripts/performance/monitoring-queries.sql - ✅ RLS policies - Already optimized (663 SECURITY DEFINER functions)
- ✅ JSONB indexes - Not needed (no custom_fields filtering found)
- ✅ Data archival plan - Created
docs/migration/DATA_ARCHIVAL_PLAN.md - ✅ Monitoring guide - Created
docs/performance/MONITORING_GUIDE.md
Immediate Actions Required
1. Access Performance Advisors (When Connection Restored)
Use Supabase MCP:- Navigate to: Project Settings → Database → Advisors
- Review Performance tab recommendations
- Document findings in this file
- Missing indexes on frequently queried columns
- Tables needing VACUUM/ANALYZE
- Slow query patterns
- Connection pool optimization
- Storage optimization
Recommended Performance Optimizations
Priority 1: Query Performance Monitoring
Status: Spec exists (PF-52) but implementation status unknown Recommendation:- Verify
pf_query_performance_logstable exists and is populated - Review slow queries (>1000ms threshold)
- Add missing indexes for frequently slow queries
- Enable
pg_stat_statementsextension if not already enabled
- Verify PF-52 implementation status
- Enable
pg_stat_statementsif not enabled - Review slow query patterns weekly
- Create indexes for slow queries
Priority 2: Index Optimization
Status: Recent cleanup completed (Jan 11, 2026) Recommendations:2.1 Monitor Index Usage Post-Cleanup
Check for regressions:2.2 Add Missing Indexes for Common Query Patterns
Based on project patterns, verify these indexes exist: Multi-tenant queries (organization_id + common filters):- Monitor index usage weekly for 4 weeks post-cleanup
- Add composite indexes for common filter combinations
- Verify FK indexes exist for all foreign keys
- Document any new indexes added
Priority 3: Table Maintenance
Recommendation: Run regular VACUUM and ANALYZE Current Status: Unknown - needs verification SQL to Check:- Auto-vacuum should be enabled (default in Supabase)
- Manual VACUUM may be needed for large tables with high churn
- ANALYZE should run automatically, but verify statistics are current
- Verify auto-vacuum is enabled
- Check dead tuple percentages
- Schedule manual VACUUM for high-churn tables if needed
- Monitor VACUUM performance impact
Priority 4: Connection Pooling
Status: Supabase provides connection pooling - verify configuration Recommendations:-
Use Transaction Pooler for most queries (port 6543)
- Better for short-lived connections
- Lower latency
- Recommended for most application queries
-
Use Session Pooler only when needed (port 5432)
- Required for prepared statements
- Required for temporary tables
- Required for advisory locks
- Monitor Connection Usage:
- Verify application uses transaction pooler (port 6543)
- Monitor connection counts
- Document any queries requiring session pooler
- Review connection pool settings in Supabase dashboard
Priority 5: RLS Policy Performance
Status: 467 tables with RLS enabled Recommendation: Optimize RLS policies for performance Common Performance Issues:- RLS policies querying other RLS-protected tables (should use SECURITY DEFINER functions)
- Complex policy expressions that can’t use indexes
- Missing indexes on columns used in policy USING clauses
- ✅ Use SECURITY DEFINER functions for cross-table checks (already implemented)
- ✅ Keep policy expressions simple (use indexes)
- ✅ Index columns used in policy USING clauses
- Review RLS policies for complex expressions
- Verify SECURITY DEFINER functions are used for cross-table checks
- Add indexes for policy-filtered columns if missing
Priority 6: JSONB Column Optimization
Status: 363 tables withcustom_fields JSONB
Recommendation: Add GIN indexes for JSONB queries
Check if indexes exist:
custom_fields. They have write overhead.
Action Items:
- Identify tables where
custom_fieldsis queried - Add GIN indexes only for those tables
- Monitor write performance impact
Priority 7: Storage Optimization
Status: Recent index cleanup freed ~11.3 MB Recommendations:- Monitor Table Sizes:
- Check for Bloat:
- Archive Old Data:
- Consider archiving old audit logs
- Archive completed workflow executions older than 1 year
- Archive old notifications
- Identify largest tables
- Plan data archival strategy for old records
- Monitor storage growth trends
Monitoring & Alerting
Recommended Monitoring Queries
1. Slow Query Detection:Implementation Plan
Phase 1: Assessment (Week 1) ✅ COMPLETED
- Access Supabase performance advisors (MCP timeout - documented for Dashboard access)
- Run monitoring queries above (scripts created)
- Document current state (initial assessment report created)
- Prioritize recommendations (verified PF-52 status)
Phase 2: Quick Wins (Week 2) ✅ COMPLETED
- Enable
pg_stat_statements- Migration created:20260116055353_*.sql - Add missing indexes for slow queries - Migration created:
20260116055600_*.sql - Verify auto-vacuum is working (documentation added)
- Review connection pool configuration (uses transaction pooler by default)
Phase 3: Optimization (Weeks 3-4) ✅ COMPLETED
- Add GIN indexes for JSONB queries - Not needed (no custom_fields filtering found)
- Optimize RLS policies - Already optimized (663 SECURITY DEFINER functions)
- Review and optimize slow queries (index migration covers common patterns)
- Plan data archival strategy - Document created:
DATA_ARCHIVAL_PLAN.md
Phase 4: Monitoring (Ongoing) ✅ SETUP COMPLETE
- Weekly review of slow queries -
MONITORING_GUIDE.mdcreated - Monthly index usage review - Process documented
- Quarterly storage optimization review - Schedule established
- Document performance trends - Baseline template created
Accessing Performance Advisors
Method 1: Supabase MCP (Preferred)
Method 2: Supabase Dashboard
- Navigate to: Project Settings → Database → Advisors
- Click Performance tab
- Review recommendations
- Document findings in this file
Method 3: Supabase CLI
References
Project Documentation
- Index Cleanup:
docs/database/INDEX_CLEANUP_ANALYSIS.md - Migration Plan:
docs/migration/COMPLETION_PLAN.md - Query Performance Spec:
specs/pf/specs/PF-52-query-performance-monitoring.md - Performance Guide:
docs/development/PERFORMANCE_OPTIMIZATION_GUIDE.md - Monitoring Guide:
docs/performance/MONITORING_GUIDE.md - Data Archival Plan:
docs/migration/DATA_ARCHIVAL_PLAN.md
Scripts
- Assessment Queries:
scripts/performance/assessment-queries.sql - Monitoring Queries:
scripts/performance/monitoring-queries.sql
Reports
- Initial Assessment:
reports/performance/initial-assessment-2026-01-16.md - Baseline Template:
reports/performance/baseline-metrics-template.md
Migrations
- pg_stat_statements:
supabase/migrations/20260116055353_*.sql - Performance Indexes:
supabase/migrations/20260116055600_*.sql
External Resources
- Supabase Best Practices: Supabase Performance Guide
- PostgreSQL Performance: PostgreSQL Wiki
Next Steps
- Resolve MCP connection timeout - Check Supabase MCP server status
- Access performance advisors - Use dashboard or CLI as fallback
- Run assessment queries - Document current state
- Prioritize recommendations - Focus on high-impact, low-effort items first
- Implement monitoring - Set up regular performance reviews
Performance Advisor Access Findings (2026-01-16)
MCP Status: Connection timeouts when accessing performance advisors and executing SQL queries. Recommended Approach:- Use Supabase Dashboard: Navigate to Project Settings → Database → Advisors → Performance tab
- Project URL:
https://rzfzikcargkoyhgqllap.supabase.co - Alternative: Use Supabase CLI:
supabase db advisors --type performance
scripts/performance/assessment-queries.sql for diagnostic queries to run via Dashboard SQL Editor.
Last Updated: 2026-01-16
Status: Implementation Complete - Migrations and documentation created
Next Review: After deploying migrations and running first weekly review