Mikhail Shytsko demonstrates hardening PostgreSQL roles used by AI agents by applying role-level settings via ALTER ROLE. By setting statement_timeout to 2 seconds and default_transaction_read_only to on, operators can contain rogue or misbehaving agent sessions at the database level. The article shows how these configurations effectively cancel long-running sleeps and block write operations like CREATE TABLE.
- Use ALTER ROLE to enforce statement_timeout and read-only defaults for AI agent service accounts.
- Role-level settings apply to all sessions, providing a consistent safety net without app code changes.
- Verify containment by testing with pg_sleep() and write attempts like CREATE TABLE.
- This pattern helps mitigate risks from autonomous agents executing untrusted queries.