Skip to main content

QUERY_HISTORY

Introduced or updated: v1.2.687

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. Defaults to 1 hour before TO.
TOOptional. End timestamp for the query range. Format: YYYY-MM-DD HH:MM:SS. 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;
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today