When I connect to CockroachDB using cockroach sql
, I have to prefix all table names with the name of the database:
SELECT * FROM db.table1;
If I forget to specify the database, like
SELECT * FROM table1;
I get the error pq: table "table1" does not exist
.
Once in the CockroachDB SQL shell, you can work with your database like you would any relational database. By default, when the SQL shell launches you’ll be in the defaultdb, so your first step will probably be to create your own database using CREATE DATABASE.
If you run your own benchmarks, or if you try to find existing benchmark results online, be sure that they do not compare apples with oranges: the default configuration of CockroachDB provides better safety and correctness than the default configuration of MySQL and PostgreSQL, but that comes at a slight performance cost.
Cockroach University is our free online course platform, with lots of courses designed to help you get up and running fast! The Cockroach Labs blog has lots of great content about building, running, and scaling a database with CockroachDB.
Here’s a quick overview of how to apply schema changes using Liquibase with your Cockroach database. Download the JDBC driver jar file for PostgreSQL and copy it into your liquibase/lib directory.
You can set the database from an active SQL session by running:
SET DATABASE = [database]
You can also specify this when you connect by passing the --database
argument to cockroach sql
:
cockroach sql --database=[database]
Both of these are set per-session, so you’ll need to use them every time you connect.
If using a connection string, you can specify the database as the path segment of the URL, e.g.:
postgresql://root@localhost:26257/[database]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With