Overview
Thecockroach init command performs one-time-only initialization of a CockroachDB cluster. After starting one or more nodes with the --join flag, you must run the init command on one node to complete cluster setup.
Cluster initialization is required before the cluster can accept SQL connections. This step creates the system databases and establishes the cluster’s identity.
Syntax
When to Use
Runcockroach init when:
- You’ve started multiple nodes with the
--joinflag - You’re setting up a new multi-node cluster
- The cluster has never been initialized before
Common Flags
The server host and port to connect to for initialization.
Path to the certificate directory for secure clusters. Required if the cluster uses TLS.
Connect to an insecure cluster (no TLS encryption). Use only for development.
Examples
Initialize an Insecure Cluster
Initialize a Secure Cluster
For production deployments with TLS certificates:The user running
init must have access to the client certificate (client.root.crt) in the certs directory.Initialize on Remote Host
How It Works
- Connection Check: The
initcommand waits for the target node to be ready (health check) - Bootstrap: Sends a Bootstrap RPC to create system databases and cluster metadata
- Confirmation: Returns success message when initialization completes
pkg/cli/init.go:68):
Troubleshooting
Error: cluster has already been initialized
Error: cluster has already been initialized
This means the cluster was previously initialized. You can verify by connecting with
cockroach sql - if it works, the cluster is initialized.Solution: No action needed. Connect to the cluster normally.Error: node not ready to perform cluster initialization
Error: node not ready to perform cluster initialization
The node hasn’t fully started yet or can’t be reached.Solutions:
- Wait a few seconds for the node to finish starting
- Verify the node is running:
ps aux | grep cockroach - Check the node logs for startup errors
- Verify the
--hostflag matches the node’s--listen-addr
Connection refused errors
Connection refused errors
Can’t connect to the specified host/port.Solutions:
- Verify the node is running on the specified address
- Check firewall rules allow connections on port 26257
- For secure clusters, ensure certificates are valid and in the correct location
Best Practices
- Run
initonly once per cluster - Use the same
--joinlist on all nodes - For production, always use
--certs-dir(secure mode) - Document which node you ran
initon for your records - Verify cluster status after initialization
Related Commands
- cockroach start - Start a CockroachDB node
- cockroach node status - Check cluster node status
- Cluster Management - Managing cluster operations