# CockroachDB

Bobby Tables connects to CockroachDB through its PostgreSQL wire protocol and opens each connection in a SQL workspace that keeps CockroachDB catalog queries and limits.

## Where to find it

| Action | How |
| --- | --- |
| Choose CockroachDB | `New connection`, `⌘N` (`Ctrl+N`), then `CockroachDB` under `Choose a provider` |
| Fill the form from a URL | `Use connection URL` with a `cockroachdb://` or `cockroach://` URL, then `Fill fields` |
| Default port and database | `26257` and `defaultdb` |
A `postgresql://` URL also fills the form as CockroachDB when it uses port `26257` or a `cockroachlabs.cloud` host. URLs the app copies use `cockroachdb://`, so change the scheme to `postgresql://` for tools that only know PostgreSQL.

## Connecting

The form asks for `Host`, `Port`, `User`, `Database` and `Password`. CockroachDB Cloud connections normally use `Verify Full` in the `TLS` section, a local insecure cluster uses `Disable`, and [SSH and TLS](https://bobbytables.app/docs/ssh-and-tls) covers certificates and tunnels. `Test connection` reads the server version and refuses a PostgreSQL server selected as CockroachDB. `Open in read-only mode` sets `default_transaction_read_only` on the session and disables editing.

## What works

- Browse databases, schemas, tables, views, sequences and enum types in the [table grid](https://bobbytables.app/docs/table-data).
- Stage inserts, updates and deletes, then commit them in one transaction, as described in [Editing](https://bobbytables.app/docs/editing).
- Change structure in the [Structure](https://bobbytables.app/docs/structure) tab, with the DDL run inside a transaction.
- [Snapshots](https://bobbytables.app/docs/snapshots) are not available, so `Create snapshot...` does not appear.
- Draw a [schema diagram](https://bobbytables.app/docs/schema-diagram) from declared foreign keys.
- Format result columns with [result directives](https://bobbytables.app/docs/result-directives).
- Stop a running statement with `Cancel`, `⌘.` (`Ctrl+.`).
- Run `Explain`, `⌘⇧E` (`Ctrl+Shift+E`), in the [SQL editor](https://bobbytables.app/docs/sql-editor).

## Engine notes

CockroachDB can abort a transaction under contention, and Bobby Tables reports the error without replaying the write. After a `40001` failure, the commit dialog says another transaction changed the same data, keeps the pending changes and asks you to retry the complete transaction. After `40003` the commit may have succeeded, so verify the rows before retrying. `25P02` means the transaction failed and must be rolled back before anything else runs.

## Good to know

- CockroachDB does not use native `COPY`, estimated row counts or the process list. CSV import takes the generic path.
- Functions and triggers are not listed in the catalog.

## Related

- [PostgreSQL](https://bobbytables.app/docs/postgresql.md)
- [SSH and TLS](https://bobbytables.app/docs/ssh-and-tls.md)
- [Editing](https://bobbytables.app/docs/editing.md)
- [Engines, file sources and platforms](https://bobbytables.app/docs/engines.md)
