How to Configure OpenHands Postgres Audit Log
You set up an openhands postgres audit log by enabling database statement logging and assigning a dedicated role to the AI agent. This setup records every query that OpenHands sends to your database tables. Teams often give an AI coding agent a single shared database role to get started fast. When permissions are too broad, the agent can read or change sensitive tables without clear user tracking. How an openhands postgres audit log works with database roles To track what OpenHands does, you
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up an openhands postgres audit log by enabling database statement logging and assigning a dedicated role to the AI agent. This setup records every query that OpenHands sends to your database tables. Teams often give an AI coding agent a single shared database role to get started fast. When permissions are too broad, the agent can read or change sensitive tables without clear user tracking.
How an openhands postgres audit log works with database roles
To track what OpenHands does, you first need a distinct database role for the agent. PostgreSQL lets you set up group roles to manage permissions across many users or services. You create a group role for your automated agents and grant your OpenHands user membership in that role.
Next, you restrict what that role can read or change inside the database. In PostgreSQL, the SELECT privilege lets a role read from an entire table, a view, or just specific columns. Note that the SELECT privilege also allows the role to export table data using the copy command. You should grant SELECT only on the specific columns that OpenHands needs for its task.
You must also check the default rights that every database role inherits upon creation. PostgreSQL includes a special role name called PUBLIC that grants permissions to every role on the system. By default, PUBLIC gets permission to connect to databases, make temporary tables, and run functions and procedures. An object owner can revoke these default PUBLIC privileges to lock down the database.
In PostgreSQL 15 and later versions, default settings stop users from creating new objects in the public schema. If you run an older version or an upgraded database, an admin must revoke that create right from PUBLIC. Once the agent has its own locked-down role, native PostgreSQL logging writes every statement from that role to disk. Your team can then ship those log files to a central log tool for review.
What native database logging solves and what it misses
Native database roles and statement logs solve the first step of tracking an AI agent. The database checks who can log in and which tables or columns that role can touch. The log file records the SQL statements that ran under the OpenHands role name.
Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static roles and disk logs leave an operational gap during live agent runs. A database role decides who logs in, not what individual statements do in flight. If OpenHands has read rights on a customer table, it can still pull raw emails, phone numbers, or card numbers. Native logs only tell you that a big query happened after the data already left the database.
Shared agent credentials also make it hard to tie a database query back to the human who prompted OpenHands. Every developer using the agent shares the same database role in the log output. Also, native logs cannot pause a risky update query to ask a human for approval first. To control queries in flight and rewrite sensitive fields like national IDs in results, teams need runtime controls.
Add query and result controls beside Postgres
Grants and pools govern who logs into PostgreSQL. Yet every query in an open session still runs with that role's full scope. In practice, hoop.dev runs beside your database as a sidecar for your Postgres. It reads plain and prepared queries on the wire with no change to your users or drivers.
When a tool or agent sends SQL, hoop.dev Postgres controls check each statement against your deny rules. An AI Analyzer you configure can also score intent or hold a risky query for human review. Matched sensitive columns in result rows are masked in memory before they reach the caller. Each query and decision is logged per listener, which generates evidence for SOC 2, HIPAA, and GDPR audits. View the binary on GitHub.
Frequently asked questions
How do we tell OpenHands queries apart from human queries in PostgreSQL?
Create a dedicated PostgreSQL role just for the OpenHands agent instead of sharing a developer login. Every statement in the database log will then show that specific agent role name.
Can we limit OpenHands to reading only safe columns in a table?
Yes, PostgreSQL lets you grant the SELECT privilege on specific columns of a table or view. Keep in mind that granting SELECT on a column also allows data export from it.
Why can a new OpenHands role run functions we did not grant to it?
PostgreSQL grants default database connection, temporary table, and function execution rights to the special PUBLIC role. A database owner must revoke those default rights from PUBLIC to restrict new roles.
Related guides
In this post