Home / Data Platform / Lakehouse

Data PlatformCheat sheetIntermediate

Trino on-call cheat sheet: find and kill queries, check workers and set session limits

The SQL, CLI and REST calls an on-call engineer needs on a Trino cluster. Find the query hurting everyone, kill it, check worker health, drain a node and cap runaway queries.

Deepak Bhardwaj7 min read

Applies toTrino 400 and later (open source), Starburst Enterprise and Amazon EMR Trino. System table columns and defaults vary by release

When to use this

Someone reports "Trino is slow" or "my query has been queued for 20 minutes". You need to find what is running, who is running it and whether a worker is unhealthy, and then do something about it without restarting the coordinator. Everything below runs from the Trino CLI or any SQL client connected to the coordinator.

Tip

The system catalog is always there. If a command here fails with a missing column, run DESCRIBE system.runtime.queries and adjust, because column names have changed between releases.

Connect with the CLI

# Interactive session
trino --server https://trino.example.com:8443 --user oncall --catalog hive --schema default

# One-off command, CSV output, useful in scripts and tickets
trino --server https://trino.example.com:8443 --user oncall \
  --output-format CSV_HEADER \
  --execute "SELECT query_id, state, \"user\" FROM system.runtime.queries WHERE state = 'RUNNING'"

# Run a file of statements
trino --server https://trino.example.com:8443 --user oncall --file triage.sql

Add --password (prompts for a password), or the Kerberos or JWT options your cluster uses. user is a reserved word, so quote it in SQL.

Find the problem query

What is running or queued now

SELECT query_id,
       state,
       "user",
       source,
       resource_group_id,
       created,
       date_diff('minute', created, now()) AS age_min,
       substr(query, 1, 120)               AS query_text
FROM system.runtime.queries
WHERE state IN ('QUEUED', 'PLANNING', 'STARTING', 'RUNNING')
ORDER BY created;
What you see Likely cause Next step
Many QUEUED, few RUNNING Resource group concurrency limit or memory limit reached Check resource_group_id and the group's hardConcurrencyLimit, then kill or wait out the heavy queries
One user or source with dozens of RUNNING A BI tool refresh storm or a looping script Kill the batch and contact the owner. Add a selector that routes them to a smaller group
Long PLANNING Slow metastore or catalog, or a huge partition listing Check the Hive metastore, Glue or the Iceberg catalog. Look for missing partition filters
One very old RUNNING query Runaway join, cross join or a full scan Inspect it, then kill it

Recent failures

SELECT query_id, "user", error_type, error_code, "end",
       substr(query, 1, 120) AS query_text
FROM system.runtime.queries
WHERE state = 'FAILED'
  AND "end" > now() - INTERVAL '30' MINUTE
ORDER BY "end" DESC;

system.runtime.queries only holds queries the coordinator still remembers (governed by query.max-history and query.min-expire-age). For anything older, use your event listener output or the query log your platform ships with.

Per-task detail for one query

SELECT node_id, stage_id, task_id, state, splits, completed_splits,
       raw_input_rows, raw_input_bytes
FROM system.runtime.tasks
WHERE query_id = '20261128_093112_01234_abcde'
ORDER BY raw_input_bytes DESC;

If one node_id has far more input bytes than the others, the problem is skew, not cluster size.

Kill a query

CALL system.runtime.kill_query(
  query_id => '20261128_093112_01234_abcde',
  message  => 'Killed by on-call: full scan without partition filter, see INC-1234');

The message is shown to the user as the failure reason, so make it useful. Killing someone else's query needs the right access control permission. If the call is denied, check the system access control rules for your cluster.

To kill every running query from one user, generate the calls and review them before you run them:

