A database architected for the unexpected

/* CockroachDB is a highly performant, resilient database so you can be confident what you build is built to survive. */

Scale fast.
Survive disaster.
Thrive everywhere.

Scale infinitely without any painful sharding. Use a platform that grows effortlessly from a single customer to massive success.

Learn more

Avoid outages and downtime. Reduce RPO/RTO to zero and keep every user happy.

Learn more

Ensure low-latency data access and comply with data regulations by instantly deploying anywhere in the world.

Learn more

Optimize where your data lives and maximize fault-tolerance by deploying across multiple clouds, public and private with CockroachDB Self-hosted.

Use a language you already know and tools you already love with Postgres-compatible SQL syntax.

Learn more

Learn from free tutorials and courses, and work with a team of experts 24x7 who are committed to your success.

Learn more

Free yourself from hassle with a fully-managed database service. Get exactly the resources you need and pay only for what you use.

Learn more

Get started for free, instantly.

/* No credit card required. Free up to 5Gb. Single-click deployment.*/

Start instantly

The cloud database
built for you

Developers

A feature-set designed for developer productivity.

Start instantly

Connect to the connection string and start building

Pay as you go

Only pay for the exact resources your app uses

Build, don’t operate

Eliminate manual tasks with auto-scaling

Use relational schema

Don’t sacrifice consistency or familiarity

Make online schema changes

Change schema with zero downtime in production

Use PostgreSQL drivers & ORMs

Use your favorite stack and third-party tools

• • •


conn = psycopg2.connect(
"postgresql://maxroach@localhost:26257/bank?sslmode=require&sslrootcert=certs/ca.crt&sslkey=certs/client.maxroach.key&sslcert=certs/client.maxroach.crt")

def create_accounts(conn):
    with conn.cursor() as cur:
        cur.execute(
            "CREATE TABLE IF NOT EXISTS accounts (id INT PRIMARY KEY, balance INT)"
        )
        cur.execute("UPSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 250)")
        logging.debug("create_accounts(): status message: %s", cur.statusmessage)
    conn.commit()


def delete_accounts(conn):
    with conn.cursor() as cur:
        cur.execute("DELETE FROM bank.accounts")
        logging.debug("delete_accounts(): status message: %s", cur.statusmessage)
    conn.commit()

create_accounts(conn)



public static void main(String[] args) {
    // Configure the database connection.
    PGSimpleDataSource ds = new PGSimpleDataSource();
    ds.setServerName("localhost");
    ds.setPortNumber(26257);
    ds.setDatabaseName("bank");
    ds.setUser("maxroach");
    ds.setPassword(null);
    ds.setSsl(true);
    ds.setSslMode("require");
    ds.setSslRootCert("certs/client.root.crt");
    ds.setSslCert("certs/client.maxroach.crt");
    ds.setSslKey("certs/client.maxroach.key.pk8");
    ds.setReWriteBatchedInserts(true); // add `rewriteBatchedInserts=true` to pg connection string
    ds.setApplicationName("BasicExample");

    // Set up the 'accounts' table.
    createAccounts();

    // Insert a few accounts "by hand", using INSERTs on the backend.
    int updatedAccounts = updateAccounts();
    System.out.printf("BasicExampleDAO.updateAccounts:\n    => %s total updated accounts\n", updatedAccounts);
}

public static void createAccounts(PGSimpleDataSource ds) {
    String sql = "CREATE TABLE IF NOT EXISTS accounts (id INT PRIMARY KEY, balance INT, CONSTRAINT balance_gt_0 CHECK (balance >= 0))";
    try (Connection connection = ds.getConnection()) {
      connection.execSQLUpdate(sql);
    }
}

public static int updateAccounts(PGSimpleDataSource ds) {
    String sql1 = "INSERT INTO accounts (id, balance) VALUES (1, 1000)";
    String sql2 = "INSERT INTO accounts (id, balance) VALUES (2, 250)";
    try (Connection connection = ds.getConnection()) {
      connection.execSQLUpdate(sql1);
      connection.execSQLUpdate(sql2);
    }
}



func main() {
    config, err := pgx.ParseConfig("postgresql://maxroach@localhost:26257/bank?sslmode=require&sslrootcert=certs/ca.crt&sslkey=certs/client.maxroach.key&sslcert=certs/client.maxroach.crt")
    if err != nil {
        log.Fatal("error configuring the database: ", err)
    }
    config.TLSConfig.ServerName = "localhost"
    // Connect to the "bank" database.
    conn, err := pgx.ConnectConfig(context.Background(), config)
    if err != nil {
        log.Fatal("error connecting to the database: ", err)
    }
    defer conn.Close(context.Background())
    // Create the "accounts" table.
    if _, err := conn.Exec(context.Background(),
        "CREATE TABLE IF NOT EXISTS accounts (id INT PRIMARY KEY, balance INT)"); err != nil {
        log.Fatal(err)
    }
    // Insert two rows into the "accounts" table.
    if _, err := conn.Exec(context.Background(),
        "INSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 250)"); err != nil {
        log.Fatal(err)
    }




# Connect to the "bank" database.
conn = PG.connect(
  user: 'maxroach',
  dbname: 'bank',
  host: 'localhost',
  port: 26257,
  sslmode: 'require',
  sslrootcert: 'certs/ca.crt',
  sslkey: 'certs/client.maxroach.key',
  sslcert: 'certs/client.maxroach.crt'
)

# Create the "accounts" table.
conn.exec('CREATE TABLE IF NOT EXISTS accounts (id INT PRIMARY KEY, balance INT)')

# Insert two rows into the "accounts" table.
conn.exec('INSERT INTO accounts (id, balance) VALUES (1, 1000), (2, 250)')

Architects

A database that delivers on the promises of the cloud.

Grow without pain

Embrace a platform that scales with your applications

Support transactions at scale

Eliminate manual tasks with auto-scaling

Deliver an exceptional experience

Customize your database’s survival and latency goals

Serve a global user-base

Deploy across multiple cloud regions around the globe

Learn more
about CockroachDB

Documentation

Access tutorials, guides, example applications, and much more.

Read Docs

Architecture

Look under the hood and understand how CockroachDB works.

Learn more

Customer Stories

Read how companies support their most important workloads.

CockroachDB in action

Deploy CockroachDB
your way

• • •

CockroachDB Dedicated

/* Ideal deployment for a cloud database */

• Fully managed service
• Dedicated, single-tenant hardware
• Flexible configurations
• Storage and compute-based pricing

Get started for Free

CockroachDB serverless

/* Great for starter projects and evaluation */

• Fully managed service

• Shared, multi-tenant hardware

• Auto-scaling

• Consumption-based pricing

Get started for Free

CockroachDB self-hosted

/* For teams that need to use their own infrastructure */

• Self-managed

• Can run in any cloud or on-prem

• Enterprise license available

Contact us