Connect to multiple databases from a single DBHub instance using TOML configuration. Useful for:
- Managing production, staging, and development databases
- Working with databases across different cloud providers
- Querying multiple database types simultaneously
Configuration
Create a dbhub.toml file:
# Database sources
[[sources]]
id = "production"
dsn = "postgres://user:[email protected]:5432/myapp"
[[sources]]
id = "staging"
dsn = "mysql://root:password@localhost:3306/myapp_staging"
[[sources]]
id = "local"
dsn = "sqlite:///./dev.db"
# Tool configuration
# Production: read-only execute_sql with row limit, plus search_objects
[[tools]]
name = "execute_sql"
source = "production"
readonly = true
max_rows = 1000
[[tools]]
name = "search_objects"
source = "production"
# Staging: full access with higher row limit
[[tools]]
name = "execute_sql"
source = "staging"
max_rows = 5000
[[tools]]
name = "search_objects"
source = "staging"
# Local: default tools (both execute_sql and search_objects)
# No [[tools]] entries = both tools enabled by default
Start DBHub:
# Automatically loads ./dbhub.toml
npx @bytebase/dbhub --transport http --port 8080
# Or specify custom location
npx @bytebase/dbhub --config=/path/to/config.toml
See Server Options for detailed option descriptions and Tool Configuration for controlling which tools are available per source.
Examples
Using DSN
Individual Parameters
With SSH Tunnel
[[sources]]
id = "production"
dsn = "postgres://user:[email protected]:5432/myapp"
[[sources]]
id = "staging"
dsn = "mysql://root:pass@localhost:3306/myapp_staging"
# Production: read-only with row limit
[[tools]]
name = "execute_sql"
source = "production"
readonly = true
max_rows = 1000
[[tools]]
name = "search_objects"
source = "production"
# Staging: full access (default tools)
# No [[tools]] for staging = both tools enabled
[[sources]]
id = "production"
type = "postgres"
host = "prod.example.com"
port = 5432
database = "myapp"
user = "app_user"
password = "p@ss:word" # No URL encoding needed
[[tools]]
name = "execute_sql"
source = "production"
readonly = true
[[sources]]
id = "production"
dsn = "postgres://user:[email protected]:5432/myapp"
ssh_host = "bastion.example.com"
ssh_user = "deploy"
ssh_key = "~/.ssh/id_rsa"
[[tools]]
name = "execute_sql"
source = "production"
readonly = true
[[tools]]
name = "search_objects"
source = "production"
The first [[sources]] entry is the default database used when no id is specified.