SELECT 'CALL system.runtime.kill_query(query_id => ''' || query_id ||
       ''', message => ''Killed by on-call, INC-1234'');'
FROM system.runtime.queries
WHERE "user" = 'bi_refresh' AND state IN ('QUEUED', 'RUNNING');

Warning

Killing an INSERT, CREATE TABLE AS or MERGE part-way through can leave partial files on connectors that don't commit atomically, such as Hive tables on object storage. Iceberg and Delta Lake writes commit atomically, so a killed query leaves no visible data, only orphan files that maintenance later removes. Check with the owner before you kill a write.

Check cluster and worker health

-- Nodes the coordinator knows about
SELECT node_id, http_uri, node_version, coordinator, state
FROM system.runtime.nodes;

-- Catalogs that loaded
SHOW CATALOGS;

A worker missing from system.runtime.nodes has stopped announcing itself. Check the worker's server.log for OutOfMemoryError or GC pauses, and check that the host is up. A worker on a different node_version after a partial upgrade causes odd failures. Fix the version mismatch before you investigate anything else.

From a shell on any host:

# Coordinator info: version, uptime, and whether it is still starting
curl -s https://trino.example.com:8443/v1/info

# Node state: ACTIVE, SHUTTING_DOWN, ...
curl -s https://trino.example.com:8443/v1/info/state

Drain a worker before maintenance

# Run against the worker, not the coordinator
curl -s -X PUT -H "Content-Type: application/json" \
  -d '"SHUTTING_DOWN"' \
  http://worker-07.internal:8080/v1/info/state

The worker stops accepting new tasks, finishes the ones it has (after a grace period set by shutdown.grace-period) and then exits. On secured clusters this call needs authentication and the matching access control permission.

Caution

Don't send SHUTTING_DOWN to the coordinator in a single-coordinator cluster. Every running and queued query fails.

Cap runaway queries with session properties

Session properties apply to the current session only. They can lower limits but can't raise them above the server config.

SHOW SESSION LIKE 'query_max%';

SET SESSION query_max_execution_time = '30m';
SET SESSION query_max_run_time = '45m';        -- includes queued time
SET SESSION query_max_memory = '20GB';
SET SESSION query_max_memory_per_node = '4GB';

RESET SESSION query_max_execution_time;

To apply limits to a whole team, use session property managers or resource groups instead of asking users to run SET SESSION. Server-wide defaults live in config.properties (query.max-execution-time, query.max-run-time) and need a restart.

Explain a slow query

-- Plan only, nothing runs
EXPLAIN (TYPE DISTRIBUTED)
SELECT ...;

-- Runs the query and reports actual rows, CPU and memory per stage
EXPLAIN ANALYZE
SELECT ...;

Things to look for:

  • ScanFilterProject reading every partition: there is no partition filter, or the filter is on a column the connector can't push down.
  • A CROSS JOIN or a join with no equality condition.
  • A REPLICATED join (broadcast) where the build side is large. Try SET SESSION join_distribution_type = 'PARTITIONED'.
  • One stage with much higher input than the others: skew.

Tip

EXPLAIN ANALYZE runs the full query. Don't use it on a write or on the runaway query you are trying to stop.

Quick reference

Task Command
Running queries SELECT ... FROM system.runtime.queries WHERE state = 'RUNNING'
Kill a query CALL system.runtime.kill_query(query_id => '...', message => '...')
Tasks for a query SELECT ... FROM system.runtime.tasks WHERE query_id = '...'
Worker list SELECT * FROM system.runtime.nodes
Node state curl .../v1/info/state
Drain a worker curl -X PUT -d '"SHUTTING_DOWN"' .../v1/info/state
Session limits SET SESSION query_max_execution_time = '30m'
Plan EXPLAIN (TYPE DISTRIBUTED) ...

Prevent it next time

  • Set query.max-execution-time on the server and lower limits per resource group, so that a runaway query stops by itself.
  • Route BI tools, ad hoc users and ETL to separate resource groups by source or user, so that one refresh storm can't queue everyone else.
  • Send query completion events to a log store with an event listener. You'll have history after system.runtime.queries forgets it.
  • Alert on queued query count and on workers that drop out of system.runtime.nodes, not only on coordinator uptime.
  • Keep a triage.sql file with the queries above in your runbook repository so the on-call engineer can run it with --file.