Get comprehensive information about your database structure including tables, indexes, sizes, and relationships.
Use Cases:
Understanding database schema
Checking table and index sizes
Identifying relationships between tables
Database documentation
Parameters:
{"include_counts":true,// Include row counts (default: true)"include_sizes":true,// Include disk sizes (default: true)"include_indexes":true,// Include index info (default: true)"include_columns":false// Include column details (default: false)}
Get detailed performance metrics, cache statistics, and table access patterns.
Use Cases:
Performance monitoring
Identifying hot tables
Finding unused indexes
Cache optimization
Query pattern analysis
Parameters:
Example Request:
Example Response:
What You Get:
Cache Statistics
Hit Ratio: Percentage of reads served from cache (higher is better)
Blocks Hit: Number of times data was found in cache
Blocks Read: Number of times data had to be read from disk
Recommended Action:
Hit ratio < 90%: Consider increasing shared_buffers
Hit ratio > 99%: Cache is well-tuned
Table Access Patterns
Sequential Scans: Full table scans (may indicate missing indexes)
Index Scans: Index-based access (efficient)
Modifications: Inserts, updates, deletes
Dead Rows: Rows marked for deletion (may need VACUUM)
Recommended Actions:
High sequential scans on large tables: Add indexes
Many dead rows: Run VACUUM ANALYZE
Low index usage: Index might not be optimal
Index Usage
Scans: How many times the index was used
Rows Fetched: How many rows were accessed via index
Recommended Actions:
Scans = 0: Index is unused, consider dropping
Many scans: Index is valuable, keep it
Unused Indexes
Lists indexes that have never been used since stats reset.
Recommended Actions:
Drop unused indexes to improve write performance
Each index slows down INSERT/UPDATE/DELETE operations
Keep only indexes that provide query benefits
3. analyze_query - Query Performance Analysis
Analyze SQL query execution plans to understand performance characteristics.
Note: This tool has limitations with the current database setup. The exec_sql RPC may not support EXPLAIN statements. For full query analysis, use direct database access.
Use Cases:
Understanding query performance
Identifying slow queries
Optimizing index usage
Planning query improvements
Parameters:
Modes:
explain: Generate execution plan without running query (fast, safe)
explain_analyze: Run query and measure actual performance (slower, provides real metrics)
Limitations:
Only SELECT queries are allowed (for safety)
May not work with all database configurations
Requires exec_sql RPC support for EXPLAIN
Alternative Approach: If this tool doesn't work in your environment, you can:
Connect directly to the database with psql
Run EXPLAIN (ANALYZE, BUFFERS) your_query;
Analyze the output manually
Common Use Cases
1. Database Health Check
Look for:
Large table sizes (may need partitioning)
Many dead rows (run VACUUM)
Low cache hit ratio (tune memory)
2. Performance Optimization
Actions:
Drop unused indexes
Add indexes for high sequential scan tables
Monitor index vs sequential scan ratios
3. Growth Monitoring
Monitor:
Row count growth
Disk space usage
Index size growth
4. Index Optimization
Strategy:
Drop unused indexes (0 scans)
Consolidate overlapping indexes
Add indexes for frequently scanned tables
Performance Metrics Interpretation
Cache Hit Ratio
Ratio
Status
Action
> 99%
Excellent
No action needed
95-99%
Good
Monitor
90-95%
Fair
Consider increasing shared_buffers
< 90%
Poor
Increase shared_buffers, check queries
Sequential vs Index Scans
Scenario
Interpretation
Action
High seq scans, small table
OK
Small tables are fine to scan
High seq scans, large table
Problem
Add index
High index scans
Good
Indexes working well
Low scans overall
Variable
Check if table is actively used
Dead Rows
Dead Rows
Action
< 5% of live rows
OK
5-20%
Schedule VACUUM
> 20%
Run VACUUM immediately
Best Practices
1. Regular Health Checks
Run these tools:
Daily: get_database_stats (cache, hot tables)
Weekly: get_database_shape (sizes, growth)
Monthly: Full analysis (unused indexes, optimization opportunities)
2. Performance Tuning Workflow
Identify slow areas using get_database_stats
Analyze specific queries (if supported)
Optimize by adding/dropping indexes
Monitor improvements with stats
3. Index Management
When to add an index:
High sequential scans on large table
Frequent WHERE/JOIN conditions on column
Slow queries using that column
When to drop an index:
0 scans in index_usage
Overlaps with another index
Table is write-heavy and read-light
4. Maintenance Schedule
Based on database stats:
VACUUM: When dead rows > 10%
ANALYZE: After large data changes
REINDEX: If index bloat suspected
Example Workflow: Finding and Fixing Performance Issues
Step 1: Check Overall Health
Step 2: Identify Problem Tables
Look for:
Tables with high sequential scans
Tables with many dead rows
Low cache hit ratios
Step 3: Check Indexes
Step 4: Review Index Usage
Step 5: Take Action
Add missing indexes
Drop unused indexes
Run VACUUM on tables with dead rows
Tune cache settings if needed
Test Script
Run the test script to see all tools in action:
This will:
Show database structure
Display performance metrics
Identify optimization opportunities
Demonstrate all available features
Troubleshooting
"Permission denied" errors
Ensure you're using SUPABASE_SERVICE_ROLE_KEY (not anon key)
# Track table sizes over time
Tool: get_database_shape
Arguments: { "include_sizes": true, "include_counts": true }
# Get all index information
Tool: get_database_shape
Arguments: { "include_indexes": true, "include_sizes": true }
# Check which indexes are being used
Tool: get_database_stats
Arguments: { "include_index_usage": true }