triaging-live-sql-activity

Diagnose live CockroachDB performance issues using SQL-only queries against active statements, sessions, and transactions.

2|1|Updated Mar 11, 2026
One-click install
npx skills add https://github.com/cockroachdb/cursor-plugin --skill triaging-live-sql-activity-cockroachdb
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: triaging-live-sql-activity
Source: https://github.com/cockroachdb/cursor-plugin/tree/main/skills/cockroachdb-observability-and-diagnostics/triaging-live-sql-activity
Command: npx skills add https://github.com/cockroachdb/cursor-plugin --skill triaging-live-sql-activity-cockroachdb

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? When a CockroachDB cluster slows down, you need to quickly identify runaway queries, stuck transactions, and resource-hogging sessions without relying on DB Console, HTTP endpoints, or Prometheus. This Skill provides SQL-only diagnostic queries for immediate live triage. ## Core Features & Use Cases - Long-Running Query Detection: Identify queries exceeding configurable time thresholds using SHOW CLUSTER STATEMENTS with drill-down by application, user, or client address. - Session and Transaction Analysis: Find busy sessions and high-retry transactions via SHOW CLUSTER SESSIONS and crdb_internal.cluster_transactions to detect contention. - Safe Cancellation Workflows: Generate and execute CANCEL QUERY and CANCEL SESSION commands with explicit safety warnings and privilege requirements. - Use Case: Users report the cluster is slow. Run the triage queries to find a payments-api query running for 20 minutes, confirm it is a runaway, and cancel it to restore performance. ## Quick Start Ask the AI to find all CockroachDB queries running longer than 5 minutes and group them by application name.

Frequently Asked Questions about triaging-live-sql-activity

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find long-running queries in CockroachDB?▼

Use SHOW CLUSTER STATEMENTS wrapped in a CTE and filter by start time, such as WHERE start < now() - INTERVAL '5 minutes'. This returns query IDs, users, applications, and running durations for all active queries cluster-wide.

How do I cancel a runaway query in CockroachDB?▼

Run CANCEL QUERY '<query_id>' using the query_id from SHOW CLUSTER STATEMENTS. You need the CANCELQUERY system privilege, and cancellation should only be used after confirming the query is genuinely runaway since it terminates user work.

What privileges are needed to view cluster-wide SQL activity?▼

You need the VIEWACTIVITY or VIEWACTIVITYREDACTED system privilege to see other users' queries and sessions. VIEWACTIVITYREDACTED hides query constants for privacy and is recommended for production and multi-tenant environments.

Why does SHOW CLUSTER STATEMENTS only show my own queries?▼

Without VIEWACTIVITY or VIEWACTIVITYREDACTED privileges, CockroachDB only shows your own session's activity. Ask an admin to run GRANT SYSTEM VIEWACTIVITYREDACTED TO your_user to gain cluster-wide visibility.

How do I detect transaction contention in CockroachDB?▼

Query crdb_internal.cluster_transactions and look for high num_retries values, which indicate contention. Transactions with more than 10 retries typically signal lock conflicts or hotspotting that need investigation.

Can this approach analyze historical query performance?▼

No, these queries only show currently active statements, sessions, and transactions. For historical trend analysis, use statement fingerprint profiling, DB Console, or Prometheus metrics instead.