> ## Documentation Index
> Fetch the complete documentation index at: https://cockroachlabs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Sessions Page

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

<Note>
  On a <InternalLink path="secure-a-cluster">secure cluster</InternalLink>, you must be an <InternalLink path="security-reference/authorization#admin-role">`admin` user</InternalLink> or a SQL user with the <InternalLink path="security-reference/authorization">`VIEWACTIVITY`</InternalLink> or <InternalLink path="security-reference/authorization">`VIEWACTIVITYREDACTED`</InternalLink> <InternalLink path="security-reference/authorization#supported-privileges">system privilege</InternalLink> (or the legacy `VIEWACTIVITY` <InternalLink path="security-reference/authorization">role option</InternalLink>). Other users will see only their own sessions. Refer to <InternalLink path="ui-overview#db-console-security-considerations">DB Console security</InternalLink>.
</Note>

The **Sessions** page provides information about open SQL sessions in your cluster, using data in the cluster's <InternalLink path="monitoring-and-alerting#crdb_internal-system-catalog">`crdb_internal` system catalog</InternalLink>. To view it, click **SQL Activity**, then click **Sessions**.

## Sessions table

Use the **Sessions** table to see active, idle, and closed sessions. A session is *active* if it has an open transaction (including implicit transactions, which are individual SQL statements), and *idle* if it has no open transaction. Active sessions consume hardware resources. A session is *closed* if it has closed the connection to CockroachDB.

<img src="https://mintcdn.com/cockroachlabs/bulMe5iV6qsi6_Jh/images/v23.2/ui-sessions-page.png?fit=max&auto=format&n=bulMe5iV6qsi6_Jh&q=85&s=dfc54edff7873a9747ee4e3f302fc50c" alt="Sessions Page" width="3924" height="552" data-path="images/v23.2/ui-sessions-page.png" />

To filter the sessions, click the **Filters** field.

<img src="https://mintcdn.com/cockroachlabs/bulMe5iV6qsi6_Jh/images/v23.2/ui-session-filter.png?fit=max&auto=format&n=bulMe5iV6qsi6_Jh&q=85&s=3877542a2299794a803604d91a991e3f" alt="Session filter" width="315" height="510" data-path="images/v23.2/ui-session-filter.png" />

* To filter by <InternalLink path="connection-parameters#additional-connection-parameters">application</InternalLink>, select **Application Name** and choose one or more applications.
  * Queries from the SQL shell are displayed under the `$ cockroach` app.
  * If you have not set `application_name` in a client connection string, it appears as `unset`.
* To filter by username or session status, select **User Name** or **Session Status** and check one or more checkboxes.
* To filter by session duration, specify the session time and unit.

Click **Columns** to select the columns to display in the table.

The following properties are displayed for each session:

