Skip to main content

Overview

CockroachDB provides multiple configuration mechanisms for controlling node behavior and cluster-wide settings. Configuration can be specified through command-line flags, environment variables, and SQL-based cluster settings.

Configuration Methods

Command-Line Flags

Flags are specified when starting a node:
cockroach start \
  --store=path=/mnt/data \
  --listen-addr=0.0.0.0:26257 \
  --cache=25% \
  --max-sql-memory=25%

Environment Variables

Many flags have corresponding environment variable equivalents:
export COCKROACH_INSECURE=true
export COCKROACH_HOST=localhost:26257
cockroach sql

Cluster Settings

Cluster-wide settings are modified via SQL:
SET CLUSTER SETTING cluster.organization = 'Acme Company';

Node Configuration Flags

Network Configuration

—listen-addrThe address for inter-node communication:
--listen-addr=0.0.0.0:26257
Default: localhost:26257—advertise-addrThe address advertised to other nodes:
--advertise-addr=node1.example.com:26257
—sql-addrSeparate address for SQL connections:
--sql-addr=0.0.0.0:26258
—http-addrAdmin UI and HTTP API address:
--http-addr=0.0.0.0:8080
Default: localhost:8080
Default ports:
  • 26257: SQL and inter-node communication
  • 8080: Admin UI and HTTP API
Custom ports:
cockroach start \
  --listen-addr=:26000 \
  --http-addr=:8000

Storage Configuration

Basic store:
--store=path=/mnt/data
Store with attributes:
--store=attrs=ssd,path=/mnt/ssd1
Store with size limit:
--store=path=/mnt/data,size=100GiB
Multiple stores:
--store=attrs=ssd,path=/mnt/ssd1,size=100GiB \
--store=attrs=ssd,path=/mnt/ssd2,size=100GiB \
--store=attrs=hdd,path=/mnt/hdd1,size=1TiB
In-memory store (testing only):
--store=type=mem,size=1GiB

Memory Configuration

—cacheSize of the cache for storing key-value data:
# Absolute size
--cache=2GiB

# Percentage of system memory
--cache=25%
Default: 128 MiB (or 25% of system memory)The cache stores frequently accessed data to reduce disk I/O.
—max-sql-memoryMaximum memory for SQL operations:
# Absolute size
--max-sql-memory=4GiB

# Percentage of system memory
--max-sql-memory=25%
Default: 128 MiB (or 25% of system memory)Controls memory available for:
  • Query execution
  • Sorting operations
  • Hash joins
  • Intermediate query results
—max-go-memoryGo runtime memory limit:
--max-go-memory=8GiB
Can also use GOMEMLIMIT environment variable:
export GOMEMLIMIT=8GiB

Locality Configuration

Configure node locality for geo-distributed deployments:
--locality=region=us-east,zone=us-east-1a,rack=rack1
Common patterns:
--locality=cloud=aws,region=us-east-1,zone=us-east-1a
Locality enables:
  • Replica placement preferences
  • Follower reads from nearby nodes
  • Geo-partitioning
  • Latency-based load balancing

Security Configuration

Secure mode (production):
cockroach start \
  --certs-dir=/path/to/certs \
  --store=path=/mnt/data
Required certificates:
  • ca.crt: Certificate authority
  • node.crt: Node certificate
  • node.key: Node private key
Insecure mode (development only):
cockroach start --insecure
Never use --insecure in production. All traffic is unencrypted and unauthenticated.

Join Configuration

Specify nodes to connect to when starting:
--join=node1:26257,node2:26257,node3:26257
Best practices:
  • List 3-5 stable nodes
  • Use DNS names or stable IPs
  • Same join list for all nodes
  • Nodes don’t need to be running
  • Can include self-reference
Examples:
# DNS-based
--join=cockroach.example.com:26257

# Multiple addresses
--join=10.0.1.1:26257,10.0.1.2:26257,10.0.1.3:26257

# With custom port
--join=node1:26000,node2:26000

Logging Configuration

Log Output Configuration

cockroach start \
  --log='file-defaults: {dir: /var/log/cockroach}'

Log Configuration Options

—log-dir (deprecated, use --log):
--log-dir=/var/log/cockroach
Equivalent to:
--log='file-defaults: {dir: /var/log/cockroach}'
—log-file-verbosity (deprecated):
--log-file-verbosity=WARNING
Equivalent to:
--log='file-defaults: {filter: WARNING}'
—log-file-max-size (deprecated):
--log-file-max-size=10MiB
Equivalent to:
--log='file-defaults: {max-file-size: 10MiB}'
See Logging Configuration for comprehensive logging setup.

