Skip to main content
The Database Management API provides endpoints for managing databases within your CockroachDB clusters. These endpoints are part of the Cluster API v2, which runs on your cluster nodes.

API Base URL

The Cluster API is hosted by all nodes in your cluster on the same port as the DB Console (default port 8080):
http://localhost:8080/api/v2
You can configure the port using --http-addr={server}:{port} when starting nodes.

Authentication

All database endpoints (except /health and /login) require authentication using a session token.

Obtaining a Session Token

POST
curl --request POST \
  --url https://localhost:8080/api/v2/login/ \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --data 'username={username}&password={password}'
Requirements:
  • A SQL role that is a member of the admin role
  • Login permissions and a password
Response:
{
  "session": "CIGAiPis4fj3CBIQ3u0rRQJ3tD8yIqee4hipow=="
}
Use this session token in subsequent requests:
curl --request GET \
  --url https://localhost:8080/api/v2/databases \
  --header 'X-Cockroach-API-Session: CIGAiPis4fj3CBIQ3u0rRQJ3tD8yIqee4hipow=='

List Databases

Retrieve all databases in the cluster.
GET /api/v2/databases
curl --request GET \
  --url https://localhost:8080/api/v2/databases \
  --header 'X-Cockroach-API-Session: {session_token}'

Response

databases
array
Array of database names
{
  "databases": [
    {
      "name": "defaultdb",
      "id": "52"
    },
    {
      "name": "postgres",
      "id": "53"
    },
    {
      "name": "production",
      "id": "54"
    }
  ]
}

Get Database Details

Get the descriptor ID and metadata for a specific database.
GET /api/v2/databases/{database}
curl --request GET \
  --url https://localhost:8080/api/v2/databases/{database} \
  --header 'X-Cockroach-API-Session: {session_token}'

Path Parameters

database
string
required
Name of the database

Response

{
  "database_name": "production",
  "descriptor_id": "54",
  "size_bytes": 1073741824,
  "table_count": 15,
  "store_ids": [1, 2, 3]
}
database_name
string
Name of the database
descriptor_id
string
Unique descriptor ID for the database
size_bytes
integer
Total size of all data in the database
table_count
integer
Number of tables in the database

List Database Grants

List all privileges granted to users for a specific database.
GET /api/v2/databases/{database}/grants
curl --request GET \
  --url https://localhost:8080/api/v2/databases/{database}/grants \
  --header 'X-Cockroach-API-Session: {session_token}'

Path Parameters

database
string
required
Name of the database

Response

{
  "grants": [
    {
      "user": "admin",
      "privileges": ["ALL"]
    },
    {
      "user": "app_user",
      "privileges": ["SELECT", "INSERT", "UPDATE"]
    },
    {
      "user": "readonly",
      "privileges": ["SELECT"]
    }
  ]
}
grants
array
Array of grant objects

List Database Tables

List all tables in a specific database.
GET /api/v2/databases/{database}/tables
curl --request GET \
  --url https://localhost:8080/api/v2/databases/{database}/tables \
  --header 'X-Cockroach-API-Session: {session_token}'

Path Parameters

database
string
required
Name of the database

Response

{
  "tables": [
    {
      "name": "users",
      "schema_name": "public",
      "table_id": "55",
      "size_bytes": 524288000
    },
    {
      "name": "orders",
      "schema_name": "public",
      "table_id": "56",
      "size_bytes": 1048576000
    }
  ]
}
tables
array
Array of table objects

Get Table Details

Get detailed information about a specific table.
GET /api/v2/databases/{database}/tables/{table}
curl --request GET \
  --url https://localhost:8080/api/v2/databases/{database}/tables/{table} \
  --header 'X-Cockroach-API-Session: {session_token}'

Path Parameters

database
string
required
Name of the database
table
string
required
Name of the table

Response

{
  "table_name": "users",
  "table_id": "55",
  "database_name": "production",
  "schema_name": "public",
  "columns": [
    {
      "name": "id",
      "type": "UUID",
      "nullable": false
    },
    {
      "name": "email",
      "type": "STRING",
      "nullable": false
    }
  ],
  "indexes": [
    {
      "name": "primary",
      "columns": ["id"],
      "unique": true
    },
    {
      "name": "users_email_idx",
      "columns": ["email"],
      "unique": true
    }
  ],
  "grants": [
    {
      "user": "admin",
      "privileges": ["ALL"]
    }
  ],
  "range_count": 12,
  "size_bytes": 524288000
}
table_name
string
Name of the table
table_id
string
Unique table descriptor ID
columns
array
Array of column definitions
indexes
array
Array of index definitions
grants
array
Privileges granted on this table
range_count
integer
Number of ranges storing this table’s data
size_bytes
integer
Total size of the table in bytes

Logout

Invalidate your session token.
POST
curl --request POST \
  --url https://localhost:8080/api/v2/logout/ \
  --header 'X-Cockroach-API-Session: {session_token}'

Support Policy

EndpointStability
/databasesStable
/databases/{database}Stable
/databases/{database}/grantsStable
/databases/{database}/tablesStable
/databases/{database}/tables/{table}Stable
Stable endpoints are supported and will maintain backward compatibility within the v2 API version.

Common Use Cases

Use /databases and /databases/{database} endpoints to track database and table sizes over time for capacity planning.
curl -X GET https://localhost:8080/api/v2/databases/production \
  -H 'X-Cockroach-API-Session: {token}' | jq '.size_bytes'
Use /databases/{database}/grants to audit which users have access to sensitive databases.
curl -X GET https://localhost:8080/api/v2/databases/production/grants \
  -H 'X-Cockroach-API-Session: {token}'
Use /databases/{database}/tables to generate an inventory of all tables and schemas.
curl -X GET https://localhost:8080/api/v2/databases/production/tables \
  -H 'X-Cockroach-API-Session: {token}'

Error Responses

401 Unauthorized

Occurs when the session token is missing, invalid, or expired.
{
  "error": "unauthorized",
  "message": "valid session required"
}

404 Not Found

Occurs when the specified database or table doesn’t exist.
{
  "error": "not found",
  "message": "database \"nonexistent\" does not exist"
}

Build docs developers (and LLMs) love