| Column                     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Session Start Time (UTC)   | The timestamp at which the session started.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Session Duration           | The amount of time the session has been open.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Session Active Duration    | The amount of time transactions were executing while the session was open.                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| Status                     | The status of the session: `Active`, `Idle`, or `Closed`. A session is `Active` if it has an open explicit or implicit transaction (individual SQL statement) with a statement that is actively running or waiting to acquire a lock. A session is `Idle` if it has no open transaction. A session is `Closed` if it has closed the connection to CockroachDB.                                                                                                                                                                                     |
| Most Recent Statement      | If more than one statement is executing, the most recent statement. If the session is Idle, the last statement.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| Statement Start Time (UTC) | The timestamp at which the statement started.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| Transaction Count          | The number of transactions completed in the session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| Memory Usage               | Amount of memory currently allocated to the session followed by the maximum amount of memory the session has ever been allocated.                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Client IP Address          | The IP address and port of the client that opened the session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| User Name                  | The user that opened the session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Application Name           | The application that ran the session.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| Actions                    | Options to cancel the active statement and cancel the session. These require the `CANCELQUERY`<InternalLink path="security-reference/authorization#supported-privileges">system privilege</InternalLink> (or the legacy `CANCELQUERY`<InternalLink path="alter-role#role-options">role option</InternalLink>.  - **Cancel Statement:** Ends the SQL statement. The session running this statement will receive an error.  - **Cancel Session:** Ends the session. The client that holds this session will receive a "connection terminated" event. |

To view details of a session, click a **Session Start Time (UTC)** to display session details.

## Session Details

If a session is idle, the **Transaction** and **Most Recent Statement** panels will display **No Active \[Transaction | Statement]**.

<img src="https://mintcdn.com/cockroachlabs/bulMe5iV6qsi6_Jh/images/v23.2/ui-sessions-details-page.png?fit=max&auto=format&n=bulMe5iV6qsi6_Jh&q=85&s=09cdc423292e1aa69970b018d5eecd4b" alt="Sessions Details Page" width="2164" height="2176" data-path="images/v23.2/ui-sessions-details-page.png" />

The **Cancel statement** button ends the SQL statement. The session running this statement will receive an error. The **Cancel session** button ends the session. The client that holds this session will receive a "connection terminated" event.

* **Session Details**
  * **Session Start Time** shows the timestamp at which the session started.
    <a id="session-details-gateway-node" /> - **Gateway Node** shows the node ID and IP address/port of the <InternalLink path="architecture/life-of-a-distributed-transaction#gateway">gateway</InternalLink> node handling the client connection.
  * **Application Name** shows the name of the application connected to the session.
  * **Client IP Address** shows the IP address/port of the client that opened the session.
  * **Memory Usage** shows the amount of memory currently allocated to this session, followed by the maximum amount of memory this session has ever allocated.
  * **User Name** displays the name of the user that started the session.
* **Transaction** displays the following information for an open transaction.
  * **Transaction Start Time** shows the timestamp at which the transaction started.
  * **Number of Statements Executed** shows the total number of SQL statements executed by the transaction.
  * **Number of Retries** shows the total number of <InternalLink path="transactions#transaction-retries">retries</InternalLink> for the transaction.
  * **Number of Automatic Retries** shows the total number of <InternalLink path="transactions#automatic-retries">automatic retries</InternalLink> run by CockroachDB for the transaction.
  * **Read Only?** shows whether the transaction is read-only.
  * **AS OF SYSTEM TIME?** shows whether the transaction uses <InternalLink path="performance-best-practices-overview#use-as-of-system-time-to-decrease-conflicts-with-long-running-queries">`AS OF SYSTEM TIME`</InternalLink> to return historical data.
  * **Priority** shows the <InternalLink path="transactions#transaction-priorities">priority</InternalLink> for the transaction.
  * **Memory Usage** shows the amount of memory currently allocated to this transaction, followed by the maximum amount of memory this transaction has ever allocated.
* **Most Recent Statement** displays the following information for an active statement.
  * The SQL statement.
  * **Execution Start Time** is the timestamp at which the statement was run.
  * **Distributed Execution?** shows whether the statement uses <InternalLink path="architecture/sql-layer#distsql">Distributed SQL (DistSQL)</InternalLink> optimization.
* **Most Recent Transaction Fingerprints Executed**

A list of the most recent transaction fingerprint IDs, represented in hexadecimal, executed by this session. The fingerprint ID is a link to the <InternalLink path="ui-transactions-page#transaction-details-page">Transaction Details page</InternalLink> for the transaction. When you click the link, in order to fetch and render the transaction details, the global date range is changed to the session's start and end time.

### Closed session cache

Details about closed sessions are stored in memory in a closed session cache. This cache is controlled by the following two <InternalLink path="cluster-settings">cluster settings</InternalLink>:

* <InternalLink path="cluster-settings">`sql.closed_session_cache.capacity`</InternalLink> is the maximum number of sessions in the cache and defaults to `1000`. Once this limit is reached, older sessions are deleted from the cache so newer sessions can be included.
* <InternalLink path="cluster-settings">`sql.closed_session_cache.time_to_live`</InternalLink> is the maximum time to live, in seconds, and defaults to `3600`. 60 minutes after a session is closed, it is deleted from the cache.

If the **Session Details** page displays the message `Unable to find session` for a closed session, the details may no longer be available because they were removed from this cache according to the previously mentioned cluster settings.

## See also

* <InternalLink path="show-sessions">`SHOW SESSIONS`</InternalLink>
* <InternalLink path="ui-statements-page">Statements page</InternalLink>
* <InternalLink path="sql-statements">SQL Statements</InternalLink>
* <InternalLink path="transactions">Transactions</InternalLink>
* <InternalLink path="transaction-retry-error-reference">Transaction Error Retry Reference</InternalLink>
* <InternalLink path="recommended-production-settings#hardware">Production Checklist</InternalLink>
