Skip to main content
The SHOW STATEMENTS lists details about currently active SQL queries, including:
  • The internal ID of the query
  • The node executing the query
  • The SQL query itself
  • How long the query has been running
  • The client address, application name, and user that issued the query
  • The ID for the current session
These details let you monitor the progress of active queries and, if necessary, identify those that may need to be to prevent unwanted resource consumption.
Schema changes and / statements are not executed as queries internally and so are not listed by SHOW STATEMENTS. To monitor such statements, use instead.

Aliases

In CockroachDB, the following are aliases for SHOW STATEMENTS:
  • SHOW QUERIES

Required privileges

All users can see their own currently active queries. Users with the can view see all users’ currently active queries. VIEWACTIVITYREDACTED causes constants in queries being executed by other users to be redacted.

Synopsis

show_statements syntax diagram
  • To list the active queries across all nodes of the cluster, use SHOW STATEMENTS or SHOW CLUSTER STATEMENTS.
  • To list the active queries just on the local node, use SHOW LOCAL STATEMENTS.

Response

The following fields are returned for each query:
FieldDescription
query_idThe ID of the query.
node_idThe ID of the node.
session_idThe ID of the session.
user_nameThe username of the connected user.
startThe at which the query started.
queryThe SQL query.
client_addressThe address and port of the client that issued the SQL query.
application_nameThe specified by the client, if any. For queries from the , this will be $ cockroach sql.
distributedIf true, the query is being executed by the Distributed SQL (DistSQL) engine. If false, the query is being executed by the standard “local” SQL engine. If NULL, the query is being prepared and it’s not yet known which execution engine will be used.
phaseThe phase of the query’s execution. If preparing, the statement is being parsed and planned. If executing, the statement is being executed.

Examples

List queries across the cluster

Alternatively, you can use SHOW STATEMENTS to receive the same response.

List queries on the local node

Filter for specific queries

You can use a statement to filter the list of active queries by one or more of the response fields.

Show all queries on node 2

Show all queries from a specific address and user

Exclude queries from the built-in SQL client

To exclude queries from the , filter for queries that do not show $ cockroach sql as the application_name:

Cancel a query

When you see a query that is taking too long to complete, you can use the statement to end it. For example, let’s say you use SHOW CLUSTER STATEMENTS to find queries that have been running for more than 3 hours:
To cancel this long-running query, and stop it from consuming resources, you note the query_id and use it with the CANCEL QUERY statement:

See also