cockroachdb-sql-patterns

cockroachdb-sql-patterns is a cursor rule for Cursor from cockroachdb/cursor-plugin. It costs 0 tokens per session (5,938 once invoked), scanned A, original, Apache-2.0.

A collection of rules for writing SQL, database schemas, and application code that works well with CockroachDB, a distributed SQL database. It highlights common mistakes and recommended patterns for spreading work across servers.

In plain words
What is it for?
Use it when designing tables and indexes, choosing primary keys, writing queries, or building applications that interact with CockroachDB.
Why use it?
It helps avoid designs that create uneven load, slow queries, or other problems specific to distributed databases.

Cursor rule for Cursor ✓ vendor

Written for Cursor: a Cursor rule (.mdc). Also seen: positional $N argument.

Good fit Use it when designing tables and indexes, choosing primary keys, writing queries, or building applications that interact with CockroachDB.

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns
About the project

CockroachDB Plugin for Cursor connects the Cursor coding agent to CockroachDB clusters for database work such as exploring schemas, writing SQL, debugging queries, and managing distributed clusters. It supports self-hosted and CockroachDB Cloud connections, and its catalogue add-ons provide database-focused agents, skills, rules, and instructions.

cockroachdb/cursor-plugin · 2 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/cockroachdb/cursor-plugin

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for cockroachdb-sql-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns/github.svg)](https://agentmods.dev/rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns)
Your own site
<a href="https://agentmods.dev/rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns"><img src="https://agentmods.dev/badge/rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for cockroachdb-sql-patterns

Your own site · 80×15
<a href="https://agentmods.dev/rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns"><img src="https://agentmods.dev/badge/rules/cockroachdb/cursor-plugin/cockroachdb-sql-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 5,938 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.05938
Opus 5.5 $0.00000 $0.02375
Sonnet 5.5 $0.00000 $0.01188
Haiku 4.5 $0.00000 $0.00594

Measured 8d ago against content hash 1da0c77270b9, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

cockroachdb-sql-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

rules/cockroachdb-sql-patterns.mdc · 698 lines

How it starts

The opening of the file, as written. The whole thing — 698 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CockroachDB SQL Best Practices & Anti-Patterns

24 production-verified best practices for CockroachDB. Each section marks anti-patterns with ❌ NEVER and correct patterns with ✅ ALWAYS. Docs: https://www.cockroachlabs.com/docs/stable/


1. Primary Keys — Avoid Sequential Hotspots

CockroachDB distributes data across ranges sorted by primary key. Sequential keys concentrate ALL inserts into a single range on a single node, creating a write hotspot.

❌ NEVER: Use SERIAL, BIGSERIAL, or auto-increment as a single-column primary key

-- BAD: All inserts land on ONE node. CPU skew: one node at 80-90%, others at 10-20%.
CREATE TABLE orders (
    id SERIAL PRIMARY KEY,  -- HOTSPOT! unique_rowid() is monotonically increasing
    customer_id UUID,
    amount DECIMAL
);

✅ ALWAYS: Use UUID with gen_random_uuid() for most tables

-- GOOD: Writes distribute evenly across all nodes
CREATE TABLE orders (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    customer_id UUID NOT NULL,
    amount DECIMAL(15,2) NOT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

✅ Use hash-sharded indexes when time ordering is required

-- GOOD: Distributes sequential timestamps across 8 buckets
CREATE TABLE audit_events (
    created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    event_id UUID NOT NULL DEFAULT gen_random_uuid(),
    event_type STRING NOT NULL,
    payload JSONB,
    PRIMARY KEY (created_at, event_id) USING HASH WITH (bucket_count = 8)
);

✅ Use composite primary keys for multi-tenant or regional data

-- GOOD: Data co-located by tenant for fast reads, distributed across tenants
CREATE TABLE tenant_data (
    tenant_id UUID NOT NULL,
    record_id UUID NOT NULL DEFAULT gen_random_uuid(),
    data JSONB,
    PRIMARY KEY (tenant_id, record_id)
);

Why one DB node has elevated CPU: SERIAL PKs route ALL inserts to the last range, which lives on one leaseholder node. That node shows 80-90% CPU while others idle at 10-20%. You're paying for 5 nodes but getting 1 node's throughput. Diagnosis: check the Hot Ranges page and Hardware dashboard in DB Console.

Read the full file on GitHub · 698 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago Changed 1da0c77270b9
  2. 1mo ago First seen · 698 lines · 0 tokens per session scan A 2b7232d636b1

Subscribe to this mod's changes

cockroachdb-sql-patterns is a cursor rule published in the GitHub repository cockroachdb/cursor-plugin (2 stars, last pushed 8d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 5,938 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.