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
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 forSHOW 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
- To list the active queries across all nodes of the cluster, use
SHOW STATEMENTSorSHOW 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:| Field | Description |
|---|---|
query\_id | The ID of the query. |
node\_id | The ID of the node. |
session\_id | The ID of the session. |
user\_name | The username of the connected user. |
start | The at which the query started. |
query | The SQL query. |
client\_address | The address and port of the client that issued the SQL query. |
application\_name | The specified by the client, if any. For queries from the , this will be $ cockroach sql. |
distributed | If 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. |
phase | The 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
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 useSHOW CLUSTER STATEMENTS to find queries that have been running for more than 3 hours:
query_id and use it with the CANCEL QUERY statement:

