Command-line tool for extracting object definitions from a PostgreSQL database.
Find a file
2026-05-19 15:07:51 -05:00
.github Add community health files and templates 2026-04-20 12:21:17 -05:00
.gitignore Initial commit. 2026-03-19 10:27:00 -05:00
CODE_OF_CONDUCT.md Add community health files and templates 2026-04-20 12:21:17 -05:00
CONTRIBUTING.md Add community health files and templates 2026-04-20 12:21:17 -05:00
Directory.Build.props Add automated version bump on merge to main 2026-04-08 14:36:28 -05:00
global.json Add automated version bump on merge to main 2026-04-08 14:36:28 -05:00
LICENSE Initial commit 2026-03-19 10:12:17 -05:00
pg-extract-schema.csproj Initial commit. 2026-03-19 10:27:00 -05:00
pg-extract-schema.sln Initial commit. 2026-03-19 10:27:00 -05:00
Program.cs Add --include-pg-toast command-line option 2026-05-19 15:05:49 -05:00
README.md Add --include-pg-toast command-line option 2026-05-19 15:05:49 -05:00
SchemaExtractor.cs Add --include-pg-toast command-line option 2026-05-19 15:05:49 -05:00
SECURITY.md Add community health files and templates 2026-04-20 12:21:17 -05:00

pg-extract-schema by Hannah Vernon

Overview

This project is designed to extract schema information from PostgreSQL databases in an efficient and comprehensive manner.

Features

  • Extracts DDL for the following object types, each into discrete .sql files:
    • Extensions
    • Schemas
    • Sequences (with full attributes)
    • Types (enums, composites, and domains)
    • Tables (with columns, defaults, primary keys, unique constraints, check constraints, and comments)
    • Indexes (non-PK, non-unique-constraint)
    • Foreign keys
    • Views
    • Materialized views
    • Functions and procedures
    • Triggers

Requirements

  • PostgreSQL 9.6 or later.
  • DotNet 9.0 Runtime or later.

Installation

  1. Clone the repository:
    git clone https://github.com/HannahVernon/pg-extract-schema.git
    cd pg-extract-schema
    
  2. Install dependencies
    winget install Microsoft.DotNet.SDK.9
    
  3. Build the binaries.
    dotnet build
    

Usage

Run the executable with appropriate parameters:

Description:
  Extract DDL from a PostgreSQL database into discrete .sql files

Usage:
  pg-extract-schema [options]

Options:
  -h, --host <host> (REQUIRED)          PostgreSQL server hostname
  -p, --port <port>                     PostgreSQL server port [default: 5432]
  -d, --database <database> (REQUIRED)  Database name
  -s, --schema <schema>                 Schema name (default: all non-system schemas)
  -o, --output <output>                 Output directory [default: output]
  -U, --username <username>             PostgreSQL username [default: postgres]
  -W, --password <password>             PostgreSQL password (or set PGPASSWORD env var).  If password is not supplied on the command-line or via the environment variable, pg-extract-schema will ask for the password.
  --include-postgres-system-objects     Include PostgreSQL system schemas (pg_catalog, pg_toast, information_schema, pg_temp) and the plpgsql extension [default: False]
  --include-pg-toast                    Include pg_toast schema objects (excluded by default) [default: False]
  --version                             Show version information
  -?, -h, --help                        Show help and usage information

Examples

pg-extract-schema.exe -h mypgserver -p 5432 -d mydatabase -U me -o c:\temp\pg_schema

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-foo).
  3. Make your changes and commit them (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature-foo).
  5. Open a pull request.

Support

For support, please open an issue in the GitHub repository. We will try to respond as quickly as possible.

Changelog

[1.0.0] - 2026-03-19

  • Initial release