Skip to content

pg_agent_gate

SQL proposal, verification and execution gate with human approval for agent roles.

pg_agent_gate · SQL proposal, verification and execution gate with human approval for agent roles.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
7470pg_agent_gatepg_agent_gate0.4.4SECApache-2.0Rust
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Relationships
Schemasagent_gate agent_gate_internal
See Alsopg_living_assertions pg_policy
Preload before agent statements. Requires READ COMMITTED. Trusted code and external effects remain outside the sandbox.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY0.4.419 18 17 16 15pg_agent_gate-
RPMPIGSTY0.4.419 18 17 16 15pg_agent_gate_$v-
DEBPIGSTY0.4.419 18 17 16 15postgresql-$v-pg-agent-gate-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 0.4.1N/AN/AN/A
el8.aarch64N/APIGSTY 0.4.1N/AN/AN/A
el9.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
el9.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
el10.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
el10.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
d12.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
d12.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
d13.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
d13.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
u22.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
u22.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
u24.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
u24.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
u26.x86_64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
u26.aarch64PIGSTY 0.4.4PIGSTY 0.4.4N/AN/AN/A
PackageVersionOSORGSIZEFile URL
pg_agent_gate_190.4.4el9.x86_64pigsty500.4 KiBpg_agent_gate_19-0.4.4-1PGSTY.el9.x86_64.rpm
pg_agent_gate_190.4.4el9.aarch64pigsty479.6 KiBpg_agent_gate_19-0.4.4-1PGSTY.el9.aarch64.rpm
pg_agent_gate_190.4.4el10.x86_64pigsty500.9 KiBpg_agent_gate_19-0.4.4-1PGSTY.el10.x86_64.rpm
pg_agent_gate_190.4.4el10.aarch64pigsty480.4 KiBpg_agent_gate_19-0.4.4-1PGSTY.el10.aarch64.rpm
postgresql-19-pg-agent-gate0.4.4d12.x86_64pigsty412.2 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~bookworm_amd64.deb
postgresql-19-pg-agent-gate0.4.4d12.aarch64pigsty365.5 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~bookworm_arm64.deb
postgresql-19-pg-agent-gate0.4.4d13.x86_64pigsty412.3 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~trixie_amd64.deb
postgresql-19-pg-agent-gate0.4.4d13.aarch64pigsty367.3 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~trixie_arm64.deb
postgresql-19-pg-agent-gate0.4.4u22.x86_64pigsty420.8 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~jammy_amd64.deb
postgresql-19-pg-agent-gate0.4.4u22.aarch64pigsty396.8 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~jammy_arm64.deb
postgresql-19-pg-agent-gate0.4.4u24.x86_64pigsty466.6 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~noble_amd64.deb
postgresql-19-pg-agent-gate0.4.4u24.aarch64pigsty391.9 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~noble_arm64.deb
postgresql-19-pg-agent-gate0.4.4u26.x86_64pigsty414.7 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~resolute_amd64.deb
postgresql-19-pg-agent-gate0.4.4u26.aarch64pigsty391.0 KiBpostgresql-19-pg-agent-gate_0.4.4-1PGSTY~resolute_arm64.deb
PackageVersionOSORGSIZEFile URL
pg_agent_gate_180.4.1el8.x86_64pigsty538.8 KiBpg_agent_gate_18-0.4.1-1PGSTY.el8.x86_64.rpm
pg_agent_gate_180.4.1el8.aarch64pigsty470.2 KiBpg_agent_gate_18-0.4.1-1PGSTY.el8.aarch64.rpm
pg_agent_gate_180.4.4el9.x86_64pigsty496.9 KiBpg_agent_gate_18-0.4.4-1PGSTY.el9.x86_64.rpm
pg_agent_gate_180.4.4el9.aarch64pigsty476.2 KiBpg_agent_gate_18-0.4.4-1PGSTY.el9.aarch64.rpm
pg_agent_gate_180.4.4el10.x86_64pigsty497.4 KiBpg_agent_gate_18-0.4.4-1PGSTY.el10.x86_64.rpm
pg_agent_gate_180.4.4el10.aarch64pigsty476.9 KiBpg_agent_gate_18-0.4.4-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-agent-gate0.4.4d12.x86_64pigsty436.8 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-agent-gate0.4.4d12.aarch64pigsty391.5 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-agent-gate0.4.4d13.x86_64pigsty436.5 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~trixie_amd64.deb
postgresql-18-pg-agent-gate0.4.4d13.aarch64pigsty392.3 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~trixie_arm64.deb
postgresql-18-pg-agent-gate0.4.4u22.x86_64pigsty469.0 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~jammy_amd64.deb
postgresql-18-pg-agent-gate0.4.4u22.aarch64pigsty446.3 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~jammy_arm64.deb
postgresql-18-pg-agent-gate0.4.4u24.x86_64pigsty463.3 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~noble_amd64.deb
postgresql-18-pg-agent-gate0.4.4u24.aarch64pigsty440.1 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~noble_arm64.deb
postgresql-18-pg-agent-gate0.4.4u26.x86_64pigsty462.7 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~resolute_amd64.deb
postgresql-18-pg-agent-gate0.4.4u26.aarch64pigsty438.7 KiBpostgresql-18-pg-agent-gate_0.4.4-1PGSTY~resolute_arm64.deb

