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
Synopsis
Generate man pages:Flags
Thegen subcommands supports the following general-use, logging, and client connection flags.
General
man
| Flag | Description |
|---|---|
--path | The path where man pages will be generated. Default:man/man1 under the current directory |
autocomplete
| Flag | Description |
|---|---|
--out | The 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
| Flag | Description |
|---|---|
--host | The 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 |
--insecure | Use an insecure connection. Env Variable:COCKROACH\_INSECURE Default:false |
--certs-dir | The path to the containing the CA and client certificates and client key. Env Variable:COCKROACH\_CERTS\_DIR Default:${HOME}/.cockroach-certs/ |
--url | A to use instead of the other arguments. Env Variable:COCKROACH\_URL Default: no URL |
--out | The 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 |
--locality | If 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. |
Logging
By default, this command logs messages tostderr. This includes events with WARNING and higher.
If you need to troubleshoot this command’s behavior, you can .
Client Connection
haproxy
| Flag | Description |
|---|---|
--cluster-name | The 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-verification | Disables 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:
Generate a bash autocompletion script
Generate bash autocompletion script:
.bashrc and .bash_profle:
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 examplestartrek database, which contains 2 tables, episodes and quotes.
-
Start up :
-
Pipe the output from
cockroach gento : -
Open a to view it:
-
Generate an example
introdatabase, which contains 1 table,mytable, with a hidden message: -
Launch the SQL client to view it:
-
Show the tables in the
introdatabase: -
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.- Secure
- Insecure
To generate an HAProxy config file for an entire secure cluster, run the To limit the HAProxy config file to nodes matching specific , use the
cockroach gen haproxy command, specifying the location of and the address of any instance running a CockroachDB node:--localities flag, specifying the explicit locality tier(s) or a regular expression to match against:haproxy.cfg and looks as follows, with the server addresses pre-populated correctly:
| Field | Description |
|---|---|
timeout connect timeout client timeout server | Timeout values that should be suitable for most deployments. |
bind | The 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. |
balance | The 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 httpchk | The 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. |
server | For 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.
See also
- (using HAProxy for load balancing)

