> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/pocketbase/pocketbase/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI Reference

> Complete reference for all PocketBase CLI commands and flags

PocketBase provides a powerful command-line interface for managing your backend. This page documents all available commands and their flags.

## Global Flags

These flags are available for all commands and should be specified before the command name.

<ParamField path="--dir" type="string" default="./pb_data">
  The PocketBase data directory where your database, migrations, and settings are stored.

  ```bash theme={null}
  ./pocketbase --dir=/custom/path serve
  ```
</ParamField>

<ParamField path="--encryptionEnv" type="string">
  The environment variable name whose value (32 characters) will be used as the encryption key for app settings.

  ```bash theme={null}
  export PB_ENCRYPTION_KEY="your-32-character-secret-key"
  ./pocketbase --encryptionEnv=PB_ENCRYPTION_KEY serve
  ```
</ParamField>

<ParamField path="--dev" type="boolean" default="false">
  Enable development mode, which prints logs and SQL statements to the console for debugging.

  ```bash theme={null}
  ./pocketbase --dev serve
  ```
</ParamField>

<ParamField path="--queryTimeout" type="integer" default="30">
  The default timeout for SELECT queries in seconds.

  ```bash theme={null}
  ./pocketbase --queryTimeout=60 serve
  ```
</ParamField>

***

## serve

Starts the PocketBase web server with optional automatic HTTPS via Let's Encrypt.

```bash theme={null}
# Start on default port (127.0.0.1:8090)
./pocketbase serve

# Start with custom HTTP address
./pocketbase serve --http=0.0.0.0:8080

# Start with automatic HTTPS for domain(s)
./pocketbase serve --https=0.0.0.0:443 yourdomain.com

# Multiple domains with auto HTTPS
./pocketbase serve yourdomain.com api.yourdomain.com
```

### Usage

```bash theme={null}
./pocketbase serve [domain(s)] [flags]
```

### Flags

<ParamField path="--http" type="string" default="127.0.0.1:8090">
  TCP address to listen for HTTP requests.

  * **Default (no domains)**: `127.0.0.1:8090`
  * **Default (with domains)**: `0.0.0.0:80`

  ```bash theme={null}
  ./pocketbase serve --http=0.0.0.0:8080
  ```
</ParamField>

<ParamField path="--https" type="string">
  TCP address to listen for HTTPS requests with automatic TLS certificate management via Let's Encrypt.

  * **Default (no domains)**: empty (no TLS)
  * **Default (with domains)**: `0.0.0.0:443`

  When enabled, HTTP traffic is automatically redirected to HTTPS.

  ```bash theme={null}
  ./pocketbase serve --https=0.0.0.0:443 yourdomain.com
  ```
</ParamField>

<ParamField path="--origins" type="string[]" default="[&#x22;*&#x22;]">
  CORS allowed domain origins list. Use this to restrict which domains can access your PocketBase API.

  ```bash theme={null}
  # Single origin
  ./pocketbase serve --origins="https://example.com"

  # Multiple origins
  ./pocketbase serve --origins="https://example.com,https://app.example.com"
  ```
</ParamField>

### Domain Parameters

When you provide domain names as arguments, PocketBase automatically:

* Obtains and manages Let's Encrypt TLS certificates
* Sets default HTTP address to `0.0.0.0:80`
* Sets default HTTPS address to `0.0.0.0:443`
* Redirects HTTP traffic to HTTPS

```bash theme={null}
# Single domain
./pocketbase serve yourdomain.com

# Multiple domains
./pocketbase serve yourdomain.com api.yourdomain.com www.yourdomain.com
```

<Note>
  For automatic HTTPS to work, your domain(s) must point to your server's public IP address and ports 80 and 443 must be accessible.
</Note>

***

## superuser

Manage superuser accounts for administrative access to your PocketBase instance.

### superuser create

Creates a new superuser account.

```bash theme={null}
./pocketbase superuser create test@example.com MySecureP@ssw0rd
```

<CodeGroup>
  ```bash Success theme={null}
  ./pocketbase superuser create admin@example.com SecurePassword123
  # Successfully created new superuser "admin@example.com"!
  ```

  ```bash Error theme={null}
  ./pocketbase superuser create admin@example.com short
  # Error: password validation failed
  ```
</CodeGroup>

### superuser update

Changes the password of an existing superuser.

```bash theme={null}
./pocketbase superuser update test@example.com NewSecureP@ssw0rd
```

<Warning>
  The superuser must already exist. Use `superuser create` for new accounts or `superuser upsert` to create or update.
</Warning>

### superuser upsert

Creates a new superuser or updates the password if the email already exists.

```bash theme={null}
./pocketbase superuser upsert admin@example.com MyP@ssw0rd123
```

This is the recommended command when you want to ensure a superuser exists with a specific password, regardless of whether the account already exists.

### superuser delete

Deletes an existing superuser account.

```bash theme={null}
./pocketbase superuser delete test@example.com
```

<CodeGroup>
  ```bash Success theme={null}
  ./pocketbase superuser delete old@example.com
  # Successfully deleted superuser "old@example.com"!
  ```

  ```bash Not Found theme={null}
  ./pocketbase superuser delete nonexistent@example.com
  # superuser "nonexistent@example.com" is missing or already deleted
  ```
</CodeGroup>

### superuser otp

Creates a new one-time password (OTP) for the specified superuser account.