Source

github.com/Manuelreyesbravo/pg_agent_gate

pig build pkg pg_agent_gate;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_agent_gate;		# install by package name

pig install pg_agent_gate -v 19;   # install for PG 19
pig install pg_agent_gate -v 18;   # install for PG 18

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_agent_gate';

Create this extension with:

CREATE EXTENSION pg_agent_gate;

Usage

Sources:

pg_agent_gate 0.4.4 routes registered agent roles through proposals, checks, dry runs and guarded execution on PostgreSQL 18/19, with optional human approval before commit. The library must be loaded before the first agent statement, through shared preload or a role-level session preload followed by reconnection.

Core Workflow

CREATE EXTENSION pg_agent_gate;
SELECT agent_gate.whoami();
SELECT agent_gate.discover('customers');
SELECT agent_gate.propose('SELECT 1', 'Check connectivity');

Operational Boundaries

Install as a superuser and register ordinary roles with narrow table privileges, row limits and a DDL allow-list. The API includes agent_gate.whoami, agent_gate.discover, agent_gate.propose, agent_gate.dry_run, agent_gate.commit and agent_gate.acts. Verbs require READ COMMITTED. Proposal-time session settings are checked again before dry-run/commit, and reads that invoke known state-changing built-ins are rejected. Re-registering a name does not inherit old proposals. agent_gate.max_proposal_bytes and agent_gate.max_intent_bytes bound input sizes. Existing duplicate committed proposals can block the upgrade and require inspection. Optional bound checks use pg_living_assertions. Rollback cannot undo every sequence or external effect; existing privileged code must remain trusted. The server log can contain literal SQL. Attempt records participate in the outer transaction, and the default fast durability mode can lose recent records on a crash.

Human Approval

Set p_requires_approval when calling agent_gate.register_agent to require consent for that agent’s proposals. A member of agent_gate_approver records consent with agent_gate.approve; the agent then commits its own proposal. Approval executes no SQL and does not bypass row limits, assertions or commit-time checks. The agent cannot approve itself, and propose_and_commit cannot bypass the approval requirement.

The fixed agent_gate_internal schema stores proposals, executions and approvals; agents do not access those tables directly. The execution record identifies the approver in approved_by.

Write Budgets and Role Membership

Version 0.4.0 introduced a default cumulative write budget: the agent’s per-statement row limit per hour. agent_gate.set_budget changes the allowance/window; agent_gate.reset_budget starts a new allowance without rewriting the record. Kept writes count actual row effects, including cascades and triggers; concurrent commits serialize the budget check.

Agent roles must have no members. Registration refuses such roles, and upgrades warn about existing memberships that an administrator must revoke. Connect each agent as its own login; a broker must not switch into the agent role.

Function and Session Checks in 0.4.3

The 0.4.3 library judges hidden function calls when they execute, including type support functions, aggregates, defaults and constraints. It rejects SQL passed as text to known execution functions, agent-alterable functions, protected-context changes and unaccounted state changes. DDL row effects also count toward row limits. These checks deliberately reject some statements that ordinary PostgreSQL roles can execute.

Protected context includes role identity, row-security settings, search path and unregistered custom application parameters. A changed context causes refusal rather than automatic reset. Native code attached to agent-owned objects is restricted. Optional pg_living_assertions 0.5.5 can leak context and cause refusals; 0.5.6 fixes that issue. Keep agent-controlled schemas out of other users’ search paths, since DDL can create code that later runs under their rights.

Library and SQL Upgrades

After replacing the library, restart or reconnect all processes that preload it, then update each database:

ALTER EXTENSION pg_agent_gate UPDATE TO '0.4.4';

The 0.4.1 to 0.4.3 migration changes no schema objects. Older upgrade paths still add budget and approval objects; inspect existing agents’ budgets after upgrading. Version 0.4.2 was not released separately. Superusers, the operating system and trusted DBA code remain outside this boundary; an authorized statement can still violate human intent.

Version 0.4.4

Release 0.4.4 changes the recorded version without changing the 0.4.3 library behavior or SQL objects. Its release review qualifies PostgreSQL 18.7 and 19.0. The protection against later role membership changes requires shared_preload_libraries; role-level session preload alone does not enforce that guarantee across other sessions.

Table reader