analyze_workload_indexes
Identify frequently executed database queries and provide recommendations for optimal indexing to improve query performance and database efficiency.
Instructions
Analyze frequently executed queries in the database and recommend optimal indexes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_index_size_mb | No | Max index size in MB |
Implementation Reference
- src/postgres_mcp/server.py:405-423 (handler)The main handler function for the 'analyze_workload_indexes' tool. It uses either DatabaseTuningAdvisor or LLMOptimizerTool to analyze workload and recommend indexes, wrapped with validation and error handling.@mcp.tool(description="Analyze frequently executed queries in the database and recommend optimal indexes") @validate_call async def analyze_workload_indexes( max_index_size_mb: int = Field(description="Max index size in MB", default=10000), method: Literal["dta", "llm"] = Field(description="Method to use for analysis", default="dta"), ) -> ResponseType: """Analyze frequently executed queries in the database and recommend optimal indexes.""" try: sql_driver = await get_sql_driver() if method == "dta": index_tuning = DatabaseTuningAdvisor(sql_driver) else: index_tuning = LLMOptimizerTool(sql_driver) dta_tool = TextPresentation(sql_driver, index_tuning) result = await dta_tool.analyze_workload(max_index_size_mb=max_index_size_mb) return format_text_response(result) except Exception as e: logger.error(f"Error analyzing workload: {e}") return format_error_response(str(e))