describe_slow_log_records
Query and retrieve slow log records for Alibaba Cloud RDS instances within a specified time range, filter by SQL statement, database, or node, and manage pagination for detailed performance analysis.
Instructions
Query slow log records for an RDS instance.
Args:
region_id: The region ID of the RDS instance.
dbinstance_id: The ID of the RDS instance.
start_time: Start time in format: yyyy-MM-dd HH:mm.
Cannot be earlier than 30 days before the current time.
end_time: End time in format: yyyy-MM-dd HH:mm.
Must be later than the start time.
sqlhash: The unique identifier of the SQL statement in slow log statistics.
Used to get slow log details for a specific SQL statement.
db_name: The name of the database.
page_size: Number of records per page. Range: 30-100. Default: 30.
page_number: Page number. Must be greater than 0 and not exceed Integer max value. Default: 1.
node_id: Node ID. Only applicable to cluster instances.
If not specified, logs from the primary node are returned by default.
Returns:
Dict[str, Any]: The response containing slow log records.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| db_name | No | ||
| dbinstance_id | Yes | ||
| end_time | Yes | ||
| node_id | No | ||
| page_number | No | ||
| page_size | No | ||
| region_id | Yes | ||
| sqlhash | No | ||
| start_time | Yes |
Input Schema (JSON Schema)
{
"properties": {
"db_name": {
"default": null,
"title": "Db Name",
"type": "string"
},
"dbinstance_id": {
"title": "Dbinstance Id",
"type": "string"
},
"end_time": {
"title": "End Time",
"type": "string"
},
"node_id": {
"default": null,
"title": "Node Id",
"type": "string"
},
"page_number": {
"default": 1,
"title": "Page Number",
"type": "integer"
},
"page_size": {
"default": 30,
"title": "Page Size",
"type": "integer"
},
"region_id": {
"title": "Region Id",
"type": "string"
},
"sqlhash": {
"default": null,
"title": "Sqlhash",
"type": "string"
},
"start_time": {
"title": "Start Time",
"type": "string"
}
},
"required": [
"region_id",
"dbinstance_id",
"start_time",
"end_time"
],
"title": "describe_slow_log_recordsArguments",
"type": "object"
}
Implementation Reference
- The main handler function for the 'describe_slow_log_records' tool. It uses the Alibaba Cloud RDS SDK to call DescribeSlowLogRecords API, transforming input times and constructing the request with optional parameters like sqlhash, db_name, etc. Returns the API response as a dictionary.async def describe_slow_log_records( region_id: str, dbinstance_id: str, start_time: str, end_time: str, sqlhash: str = None, db_name: str = None, page_size: int = 30, page_number: int = 1, node_id: str = None ) -> Dict[str, Any]: """Query slow log records for an RDS instance. Args: region_id: The region ID of the RDS instance. dbinstance_id: The ID of the RDS instance. start_time: Start time in format: yyyy-MM-dd HH:mm. Cannot be earlier than 30 days before the current time. end_time: End time in format: yyyy-MM-dd HH:mm. Must be later than the start time. sqlhash: The unique identifier of the SQL statement in slow log statistics. Used to get slow log details for a specific SQL statement. db_name: The name of the database. page_size: Number of records per page. Range: 30-100. Default: 30. page_number: Page number. Must be greater than 0 and not exceed Integer max value. Default: 1. node_id: Node ID. Only applicable to cluster instances. If not specified, logs from the primary node are returned by default. Returns: Dict[str, Any]: The response containing slow log records. """ try: # Initialize the client client = get_rds_client(region_id) start_time = transform_to_datetime(start_time) end_time = transform_to_datetime(end_time) # Create request request = rds_20140815_models.DescribeSlowLogRecordsRequest( dbinstance_id=dbinstance_id, start_time=transform_to_iso_8601(start_time, "minutes"), end_time=transform_to_iso_8601(end_time, "minutes"), page_size=page_size, page_number=page_number ) # Add optional parameters if provided if sqlhash: request.sqlhash = sqlhash if db_name: request.db_name = db_name if node_id: request.node_id = node_id # Make the API request response = client.describe_slow_log_records(request) return response.body.to_map() except Exception as e: logger.error(f"Error occurred while querying slow log records: {str(e)}") raise OpenAPIError(f"Failed to query slow log records: {str(e)}")