> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to a CockroachDB Cluster

This page documents the required connection configuration for [fully-supported third-party tools](https://docs.cockroachlabs.com/docs/v24.2/third-party-database-tools).

For a list of all supported cluster connection parameters, see the [`cockroach` Connection Parameters](https://docs.cockroachlabs.com/docs/v24.2/connection-parameters).

For a list of community-supported third-party tools, see [Third-Party Tools Supported by the Community](https://docs.cockroachlabs.com/docs/v24.2/community-tooling). CockroachDB supports both native drivers and the PostgreSQL wire protocol. Most client drivers and ORM frameworks connect to CockroachDB like they connect to PostgreSQL.

## Step 1. Select your deployment

> [tab] CockroachDB Basic/Standard
>
> To connect to a CockroachDB Cloud cluster, you need a general connection string or connection parameters, which include the username, host, database, and port. To find these, open the **Connect** dialog for your cluster in the [CockroachDB Cloud Console](https://cockroachlabs.cloud) and select either **General connection string** or **Parameters only** as the option.

> [tab] CockroachDB Advanced
>
> To connect to a CockroachDB Cloud cluster, you need a general connection string or connection parameters, which include the username, host, database, and port. To find these, open the **Connect** dialog for your cluster in the [CockroachDB Cloud Console](https://cockroachlabs.cloud) and select either **General connection string** or **Parameters only** as the option.

> [tab] CockroachDB self-hosted
>
> To connect to a CockroachDB self-hosted cluster, you need the [general connection string](https://docs.cockroachlabs.com/docs/v24.2/connection-parameters#connect-using-a-url) or [connection parameters](https://docs.cockroachlabs.com/docs/v24.2/connection-parameters#connect-using-discrete-parameters) for your cluster.
>
> The connection strings and parameters for your cluster are output when you [start the cluster](https://docs.cockroachlabs.com/docs/v24.2/cockroach-start#standard-output).

## Step 2. Select your language and driver

> [tab] JavaScript/TypeScript
>
> > [tab] node-postgres
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > $env:DATABASE_URL = "{connection string}"
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [node-postgres](https://node-postgres.com), create a new [`Client`](https://node-postgres.com/apis/client) object with a connection string.
> >
> > For example:
> >
> > ```js theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > const { Client } = require('pg')
> >
> > const client = new Client(process.env.DATABASE_URL)
> >
> > client.connect()
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > For more information about connecting with node-postgres, see the [official node-postgres documentation](https://node-postgres.com/features/connecting).
>
> > [tab] Sequelize
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > $env:DATABASE_URL = "{connection string}"
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [Sequelize](https://sequelize.org), create a `Sequelize` object with the [CockroachDB Sequelize adapter](https://github.com/cockroachdb/sequelize-cockroachdb).
> >
> > For example:
> >
> > ```js theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > const Sequelize = require("sequelize-cockroachdb");
> >
> > const connectionString = process.env.DATABASE_URL
> > const sequelize = new Sequelize(connectionString)
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > > [!NOTE]
> > >
> > > To connect to CockroachDB with Sequelize, you must install the [CockroachDB Sequelize adapter](https://github.com/cockroachdb/sequelize-cockroachdb).
> > >
> > > For more information about connecting with Sequelize, see the [official Sequelize documentation](https://sequelize.org/docs/v6/).
>
> > [tab] TypeORM
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}
> > > ```
> > >
> > > TypeORM configures SSL separately in the DataSource object (`ssl: true`).
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}
> > > ```
> > >
> > > TypeORM configures SSL separately in the DataSource object:
> > >
> > > ```ts theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > ssl: {
> > >   ca: process.env.CA_CERT
> > > }
> > > ```
> > >
> > > Where `CA_CERT` is an environment variable set to the root certificate [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification).
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}
> > > ```
> > >
> > > TypeORM configures SSL separately in the DataSource object:
> > >
> > > ```ts theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > ssl: {
> > >   ca: process.env.CA_CERT,
> > >   key: process.env.CLIENT_KEY,
> > >   cert: process.env.CLIENT_CERT
> > > }
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > $env:DATABASE_URL = "{connection string}"
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [TypeORM](https://typeorm.io), update your project's [`DataSource`](https://typeorm.io/data-source) with the required connection properties.
> >
> > For example, suppose that you are defining the `DataSource` for your application in a file named `datasource.ts`:
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```ts theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > export const AppDataSource = new DataSource({
> > >     type: "cockroachdb",
> > >     url: process.env.DATABASE_URL,
> > >     ssl: true,
> > >     ...
> > > });
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```ts theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > export const AppDataSource = new DataSource({
> > >     type: "cockroachdb",
> > >     url: process.env.DATABASE_URL,
> > >     ssl: {
> > >       ca: process.env.CA_CERT
> > >     },
> > >     ...
> > > });
> > > ```
> > >
> > > Where `CA_CERT` is an environment variable set to the root certificate [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification).
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```ts theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > export const AppDataSource = new DataSource({
> > >     type: "cockroachdb",
> > >     url: process.env.DATABASE_URL,
> > >     ssl: {
> > >       ca: process.env.CA_CERT,
> > >       key: process.env.CLIENT_KEY,
> > >       cert: process.env.CLIENT_CERT
> > >     },
> > >   ...
> > > });
> > > ```
> > >
> > > Where:
> > >
> > > * `CA_CERT` is an environment variable set to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/v24.2/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/v24.2/create-security-certificates-custom-ca).
> > > * `CLIENT_KEY` is an environment variable set to the [client key](https://docs.cockroachlabs.com/docs/v24.2/cockroach-cert#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/v24.2/cockroach-cert#subcommands).
> > > * `CLIENT_CERT` is an environment variable set to the [client certificate](https://docs.cockroachlabs.com/docs/v24.2/cockroach-cert#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/v24.2/cockroach-cert#subcommands).
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > You can then import the `AppDataSource` into any file in your project and call `AppDataSource.initialize()` to connect to CockroachDB:
> >
> > ```ts theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > AppDataSource.initialize()
> >   .then(async () => {
> >     // Execute operations
> >   });
> > ```
> >
> > For more information about connecting with TypeORM, see the [official TypeORM documentation](https://typeorm.io/#/).
>
> > [tab] Prisma
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > $env:DATABASE_URL = "{connection string}"
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [Prisma](https://prisma.io/), set the `url` field of the `datasource` block in your Prisma schema to your database connection URL:
> >
> > ```js theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > generator client {
> >   provider = "prisma-client-js"
> > }
> >
> > datasource db {
> >   provider = "cockroachdb"
> >   url      = env("DATABASE_URL")
> > }
> >
> > model Widget {
> >   id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
> > }
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > For more information about connecting with Prisma, see the [official Prisma documentation](https://www.prisma.io/cockroachdb).

> [tab] Python
>
> > [!NOTE]
> >
> > To connect to a CockroachDB Basic or Standard cluster from a Python application, you must have a valid CA certificate located at `~/.postgresql/root.crt`.
> >
> > For instructions on downloading a CA certificate from the CockroachDB Cloud Console, see [Connect to a CockroachDB Basic Cluster](https://www.cockroachlabs.com/docs/cockroachcloud/connect-to-a-basic-cluster) or [Connect to a CockroachDB Standard Cluster](https://www.cockroachlabs.com/docs/cockroachcloud/connect-to-your-cluster).
>
> > [tab] Psycopg2
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [Psycopg2](https://www.psycopg.org), pass a connection string to the [`psycopg2.connect` function](https://www.psycopg.org/docs/connection.html).
> >
> > For example:
> >
> > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > import psycopg2
> > import os
> >
> > conn = psycopg2.connect(os.environ['DATABASE_URL'])
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > For more information about connecting with Psycopg, see the [official Psycopg documentation](https://www.psycopg.org/docs).
>
> > [tab] Psycopg3
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [Psycopg3](https://www.psycopg.org), pass a connection string to the [`psycopg.connect` function](https://www.psycopg.org/psycopg3/docs/basic/usage.html).
> >
> > For example:
> >
> > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > import psycopg
> > import os
> >
> > with psycopg.connect(os.environ['DATABASE_URL']) as conn:
> >   # application logic here
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > For more information about connecting with Psycopg, see the [official Psycopg documentation](https://www.psycopg.org/psycopg3/docs/basic/index.html).
>
> > [tab] SQLAlchemy
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > cockroachdb://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > cockroachdb://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > cockroachdb://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [SQLAlchemy](http://docs.sqlalchemy.org/), [create an `Engine` object](https://docs.sqlalchemy.org/core/engines.html) by passing the connection string to the `create_engine` function.
> >
> > For example:
> >
> > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > from sqlalchemy import create_engine
> > import os
> >
> > engine = create_engine(os.environ['DATABASE_URL'])
> > engine.connect()
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > > [!NOTE]
> > >
> > > To connect to CockroachDB with SQLAlchemy, you must install the [CockroachDB SQLAlchemy adapter](https://github.com/cockroachdb/sqlalchemy-cockroachdb).
> > >
> > > For more information about connecting with SQLAlchemy, see the [official SQLAlchemy documentation](https://docs.sqlalchemy.org/core/engines_connections.html).
> > >
> > > In order for SQLAlchemy to use the CockroachDB adapter, the connection string must begin with `cockroachdb://`. You can use the following code to modify the general connection string, which begins with `postgresql://`, to the format that works with SQLAlchemy and the CockroachDB adapter:
> > >
> > > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > engine = create_engine(os.environ['DATABASE_URL'].replace("postgresql://", "cockroachdb://"))
> > > engine.connect()
> > > ```
>
> > [tab] Django
> >
> > ### Connection string format
> >
> > Django does not use a connection string. Instead, you configure connection parameters in the `DATABASES` property in your project's `settings.py` file.
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB from a [Django](https://www.djangoproject.com) application, update the `DATABASES` property in the project's `settings.py` file.
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > ## settings.py
> > >
> > > ...
> > >
> > > DATABASES = {
> > >     'default': {
> > >         'ENGINE': 'django_cockroachdb',
> > >         'NAME': '{database}',
> > >         'USER': '{username}',
> > >         'PASSWORD': '{password}',
> > >         'HOST': '{host}',
> > >         'PORT': '{port}',
> > >         'OPTIONS': {
> > >             'sslmode': 'verify-full'
> > >         },
> > >     },
> > > }
> > >
> > > ...
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > ## settings.py
> > >
> > > ...
> > >
> > > DATABASES = {
> > >     'default': {
> > >         'ENGINE': 'django_cockroachdb',
> > >         'NAME': '{database}',
> > >         'USER': '{username}',
> > >         'PASSWORD': '{password}',
> > >         'HOST': '{host}',
> > >         'PORT': '{port}',
> > >         'OPTIONS': {
> > >             'sslmode': 'verify-full',
> > >             'sslrootcert': os.path.expandvars('{root-cert}'),
> > >         },
> > >     },
> > > }
> > >
> > > ...
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```python theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > > ## settings.py
> > >
> > > ...
> > >
> > > DATABASES = {
> > >     'default': {
> > >         'ENGINE': 'django_cockroachdb',
> > >         'NAME': '{database}',
> > >         'USER': '{username}',
> > >         'HOST': '{host}',
> > >         'PORT': '{port}',
> > >         'OPTIONS': {
> > >             'sslmode': 'verify-full',
> > >             'sslrootcert': os.path.expandvars('{root-cert}'),
> > >             'sslcert': os.path.expandvars('{client-cert}'),
> > >             'sslkey': os.path.expandvars('{client-key}'),
> > >         },
> > >     },
> > > }
> > >
> > > ...
> > > ```
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > > [!NOTE]
> > >
> > > To connect to CockroachDB with Django, you must install the [CockroachDB Django adapter](https://github.com/cockroachdb/django-cockroachdb).
> > >
> > > For more information about connecting with Django, see the [official Django documentation](https://docs.djangoproject.com/en/4.0/).

> [tab] Go
>
> > [tab] pgx
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [pgx](https://github.com/jackc/pgx), use the `pgx.Connect` function.
> >
> > For example:
> >
> > ```go theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > package main
> >
> > import (
> > 	"context"
> > 	"log"
> > 	"os"
> >
> > 	"github.com/jackc/pgx/v4"
> > )
> >
> > func main() {
> > 	conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
> > 	if err != nil {
> > 		log.Fatal(err)
> > 	}
> > 	defer conn.Close(context.Background())
> > }
> > ```
> >
> > For more information about connecting with pgx, see the [official pgx documentation](https://pkg.go.dev/github.com/jackc/pgx).
>
> > [tab] pq
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [pq](https://godoc.org/github.com/lib/pq), use the [`sql.Open` function](https://go.dev/doc/tutorial/database-access).
> >
> > For example:
> >
> > ```go theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > package main
> >
> > import (
> > 	"database/sql"
> > 	"log"
> > 	"os"
> >
> > 	_ "github.com/lib/pq"
> > )
> >
> > func main() {
> > 	db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
> > 	if err != nil {
> > 		log.Fatal(err)
> > 	}
> > 	defer db.Close()
> > }
> > ```
> >
> > For more information about connecting with pq, see the [official pq documentation](https://pkg.go.dev/github.com/lib/pq).
>
> > [tab] GORM
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [GORM](http://gorm.io), use the `gorm.Open` function, with the GORM `postgres` driver.
> >
> > For example:
> >
> > ```go theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > package main
> >
> > import (
> > 	"log"
> > 	"os"
> >
> > 	"gorm.io/driver/postgres"
> > 	"gorm.io/gorm"
> > )
> >
> > func main() {
> > 	db, err := gorm.Open(postgres.Open(os.Getenv("DATABASE_URL")), &gorm.Config{})
> > 	if err != nil {
> > 		log.Fatal(err)
> > 	}
> > }
> > ```
> >
> > For more information about connecting with GORM, see the [official GORM documentation](https://gorm.io/docs).

> [tab] Java
>
> > [tab] JDBC
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > jdbc:postgresql://{host}:{port}/{database}?password={password}&sslmode=verify-full&user={username}
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > jdbc:postgresql://{host}:{port}/{database}?user={username}&password={password}&sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > jdbc:postgresql://{host}:{port}/{database}?user={username}&sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the [PKCS#8](https://tools.ietf.org/html/rfc5208)-formatted [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client --also-generate-pkcs8-key`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `JDBC_DATABASE_URL` environment variable to your JDBC connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export JDBC_DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > $env:JDBC_DATABASE_URL = "{connection string}"
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with the [JDBC](https://jdbc.postgresql.org) driver, create a `DataSource` object ([`PGSimpleDataSource` or `PGPoolingDataSource`](https://jdbc.postgresql.org/documentation/datasource/#applications-datasource)), and set the connection string with the `setUrl` class method.
> >
> > For example:
> >
> > ```java theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > PGSimpleDataSource ds = new PGSimpleDataSource();
> > ds.setUrl(System.getenv("JDBC_DATABASE_URL"));
> > ```
> >
> > Where `JDBC_DATABASE_URL` is an environment variable set to a valid JDBC-compatible CockroachDB connection string.
> >
> > For more information about connecting with JDBC, see the [official JDBC documentation](https://jdbc.postgresql.org/documentation/).
>
> > [tab] Hibernate
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > jdbc:postgresql://{host}:{port}/{database}?password={password}&sslmode=verify-full&user={username}
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > jdbc:postgresql://{host}:{port}/{database}?user={username}&password={password}&sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > jdbc:postgresql://{host}:{port}/{database}?user={username}&sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The [URL-encoded](https://wikipedia.org/wiki/Percent-encoding) path to the [PKCS#8](https://tools.ietf.org/html/rfc5208)-formatted [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client --also-generate-pkcs8-key`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `JDBC_DATABASE_URL` environment variable to your JDBC connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export JDBC_DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > $env:JDBC_DATABASE_URL = "{connection string}"
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [Hibernate](https://hibernate.org/orm) ORM, set the object's `hibernate.connection.url` property to a valid CockroachDB connection string.
> >
> > For example, if you are bootstrapping your application with a [`ServiceRegistry`](https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#bootstrap-native-registry) object, first read from the Hibernate configuration file, and then set the `hibernate.connection.url` with the `applySetting` class method:
> >
> > ```java theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
> >     .configure( "hibernate.cfg.xml" ).applySetting("hibernate.connection.url", System.getenv("JDBC_DATABASE_URL"))
> >     .build();
> >
> > Metadata metadata = new MetadataSources( standardRegistry )
> >     .getMetadataBuilder()
> >     .build();
> >
> > SessionFactory sessionFactory = metadata.getSessionFactoryBuilder()
> >     .build();
> > ```
> >
> > Where `JDBC_DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > > [!NOTE]
> > >
> > > To connect to CockroachDB with Hibernate, you must specify the [CockroachDB Hibernate dialect](https://www.cockroachlabs.com/docs/v26.2/install-client-drivers?filters=java#hibernate) in your `hibernate.cfg.xml` configuration file.
> > >
> > > For more information about connecting with Hibernate, see the [official Hibernate documentation](https://hibernate.org/orm/documentation).

> [tab] Ruby
>
> > [!NOTE]
> >
> > To connect to a CockroachDB Basic or Standard cluster from a Ruby application, you must have a valid CA certificate located at `~/.postgresql/root.crt`.
> >
> > For instructions on downloading a CA certificate from the CockroachDB Cloud Console, see [Connect to a CockroachDB Basic Cluster](https://www.cockroachlabs.com/docs/cockroachcloud/connect-to-a-basic-cluster) or [Connect to a CockroachDB Standard Cluster](https://www.cockroachlabs.com/docs/cockroachcloud/connect-to-your-cluster).
>
> > [tab] pg
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > postgresql://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > postgresql://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with the [Ruby pg](https://rubygems.org/gems/pg) driver, use the `PG.connect` function.
> >
> > For example:
> >
> > ```ruby theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > #!/usr/bin/env ruby
> >
> > require 'pg'
> >
> > conn = PG.connect(ENV['DATABASE_URL'])
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > For more information about connecting with pg, see the [official pg documentation](https://www.rubydoc.info/gems/pg).
>
> > [tab] Active Record
> >
> > ### Connection string format
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > ```
> > > cockroachdb://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full
> > > ```
> >
> > > [tab] CockroachDB Advanced
> > >
> > > ```
> > > cockroachdb://{username}:{password}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}
> > > ```
> >
> > > [tab] CockroachDB self-hosted
> > >
> > > ```
> > > cockroachdb://{username}@{host}:{port}/{database}?sslmode=verify-full&sslrootcert={root-cert}&sslcert={client-cert}&sslkey={client-key}
> > > ```
> > >
> > > > [!NOTE]
> > > >
> > > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > > >
> > > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > > >
> > > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > **Connection parameters**
> >
> > > [tab] CockroachDB Basic/Standard
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> >
> > > [tab] CockroachDB Advanced
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{password}` | The password for the SQL user connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate that you [downloaded from the CockroachDB Cloud Console](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md#node-identity-verification). |
> >
> > > [tab] CockroachDB Core
> > >
> > > | Parameter | Description |
> > > | - | - |
> > > | `{username}` | The [SQL user](https://docs.cockroachlabs.com/docs/stable/security-reference/authorization.md#sql-users) connecting to the cluster. |
> > > | `{host}` | The host on which the CockroachDB node is running. |
> > > | `{port}` | The port at which the CockroachDB node is listening. |
> > > | `{database}` | The name of the (existing) database. |
> > > | `{root-cert}` | The path to the root certificate. You can generate this certificate with [`cockroach cert create-ca`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands), or you can use a [custom CA cert](https://docs.cockroachlabs.com/docs/stable/create-security-certificates-custom-ca.md). |
> > > | `{client-cert}` | The path to the [client certificate](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this certificate with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > > | `{client-key}` | The path to the [client key](https://docs.cockroachlabs.com/docs/stable/cockroach-cert.md#client-key-and-certificates) for the user connecting to the cluster. You can generate this key with [`cockroach cert create-client`](https://docs.cockroachlabs.com/docs/stable/cockroach-cert#subcommands). |
> > >
> > > The connection information shown on this page uses [client certificate and key authentication](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md) to connect to a secure, CockroachDB self-hosted cluster.
> > >
> > > To connect to a CockroachDB self-hosted cluster with client certificate and key authentication, you must first [generate server and client certificates](https://docs.cockroachlabs.com/docs/cockroachcloud/authentication.md).
> > >
> > > For instructions on starting a secure cluster, see [Start a Local Cluster (Secure)](https://docs.cockroachlabs.com/docs/v26.2/secure-a-cluster.md).
> >
> > ### Set environment variable
> >
> > Set a `DATABASE_URL` environment variable to your connection string:
> >
> > ```shell Mac or Linux theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > export DATABASE_URL="{connection string}"
> > ```
> >
> > ```shell Windows theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > set DATABASE_URL={connection string}
> > ```
> >
> > ### Connect to the cluster
> >
> > To connect to CockroachDB with [Active Record](https://github.com/rails/rails/tree/main/activerecord) from a Rails app, update the database configuration in `config/database.yml`:
> >
> > ```yaml theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> > default: &default
> >   adapter: cockroachdb
> >   url: <%= ENV['DATABASE_URL'] %>
> >
> > ...
> > ```
> >
> > Where `DATABASE_URL` is an environment variable set to a valid CockroachDB connection string.
> >
> > > [!NOTE]
> > >
> > > To connect to CockroachDB with Active Record, you must install the [Active Record CockroachDB adapter](https://rubygems.org/gems/activerecord-cockroachdb-adapter).
> > >
> > > For more information about connecting with Active Record, see the [official Active Record documentation](https://guides.rubyonrails.org/active_record_querying.html).

## See also

* [Install a Driver or ORM Framework](https://docs.cockroachlabs.com/docs/v24.2/install-client-drivers)
* [Connection Pooling](https://docs.cockroachlabs.com/docs/v24.2/connection-pooling)
* [`cockroach` Connection Parameters](https://docs.cockroachlabs.com/docs/v24.2/connection-parameters)
