Skip to main content
This page explains the cockroach start , which you use to start a new multi-node cluster or add nodes to an existing cluster.
If you need a simple single-node backend for app development, use instead, and follow the best practices for local testing described in .For quick SQL testing, consider using to start a temporary, in-memory cluster with immediate access to an interactive SQL shell.
Node-level settings are defined by flags passed to the cockroach start command and cannot be changed without stopping and restarting the node. In contrast, some cluster-wide settings are defined via SQL statements and can be updated anytime after a cluster has been started. For more details, see .

Synopsis

Start a node to be part of a new multi-node cluster:
Initialize a new multi-node cluster:
Add a node to an existing cluster:
View help:

Flags

The cockroach start command supports the following general-use, networking, security, and logging flags. Many flags have useful defaults that can be overridden by specifying the flags explicitly. If you specify flags explicitly, however, be sure to do so each time the node is restarted, as they will not be remembered. The one exception is the --join flag, which is stored in a node’s data directory. We still recommend specifying the --join flag every time, as this will allow nodes to rejoin the cluster even if their data directory was destroyed.

General

Networking

Security

Locality

The --locality flag accepts arbitrary key-value pairs that describe the location of the node. Locality should include a region key-value if you are using CockroachDB’s . Depending on your deployment you can also specify country, availability zone, etc. The key-value pairs should be ordered into locality tiers from most inclusive to least inclusive (e.g., region before availability zone as in region=eu-west-1,zone=eu-west-1a), and the keys and order of key-value pairs must be the same on all nodes. It’s typically better to include more pairs than fewer.
  • Specifying a region with a region tier is required in order to enable CockroachDB’s .
  • CockroachDB spreads the replicas of each piece of data across as diverse a set of localities as possible, with the order determining the priority. Locality can also be used to influence the location of data replicas in various ways using high-level or low-level .
  • When there is high latency between nodes (e.g., cross-availability zone deployments), CockroachDB uses locality to move range leases closer to the current workload, reducing network round trips and improving read performance, also known as . In a deployment across more than 3 availability zones, however, to ensure that all data benefits from “follow-the-workload”, you must increase your replication factor to match the total number of availability zones.
  • Locality is also a prerequisite for using the , , and Enterprise features.

Example

The following shell commands use the --locality flag to start 9 nodes to run across 3 regions: us-east-1, us-west-1, and europe-west-1. Each region’s nodes are further spread across different availability zones within that region.
This example follows the conventions required to use CockroachDB’s .
Nodes in us-east-1:
Nodes in us-west-1:
Nodes in europe-west-1:
For another multi-region example, see Start a multi-region cluster. For more information about how to use CockroachDB’s multi-region capabilities, see the .

Storage

Storage engine

The --storage-engine flag is used to choose the storage engine used by the node. Note that this setting applies to all stores on the node, including the temp store. As of v21.1 and later, CockroachDB always uses the . As such, pebble is the default and only option for the --storage-engine flag.

Store

The --store flag allows you to specify details about a node’s storage. To start a node with multiple disks or SSDs, you can use either of these approaches:
  • Configure the disks or SSDs as a single RAID volume, then pass the RAID volume to the --store flag when starting the cockroach process on the node.
  • Provide a separate --store flag for each disk when starting the cockroach process on the node. For more details about stores, see .
If you start a node with multiple --store flags, it is not possible to scale back down to only using a single store on the node. Instead, you must decommission the node and start a new node with the updated --store.
The --store flag supports the following fields. Note that commas are used to separate fields, and so are forbidden in all field values.
In-memory storage is not suitable for production deployments at this time.
Use dedicated volumes for the CockroachDB store. Do not share the store volume with any other I/O activity.

Logging

By , cockroach start writes all messages to log files, and prints nothing to stderr. This includes events with INFO and higher. However, you can of this command by using the --log flag:

Defaults

See the .

Standard output

When you run cockroach start, some helpful details are printed to the standard output:
These details are also written to the INFO log in the /logs directory. You can retrieve them with a command like grep 'node starting' node1/logs/cockroach.log -A 11.

Examples

Start a multi-node cluster

To start a multi-node cluster, run the cockroach start command for each node, setting the --join flag to the addresses of the initial nodes. For a cluster in a single region, set 3-5 --join addresses. Each starting node will attempt to contact one of the join hosts. In case a join host cannot be reached, the node will try another address on the list until it can join the gossip network. When starting a multi-region cluster, set more than one --join address per region, and select nodes that are spread across failure domains. This ensures .
Before starting the cluster, use to generate node and client certificates for a secure cluster connection.
Then run the command against any node to perform a one-time cluster initialization:

Start a multi-region cluster

In this example we will start a multi-node with a multi-region setup that uses the same regions (passed to the --locality flag) as the .
  1. Start a node in the us-east1 region:
  2. Start a node in the us-west1 region:
  3. Start a node in the europe-west1 region:
  4. Initialize the cluster:
  5. Connect to the cluster using :
  6. Issue the statement to verify that the list of regions is expected:
For more information about running CockroachDB multi-region, see the . For a more advanced example showing how to run a simulated workload on a multi-region CockroachDB cluster on your local machine, see .
For more information about the --locality flag, see Locality.

Start a multi-node cluster across private networks

Scenario:
  • You have a cluster that spans GCE and AWS.
  • The nodes on each cloud can reach each other on public addresses, but the private addresses aren’t reachable from the other cloud.
Approach:
  1. Start each node on GCE with --locality set to describe its location, --locality-advertise-addr set to advertise its private address to other nodes in on GCE, --advertise-addr set to advertise its public address to nodes on AWS, and --join set to the public addresses of 3-5 of the initial nodes:
  2. Start each node on AWS with --locality set to describe its location, --locality-advertise-addr set to advertise its private address to other nodes on AWS, --advertise-addr set to advertise its public address to nodes on GCE, and --join set to the public addresses of 3-5 of the initial nodes:
  3. Run the command against any node to perform a one-time cluster initialization:

Add a node to a cluster

To add a node to an existing cluster, run the cockroach start command, setting the --join flag to the same addresses you used when starting the cluster:

Create a table with node locality information

Start a three-node cluster with locality information specified in the cockroach start commands:
You can use the built-in function to return the current node’s locality information from inside a SQL shell. The example below uses the output of crdb_internal.locality_value('zone') as the DEFAULT value to use for the zone column of new rows. Other available locality keys for the running three-node cluster include region and cloud.
The zone column has the zone of the node on which the row was created. In a separate terminal window, open a SQL shell to a different node on the cluster:
In a separate terminal window, open a SQL shell to the third node:

Start a cluster with separate RPC and SQL networks

Separating the network addresses used for intra-cluster RPC traffic and application SQL connections can provide an additional level of protection against security issues as a form of defense in depth. This separation is accomplished with a combination of the --sql-addr flag and firewall rules or other network-level access control (which must be maintained outside of CockroachDB). For example, suppose you want to use port 26257 for SQL connections and 26258 for intra-cluster traffic. Set up firewall rules so that the CockroachDB nodes can reach each other on port 26258, but other machines cannot. Start the CockroachDB processes as follows:
Note the use of port 26258 (the value for listen-addr, not sql-addr) in the --join flag. Also, if your environment requires the use of the --advertise-addr flag, you should probably also use the --advertise-sql-addr flag when using a separate SQL address. Clusters using this configuration with client certificate authentication may also wish to use .

See also