Skip to main content

Query History

Read the Overview first for authentication, request conventions, and errors.

Search Query History​

POST /api/v1/query/orgs/{orgSlug}/query-history/query · Read · Member

Searches the query history of the organization. All body fields are optional, but the body must be a JSON object. Send {} to search without filters. The server sets the organization from the path. Do not send orgId, orgSlug, tenantId, or accountId.

FieldTypeRequiredDescription
sizeintegerNoRows per page. Default: 15.
cursorsarrayNoThe cursors value from the previous response. Omit it for the first page.
startTimestringNoStart of the time range. RFC 3339 (2026-11-09T00:00:00Z) or date (2026-11-09).
endTimestringNoEnd of the time range. Same format as startTime.
warehousestringNoWarehouse name.
emailstringNoSQL user name. Use a value from List SQL Users.
queryIdstringNoQuery ID. Partial values match.
queryTextstringNoText in the SQL statement. All words must match.
queryKindstringNoStatement kind, for example Query, Insert, or CopyIntoTable.
databasestringNoCurrent database of the query.
sessionIdstringNoSession ID.
userAgentstringNoText in the client user agent. Any word can match. Use the userAgent value of a result item.
clusterIdstringNoCluster ID. Use the clusterId value of a result item.
nodeIDstringNoNode ID. Use the nodeID value of a result item. The field name ends in an uppercase ID.
statusintegerNoOne query status.
statusListinteger[]NoSeveral query statuses.
queryDurationGteintegerNoMinimum duration in milliseconds.
queryDurationLteintegerNoMaximum duration in milliseconds.
exceptionCodeintegerNoError code.
exceptionTextstringNoText in the error message.
queryTagstringNoQuery tag.
queryHashstringNoQuery hash.
queryParameterizedHashstringNoHash of the statement without literal values.
sortstringNoOne of startTime, queryDuration, queryQueuedDuration, resultRows, scanRows, warehouse. Send it together with direction.
directionstringNoasc or desc. Send it together with sort. If you omit both, the order is startTime desc.

Request example:

{
"size": 20,
"startTime": "2026-11-09T00:00:00Z",
"endTime": "2026-11-09T12:00:00Z",
"warehouse": "<warehouse-name>",
"statusList": [3, 4],
"sort": "queryDuration",
"direction": "desc"
}

Response example. Each item has about 70 fields. This example shows the most useful ones.

{
"success": true,
"data": {
"total": 1,
"cursors": [35],
"list": [
{
"queryId": "01a1b2c3-4d5e",
"queryKind": "Query",
"queryText": "SELECT count(*) FROM sales.orders",
"status": 3,
"logTypeName": "Error",
"fail": true,
"exceptionCode": 1025,
"exceptionText": "Unknown table 'orders'",
"sqlUser": "alice@example.com",
"warehouse": "default",
"currentDatabase": "sales",
"startTime": "2026-11-09T08:00:01Z",
"endTime": "2026-11-09T08:00:01Z",
"queryDuration": 35,
"scanRows": 0,
"resultRows": 0,
"hasProfiles": false,
"sessionId": "8f6e1c2a"
}
]
}
}

To get the next page, send the same body with cursors set to the cursors value of the response. An empty list means that there are no more rows.

Count Query History​

POST /api/v1/query/orgs/{orgSlug}/query-history/count · Read · Member

Counts the queries that match the filters. The body is the same as Search Query History. The server ignores size, cursors, sort, and direction.

Response example:

{ "success": true, "data": 1284 }

Get Query Details​

GET /api/v1/query/orgs/{orgSlug}/query-history/{queryId}/detail · Read · Member

Returns the details of one query.

ParameterInTypeRequiredDescription
orgSlugpathstringYesOrganization ID.
queryIdpathstringYesQuery ID.

Response example:

{
"success": true,
"data": {
"queryId": "01a1b2c3-4d5e",
"queryKind": "Query",
"queryText": "SELECT count(*) FROM sales.orders",
"startTime": "2026-11-09T08:00:01Z",
"endTime": "2026-11-09T08:00:02Z",
"queryDuration": 812,
"queryQueuedDurationMS": 0,
"status": 2,
"fail": false,
"failText": "",
"database": "sales",
"warehouse": "default",
"warehouseSize": "Small",
"tables": "sales.orders",
"scanRows": 1200000,
"bytesScanned": 48230000,
"resultRows": 1,
"resultBytes": 8,
"hasProfiles": true,
"accountEmail": "alice@example.com",
"sessionId": "8f6e1c2a",
"serverVersion": "v1.2.961-nightly"
}
}

Get a Query Profile​

GET /api/v1/query/orgs/{orgSlug}/query-history/{queryId}/profile · Read · Member

Returns the execution profile of one query. Use it to find slow operators. Call this endpoint only if hasProfiles is true in the query details. Parameters are the same as Get Query Details.

The response uses snake_case. profiles is a list of plan nodes. parent_id links a node to its parent. statistics is a list of numbers. statistics_desc gives the name, unit, and index of each number.

{
"success": true,
"data": {
"query_id": "01a1b2c3-4d5e",
"warehouse": "default",
"warehouse_size": "Small",
"profiles": [
{
"id": 0,
"parent_id": null,
"name": "EvalScalar",
"title": "",
"cpu_time": 1520000,
"wait_time": 0,
"labels": [{ "name": "List of Expressions", "value": ["count(*)"] }],
"statistics": [1520000, 0, 0, 0, 1, 8]
}
],
"statistics_desc": {}
}
}

The example leaves out the content of statistics_desc. Each key is a statistic name. Each value has an index field, which is the position of the statistic in the statistics list of each node.

List SQL Users in Query History​

GET /api/v1/query/orgs/{orgSlug}/query-history/sql-users · Read · Member

Returns the SQL user names that appear in the query history. Use a value as the email filter of Search Query History.

{ "success": true, "data": ["alice@example.com", "etl_user"] }

Types​

Query Status​

Used by query history (status, statusList).

ValueName
1Start (running)
2Finish
3Error
4Aborted
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