Analyze PostgreSQL Call Graphs and Query Plans with Safegres
Dan Lynch
Use the rule reference to look up a finding. Then choose a check for what the regular audit couldn't answer.
Look at functions and query plans
bashpnpm exec safegres audit --call-graph --verbose pnpm exec safegres audit --perf --explain
The call graph shows where privileged paths cross a boundary, such as an exposed definer routine reaching an internal table (CG4). It's separate from the security grade. Capture reviewed findings with --write-baseline; enforce with --baseline and --fail-on-new-boundaries.
--perf adds a separate performance grade. On the course's Postgres 18 image, --explain checks index findings with generic plans, not executed queries. Use --stats only where real workload counters have accumulated. Statement hotspots require pg_stat_statements.
Make an evaluation reproducible
Use a sealed audit when local configuration must not change the evaluation policy:
bashpnpm exec safegres audit --pgpm . --sealed --preset recommended --out safegres-reports/sealed pnpm exec safegres eval --list
A sealed audit ignores the workspace config, so pass --pgpm . explicitly. It rejects local rule, exposure, and baseline overrides. Verify the recorded fingerprint with --verify-fingerprint. A sealed grade doesn't replace a grade scoped to your actual app.
eval tests the auditor against known-answer cases. Run it on a separate disposable database; it creates and removes schemas. Use --case to narrow the suite or --corpus for your own cases with case.json and schema.sql.
For scripts or test suites, see the library API, including auditPgpmWorkspace from safegres/pgpm-test.

