Before You Start
Before connecting to your cluster, you need to:- Create a cluster (see Creating a Cluster)
- Create at least one SQL user (see Authentication)
- Understand network authorization requirements
Authorize Your Network
By default, CockroachDB Cloud clusters restrict network access for security. You must authorize networks before connecting.Add IP Allowlist Entry
Navigate to Networking
- Select your cluster from the Clusters page
- Click Networking in the left navigation
- Click IP Allowlist tab
Add Network
Click Add Network and choose:
- Current Network: Automatically adds your current IP
- Custom: Specify an IP address or CIDR range
IP Allowlist Limits
| Cluster Type | Maximum Rules |
|---|---|
| Basic | 50 |
| Standard | 50 |
| Advanced (AWS) | 20 |
| Advanced (GCP/Azure) | 200 |
Establish Private Connectivity
For enhanced security and performance, use private connectivity to connect your cluster without exposing it to the public internet.AWS PrivateLink
Available for Standard and Advanced clusters on AWS.Create AWS Endpoint
In AWS Console:
- Navigate to VPC > Endpoints
- Create endpoint with the Service Name
- Select your VPC and subnets
- Copy the Endpoint ID
GCP Private Service Connect
Available for Standard and Advanced clusters on GCP.Create GCP Endpoint
In Google Cloud Console:
- Go to Private Service Connect
- Create endpoint in the same VPC as your application
- Set Target to Published service
- Enter the Target Service ID
- Enable global access if multi-region
GCP VPC Peering
Legacy option for GCP clusters. PSC is recommended for new deployments.VPC Peering requires configuration during cluster creation. Contact Support to set up VPC Peering for existing clusters.
Connect to Your Cluster
Once you’ve authorized your network, you can connect to your cluster.Get Connection Information
Select Connection Type
Choose how you want to connect:
- CockroachDB Client: Command-line SQL client
- Connection string: For application code
- Connection parameters: Individual parameters
Using CockroachDB SQL Client
Download the Client
Follow the instructions in the Connect dialog to download the CockroachDB binary for your OS.
Using a Connection String
For application connections, use the connection string provided:Using Connection Parameters
For tools that require individual parameters:| Parameter | Description | Example |
|---|---|---|
| Host | Cluster hostname | cluster-name.cloud.cockroachlabs.cloud |
| Port | Always 26257 | 26257 |
| Database | Database name | defaultdb |
| Username | SQL user | myuser |
| Password | SQL user password | (from SQL user creation) |
| SSL Mode | verify-full (required) | verify-full |
| CA Certificate | Path to root cert | ~/.postgresql/root.crt |
Connection String Components
Understanding the connection string format:postgresql://- Protocoluser:password- Credentialshost:26257- Cluster address and port/database- Target databasesslmode=verify-full- Encryption and verification modesslrootcert=...- CA certificate path
SSL Mode Settings
| SSL Mode | Encryption | Server Verification | Recommended |
|---|---|---|---|
require | Yes | No | No (testing only) |
verify-full | Yes | Yes | Yes (production) |
verify-full for production use to:
- Encrypt data in transit
- Verify server identity
- Prevent man-in-the-middle attacks
Special Characters in Passwords
If your SQL user password contains special characters, you must URL-encode them:| Character | Encoded |
|---|---|
@ | %40 |
# | %23 |
$ | %24 |
% | %25 |
& | %26 |
/ | %2F |
Troubleshooting
Connection Refused
Cause: Your IP address is not in the allowlist. Solution: Add your IP address to the allowlist under Networking > IP Allowlist.Certificate Verification Failed
Cause: Missing or incorrect CA certificate. Solution: Download the CA certificate from the Connect dialog and verify the path in your connection string.Authentication Failed
Cause: Incorrect username or password. Solution: Verify credentials. A Cluster Admin can reset passwords on the SQL Users page.Connection Timeout
Causes:- Firewall blocking port 26257
- Incorrect hostname
- Network connectivity issues
- Check firewall rules
- Verify hostname from Connect dialog
- Test network connectivity
Connection Pooling
For production applications, use connection pooling to:- Reduce connection overhead
- Improve performance
- Handle connection failures
- Pool size: 5-20 connections per application instance
- Idle timeout: 30 seconds
- Connection timeout: 2 seconds
- Maximum lifetime: 30 minutes
Next Steps
Build an Application
Build a sample app with your preferred language
Learn SQL
Learn CockroachDB SQL syntax
Manage SQL Users
Create and manage SQL users
Network Security
Learn about network security