Skip to main content
On a , you must be an or a SQL user with the or (or the legacy VIEWACTIVITY ) to access this area of the DB Console. Refer to .
The Insights page exposes problems that CockroachDB has detected in your workloads and schemas. The page also offers recommendations to improve the performance of your workloads. These are called insights in the DB Console. The Insights page helps you:
  • Identify SQL statements with , , or .
  • Identify that should be created, altered, replaced, or dropped to improve performance.

Workload Insights tab

The Workload Insights tab displays insights related to and executions.

Transaction Executions view

To display this view, click Insights in the left-hand navigation of the DB Console and select Workload Insights > Transaction Executions. The Transaction Executions view provides an overview of all that have been flagged with insights.
The rows in this page are populated from the crdb_internal.transaction_contention_events and crdb_internal.cluster_txn_execution_insights tables.
  • The results displayed in the Transaction Executions view will be available as long as a corresponding row in the crdb_internal.transaction_contention_events or crdb_internal.cluster_txn_execution_insights tables exists. The rows in crdb_internal.transaction_contention_events on each node must use less space than sql.contention.event_store.capacity, and the rows in crdb_internal.transaction_contention_events cannot exceed sql.insights.execution_insights_capacity.
  • The default tracing behavior captures a small percent of transactions so not all contention events will be recorded. When investigating transaction contention, you can set the sql.trace.txn.enable_threshold cluster setting to always capture contention events.
The transaction insights table has the following columns:

Transaction Execution details

The transaction execution details view provides more information on a transaction execution insight.

Default details

This information is displayed for all insight types.

Conditional details

Additional information is displayed for the following insight types:
  1. High Contention: All transaction executions flagged with this insight type will display a Transaction with ID {transaction ID} waited on section which provides details of the blocking transaction execution.
  2. Failed Execution: Certain transaction executions flagged with this insight type will display a Failed Execution section with Conflicting Transaction and Conflicting Location information. The following 3 conditions are required:

Statement Executions view

The Statement Executions view provides an overview of all that have been flagged with insights. To display this view, click Insights in the left-hand navigation of the DB Console and select Workload Insights > Statement Executions.
The rows in this page are populated from the table.
  • The default tracing behavior captures a small percent of transactions, so not all contention events will be recorded. When investigating transaction contention, you can set the sql.trace.txn.enable_threshold cluster setting to always capture contention events.
Click Columns to select the columns to display in the table. The statement insights table has the following columns available:

Query tags

The Query Tags column displays the comments embedded in SQL statements, as defined by the SQL commenter specification. These comments, referred to as query tags, must be instrumented by the user and can include application context such as the application name, user ID, or feature flags. This information helps correlate slow query performance with specific application states. The Query Tags column is available in the Statement Executions view’s Statement Insights table, but is hidden by default. To display it, use the Columns selector. Query tags are also included in the following locations:
  • The Statement Execution details page
  • All log entries generated during the execution of a SQL statement (prefixed with querytag-)
  • (prefixed with querytag-)
  • The crdb_internal.cluster_execution_insights and crdb_internal.node_execution_insights , in a new query_tags JSONB column
This feature is disabled by default. To enable it, set the sql.sqlcommenter.enabled cluster setting to true. To test this functionality, you can generate a SQL query with a Slow Execution, then view it on the Insights page:
  1. Enable SQL commenter query tagging:
  2. Check the value of cluster setting sql.insights.latency_threshold:
  3. Execute the following statement, using a pg_sleep value greater than the latency_threshold:
  4. On the Insights page, in the Columns selector, check Query Tags and click Apply.
  5. For the row where Statement Execution is SELECT pg_sleep(), scroll to the right to see the key-value pairs from the SQL comment displayed in the Query Tags column. Query tags
  6. On the same row, click on the Latest Statement Execution ID (the first column on the left) to open the Statement Execution details page. These key-value pairs also appear on the Overview tab under Query Tags.

Statement Execution details

The statement execution details view provides more information on a statement execution insight.

Default details

This information is displayed for all insight types.

Conditional details

This information is displayed for only the High Contention insight type. All statement executions flagged with this insight type will display a Statement with ID {statement ID} waited on section which provides details of the blocking transaction execution.

Workload Insight types

