pgbrake: an undo button for Postgres when an AI agent is driving
Описание и применение
pgbrake позволяет отменять изменения, внесённые ИИ‑агентами в PostgreSQL, блокируя опасные операции до одобрения человека и записывая все действия в локальный журнал.
Задача
AI agents can execute destructive SQL on development databases, and existing safeguards like client‑side permission prompts are insufficient.
Результат
pgbrake provides an undo mechanism for writes performed by AI agents, blocks potentially destructive operations until human approval, and logs all activity locally.
Рабочий процесс
- 1. Install pgbrake and configure it as an MCP server.
2. Point the AI agent to pgbrake instead of the database.
3. Agent submits SQL through pgbrake.
4. pgbrake parses the statement with pglast.
5. For UPDATE/DELETE, pgbrake saves affected rows locally and returns a change id.
6. If the agent wants to revert, run
pgbrake undo <id>. 7. For DDL, UPDATE/DELETE without WHERE, or operations affecting >100 rows, pgbrake pauses and requires a human prompt orpgbrake approve <id>in a terminal with a TTY. 8. All statements and approvals are written to a local audit log; nothing leaves the machine.
Доказательства
pgbrake is a small MCP server the agent uses in place of direct database access. Every statement goes through the real Postgres parser (pglast).
Before an UPDATE or DELETE it saves the affected rows locally, so pgbrake undo <id> puts them back, and it refuses if those rows changed since.
DDL, UPDATE/DELETE without WHERE, and anything touching more than 100 rows wait for a human: the client's own prompt, or pgbrake approve <id> in a terminal. That command refuses to run without a TTY, so the agent can't approve its own SQL.
- Дата записи: 2026-11-01T09:29:13.299Z