auditing-table-statistics

Audits CockroachDB optimizer table statistics for staleness, missing coverage, and row count drift.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Stale or missing optimizer statistics cause poor query plans and sudden performance degradation in CockroachDB, and diagnosing them without DB Console access is difficult. This Skill provides read-only SQL queries using SHOW STATISTICS to detect stale statistics, missing column coverage, and row count drift before they impact production queries. ## Core Features & Use Cases - Staleness Detection: Identify tables with outdated or missing statistics, ranked by age, with workload-specific thresholds for OLTP and OLAP. - Drift and Coverage Analysis: Compare actual row counts against cached statistics, find columns lacking statistics or histograms, and detect missing multi-column statistics for correlated columns. - Remediation Guidance: Generate ready-to-run CREATE STATISTICS commands, monitor collection jobs via SHOW JOBS, and follow batch execution patterns that avoid overwhelming the cluster. - Use Case: After a bulk data load, run the drift detection query on affected tables, generate CREATE STATISTICS commands for tables exceeding 20% drift, and monitor the jobs to completion to restore accurate optimizer estimates. ## Quick Start Ask the AI to audit table statistics in your CockroachDB database and list any tables with stale or missing optimizer statistics.

Frequently Asked Questions about auditing-table-statistics

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

FAQPage Schema
How do I check if CockroachDB table statistics are stale?▼

Run SHOW STATISTICS FOR TABLE and compare the created timestamp against the current time. Statistics older than 7 days are considered stale for OLTP workloads, while OLAP tables can tolerate 14 to 30 days before refresh.

How to detect row count drift in CockroachDB statistics?▼

Compare the actual row count from a COUNT query against the row_count in SHOW STATISTICS table-level output. Drift above 30% requires urgent refresh, 20-30% warrants refresh if performance issues appear, and under 10% is normal variance.

Does CREATE STATISTICS lock tables or block writes in CockroachDB?▼

CREATE STATISTICS does not lock tables or block writes; it runs as a non-blocking background job. However, it consumes CPU and I/O resources, so run it during low-traffic periods for tables larger than 10 million rows.

Why does automatic statistics collection not create multi-column statistics?▼

Automatic collection covers index column groups when multi-column collection is enabled, but correlated non-indexed columns require manual CREATE STATISTICS with an explicit column list, such as city and state for geographic data.

What privileges are needed to run SHOW STATISTICS in CockroachDB?▼

Any privilege on the target table, including SELECT, INSERT, UPDATE, DELETE, or admin, grants visibility into its statistics. SHOW STATISTICS itself is read-only and safe to run in production at any time.

How do I cancel a long-running CREATE STATISTICS job?▼

Find the job ID with SHOW JOBS WHERE job_type = 'CREATE STATS', then run CANCEL JOB with that ID. Cancellation is non-destructive; existing statistics remain intact and you can safely re-run the collection later.