📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

QUERY_HISTORY



Retrieves query execution logs for analysis and monitoring purposes.

Syntax

QUERY_HISTORY [ BY WAREHOUSE <warehouse_name> ] [ FROM '<timestamp>' ] [ TO '<timestamp>' ] [ LIMIT <unsigned_integer> ]
ParameterDescription
BY WAREHOUSEOptional. Filters logs to a specific warehouse. Empty names raise an error.
FROMOptional. Start timestamp for the query range. Format: YYYY-MM-DD HH:MM:SS (UTC or explicit timezone). Defaults to 1 hour before TO.
TOOptional. End timestamp for the query range. Format: YYYY-MM-DD HH:MM:SS (UTC or explicit timezone). Defaults to current time.
LIMITOptional. Maximum number of records to return. Defaults to 10. Must be a positive integer.

Output Columns

The result includes columns such as:

ColumnDescription
query_idUnique identifier for the query
query_textThe SQL statement executed
scan_bytesAmount of data scanned
...Additional query metrics and metadata

Examples

Get recent query history for a specific warehouse:

QUERY_HISTORY BY WAREHOUSE 'etl-wh' FROM '2023-08-20 00:00:00' TO '2023-08-20 06:00:00' LIMIT 200;

Get the last 10 queries across all warehouses:

QUERY_HISTORY;

Get query history with a custom limit:

QUERY_HISTORY LIMIT 50;

Was this page helpful?