pg_policy
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_policy | 0.1.0 | SEC | PostgreSQL | SQL |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 7440 | pg_policy | No | No | No | Yes | No | No | policy |
PIGSTY patches the reserved upstream schema pg_policy to policy and quotes the reserved check function, so the packaged API is policy.check() rather than pg_policy.check(); pure SQL and PL/pgSQL, no preload.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.1.0 | 1817161514 | pg_policy | - |
| RPM | PIGSTY | 0.1.0 | 1817161514 | pg_policy_$v | - |
| DEB | PIGSTY | 0.1.0 | 1817161514 | postgresql-$v-pg-policy | - |
| OS / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 0.1.0 el8.x86_64.pg18 : pg_policy_18 pg_policy_18-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.x86_64.pg17 : pg_policy_17 pg_policy_17-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.x86_64.pg16 : pg_policy_16 pg_policy_16-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.x86_64.pg15 : pg_policy_15 pg_policy_15-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.x86_64.pg14 : pg_policy_14 pg_policy_14-0.1.0-1PIGSTY.el8.noarch.rpm
|
| el8.aarch64 | PIGSTY 0.1.0 el8.aarch64.pg18 : pg_policy_18 pg_policy_18-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.aarch64.pg17 : pg_policy_17 pg_policy_17-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.aarch64.pg16 : pg_policy_16 pg_policy_16-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.aarch64.pg15 : pg_policy_15 pg_policy_15-0.1.0-1PIGSTY.el8.noarch.rpm
| PIGSTY 0.1.0 el8.aarch64.pg14 : pg_policy_14 pg_policy_14-0.1.0-1PIGSTY.el8.noarch.rpm
|
| el9.x86_64 | PIGSTY 0.1.0 el9.x86_64.pg18 : pg_policy_18 pg_policy_18-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.x86_64.pg17 : pg_policy_17 pg_policy_17-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.x86_64.pg16 : pg_policy_16 pg_policy_16-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.x86_64.pg15 : pg_policy_15 pg_policy_15-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.x86_64.pg14 : pg_policy_14 pg_policy_14-0.1.0-1PIGSTY.el9.noarch.rpm
|
| el9.aarch64 | PIGSTY 0.1.0 el9.aarch64.pg18 : pg_policy_18 pg_policy_18-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.aarch64.pg17 : pg_policy_17 pg_policy_17-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.aarch64.pg16 : pg_policy_16 pg_policy_16-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.aarch64.pg15 : pg_policy_15 pg_policy_15-0.1.0-1PIGSTY.el9.noarch.rpm
| PIGSTY 0.1.0 el9.aarch64.pg14 : pg_policy_14 pg_policy_14-0.1.0-1PIGSTY.el9.noarch.rpm
|
| el10.x86_64 | PIGSTY 0.1.0 el10.x86_64.pg18 : pg_policy_18 pg_policy_18-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.x86_64.pg17 : pg_policy_17 pg_policy_17-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.x86_64.pg16 : pg_policy_16 pg_policy_16-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.x86_64.pg15 : pg_policy_15 pg_policy_15-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.x86_64.pg14 : pg_policy_14 pg_policy_14-0.1.0-1PIGSTY.el10.noarch.rpm
|
| el10.aarch64 | PIGSTY 0.1.0 el10.aarch64.pg18 : pg_policy_18 pg_policy_18-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.aarch64.pg17 : pg_policy_17 pg_policy_17-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.aarch64.pg16 : pg_policy_16 pg_policy_16-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.aarch64.pg15 : pg_policy_15 pg_policy_15-0.1.0-1PIGSTY.el10.noarch.rpm
| PIGSTY 0.1.0 el10.aarch64.pg14 : pg_policy_14 pg_policy_14-0.1.0-1PIGSTY.el10.noarch.rpm
|
| d12.x86_64 | PIGSTY 0.1.0 d12.x86_64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.x86_64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.x86_64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.x86_64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.x86_64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
|
| d12.aarch64 | PIGSTY 0.1.0 d12.aarch64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.aarch64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.aarch64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.aarch64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
| PIGSTY 0.1.0 d12.aarch64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~bookworm_all.deb
|
| d13.x86_64 | PIGSTY 0.1.0 d13.x86_64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.x86_64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.x86_64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.x86_64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.x86_64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~trixie_all.deb
|
| d13.aarch64 | PIGSTY 0.1.0 d13.aarch64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.aarch64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.aarch64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.aarch64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~trixie_all.deb
| PIGSTY 0.1.0 d13.aarch64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~trixie_all.deb
|
| u22.x86_64 | PIGSTY 0.1.0 u22.x86_64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.x86_64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.x86_64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.x86_64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.x86_64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~jammy_all.deb
|
| u22.aarch64 | PIGSTY 0.1.0 u22.aarch64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.aarch64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.aarch64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.aarch64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~jammy_all.deb
| PIGSTY 0.1.0 u22.aarch64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~jammy_all.deb
|
| u24.x86_64 | PIGSTY 0.1.0 u24.x86_64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.x86_64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.x86_64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.x86_64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.x86_64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~noble_all.deb
|
| u24.aarch64 | PIGSTY 0.1.0 u24.aarch64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.aarch64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.aarch64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.aarch64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~noble_all.deb
| PIGSTY 0.1.0 u24.aarch64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~noble_all.deb
|
| u26.x86_64 | PIGSTY 0.1.0 u26.x86_64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.x86_64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.x86_64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.x86_64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.x86_64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~resolute_all.deb
|
| u26.aarch64 | PIGSTY 0.1.0 u26.aarch64.pg18 : postgresql-18-pg-policy postgresql-18-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.aarch64.pg17 : postgresql-17-pg-policy postgresql-17-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.aarch64.pg16 : postgresql-16-pg-policy postgresql-16-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.aarch64.pg15 : postgresql-15-pg-policy postgresql-15-pg-policy_0.1.0-1PGSTY~resolute_all.deb
| PIGSTY 0.1.0 u26.aarch64.pg14 : postgresql-14-pg-policy postgresql-14-pg-policy_0.1.0-1PGSTY~resolute_all.deb
|
Build
You can build the RPM / DEB packages for pg_policy using pig build:
Install
You can install pg_policy directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
Sources:
- pg_policy 0.1.0 on PGXN
- pg_policy 0.1.0 README
- Agent Policy Language reference
- pg_policy 0.1.0 security policy
- pg_policy 0.1.0 control file
- pg_policy 0.1.0 extension SQL
- Pigsty pg_policy package page
pg_policy 0.1.0 is an experimental SQL and PL/pgSQL policy evaluator for agent and tool actions. It stores Agent Policy Language rules, evaluates context and session history, records every decision, and returns obligations for a gateway to enforce. It complements PostgreSQL roles and row-level security; it does not intercept SQL or tool calls by itself.
Pigsty Schema Compatibility
Upstream 0.1.0 declares the reserved schema name pg_policy and defines an unquoted function named check. Pigsty packages patch the installed schema to policy, quote the reserved function name as policy."check"(), and fix function search paths. The upstream examples therefore cannot be copied verbatim into a Pigsty installation.
The extension is not relocatable, requires PostgreSQL 14 or later, and does not require shared_preload_libraries or a PostgreSQL restart. Current Pigsty packages cover PostgreSQL 14–18.
Define and Evaluate a Guardrail
policy.evaluate(...) returns JSON containing decision, allowed, matched_policies, obligations, reasons, and mode. The convenience wrapper policy."check"() returns only a boolean. policy.enforce() requests exception-on-deny behavior when the mode is enforce.
APL Surface
An APL document begins with one effect: permit, forbid, or guide. It can match principal, action, and resource types and identifiers. In 0.1.0, context conditions support only ==, in [...], and and. A temporal clause can count matching session events inside an interval when evaluation receives a session identifier.
forbid overrides matching permit rules. guide allows the action and can return advice, prefer_tool, or max_rows obligations. The caller—not the extension—must interpret and apply those obligations.
Sessions, Temporal Limits, and Audit
policy.open_session() creates or updates a session. Evaluations with a session identifier append an event and can satisfy temporal predicates. Every evaluation writes policy.decision_log; other important relations are policy.policies, policy.sessions, policy.events, and policy.settings.
Enforcement and Security Boundaries
- The default
enforcement_modeislog_onlyand the default decision ispermit. A matched deny becomes an allow with ashadow_denyobligation. - In
guidemode, a matched deny becomes an allow withwould_deny. Onlyenforcepreserves a deny and allowspolicy.enforce()to raise an error. - A gateway must call the evaluator before the protected action and hard-fail on deny. Calling
policy.evaluate(...)after executing a tool is only auditing. - Keep PostgreSQL
GRANTandREVOKE, row-level security, network controls, and least-privilege credentials as the authoritative data-plane controls. Superusers and roles withBYPASSRLScan bypass row-level controls. - The 0.1 line is explicitly an experimental MVP, not a hardened production security boundary. Shadow-test policies, restrict who can change
policy.settingsorpolicy.policies, and monitorpolicy.decision_logbefore switching toenforce.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)