plan command generates a migration plan to apply a desired schema state to a target database schema. It compares the desired state (from a file) with the current state of a specific schema and shows what changes would be applied.
Overview
The plan command follows infrastructure-as-code principles similar to Terraform:- Read the desired state from a SQL file (with include directive support)
- Apply the desired state SQL to a temporary PostgreSQL instance (embedded by default, or external via
--plan-*flags) - Connect to the target database and analyze current state of the specified schema
- Compare the two states
- Generate a detailed migration plan with proper dependency ordering
- Display the plan without making any changes
auth.users) work with the default embedded instance when you ignore those schemas. For PostgreSQL extensions, or when referenced tables are not on the target, see External Plan Database.
Basic Usage
Connection Options
string
default:"localhost"
Database server host (env: PGHOST)
integer
default:"5432"
Database server port (env: PGPORT)
string
required
Database name (required) (env: PGDATABASE)
string
required
Database user name (required) (env: PGUSER)
string
Database password (optional, can also use PGPASSWORD env var or .pgpass file)You can provide the password in multiple ways (in order of precedence):Password Resolution Order:
- Command line
--passwordflag (highest priority) PGPASSWORDenvironment variable.pgpassfile in user’s home directory- PostgreSQL will prompt for password if none found
string
default:"prefer"
SSL mode for database connection (env: PGSSLMODE)Valid values:
disable, allow, prefer, require, verify-ca, verify-fullFor verify-ca and verify-full modes, you can configure certificate paths using standard PostgreSQL environment variables (PGSSLROOTCERT, PGSSLCERT, PGSSLKEY).string
default:"public"
Schema name to target for comparison
Plan Database Options
By default, the plan command uses an embedded PostgreSQL instance to validate your desired state SQL. Cross-schema FKs to ignored tables are stubbed from the target automatically; extensions and other edge cases may need an external database. See External Plan Database for complete documentation.Plan Options
string
required
Path to desired state SQL schema file
string
Output human-readable format to stdout or file pathExamples:
--output-human stdout- Display to terminal--output-human plan.txt- Save to file
string
Output JSON format to stdout or file pathThis JSON format is the same format accepted by the apply command for executing migration plans.Examples:
--output-json stdout- Display to terminal--output-json plan.json- Save to file
string
Output SQL format to stdout or file pathExamples:
--output-sql stdout- Display to terminal--output-sql migration.sql- Save to file
boolean
default:"false"
Disable colored output for human format when writing to stdoutThis is useful for:
- Scripts and automation that need to parse output
- CI/CD environments that don’t support color codes
- Redirecting output to files where color codes are unwanted
Ignoring Objects
You can exclude specific database objects from migration planning using a.pgschemaignore file. See Ignore (.pgschemaignore) for complete documentation.
Examples
Default Human-Readable Output
JSON Output for Automation
SQL Migration Script
Plan for Specific Schema
Use Cases
Pre-deployment Validation
CI/CD Integration
Change Tracking
Multiple Output Formats
You can generate multiple output formats simultaneously:stdout. If no output flags are specified, the command defaults to human-readable output to stdout with colors enabled.
Comparison Direction
The plan command is unidirectional: it always plans changes from the current state (database) to the desired state (file).- Consistent infrastructure-as-code workflow
- Clear source of truth (the file)
- Predictable change direction

