A tool to generate Markdown documentation for PostgreSQL database schemas.
- Extracts table structure (columns, types, constraints, defaults)
- Extracts column comments from PostgreSQL
pg_descriptionsystem catalog - Extracts index and constraint information
- Extracts table comments
- Creates a template for documentation on the first run
- Preserves manual documentation (everything after
## Notes) when regenerating
go mod download
go build -o dbdocs .To install the latest tagged version:
go install github.com/birkirb/dbdocs@latestTo install a specific version:
go install github.com/birkirb/dbdocs@v1.0.0Note: When installing via go install, the version will be automatically detected from git tags. For proper version information, install from a tagged release rather than @main.
./dbdocs -d <database_name> [options]-d, --database: Database name (required)-h, --hostname: Server hostname (default: localhost)-P, --port: Database port (default: 5432)-u, --username: Username to connect as (default: postgres)-p, --password: User's password (will prompt if not provided)-s, --schema: Schema name (default: public)-t, --tables: List of tables to scan (omit for all tables)-o, --output: Output folder path (default: ./)--version: Print version and exit
./dbdocs -d mydb -u postgres -h localhost -s public -o ./docs/The tool generates a Markdown file for each table with the following structure:
- Table Name (H1 header)
- Table Comment (if present)
- Table Schema (Field, Type, Null, Key, Default, Extra columns)
- Column Comments (if any columns have comments)
- Indices (Primary keys, unique constraints, indexes, foreign keys)
- Index Comments (if any indexes have comments)
- Notes (preserved from previous runs)
All content after the ## Notes section is considered manual documentation and will be preserved when the tool is run again. This includes:
- The
## Notessection itself - Any
## Columnssection - Any other custom sections you add