Cluster Settings

Viewing Cluster Settings

SHOW CLUSTER SETTINGS;

Modifying Cluster Settings

-- Set a string setting
SET CLUSTER SETTING cluster.organization = 'Acme Company';

-- Set a numeric setting
SET CLUSTER SETTING kv.range_descriptor_cache.size = '128MiB';

-- Set a boolean setting
SET CLUSTER SETTING sql.stats.automatic_collection.enabled = true;

-- Set a duration setting
SET CLUSTER SETTING server.time_until_store_dead = '5m0s';

-- Reset to default
RESET CLUSTER SETTING cluster.organization;

Important Cluster Settings

SettingDescriptionDefault
kv.range_descriptor_cache.sizeRange descriptor cache size64 MiB
kv.raft.command.max_sizeMaximum Raft command size64 MiB
sql.distsql.distribute_index_joinsEnable distributed index joinstrue
sql.stats.automatic_collection.enabledAuto-collect table statisticstrue
SettingDescriptionDefault
kv.snapshot_rebalance.max_rateMaximum rebalance rate32 MiB/s
kv.snapshot_recovery.max_rateMaximum recovery rate32 MiB/s
server.time_until_store_deadStore considered dead after5m0s
SettingDescriptionDefault
sql.defaults.default_int_sizeDefault integer size (4 or 8)8
sql.defaults.serial_normalizationSerial type normalizationrowid
sql.log.slow_query.latency_thresholdLog slow queries threshold0s (disabled)
SettingDescriptionDefault
diagnostics.reporting.enabledEnable diagnostic reportingtrue
cluster.organizationOrganization nameempty
enterprise.licenseEnterprise license keyempty

Environment Variables

Common Environment Variables

VariablePurposeExample
COCKROACH_INSECUREEnable insecure modeexport COCKROACH_INSECURE=true
COCKROACH_HOSTDefault hostexport COCKROACH_HOST=localhost:26257
COCKROACH_CERTS_DIRCertificate directoryexport COCKROACH_CERTS_DIR=/certs
GOMEMLIMITGo memory limitexport GOMEMLIMIT=8GiB
GOGCGo GC percentageexport GOGC=50

Development Variables

# Skip telemetry
export COCKROACH_SKIP_ENABLING_DIAGNOSTIC_REPORTING=true

# Debug mode
export COCKROACH_DEBUG_MODE=true

Configuration Files

CockroachDB does not use traditional configuration files. Instead:
  1. Command-line flags: Set at node startup
  2. Cluster settings: Stored in system.settings table
  3. Environment variables: Set in shell environment
To persist configuration, use init scripts or systemd unit files to set flags and environment variables.

Resource Limits

File Descriptors

CockroachDB requires high file descriptor limits:
# Check current limit
ulimit -n

# Set limit (requires root)
ulimit -n 35000
Recommended minimum: 35,000 file descriptors Permanent configuration in /etc/security/limits.conf:
cockroach soft nofile 35000
cockroach hard nofile 35000

Memory Limits

Recommended memory allocation:
  • Cache: 25% of system memory
  • SQL Memory: 25% of system memory
  • Go Runtime: Remaining system memory
Example for 16GB system:
cockroach start \
  --cache=4GiB \
  --max-sql-memory=4GiB \
  --max-go-memory=8GiB

Best Practices

  1. Document all changes: Maintain a record of non-default settings
  2. Test in staging: Validate configuration changes before production
  3. Use percentages for memory: Adapts to different hardware
  4. Set explicit locality: Required for geo-distributed deployments
  5. Monitor resource usage: Adjust settings based on actual workload
  6. Use secure mode: Always use certificates in production
  7. Consistent configuration: Use same settings across similar nodes
  8. Version awareness: Some settings require specific CockroachDB versions

Troubleshooting

Configuration Issues

Invalid flag values:
  • Check flag syntax and units (GiB vs GB)
  • Verify flag is supported in your version
  • Review startup logs for error messages
Setting not taking effect:
  • Cluster settings require SQL connection
  • Some settings require node restart
  • Check permissions for setting modification
Memory issues:
  • Increase --cache and --max-sql-memory
  • Check system memory availability
  • Monitor OOM events in system logs

See Also

Build docs developers (and LLMs) love