{"id":51206074,"url":"https://github.com/jconway/pg_proc_diff","last_synced_at":"2026-06-28T03:04:30.505Z","repository":{"id":365761927,"uuid":"1273490356","full_name":"jconway/pg_proc_diff","owner":"jconway","description":"Detect and reconcile drift in PostgreSQL built-in functions by diffing a target database against the pristine template0 baseline on the same cluster.","archived":false,"fork":false,"pushed_at":"2026-06-18T18:37:59.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-06-18T20:15:05.636Z","etag":null,"topics":["cli","database-tools","dba","postgres","postgresql","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jconway.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-18T15:16:17.000Z","updated_at":"2026-06-18T18:57:04.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jconway/pg_proc_diff","commit_stats":null,"previous_names":["jconway/pg_proc_diff"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/jconway/pg_proc_diff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jconway%2Fpg_proc_diff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jconway%2Fpg_proc_diff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jconway%2Fpg_proc_diff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jconway%2Fpg_proc_diff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jconway","download_url":"https://codeload.github.com/jconway/pg_proc_diff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jconway%2Fpg_proc_diff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34875385,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","database-tools","dba","postgres","postgresql","python"],"created_at":"2026-06-28T03:04:30.423Z","updated_at":"2026-06-28T03:04:30.484Z","avatar_url":"https://github.com/jconway.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pg_proc_diff\n\n[![CI](https://github.com/jconway/pg_proc_diff/actions/workflows/ci.yml/badge.svg)](https://github.com/jconway/pg_proc_diff/actions/workflows/ci.yml)\n\nCompare built-in functions (`pg_catalog.pg_proc` rows with `oid \u003c 16384`) in a\n**target** database against the pristine **template0** baseline on the same\ncluster. Report differences and optionally emit SQL that brings a freshly\ncreated, template0-cloned database up to the target's state.\n\n## Requirements\n\n- Python 3, `psycopg2`\n- A superuser connection to the target (the tool temporarily toggles\n  `template0.datallowconn`, restoring it afterward)\n\n## Usage\n\n    python3 -m pg_proc_diff \"host=/tmp port=5432 user=postgres dbname=app\" \\\n        --emit-ddl app.sql\n\nOptions:\n\n- `--emit-ddl FILE`  write the make-it-match SQL to FILE\n- `--report-only`    print the difference report only; generate no SQL\n- `--no-acl`         skip ACL (`proacl`) differences\n- `--include-acl`    include ACL differences (default)\n- `-q, --quiet`      print only the summary line\n\nThe target conninfo must be in keyword/value form (e.g. `host=... dbname=...`),\nnot a URI, because the tool re-targets the connection to `template0`.\n\nExit codes: `0` no differences, `1` differences found, `2` error\n(e.g. not a superuser, cannot connect).\n\n## Output\n\nThe emitted SQL has three parts:\n\n1. **Runnable DDL** — `ALTER FUNCTION` / `GRANT` / `REVOKE` for attributes with a\n   clean mapping (cost, rows, volatility, strictness, security, leakproof,\n   parallel, support, rename, schema, owner, config, ACLs).\n2. **Commented-out catalog DML** — `UPDATE pg_catalog.pg_proc ...` for columns\n   with no clean DDL, wrapped in an `allow_system_table_mods` scaffold. Review\n   and uncomment to apply.\n3. **Manual notes** — `pg_node_tree` columns (`proargdefaults`, `prosqlbody`)\n   and functions present in only one database, which are reported but not\n   auto-applied.\n\n## Limitations\n\n- **`pg_node_tree` columns are report-only.** Drift in `proargdefaults`\n  (argument default expressions) or `prosqlbody` (SQL-language function bodies,\n  PG14+) is detected and reported, but no SQL is generated — these columns\n  reject literal input, so they cannot be safely reconstructed. Resolve them by\n  recreating the function manually.\n- **DML-fallback columns are emitted commented-out.** Identity- and\n  body-defining columns (`prolang`, `prokind`, `proretset`, `provariadic`,\n  `prorettype`, `proargtypes`, `proallargtypes`, `proargmodes`, `proargnames`,\n  `protrftypes`, `prosrc`, `probin`) have no clean DDL form, so the tool writes\n  raw `UPDATE pg_catalog.pg_proc` statements wrapped in an\n  `allow_system_table_mods` scaffold. These are **commented out** and require\n  manual review before applying — directly modifying system catalogs is\n  unsupported by PostgreSQL and can corrupt the catalog if done wrong.\n- **ACL diffing covers `EXECUTE` only.** `proacl` is the only privilege\n  meaningful for functions, so other privilege bits are ignored. A `NULL`\n  `proacl` is treated as the built-in default (EXECUTE granted to `PUBLIC`).\n- **Added/removed functions are report-only.** Functions present in just one of\n  the two databases are reported but never created or dropped; the diff is\n  keyed by `oid` and only generates SQL for functions that exist in both.\n- **Superuser required.** The tool temporarily toggles\n  `template0.datallowconn`, which only a superuser may do. Non-superuser\n  connections exit with code `2`.\n\n## Testing\n\nUnit tests (no database needed) and the catalog integration tests run via\n`unittest`:\n\n    python3 -m unittest discover -s tests\n\nThe integration tests are skipped unless `PGPROCDIFF_TEST_DSN` points at a\nsuperuser connection. GitHub Actions runs both, with integration coverage\nacross PostgreSQL 16, 17, 18, and 19beta1.\n\nFor a deeper end-to-end check against a live cluster, run the shakedown script:\n\n    PGPROCDIFF_SHAKEDOWN_DSN='host=/tmp port=5432 user=postgres' \\\n        scripts/shakedown_live.sh\n\nIt exercises behaviours the unit tests cannot: zero false positives on a clean\n`template0` clone, DDL/ACL drift detection plus reconciliation onto a fresh\nclone, the commented catalog-DML fallback path (when the server runs with\n`allow_system_table_mods=on`), and the `template0.datallowconn` restore\ninvariant under `SIGINT`. It also accepts an optional\n`PGPROCDIFF_SHAKEDOWN_REAL_DB=\u003cdbname\u003e` to assert that a real database has no\nbuilt-in drift.\n\n    PGPROCDIFF_SHAKEDOWN_REAL_DB='testdb' \\\n    PGPROCDIFF_SHAKEDOWN_DSN='host=/tmp port=5432 user=postgres' \\\n        scripts/shakedown_live.sh\n\n**Safety:** the script connects as a superuser and briefly toggles\n`template0.datallowconn` (always restored), and creates and drops scratch\ndatabases named `pgpd_shakedown_*`. Point it at a throwaway clone or staging\ncluster — never a production primary. With no `PGPROCDIFF_SHAKEDOWN_DSN` set it\nskips cleanly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjconway%2Fpg_proc_diff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjconway%2Fpg_proc_diff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjconway%2Fpg_proc_diff/lists"}