The Workload Insights tab surfaces the following type of insights:

Failed Execution

The transaction or statement execution failed. The following screenshot shows a failed transaction execution: Failed transaction execution The following screenshot shows the default details of the preceding failed transaction execution. Failed transaction execution details The Insights column shows the name of the insight, in this case Failed Execution. The Details column provides the Error Code and Error Message. CockroachDB uses PostgreSQL Error Codes. In this example, Error Code 40001 is a serialization_failure.

Serialization conflict due to transaction contention

The following screenshot shows the conditional details of the preceding failed transaction execution. In this case, there was a serialization conflict, also known as an isolation conflict, due to transaction contention. (For transaction contention that causes lock contention, see High Contention). Failed transaction execution details conditional To capture more information in the event of a failed transaction execution due to a serialization conflict, set the sql.contention.record_serialization_conflicts.enabled cluster setting to true (default). With this setting enabled, when the Error Code is 40001 and the Error Message specifically has RETRY_SERIALIZABLE - failed preemptive refresh due to conflicting locks, a conditional Failed Execution section is displayed with Conflicting Transaction and Conflicting Location information. To troubleshoot, refer to the performance tuning recipe for transaction retry errors.

High Contention

The transaction or statement execution experienced high contention time according to the threshold set in the sql.insights.latency_threshold cluster setting. This type of contention is also known as lock contention. (For transaction contention that causes serialization conflict, see serialization conflict due to transaction contention.) To troubleshoot, refer to the performance tuning recipe for identifying and unblocking a waiting transaction. The following screenshot shows the execution of a transaction flagged with High Contention: Transaction execution The following screenshot shows the execution details of the preceding transaction execution: Transaction execution details

High Retry Count

The statement execution experienced a high number of retries according to the threshold set in the sql.insights.high_retry_count.threshold cluster setting.

Slow Execution

The statement (or a statement in the transaction) experienced slow execution. Depending on the settings in Configuration, either of the following conditions trigger this insight:

Suboptimal Plan

The plan could be improved for some statement(s) in the transaction execution. Possible causes include outdated statistics and missing indexes. The statement execution has resulted in one or more index recommendations that would improve the plan. The following screenshot shows the statement execution of the query described in Use the right index: Statement execution The following screenshot shows the execution details of the preceding statement execution: Statement execution details The Insights column shows the name of the insight, in this case Suboptimal Plan. The Details column provides details on the insight, such as a Description with the cause of the suboptimal plan and a Recommendation with a CREATE INDEX statement. The final column contains a Create Index button. Click the Create Index button to execute the recommended statement to mitigate the cause of the insight.

Schema Insights tab

To display this view, click Insights in the left-hand navigation of the DB Console and select Schema Insights. This view lists the that have not been used and should be dropped, and/or the ones that should be created, altered, or replaced (based on statement execution).
  • The drop recommendations are the same as those on the Databases page.
  • The create, alter, and replace recommendations are the same as those on the Explain Plans tab on the Statements page. Whereas the Explain Plans tab shows all recommendations, the Schema Insights view shows only the latest recommendations for that statement fingerprint. If you execute a statement again after creating or updating an index, the recommendation disappears.
The following screenshot shows the insight that displays after you run the query described in Use the right index six or more times: Schema insight CockroachDB uses the threshold of six executions before offering an insight because it assumes that you are no longer merely experimenting with a query at that point.
  • Insights: Contains one of the following insight types: Create Index, Alter Index, Replace Index, Drop Unused Index.
  • Details: Details for each insight. Different insight types display different details fields:
    • Create Index, Alter Index, or Replace Index: A Statement Fingerprint field displays the statement fingerprint that would be optimized with the creation, alteration, or replacement of the index; and a Recommendation field displays the SQL query to create, alter, or replace the index.
    • Drop Unused Index: An Index field displays the name of the index to drop; and a Description field displays the reason for dropping the index.
Admin users will see an action button in the final column, which will execute the SQL statement suggested by the schema insight, for example “Create Index”. Upon clicking the action button, a confirmation dialog displays a warning about the cost of and the option to copy the SQL statement for later execution in a SQL client.

workload_index_recs function

This feature is in and subject to change. To share feedback and/or issues, contact Support.
The SQL built-in function workload_index_recs returns index recommendations and the fingerprint IDs of the statements they impact. The function returns two columns:
  • index_rec (STRING): Contains the index recommendation.
  • fingerprint_ids (BYTES[]): Contains the fingerprint IDs of the affected statements.
You can use the workload_index_recs function to determine workload-level index recommendations. By default, the function returns index recommendations sourced from all statement fingerprints in the crdb_internal.statement_statistics table. When passed an optional parameter, the function will provide workload-level index recommendations only for statements executed after the timestamp. For example, SELECT workload_index_recs('2025-05-08 16:00:00+00'); returns index recommendations for statements executed after '2025-05-08 16:00:00+00'.

workload_index_recs example

After running the query mentioned in the preceding Schema Insights tab section, run the following related query more than six times to generate another Create Index insight.
Run the workload_index_recs function to return the CREATE INDEX recommendation associated with two fingerprint IDs:
To display the query strings corresponding to the fingerprint IDs, run a query that joins the workload_index_recs function with the crdb_internal.statement_statistics table.

Search and filter

By default, the Workload Insights view shows all statements or transactions that have insights. By default, the Schema Insights view shows all Schema Insights. To search using the search field:
  1. Enter a string in the search box at the top of the tab. To search for exact terms in order, wrap the search string in quotes.
  2. Press Enter. The list is filtered by the string.

Time interval

In the Workload Insights view, to see transactions or statement executions within a specific time interval, select a time interval from the selector at the top of the tab. The time interval field supports preset time intervals (1 Hour, 6 Hours, 1 Day, etc.) and custom time intervals. To select a custom time interval, click the time interval field and select Custom time interval. In the Start (UTC) and End (UTC) fields select or type a date and time. Use the arrow buttons to cycle through previous and next time intervals. To select the most recent interval, click Now. When you select a time interval, the same interval is selected in the Metrics page.
It’s possible to select an interval for which no workload insights exist.

Filter

To filter the results on the Workload Insights or Schema Insights view:
  1. Click the Filters field.
    • To filter by application, select Application Name and select one or more applications.
      • Queries from the SQL shell are displayed under the $ cockroach app.
      • If you haven’t set application_name in a client connection string, it appears as unset.
    • To filter by one or more insight types, select Workload Insight Type or Schema Insight Type and select one or more types.
  2. Click Apply

Configuration

You can configure the behavior of insights using the following .

Workload insights settings

You can configure Workload Insights with the following :

Detect slow executions

There are two different methods for detecting slow executions. By default, they are both enabled and you can configure them based on your workload. The first method flags all executions running longer than sql.insights.latency_threshold. This is analogous to checking the slow query log. The second method attempts to detect unusually slow executions. You can enable this detection with sql.insights.anomaly_detection.enabled and configure it with sql.insights.anomaly_detection.latency_threshold. CockroachDB will then keep a streaming histogram in memory for each distinct statement fingerprint that has seen an execution latency longer than sql.insights.anomaly_detection.latency_threshold, and will flag any execution with a latency in the 99th percentile (greater than p99) for its fingerprint. Additional controls filter out executions that are less actionable:
  • The execution’s latency must also be longer than twice the median latency (> 2*p50) for that fingerprint. This ensures that the elevated latency is significant enough to warrant attention.
  • The execution’s latency must also be longer than sql.insights.anomaly_detection.latency_threshold. Some executions are slower than usual, but are still fast enough for the workload.
The sql.insights.anomaly_detection.memory_limit cluster setting cluster setting limits the amount of memory available for tracking these streaming latency histograms. When this threshold is surpassed, the least-recently touched histogram is evicted. The default setting is sufficient for tracking about 1,000 fingerprints. You can track the sql.insights.anomaly_detection.memory and sql.insights.anomaly_detection.evictions to determine if the settings are appropriate for your workload. If you see a steady stream of evictions or churn, you can either raise the sql.insights.anomaly_detection.memory_limit cluster setting, to allow for more storage; or raise the sql.insights.anomaly_detection.latency_threshold cluster setting, to examine fewer statement fingerprints.

Schema insights settings

You can configure the index recommendations in the Schema Insights tab, Explain Plans tab, and with the following :

See also