Cockroach Commands

This page introduces the cockroach commands for configuring, starting, and managing a CockroachDB cluster, as well as environment variables that can be used in place of certain flags.

You can run cockroach help in your shell to get similar guidance.

Commands

CommandUsage
cockroach startStart a node.
cockroach initInitialize a cluster.
cockroach certCreate CA, node, and client certificates.
cockroach quitTemporarily stop a node or permanently remove a node.
cockroach sqlUse the built-in SQL client.
cockroach sqlfmtReformat SQL queries for enhanced clarity.
cockroach userGet, set, list, and remove users.
cockroach zoneDeprecated To configure the number and location of replicas for specific sets of data, use ALTER … CONFIGURE ZONE and SHOW ZONE CONFIGURATIONS.
cockroach nodeList node IDs, show their status, decommission nodes for removal, or recommission nodes.
cockroach dumpBack up a table by outputting the SQL statements required to recreate the table and all its rows.
cockroach demoStart a temporary, in-memory, single-node CockroachDB cluster, and open an interactive SQL shell to it.
cockroach genGenerate manpages, a bash completion file, example SQL data, or an HAProxy configuration file for a running cluster.
cockroach versionOutput CockroachDB version details.
cockroach debug encryption-active-keyView the encryption algorithm and store key.
cockroach debug zipGenerate a .zip file that can help Cockroach Labs troubleshoot issues with your cluster.
cockroach debug merge-logsMerge multiple log files from different machines into a single stream.
cockroach workloadRun a built-in load generator against a cluster.

Environment variables

For many common cockroach flags, such as —port and —user, you can set environment variables once instead of manually passing the flags each time you execute commands.

  • To find out which flags support environment variables, see the documentation for each command.
  • To output the current configuration of CockroachDB and other environment variables, run env.
  • When a node uses environment variables on startup, the variable names are printed to the node's logs; however, the variable values are not.
    CockroachDB prioritizes command flags, environment variables, and defaults as follows:

  • If a flag is set for a command, CockroachDB uses it.

  • If a flag is not set for a command, CockroachDB uses the corresponding environment variable.
  • If neither the flag nor environment variable is set, CockroachDB uses the default for the flag.
  • If there's no flag default, CockroachDB gives an error.
    For more details, see Client Connection Parameters.

Was this page helpful?
YesNo