Databases & add-ons

Databases and add-ons

Attach managed services and open a database shell through a private tunnel.

stackblaze connect

Opens an interactive database client (psql, mysql or redis-cli) for an add-on attached to the linked app. [addon] is postgres, mysql or redis, and can be left out when the app has exactly one database add-on.

usage
stackblaze connect [addon] [--instance <name>] [--local | --tunnel] [--port <port>] [--print-only]

By default the client runs inside the app, using the connection details the app already has; the client program must exist in the app's image. With --local the client runs on your machine through a private tunnel. With --tunnel the tunnel stays open and the CLI prints host, port, user and database for GUI tools.

The tunnel listens on 127.0.0.1 only and carries each connection over an authenticated connection to the StackBlaze API, so the database is never exposed publicly. It needs write access to the app, closes after 30 minutes idle, and Ctrl-C closes it. With --local the password is passed to the client through its environment, never on the command line.

FlagDescription
--instance <name>Which add-on instance, when several match
--localRun the client on this machine through a private tunnel (needs psql, mysql or redis-cli installed)
--tunnelKeep a private tunnel open for GUI tools and print host, port, user and database
--port <port>Local port for --local or --tunnel (default: a free port)
--print-onlyOpen the tunnel and print its connection string instead of launching a client

Also accepts the scope flags (-p, --project, -e, --env, -a, --app), plus --token, --api-url and --org. Common flags

Examples

terminal
stackblaze connect postgres                          # psql inside the app
stackblaze connect postgres --local                  # psql on this machine, via the tunnel
stackblaze connect mysql --local --instance orders   # pick one of several add-ons
stackblaze connect postgres --local --port 15432 --print-only
stackblaze connect redis --tunnel --port 16379       # host/port/user/db for a GUI tool

stackblaze addons

Alias: addon

Add-ons are managed services, such as PostgreSQL or Redis, attached to an app. list shows the kinds you can attach (with --attached, the ones on the app); add attaches one; delete detaches one, and with --destroy also deletes it and its data. Backups and public access have their own commands, below.

usage
stackblaze addons list [--attached]
stackblaze addons add [kind] [--wait] [--timeout <seconds>]
stackblaze addons delete [kind] [--instance <name>] [--destroy] [-y]
stackblaze addons backups …
stackblaze addons expose | unexpose | info [addon]

Use addons list for the exact kind names. With add --wait --json, stdout carries one JSON document with the readiness check under wait; a wait that ends without the app and add-on running exits 1. Progress lines go to stderr.

By default delete only detaches a shared add-on: it keeps running with its data. When no app uses it any more, delete says so and prints the command to remove it (stackblaze addons delete <name> --destroy); in a terminal it offers to delete it there, after you type its name.

--destroy deletes the shared add-on and all its data, and is refused while another app still uses it. With an instance name, it deletes an add-on that no app uses any more. A private (per-app) add-on always goes with its data, so delete asks you to type its name first.

FlagDescription
--attachedlist: list the add-ons attached to the app
--kind <name>add, delete: same as the positional kind
--waitadd: wait until the app and the add-on are running
--timeout <seconds>add: maximum --wait time (default 600; a new database can take several minutes)
--instance <name>delete: which instance, when several match
--destroydelete: also delete the add-on and all its data (refused while another app uses it)
-y, --yesdelete: skip the confirmation

Also accepts the scope flags (-p, --project, -e, --env, -a, --app) and the output flags (-o, --output, --json), plus --token, --api-url and --org. Common flags

Examples

terminal
stackblaze addons list
stackblaze addons add <kind> --wait            # kind names from addons list
stackblaze addons list --attached -o json
stackblaze addons delete redis                 # detach only; the add-on keeps its data
stackblaze addons delete redis --destroy -y    # detach and delete it with its data

stackblaze addons backups

Alias: addons backup

Dumps of one PostgreSQL or MariaDB add-on. list shows its dumps and running dump and restore jobs; status shows whether the environment's scheduled backups cover it; create takes a dump now; restore loads a dump into another database.

usage
stackblaze addons backups list [addon]
stackblaze addons backups status [addon]
stackblaze addons backups create [addon] [--wait] [--timeout <seconds>] [--ci]
stackblaze addons backups restore [addon] --to <instance> [--backup <name>] [-y] [--wait] [--timeout <seconds>] [--ci]

<addon> is the add-on's instance name, or its type (for example postgres) when the app has one add-on of that type; without it, the app's only database add-on is used.

Every recovery point of the environment also dumps each database, so a scheduled backup covers it (see Backups & restore). To put one database back from a recovery point, in place or as a copy, use stackblaze backups restore <id> --database <name> [--copy].

restore --to <db> loads a dump (--backup, default the newest) into ANOTHER existing database of the same engine in this environment and replaces its data; the source is never changed. Dumps have no point in time.

Valkey has no dumps. These commands never turn on scheduled backups; create exits 3 with the server's message when backups are switched off or the disk cap is reached.

FlagDescription
--waitcreate, restore: wait until the job finishes (exit 1 if it fails)
--timeout <seconds>create, restore: maximum --wait time (default 1800)
--cicreate, restore: print NDJSON events
--to <instance>restore: the existing database to restore into (required)
--backup <name>restore: dump to restore, from addons backups list (default the newest)
-y, --yesrestore: skip the confirmation prompt

Also accepts the scope flags (-p, --project, -e, --env, -a, --app) and the output flags (-o, --output, --json), plus --token, --api-url and --org. Common flags

Examples

terminal
stackblaze addons backups status web-postgresql
stackblaze addons backups create --wait
stackblaze addons backups restore web-postgresql --to web-pg-copy -y

stackblaze addons expose

Public access to a database add-on. expose makes it reachable from outside the platform through the edge, at db.edge.stackblaze.cloud:<port>, for the addresses on its IP allow-list. unexpose turns public access off again, so the database is reachable from inside the platform only. info prints the connection details: host, port, user and the public address.

usage
stackblaze addons expose [addon] [--allow <ip/cidr>]... [--allow-all [-y]]
stackblaze addons unexpose [addon]
stackblaze addons info [addon] [--reveal]

Re-run expose with a different --allow list to change who may connect. --allow-all accepts any address, leaving only the database password to protect it, and asks for confirmation first.

The server decides which databases can be exposed and says why when one cannot, for example a database without a password; the CLI prints the reason and exits 3.

info --reveal adds the password and connection strings for the public address.

FlagDescription
--allow <ip/cidr>expose: address allowed to connect (repeatable, or comma-separated)
--allow-allexpose: allow any address (only the database password protects it)
-y, --yesexpose: skip the --allow-all confirmation
--revealinfo: show passwords and connection strings

Also accepts the scope flags (-p, --project, -e, --env, -a, --app) and the output flags (-o, --output, --json), plus --token, --api-url and --org. Common flags

Examples

terminal
stackblaze addons expose postgres --allow 203.0.113.7
stackblaze addons info postgres --reveal
stackblaze addons unexpose postgres