Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 175 additions & 0 deletions skills/onboarding-and-migrations/setting-up-local-cluster/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
---
name: setting-up-local-cluster
description: Downloads and starts a local CockroachDB cluster for development using the official binary. Use when a developer needs a local CockroachDB instance, when no cluster is available, or when setting up a new development environment.
---

# Setting Up a Local CockroachDB Cluster
Comment on lines +2 to +6

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scripts/validate-spec.py emits a naming warning when the skill name doesn’t end with ing (and doesn’t match one of its allowed gerund prefixes). setting-up-local-cluster will trigger that warning; consider renaming to an *-ing form (and matching the directory name) if you want validation to be clean even under --strict.

Suggested change
name: setting-up-local-cluster
description: Downloads and starts a local CockroachDB cluster for development using the official binary. Use when a developer needs a local CockroachDB instance, when no cluster is available, or when setting up a new development environment.
---
# Setting Up a Local CockroachDB Cluster
name: local-cockroachdb-cluster-provisioning
description: Downloads and starts a local CockroachDB cluster for development using the official binary. Use when a developer needs a local CockroachDB instance, when no cluster is available, or when setting up a new development environment.
---
# Local CockroachDB Cluster Provisioning

Copilot uses AI. Check for mistakes.

Guides you through downloading, installing, and starting a local CockroachDB cluster for development. Uses the official binary -- no Docker or external runtime dependencies required.

## When to Use This Skill

- Developer asks to "set up CockroachDB" or "start a local database"
- No CockroachDB cluster is reachable
- Developer wants to build an app with CockroachDB from scratch
- Setting up a new development environment

## Prerequisites

- macOS (Intel or Apple Silicon), Linux (Intel or ARM), or Windows (Intel)
- `curl` or `wget` available for downloading the binary
- ~500 MB disk space per node
- Ports 26257-26259 (SQL), 26357-26359 (RPC), and 8080-8082 (DB Console) available for a 3-node cluster

## Step 1: Detect Platform and Download

Detect the OS and architecture, then download the appropriate binary.

Comment on lines +24 to +27

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description calls out “platform detection”, and this section says “Detect the OS and architecture”, but no concrete detection commands or decision logic are provided. Either add minimal uname/arch/PowerShell detection steps (and how to map them to the filename patterns) or reword this section to indicate that the user must select the correct artifact manually.

Copilot uses AI. Check for mistakes.
### Download URLs

Base URL: `https://binaries.cockroachdb.com/`

| OS | Architecture | Filename Pattern |
|----|-------------|-----------------|
| Linux | Intel (amd64) | `cockroach-v{VERSION}.linux-amd64.tgz` |
| Linux | ARM (arm64) | `cockroach-v{VERSION}.linux-arm64.tgz` |
| macOS | Intel (amd64) | `cockroach-v{VERSION}.darwin-10.9-amd64.tgz` |
| macOS | Apple Silicon (arm64) | `cockroach-v{VERSION}.darwin-11.0-arm64.tgz` |
| Windows | Intel (amd64) | `cockroach-v{VERSION}.windows-6.2-amd64.zip` |

