Skip to main content
The cockroach gen can generate command-line interface (CLI) utilities (man pages and a bash autocompletion script), example SQL data suitable to populate test databases, and an HAProxy configuration file for load balancing a running cluster.

Subcommands

SubcommandUsage
manGenerate man pages for CockroachDB.
autocompleteGenerate bash or zsh autocompletion script for CockroachDB.

Default: bash
example-dataGenerate example SQL datasets. You can also use the command to generate these sample datasets in a persistent cluster and the command to generate these datasets in a temporary, in-memory cluster.
haproxyGenerate an HAProxy config file for a running CockroachDB cluster. The node addresses included in the config are those advertised by the nodes. Make sure hostnames are resolvable and IP addresses are routable from HAProxy.

Decommissioned nodes are excluded from the config file.
dashboardGenerate a standardized monitoring dashboard as a JSON file for either Datadog or Grafana. The generated dashboard includes Overview, Hardware, Runtime, Networking, SQL, and Storage metrics.

Synopsis

Generate man pages:
Generate bash autocompletion script:
Generate example SQL data:
Generate an HAProxy config file for a running cluster:
Generate a Grafana dashboard:
View help:

Flags

The gen subcommands supports the following general-use, logging, and client connection flags.

General

man

FlagDescription
--pathThe path where man pages will be generated.

Default: man/man1 under the current directory

autocomplete

FlagDescription
--outThe path where the autocomplete file will be generated.

Default: cockroach.bash in the current directory

example-data

No flags are supported. See the Generate Example Data example for guidance.

haproxy

FlagDescription
--hostThe server host and port number to connect to. This can be the address of any node in the cluster.

Env Variable: COCKROACH_HOST
Default: localhost:26257
--port
-p
The server port to connect to. Note: The port number can also be specified via --host.

Env Variable: COCKROACH_PORT
Default: 26257
--insecureUse an insecure connection.

Env Variable: COCKROACH_INSECURE
Default: false
--certs-dirThe path to the containing the CA and client certificates and client key.

Env Variable: COCKROACH_CERTS_DIR
Default: ${HOME}/.cockroach-certs/
--urlA to use instead of the other arguments.

Env Variable: COCKROACH_URL
Default: no URL
--outThe path where the haproxy.cfg file will be generated. If an haproxy.cfg file already exists in the directory, it will be overwritten.

Default: haproxy.cfg in the current directory
--localityIf nodes were started with details, you can use the --locality flag here to filter the nodes included in the HAProxy config file, specifying the explicit locality tier(s) or a regular expression to match against. This is useful in cases where you want specific instances of HAProxy to route to specific nodes. See the Generate an HAProxy configuration file example for more details.

dashboard

FlagDescription
--toolWhich tool you would like your dashboard to be compatible with.

Acceptable values: datadog, grafana
--outputThe path for the output file.
--rollup-intervalThe interval, in seconds, for the rollup policy to control metric aggregation.

Logging

By default, this command logs messages to stderr. This includes events with WARNING and higher. If you need to troubleshoot this command’s behavior, you can .

Client Connection

haproxy

FlagDescription
--cluster-nameThe cluster name to use to verify the cluster’s identity. If the cluster has a cluster name, you must include this flag. For more information, see .
--disable-cluster-name-verificationDisables the cluster name check for this command. This flag must be paired with --cluster-name. For more information, see .

Examples

Generate man pages

Generate man pages:
Move the man pages to the man directory:
Access man pages:

Generate a bash autocompletion script

Generate bash autocompletion script:
Add the script to your .bashrc and .bash_profle:
You can now use tab to autocomplete cockroach commands.

Generate example data

You can also use the command to generate these sample datasets in a persistent cluster and the command to generate these datasets in a temporary, in-memory cluster. To test out CockroachDB, you can generate an example startrek database, which contains 2 tables, episodes and quotes.
  1. Start up :
  2. Pipe the output from cockroach gen to :
  3. Open a to view it:
  4. Generate an example intro database, which contains 1 table, mytable, with a hidden message:
  5. Launch the SQL client to view it:
  6. Show the tables in the intro database:
  7. Select the message from the table:

Generate an HAProxy config file

HAProxy is one of the most popular open-source TCP load balancers, and CockroachDB includes a built-in command for generating a configuration file that is preset to work with your running cluster.
To generate an HAProxy config file for an entire secure cluster, run the cockroach gen haproxy command, specifying the location of and the address of any instance running a CockroachDB node:
To limit the HAProxy config file to nodes matching specific , use the --localities flag, specifying the explicit locality tier(s) or a regular expression to match against:
By default, the generated configuration file is called haproxy.cfg and looks as follows, with the server addresses pre-populated correctly:
The file is preset with the minimal configurations needed to work with your running cluster:
FieldDescription
timeout connect
timeout client
timeout server
Timeout values that should be suitable for most deployments.
bindThe port that HAProxy listens on. This is the port clients will connect to and thus needs to be allowed by your network configuration.

This tutorial assumes HAProxy is running on a separate machine from CockroachDB nodes. If you run HAProxy on the same machine as a node (not recommended), you’ll need to change this port, as 26257 is likely already being used by the CockroachDB node.
balanceThe balancing algorithm. This is set to roundrobin to ensure that connections get rotated amongst nodes (connection 1 on node 1, connection 2 on node 2, etc.). Check the HAProxy Configuration Manual for details about this and other balancing algorithms.
option httpchkThe HTTP endpoint that HAProxy uses to check node health. ensures that HAProxy doesn’t direct traffic to nodes that are live but not ready to receive requests.
serverFor each included node, this field specifies the address the node advertises to other nodes in the cluster, i.e., the addressed pass in the on node startup. Make sure hostnames are resolvable and IP addresses are routable from HAProxy.
For full details on these and other configuration settings, see the HAProxy Configuration Manual.

Generate a dashboard

Generate a Datadog dashboard:
Generate a Grafana dashboard:

See also

  • (using HAProxy for load balancing)