show_ranges
Display range distribution across a CockroachDB cluster to analyze data placement and identify hotspots. Filter by table and set result limits for targeted monitoring.
Instructions
Show range distribution in the cluster.
Args:
table: Optional table to filter ranges.
limit: Maximum ranges to return.
Returns:
Range distribution information.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table | No | ||
| limit | No |
Implementation Reference
- src/cockroachdb_mcp/server.py:534-534 (registration)Registration of the 'show_ranges' tool using the @mcp.tool() decorator.@mcp.tool()
- src/cockroachdb_mcp/server.py:534-548 (handler)MCP tool handler for 'show_ranges', which delegates to the cluster helper function.@mcp.tool() async def show_ranges(table: str | None = None, limit: int = 50) -> dict[str, Any]: """Show range distribution in the cluster. Args: table: Optional table to filter ranges. limit: Maximum ranges to return. Returns: Range distribution information. """ try: return await cluster.show_ranges(table, limit) except Exception as e: return {"status": "error", "error": str(e)}
- Core implementation of show_ranges that executes SQL queries against crdb_internal.ranges_no_leases to retrieve and format range distribution information.async def show_ranges(table: str | None = None, limit: int = 50) -> dict[str, Any]: """Show range distribution in the cluster. Args: table: Optional table to filter ranges. limit: Maximum ranges to return. Returns: Range distribution information. """ conn = await connection_manager.ensure_connected() try: if table: # Parse table name (schema ignored - CockroachDB ranges use just table_name) if "." in table: _schema, table_name = table.rsplit(".", 1) else: table_name = table query = f""" SELECT range_id, start_pretty, end_pretty, lease_holder, replicas, range_size_mb FROM crdb_internal.ranges_no_leases WHERE table_name = '{table_name}' LIMIT {limit} """ else: query = f""" SELECT range_id, database_name, table_name, start_pretty, end_pretty, lease_holder, replicas, range_size_mb FROM crdb_internal.ranges_no_leases LIMIT {limit} """ async with conn.cursor() as cur: await cur.execute(query) rows = await cur.fetchall() ranges = [] for row in rows: range_info: dict[str, Any] = { "range_id": row.get("range_id"), "start": row.get("start_pretty"), "end": row.get("end_pretty"), "lease_holder": row.get("lease_holder"), "replicas": row.get("replicas"), "size_mb": row.get("range_size_mb"), } if not table: range_info["database"] = row.get("database_name") range_info["table"] = row.get("table_name") ranges.append(range_info) return {"ranges": ranges, "count": len(ranges), "table_filter": table} except Exception as e: return {"status": "error", "error": str(e)}