Skip to main content
The SHOW SESSIONS lists details about currently active sessions, including:
  • The address of the client that opened the session
  • The node connected to
  • How long the connection has been open
  • Which queries are active in the session
  • Which query has been running longest in the session
These details let you monitor the overall state of client connections and identify those that may need further investigation or adjustment.

Required privileges

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

Synopsis

show_sessions syntax diagram SQL syntax diagram
  • To list the active sessions across all nodes of the cluster, use SHOW SESSIONS or SHOW CLUSTER SESSIONS.
  • To list the active sessions just on the local node, use SHOW LOCAL SESSIONS.

Response

The following fields are returned for each session:
FieldDescription
node\_idThe ID of the node connected to.
session\_idThe ID of the connected session.
statusThe session’s status.
user\_nameThe username of the connected user.
client\_addressThe address and port of the connected client.
application\_nameThe specified by the client, if any. For sessions from the , this will be cockroach.
active\_queriesThe SQL queries currently active in the session.
last\_active\_queryThe most recently completed SQL query in the session.
session\_startThe when the session was started.
active\_query\_startThe when the current active query in the session was started.
num\_txns\_executedThe number of that have been opened in this session. This count includes transactions that are open.

Examples

List active sessions across the cluster

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

List active sessions on the local node

Filter for specific sessions

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

Show sessions associated with a specific user

Exclude sessions from the built-in SQL client

To exclude sessions from the , filter for sessions that do not show cockroach as the application_name:

Identify and cancel a problematic query

If a session has been open for a long time and you are concerned that the oldest active SQL query may be problematic, you can use the statement to further investigate the query and then, if necessary, use the statement to cancel it. For example, let’s say you run SHOW SESSIONS and notice that the following session has been open for more than 2 hours:
Since the oldest_query_start timestamp is the same as the session_start timestamp, you are concerned that the SELECT query shown in active_queries has been running for too long and may be consuming too many resources. So you use the statement to get more information about the query, filtering based on details you already have:
Using the start field, you confirm that the query has been running since the start of the session and decide that is too long. So to cancel the query, and stop it from consuming resources, you note the query_id and use it with the statement:
Alternatively, if you know that you want to cancel the query based on the details in SHOW SESSIONS, you could execute a single statement with a nested SELECT statement that returns the query_id:

See also