The SHOW DATABASES
statement lists all databases in the CockroachDB cluster.
Synopsis
Required privileges
The user must be granted the CONNECT
privilege to specific databases in order to list those databases in the CockroachDB cluster.
Example
Show databases
> SHOW DATABASES;
database_name | owner | primary_region | secondary_region | regions | survival_goal
----------------+-------+----------------+------------------+---------+----------------
defaultdb | root | NULL | NULL | {} | NULL
movr | demo | NULL | NULL | {} | NULL
postgres | root | NULL | NULL | {} | NULL
system | node | NULL | NULL | {} | NULL
(4 rows)
Alternatively, within the built-in SQL shell, you can use the \l
shell command to list all databases:
> \l
database_name | owner | primary_region | secondary_region | regions | survival_goal
----------------+-------+----------------+------------------+---------+----------------
defaultdb | root | NULL | NULL | {} | NULL
movr | demo | NULL | NULL | {} | NULL
postgres | root | NULL | NULL | {} | NULL
system | node | NULL | NULL | {} | NULL
(4 rows)
Show databases with comments
You can use COMMENT ON
to add comments on a database.
COMMENT ON DATABASE movr IS 'This database holds information about users, vehicles, and rides.';
To view a database's comments:
> SHOW DATABASES WITH COMMENT;
database_name | owner | primary_region | secondary_region | regions | survival_goal | comment
----------------+-------+----------------+------------------+---------+---------------+--------------------------------------------------------------------
defaultdb | root | NULL | NULL | {} | NULL | NULL
movr | demo | NULL | NULL | {} | NULL | This database holds information about users, vehicles, and rides.
postgres | root | NULL | NULL | {} | NULL | NULL
system | node | NULL | NULL | {} | NULL | NULL
(4 rows)
For more information, see COMMENT ON
.
Preloaded databases
New clusters and existing clusters upgraded to v24.3 or later will include auto-generated databases, with the following purposes:
- The empty
defaultdb
database is used if a client does not specify a database in the connection parameters. - The
movr
database contains data about users, vehicles, and rides for the vehicle-sharing app MovR (only when the cluster is started using thedemo
command). - The empty
postgres
database is provided for compatibility with PostgreSQL client applications that require it. - The
system
database contains CockroachDB metadata and is read-only.
All databases except for the system
database can be deleted if they are not needed.
Do not query the system
database directly. Instead, use objects within the system catalogs.