dump --multi-file option allows you to split your schema into modular files organized by database objects, enabling better collaboration, clearer ownership, and easier maintenance.
This approach is ideal for:
- Large schemas with hundreds of tables, views, and functions
- Teams where different developers/teams own different parts of the schema
- Schemas that need granular code review processes
Workflow
Step 1: Initialize Multi-File Structure
Set up your schema directory structure and dump your existing schema into multiple files:Step 2: Development Workflow
Use the multi-file structure to define the desired state of your schema components:Step 3: Team Collaboration
Teams work on separate branches and test independently before combining changes for production deployment:Step 4: Production Deployment
Deploy schema changes safely to production using the established multi-file workflow:Ordering Requirements
pgschema applies your schema files in the order of their\i directives (and alphabetically within folder includes) to build the desired state. Most objects resolve regardless of order, but some objects depend on others existing at creation time. When a dependency is created after the object that references it, you’ll see an error such as:
recipe_user_save table must be included before the function. Other cases that require the referenced object first include %ROWTYPE parameters, table- or composite-typed arguments, and domains used in table columns.
Schema qualification (
public.recipe_user_save) does not affect this — pgschema strips the target-schema prefix internally. Only the include order matters.dump --multi-file output already orders directives correctly (types → tables → views → functions → indexes), so this only comes up when you reorganize files yourself. If you use Custom Organization, make sure tables (and any other referenced objects) are included before the functions, views, and procedures that depend on them:
File Organization Strategies
By Object Type (Default)
pgschema generates files organized by database object type:Custom Organization
You can reorganize files into any structure you prefer and update the\i directives in main.sql:
By Business Domain
main.sql to match your structure:
Hybrid Approach
main.sql file contains the correct \i directives that match your chosen file organization.
Folder Includes
The\i directive supports including entire folders by adding a trailing slash (/). This automatically includes all .sql files in the folder in alphabetical order, and recursively processes any subdirectories:
main.sql:
- Files are processed in alphabetical order by filename
- Subdirectories are processed recursively using depth-first search
- Only
.sqlfiles are included; other files are ignored - Folder paths must end with
/to be recognized as folders - Error if folder doesn’t exist or if you try to include a file as a folder
Nested Includes
The\i directive can be nested, allowing for hierarchical file organization:

