Getting Started
Make sure to first set up your PlanetScale developer environment. Once you’ve installed the pscale CLI, you can interact with PlanetScale and manage your databases straight from the command line.
The branch command
This command allows you to create, delete, diff, and manage branches.
Usage:
pscale branch <SUB-COMMAND> <FLAG>
Available sub-commands
| Sub-command | Sub-command flags | Description | Product |
|---|
connections <COMMAND> | show, top, kill, kill-transaction | Inspect and act on live branch connections. See the connections reference. | Postgres, Vitess |
create <DATABASE_NAME> <BRANCH_NAME> | --from <SOURCE_BRANCH>, --region <BRANCH_REGION>, --restore <BACKUP_NAME>, --seed-data, --wait | Create a new branch on the specified database | Postgres, Vitess |
delete <DATABASE_NAME> <BRANCH_NAME> | --force, --delete-descendants | Delete the specified branch from a database | Postgres, Vitess |
diff <DATABASE_NAME> <BRANCH_NAME> | --web | Show the diff of the specified branch against the parent branch. | Vitess |
list <DATABASE_NAME> | --web | List all branches of a database | Postgres, Vitess |
promote <DATABASE_NAME> <BRANCH_NAME> | | Promote a database branch to production | Vitess |
query-patterns download <DATABASE_NAME> <BRANCH_NAME> | --output <PATH> | Generate and download a CSV report of branch query patterns. See the query-patterns reference. | Postgres, Vitess |
refresh-schema <DATABASE_NAME> <BRANCH_NAME> | | Refresh the schema for a database branch | Vitess |
safe-migrations enable <DATABASE_NAME> <BRANCH_NAME> | | Enables safe migrations for a database branch | Vitess |
safe-migrations disable <DATABASE_NAME> <BRANCH_NAME> | | Disables safe migrations for a database branch | Vitess |
schema <DATABASE_NAME> <BRANCH_NAME> | --web | Show the schema of a branch | Vitess |
show <DATABASE_NAME> <BRANCH_NAME> | --web | Show a specific backup of a branch | Postgres, Vitess |
switch <BRANCH_NAME> --database <DATABASE_NAME> | --database <DATABASE_NAME>*, --create, parent-branch <BRANCH_NAME> | Switch to the specified branch | Postgres, Vitess |
Service token automation: branch
Legend: ✅ supported · 🚫 unavailable · 👤 interactive login only. All sub-commands require --org or PLANETSCALE_ORG.
| Sub-command | Env-var auth | --service-token flag | Requires --org | Postgres / Vitess | --format json | API equivalent |
|---|
list <database> | ✅ | ✅ | ✅ | Both | ✅ | pscale api organizations/<org>/databases/<database>/branches --format json |
show <database> <branch> | ✅ | ✅ | ✅ | Both | ✅ | pscale api organizations/<org>/databases/<database>/branches/<branch> --format json |
create / delete | ✅ | ✅ | ✅ | Both | ✅ | POST pscale api organizations/<org>/databases/<database>/branches --format json · DELETE pscale api organizations/<org>/databases/<database>/branches/<branch> --format json |
schema <database> <branch> | ✅ | ✅ | ✅ | Both | ✅ | pscale api organizations/<org>/databases/<database>/branches/<branch>/schema --format json |
diff / promote | ✅ | ✅ | ✅ | Vitess | ✅ | pscale api organizations/<org>/databases/<database>/branches/<branch>/schema/lint --format json · POST pscale api organizations/<org>/databases/<database>/branches/<branch>/promote --format json |
connections | ✅ | ✅ | ✅ | Both | ✅ | pscale branch connections top <database> <branch> --org <org> --format json |
export PLANETSCALE_ORG="<org>"
pscale branch list <database> --format json
pscale branch show <database> <branch> --format json
Setup and commands to avoid: CLI overview · Service tokens
* Flag is required
Sub-command flag descriptions
Some of the sub-commands have additional flags unique to the sub-command. This section covers what each of those does. See the above table for which context.
| Sub-command flag | Description | Applicable sub-commands |
|---|
--from <SOURCE_BRANCH> | Parent branch that you want to create a new branch off of | create |
--region <BRANCH_REGION> | Region where database should be created | create |
--restore <BACKUP_NAME> | Create a new branch from a specified backup | create |
--seed-data | Create a new branch and seed data using the Data Branching® feature | create |
--web | Perform the action in your web browser | create, diff, list, schema, show |
--wait | Wait until the branch is ready | create |
--major-version | The major version of the branch (Postgres only). Currently supports 17 or 18. | create |
--database <DATABASE_NAME> | Specify the database name | switch |
--create | Create a new branch if it does not exist | switch |
--parent-branch <BRANCH_NAME> | If a new branch is being created, use this to specify a parent branch. Default is main. | switch |
--delete-descendants | Recursively delete all descendant branches when deleting a branch | delete |
--output <PATH> | Write the query patterns CSV report to a specific file path. | query-patterns download |
The --region flag can not be used with --restore when creating a branch. Branch backups will be restored to their original region.
Available flags
| Flag | Description |
|---|
-h, --help | View help for auth command |
--org <ORGANIZATION_NAME> | The organization for the current user |
Global flags
| Command | Description |
|---|
--api-token <TOKEN> | The API token to use for authenticating against the PlanetScale API. |
--api-url <URL> | The base URL for the PlanetScale API. Default is https://api.planetscale.com/. |
--config <CONFIG_FILE> | Config file. Default is $HOME/.config/planetscale/pscale.yml. |
--debug | Enable debug mode. |
-f, --format <FORMAT> | Show output in a specific format. Possible values: human (default), json, csv. |
--no-color | Disable color output. |
--service-token <TOKEN> | The service token for authenticating. |
--service-token-id <TOKEN_ID> | The service token ID for authenticating. |
Examples
The connections sub-command
Command:
pscale branch connections top <database> <branch>
Opens a live view of the branch’s connection activity. It works for Postgres and Vitess branches; for
Vitess, pass --keyspace and --shard to target a tablet, or run interactively to select them. See
the connections reference, Inspect live Postgres connections,
and Inspect live Vitess connections for the full workflow.
The query-patterns sub-command
Command:
pscale branch query-patterns download <DATABASE_NAME> <BRANCH_NAME> --org <ORGANIZATION_NAME>
Creates a Query Insights report for the branch, waits for it to finish generating, and downloads the
CSV file. Use --output to choose the file path. See the query-patterns reference
for the full workflow.
The list sub-command with --web flag
Command:
pscale branch list <DATABASE_NAME> --web
Output:
Opens the Branches page, <https://app.planetscale.com/org/database/branches>, in browser.
The diff sub-command
Command:
pscale branch diff <DATABASE_NAME> <BRANCH_NAME>
Output:
-- users --
+CREATE TABLE `users` (
+ `id` bigint unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
This will return the diff against the parent branch.
Need help?
Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.