Install and set up
-
Get a PostgreSQL with pledge. Pick one:
The repository comes with a Docker setup: PostgreSQL 18 with pledge already installed. From the repository root, run:
docker compose up -d --wait dbThe first run builds the image, which takes a few minutes.
It listens on
localhost:5432. User, password and database are allpledge.You need Rust and cargo-pgrx 0.19.3. Then build and install into your own PostgreSQL 18:
cargo pgrx init --pg18 $(which pg_config) cargo pgrx install --release --pg-config $(which pg_config)For PostgreSQL 17, use
--pg17and add--no-default-features --features pg17. -
Create the extension. Connect as a superuser and run:
CREATE EXTENSION pledge;Everything pledge adds lives in the
pledgeschema. Your own tables are not touched. -
Give your app access. Your app should connect with its own role, not a superuser. Run this once per database, replacing
appwith your role name:GRANT USAGE ON SCHEMA pledge TO app; GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA pledge TO app; GRANT SELECT ON pledge.accounts_view, pledge.transfers_view, pledge.entries_view TO app; GRANT SELECT, INSERT, UPDATE ON pledge.accounts, pledge.transfers, pledge.entries TO app; -
Check it works.
SELECT * FROM pledge.verify();Every row should say
ok = t.
Don’t grant DELETE or TRUNCATE. Ledger rows are never removed, and pledge rejects it anyway.
The Django app can run CREATE EXTENSION for you in a migration. See
Django setup.
Next: create some accounts.