Replace `{VERSION}` with the desired release (e.g., `25.4.9`). See [CockroachDB Releases](https://www.cockroachlabs.com/docs/releases/) for the latest GA version.

### Installation

```bash
# Example: macOS Apple Silicon, v25.4.9
curl -fsSL https://binaries.cockroachdb.com/cockroach-v25.4.9.darwin-11.0-arm64.tgz | tar xz
mkdir -p ~/.cockroachdb/bin
cp cockroach-v25.4.9.darwin-11.0-arm64/cockroach ~/.cockroachdb/bin/
Comment on lines +40 to +48

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The skill includes a specific CockroachDB version (e.g., 25.4.9) and refers to “the latest GA version”. The repo PR template explicitly calls out avoiding time-sensitive information (including version numbers), so this should be rewritten to use placeholders (e.g., {VERSION}) throughout the example commands and avoid wording that implies a moving target.

Suggested change
Replace `{VERSION}` with the desired release (e.g., `25.4.9`). See [CockroachDB Releases](https://www.cockroachlabs.com/docs/releases/) for the latest GA version.
### Installation
```bash
# Example: macOS Apple Silicon, v25.4.9
curl -fsSL https://binaries.cockroachdb.com/cockroach-v25.4.9.darwin-11.0-arm64.tgz | tar xz
mkdir -p ~/.cockroachdb/bin
cp cockroach-v25.4.9.darwin-11.0-arm64/cockroach ~/.cockroachdb/bin/
Replace `{VERSION}` with the desired CockroachDB release. See [CockroachDB Releases](https://www.cockroachlabs.com/docs/releases/) to choose a release.
### Installation
```bash
# Example: macOS Apple Silicon
curl -fsSL https://binaries.cockroachdb.com/cockroach-v{VERSION}.darwin-11.0-arm64.tgz | tar xz
mkdir -p ~/.cockroachdb/bin
cp cockroach-v{VERSION}.darwin-11.0-arm64/cockroach ~/.cockroachdb/bin/

Copilot uses AI. Check for mistakes.
export PATH="$HOME/.cockroachdb/bin:$PATH"
```
Comment on lines +42 to +50

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prerequisites and download table mention Windows, but the Installation section only shows a macOS curl | tar example and doesn’t include Windows (PowerShell) download/extract steps or PATH guidance. Add a Windows-specific snippet (or explicitly scope the skill to WSL/macOS/Linux) so the Windows claim is actionable.

Copilot uses AI. Check for mistakes.

If `cockroach` is already on PATH, skip the download.

## Step 2: Start the Cluster

A 3-node cluster is recommended for development because it exercises replication, range distribution, leaseholder balancing, and survival goals -- core CockroachDB capabilities that a single node cannot demonstrate.

### 3-Node Cluster (Recommended)

```bash
# Start 3 nodes with separate SQL, RPC, and HTTP ports
cockroach start --insecure --listen-addr=localhost:26357 --sql-addr=localhost:26257 \
--http-addr=localhost:8080 --store=~/.cockroachdb/data/node1 \
--log-dir=~/.cockroachdb/logs/node1 \
--join=localhost:26357,localhost:26358,localhost:26359 --background

cockroach start --insecure --listen-addr=localhost:26358 --sql-addr=localhost:26258 \
--http-addr=localhost:8081 --store=~/.cockroachdb/data/node2 \
--log-dir=~/.cockroachdb/logs/node2 \
--join=localhost:26357,localhost:26358,localhost:26359 --background

cockroach start --insecure --listen-addr=localhost:26359 --sql-addr=localhost:26259 \
--http-addr=localhost:8082 --store=~/.cockroachdb/data/node3 \
--log-dir=~/.cockroachdb/logs/node3 \
--join=localhost:26357,localhost:26358,localhost:26359 --background

# Initialize the cluster (only needed on first start)
cockroach init --insecure --host=localhost:26357
```

### Single-Node (Lightweight)

For minimal resource usage when full cluster capabilities are not needed:

```bash
cockroach start-single-node --insecure --listen-addr=localhost:26257 \
--http-addr=localhost:8080 --store=~/.cockroachdb/data/node1 \
--log-dir=~/.cockroachdb/logs/node1 --background
```

## Step 3: Verify the Cluster

```bash
# Check SQL connectivity
cockroach sql --insecure --host=localhost:26257 -e "SELECT version();"

# Verify all nodes joined (3-node cluster)
cockroach sql --insecure --host=localhost:26257 \
-e "SELECT node_id, address, is_live FROM crdb_internal.gossip_nodes;"

# Check replication (should show num_replicas=3)
cockroach sql --insecure --host=localhost:26257 \
-e "SHOW RANGES FROM DATABASE defaultdb;"
```

## Connection Details

| Property | Value |
|----------|-------|
| SQL URL | `postgresql://root@localhost:26257/defaultdb?sslmode=disable` |
| DB Console | `http://localhost:8080` |
| User | `root` (no password in insecure mode) |
| Database | `defaultdb` |

### Environment Variables for MCP Toolbox

```bash
export COCKROACHDB_HOST=localhost
export COCKROACHDB_PORT=26257
export COCKROACHDB_USER=root
export COCKROACHDB_PASSWORD=
export COCKROACHDB_DATABASE=defaultdb
export COCKROACHDB_SSLMODE=disable
```

## Stopping the Cluster

```bash
# Graceful shutdown via PID files
kill $(cat ~/.cockroachdb/data/node1/cockroach.pid) 2>/dev/null
kill $(cat ~/.cockroachdb/data/node2/cockroach.pid) 2>/dev/null
kill $(cat ~/.cockroachdb/data/node3/cockroach.pid) 2>/dev/null
Comment on lines +130 to +132

Copilot AI Apr 24, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stop commands will still emit errors from cat if a PID file doesn’t exist (stderr redirection only applies to kill). Consider guarding with a file existence check or redirecting cat stderr as well, so “stop” is quiet/idempotent when nodes aren’t running.

Suggested change
kill $(cat ~/.cockroachdb/data/node1/cockroach.pid) 2>/dev/null
kill $(cat ~/.cockroachdb/data/node2/cockroach.pid) 2>/dev/null
kill $(cat ~/.cockroachdb/data/node3/cockroach.pid) 2>/dev/null
[ -f ~/.cockroachdb/data/node1/cockroach.pid ] && kill "$(cat ~/.cockroachdb/data/node1/cockroach.pid)" 2>/dev/null
[ -f ~/.cockroachdb/data/node2/cockroach.pid ] && kill "$(cat ~/.cockroachdb/data/node2/cockroach.pid)" 2>/dev/null
[ -f ~/.cockroachdb/data/node3/cockroach.pid ] && kill "$(cat ~/.cockroachdb/data/node3/cockroach.pid)" 2>/dev/null

Copilot uses AI. Check for mistakes.
```

## Destroying All Data

```bash
rm -rf ~/.cockroachdb/data ~/.cockroachdb/logs
```

## Air-Gapped / Restricted Environments

For environments without internet access:

1. Pre-download the binary on an allowed machine
2. Transfer to the target machine via approved channels
3. Place at `~/.cockroachdb/bin/cockroach` or any PATH location

## What a 3-Node Cluster Enables

| Capability | Single Node | 3-Node |
|-----------|-------------|--------|
| SQL execution | Yes | Yes |
| Replication (num_replicas=3) | No | Yes |
| Range distribution | No | Yes |
| Leaseholder balancing | No | Yes |
| Node failure simulation | No | Yes |
| `SHOW RANGES` with real distribution | No | Yes |
| Survival goals (`SURVIVE ZONE FAILURE`) | No | Yes |
| Contention between nodes | No | Yes |

## Safety Considerations

- The cluster runs in **insecure mode** (no TLS, no authentication) -- suitable for local development only.
- Data persists in `~/.cockroachdb/data` across restarts.
- The binary and data are user-local (`~/.cockroachdb/`) -- no `sudo` or system modifications.
- A 3-node cluster uses approximately 750 MB of RAM total.

## References

- [Install CockroachDB](https://www.cockroachlabs.com/docs/stable/install-cockroachdb.html)
- [Start a Local Cluster](https://www.cockroachlabs.com/docs/stable/start-a-local-cluster.html)
- [CockroachDB Releases](https://www.cockroachlabs.com/docs/releases/)
- [cockroach start](https://www.cockroachlabs.com/docs/stable/cockroach-start.html)
- [cockroach init](https://www.cockroachlabs.com/docs/stable/cockroach-init.html)
Loading