psqldef (sqldef)
$ psqldef Official Med Riskpsqldef (part of the sqldef suite alongside mysqldef, sqlite3def, and mssqldef) computes idempotent PostgreSQL DDL diffs between a local schema.sql file and a live database. Supports --export for schema dumps and --dry-run / --check for zero-mutation previews.
brew install sqldef/sqldef/psqldef psqldef reads local schema.sql files via stdin/file flags and computes exact idempotent PostgreSQL DDL diffs locally.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Supports --dry-run, --check (exit code 2 on drift), --export, and stdin piping with deterministic CLI flags, though output is SQL DDL rather than JSON.
- Built-in
--dry-run,--check, and--exportflags - Outputs SQL DDL text rather than structured JSON
Skips destructive DROP statements by default unless --enable-drop is passed, and --dry-run makes pre-flight inspection effortless.
- Safe-by-default drop suppression without
--enable-drop --dry-runpreviews exact SQL without mutations
Single static Go binary available via Homebrew tap, go install, and GitHub releases for macOS, Linux, and Windows.
- Static Go binary with
brew install sqldef/sqldef/psqldef
Idempotent single-file schema.sql workflow eliminates migration folder bookkeeping for straightforward PostgreSQL schemas.
- Converges live DB from single declarative
schema.sql
Actively maintained sqldef/sqldef organization under MIT license with wide production adoption.
- Maintained at
github.com/sqldef/sqldef
Clear README and command usage examples covering flags, --config, and supported PostgreSQL DDL features.
- Well-documented flags and examples in
sqldefREADME
Security, Auth & Guardrails
Reads PGPASSWORD, PGHOST, PGUSER, PGSSLMODE, or psqldef -h/-U/-W flags; supports YAML config files via --config.
MIT open-source CLI (internal SQL parser under Apache-2.0); completely free.
# psqldef (sqldef) Agent Rules - Always run `psqldef ... --dry-run < schema.sql` before applying changes. - Never pass `--enable-drop` without explicit user review of the dry-run DDL output.
Agent-Ready Command Recipes
Safe Read-Only Queries
psqldef -h localhost -U postgres mydb --export
Dumps the current database DDL in normalized sqldef format without modifying anything.
psqldef -h localhost -U postgres mydb --dry-run < schema.sql
Prints exact ALTER/CREATE/DROP statements needed to converge without applying them.
Controlled Writes & Previews
psqldef -h localhost -U postgres mydb --file schema.sql
Applies non-drop DDL changes to converge the database to schema.sql (skips DROP unless --enable-drop is set).
Strengths for Agents
- + First-class
--dry-run,--check, and--exportflags fit CI and agent pre-flight checks. - + Suppresses
DROPoperations by default unless--enable-dropis explicitly provided. - + Fast, single Go binary with
psql-compatible connection flags and env vars.
Caveats & Pitfalls
- ! Outputs raw SQL DDL rather than
--jsondiagnostics. - ! Advanced PostgreSQL features (custom procedural triggers or complex extensions) may require workarounds outside
schema.sql.