```bash theme={null}
./pocketbase superuser otp admin@example.com
```

Output example:

```
Successfully created OTP for superuser "admin@example.com":
├─ Id:    abc123def456
├─ Pass:  123456
└─ Valid: 180s
```

<Note>
  OTP authentication must be enabled for the `_superusers` collection for this command to work. The OTP length and validity duration are configured in the collection settings.
</Note>

***

## migrate

Executes database migration scripts. This command is available when the `migratecmd` plugin is registered.

### Usage

```bash theme={null}
./pocketbase migrate [command] [flags]
```

### Commands

<ParamField path="up">
  Runs all available migrations that haven't been applied yet.

  ```bash theme={null}
  ./pocketbase migrate up
  ```
</ParamField>

<ParamField path="down [number]">
  Reverts the last `[number]` applied migrations.

  ```bash theme={null}
  # Revert last migration
  ./pocketbase migrate down 1

  # Revert last 3 migrations
  ./pocketbase migrate down 3
  ```
</ParamField>

<ParamField path="create [name]">
  Creates a new blank migration template file with the specified name.

  ```bash theme={null}
  ./pocketbase migrate create add_users_table
  # Creates: migrations/1234567890_add_users_table.go
  ```
</ParamField>

<ParamField path="collections">
  Creates a new migration file with a snapshot of the current collections configuration.

  ```bash theme={null}
  ./pocketbase migrate collections
  # Creates: migrations/1234567890_collections_snapshot.go
  ```

  This is useful for version controlling your schema changes.
</ParamField>

<ParamField path="history-sync">
  Ensures that the `_migrations` history table doesn't have references to deleted migration files.

  ```bash theme={null}
  ./pocketbase migrate history-sync
  ```
</ParamField>

### Examples

<CodeGroup>
  ```bash Create Migration theme={null}
  ./pocketbase migrate create add_verified_field
  # Do you really want to create migration "migrations/1234567890_add_verified_field.go"?
  # Successfully created file "migrations/1234567890_add_verified_field.go"
  ```

  ```bash Run Migrations theme={null}
  ./pocketbase migrate up
  # Running system migrations...
  # Running app migrations...
  # Applied 1234567890_add_verified_field.go
  ```

  ```bash Collections Snapshot theme={null}
  ./pocketbase migrate collections
  # Creates a snapshot of all collections
  # Successfully created file "migrations/1234567890_collections_snapshot.go"
  ```
</CodeGroup>

<Note>
  Migration files are created in the `migrations/` directory by default (Go templates) or `pb_migrations/` (JavaScript templates). The directory can be customized via plugin configuration.
</Note>

***

## update

Automatically updates the current PocketBase executable with the latest available version from GitHub releases. This command is available when the `ghupdate` plugin is registered.

```bash theme={null}
./pocketbase update
```

### Flags

<ParamField path="--backup" type="boolean" default="true">
  Creates a backup of the `pb_data` directory at the end of the update process.

  ```bash theme={null}
  # Update without creating a backup
  ./pocketbase update --backup=false

  # Update with backup (default)
  ./pocketbase update --backup=true
  ```
</ParamField>

### Process

When you run the update command, PocketBase will:

1. Fetch the latest release information from GitHub
2. Compare versions and skip if already up to date
3. Download the appropriate release for your platform
4. Extract the new executable
5. Replace the current executable
6. Create a backup (if `--backup=true`)
7. Display release notes

### Example Output

```bash theme={null}
./pocketbase update

# Fetching release information...
# Downloading pocketbase_0.23.0_linux_amd64.zip...
# Extracting pocketbase_0.23.0_linux_amd64.zip...
# Replacing the executable...
# Creating pb_data backup...
# ---
# Update completed successfully! You can start the executable as usual.
#
# Here is a list with some of the v0.23.0 changes:
# - Added new feature X
# - Fixed bug Y
# - Improved performance Z
```

<Warning>
  The update command may not work as expected in Docker containers or NixOS environments. PocketBase will warn you if it detects these environments and ask for confirmation before proceeding.
</Warning>

***

## version

Displays the current PocketBase version.

```bash theme={null}
./pocketbase version
# pocketbase version 0.23.0

./pocketbase --version
# pocketbase version 0.23.0
```

***

## help

Displays help information for PocketBase commands.

```bash theme={null}
# General help
./pocketbase --help

# Help for specific command
./pocketbase serve --help
./pocketbase superuser --help
./pocketbase migrate --help
```

***

## Example Workflows

### Development Setup

```bash theme={null}
# Start in development mode with custom data directory
./pocketbase --dev --dir=./dev_data serve
```

### Production Deployment

```bash theme={null}
# Production setup with HTTPS and CORS
./pocketbase serve \
  --https=0.0.0.0:443 \
  --origins="https://app.example.com,https://www.example.com" \
  example.com
```

### Initial Setup

```bash theme={null}
# 1. Create superuser
./pocketbase superuser create admin@example.com SecurePassword123

# 2. Start server
./pocketbase serve
```

### Migration Workflow

```bash theme={null}
# 1. Make schema changes in Admin UI
# (Create/modify collections)

# 2. Create migration snapshot
./pocketbase migrate collections

# 3. Apply migrations (on another environment)
./pocketbase migrate up
```

### Backup Before Update

```bash theme={null}
# Update with automatic backup
./pocketbase update

# Backups are stored in pb_data/backups/@update_v0.23.0.zip
```
