Skip to main content

Troubleshooting

Diagnose slow queries, errors, resource usage, and login issues using system_history tables. Use profile_history for per-operator execution analysis (CPU time, I/O, spill, output rows). All tables are per-tenant isolated.

Tables

system_history.query_history

Complete SQL execution audit trail. Every query generates entries with start/finish status.

FieldTypeDescription
log_typeTINYINTQuery status: 1=Start, 2=Finish, 3=Error, 4=Aborted, 5=Closed
log_type_nameVARCHARString name: "Start", "Finish", "Error", "Aborted", "Closed"
handler_typeVARCHARProtocol used (e.g., HTTPQuery, MySQL)
tenant_idVARCHARTenant identifier
cluster_idVARCHARCluster identifier
node_idVARCHARNode identifier
sql_userVARCHARUser who executed the query
sql_user_quotaVARCHARUser quota information
sql_user_privilegesVARCHARUser privileges
query_idVARCHARUnique query identifier
query_kindVARCHARQuery kind (e.g., Query, Insert, CopyIntoTable)
query_textVARCHARSQL text of the query
query_hashVARCHARHash of the query text
query_parameterized_hashVARCHARHash ignoring literal values
event_dateDATEDate of the event
event_timeTIMESTAMPTimestamp of the event
query_start_timeTIMESTAMPQuery start timestamp
query_duration_msBIGINTTotal duration in ms (queue + execution)
query_queued_duration_msBIGINTTime spent in queue (ms)
current_databaseVARCHARDatabase in use
written_rowsBIGINT UNSIGNEDRows written
written_bytesBIGINT UNSIGNEDBytes written
join_spilled_rowsBIGINT UNSIGNEDRows spilled during joins
join_spilled_bytesBIGINT UNSIGNEDBytes spilled during joins
agg_spilled_rowsBIGINT UNSIGNEDRows spilled during aggregation
agg_spilled_bytesBIGINT UNSIGNEDBytes spilled during aggregation
group_by_spilled_rowsBIGINT UNSIGNEDRows spilled during group by
group_by_spilled_bytesBIGINT UNSIGNEDBytes spilled during group by
written_io_bytesBIGINT UNSIGNEDBytes written to IO
written_io_bytes_cost_msBIGINT UNSIGNEDIO write cost (ms)
scan_rowsBIGINT UNSIGNEDRows scanned
scan_bytesBIGINT UNSIGNEDBytes scanned
scan_io_bytesBIGINT UNSIGNEDIO bytes read during scan
scan_io_bytes_cost_msBIGINT UNSIGNEDIO scan cost (ms)
scan_partitionsBIGINT UNSIGNEDPartitions scanned
total_partitionsBIGINT UNSIGNEDTotal partitions involved
result_rowsBIGINT UNSIGNEDRows in result
result_bytesBIGINT UNSIGNEDBytes in result
bytes_from_remote_diskBIGINT UNSIGNEDBytes read from remote disk
bytes_from_local_diskBIGINT UNSIGNEDBytes read from local disk
bytes_from_memoryBIGINT UNSIGNEDBytes read from memory
client_addressVARCHARClient address
user_agentVARCHARClient user agent
exception_codeINTException code (0 = success)
exception_textVARCHARException message
server_versionVARCHARServer version
query_tagVARCHARQuery tag
has_profileBOOLEANWhether query has execution profile
peek_memory_usageVARIANTPeak memory usage (JSON)
session_idVARCHARSession identifier
session_settingsVARCHARSession settings

system_history.profile_history

Detailed execution profiles for every query. Use jq() to extract per-operator statistics.

FieldTypeDescription
timestampTIMESTAMPWhen the profile was recorded
query_idVARCHARQuery ID
profilesVARIANTJSON array of operators, each with id, name, statistics[]
statistics_descVARIANTJSON describing statistics format

Statistics array indices: [0]=OutputRows, [1]=OutputBytes, [2]=InputRows, [3]=InputBytes, [4]=CpuTime(ns).

system_history.log_history

Raw log entries from all Databend nodes and components.

FieldTypeDescription
timestampTIMESTAMPLog entry timestamp
pathVARCHARSource file path and line number
targetVARCHARTarget module or component
log_levelVARCHARLog level (INFO, ERROR, WARN, etc.)
cluster_idVARCHARCluster identifier
node_idVARCHARNode identifier
warehouse_idVARCHARWarehouse identifier
query_idVARCHARAssociated query ID
messageVARCHARLog message (plain text)
fieldsVARIANTAdditional fields (JSON)
batch_numberBIGINTInternal use

system_history.access_history

Data lineage and access control audit. Tracks all objects accessed or modified.

FieldTypeDescription
query_idVARCHARQuery ID
query_startTIMESTAMPQuery start time
user_nameVARCHARUser who executed the query
base_objects_accessedVARIANTObjects accessed (JSON array)
direct_objects_accessedVARIANTReserved for future use
objects_modifiedVARIANTObjects modified by DML (JSON array)
object_modified_by_ddlVARIANTObjects modified by DDL (JSON array)

JSON object fields: object_domain (Database/Table/Stage), object_name, columns[], stage_type, operation_type (Create/Alter/Drop/Undrop), properties.

system_history.login_history

Authentication audit trail for all login attempts.

FieldTypeDescription
event_timeTIMESTAMPLogin event timestamp
handlerVARCHARProtocol (e.g., HTTP, MySQL)
event_typeVARCHARLoginSuccess or LoginFailed
connection_uriVARCHARConnection URI
auth_typeVARCHARAuthentication method (e.g., Password)
user_nameVARCHARUser attempting login
client_ipVARCHARClient IP address
user_agentVARCHARClient user agent
session_idVARCHARSession ID
node_idVARCHARNode ID
error_messageVARCHARError message if failed

Quick Examples

Find slow queries (>5s) in the last hour:

SELECT query_id, sql_user, query_duration_ms, query_text
FROM system_history.query_history
WHERE query_duration_ms > 5000
AND event_time > now() - INTERVAL 1 HOUR
AND log_type = 2
ORDER BY query_duration_ms DESC
LIMIT 20;

Find failed queries:

SELECT query_id, sql_user, exception_code, exception_text, query_text
FROM system_history.query_history
WHERE exception_code != 0
AND event_time > now() - INTERVAL 1 HOUR
ORDER BY event_time DESC;

Check login failures:

SELECT event_time, user_name, client_ip, error_message
FROM system_history.login_history
WHERE event_type = 'LoginFailed'
AND event_time > now() - INTERVAL 24 HOUR
ORDER BY event_time DESC;
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