dump command extracts a PostgreSQL database schema for a specific schema and outputs it in a developer-friendly format. The dumped schema serves as a baseline that developers can modify and apply to target databases using the plan and apply commands.
Overview
The dump command provides comprehensive schema extraction with:- Single schema targeting (defaults to ‘public’)
- Dependency-aware object ordering
- Cross-schema reference handling with smart qualification
- Developer-friendly SQL output format
- Single-file and multi-file organization options
Basic Usage
Integration with Plan/Apply
Connection Options
Database server host (env: PGHOST)
Database server port (env: PGPORT)
Database name (required) (env: PGDATABASE)
Database user name (required) (env: PGUSER)
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
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).Schema name to dump
Output Options
Output schema to multiple files organized by object type. See Multi-file Schema Management Workflow.When enabled, creates a structured directory with:
- Main file with header and include statements
- Separate directories for different object types (tables, views, functions, etc.)
- Each database object in its own file
--file to specify the main output file path.Output file path (required when —multi-file is used)For single-file mode, this is optional (defaults to stdout).
For multi-file mode, this specifies the main file path.
Do not output object comment headers (e.g.,
-- Name: users; Type: TABLE; Schema: -; Owner: -).The dump header with pgschema version information is retained. This option is useful when you need pure DDL output without per-object commentary.Ignoring Objects
You can exclude specific database objects from dumps using a.pgschemaignore file. See Ignore (.pgschemaignore) for complete documentation.
Examples
Schema Dump
Multi-File Output
schema.sql file contains:
tables/users.sql) contains the specific object definition:
Schema Qualification
pgschema uses smart schema qualification to make dumps portable:
- Objects within the dumped schema: No schema qualifier added
- Objects from other schemas: Fully qualified with schema name

