How to Configure Codex Postgres Permissions
You set up codex postgres permissions by creating a dedicated read-only database role. Then you grant select access on only the tables and columns the agent needs. Many engineering teams start by sharing a broad developer account with their AI agent. When permissions are too wide, an automated prompt can alter rows or pull sensitive data. Scoping down database privileges is the first step toward safer AI database tasks. How codex postgres permissions work in practice OpenAI Codex and similar
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 codex postgres permissions by creating a dedicated read-only database role. Then you grant select access on only the tables and columns the agent needs. Many engineering teams start by sharing a broad developer account with their AI agent. When permissions are too wide, an automated prompt can alter rows or pull sensitive data. Scoping down database privileges is the first step toward safer AI database tasks.
How codex postgres permissions work in practice
OpenAI Codex and similar coding agents interact with databases using standard database roles. The agent reads a database string or runs local shell commands to send queries. Postgres does not know that an AI agent is on the other end. The database simply checks the privileges attached to the active login role.
To keep data safe, admins build group roles to manage privileges across users. You can create a read-only group role and assign the agent role to it. In Postgres, the select privilege lets a role read from tables and views. It also works on materialized views and other table-like objects. You can grant select on an entire table or on specific columns only. Column-level grants help when a table holds both public fields and private keys. Still, you should remember that the select privilege also allows data export commands.
When you set up a new role, you must also check the public role. Postgres uses a special role named public that includes every user on the system. By default, every new role gets connect and temporary privileges on databases through public. Every role also gets execute rights on functions and procedures from this default group. Database owners have to revoke those default rights if an agent should not run functions.
Locking down schemas and default role grants
Schema rules also affect what an AI agent can do inside your database. In Postgres 15 and newer versions, regular users cannot create objects in the public schema. That safe default stops a read-only agent from building new tables in shared spaces. Older databases, or systems upgraded from older versions, still allow public schema writes. On those systems, an admin must revoke create rights on the public schema from public.
Even when you remove write access, temporary tables can still cause resource trouble. If the public role keeps temporary privileges, the agent can build temp tables during sessions. Large temporary tables can fill up disk space and slow down production work. Revoking temporary privileges from the public role closes that resource gap for good.
AI Agent Permissions + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native database roles solve and what they miss
Native database privileges do a great job of blocking direct schema changes and writes. A clean read-only role stops an agent from dropping tables or changing user balances. Column grants also let you leave out secret columns when you know where they live. These native checks happen at the database layer as soon as a query starts.
Still, database roles only decide who can log in and which objects they touch. Once a role has select access on a table, it can read every row by default. Native roles cannot pause a single slow query for human review in real time. They also cannot rewrite sensitive fields like emails, phone numbers, or card numbers in results. Finally, sharing static database passwords in local agent config files creates a credential risk. Teams often need runtime controls that inspect each statement and mask sensitive fields in flight.
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 sits inline in the wire protocol beside your database as a sidecar for your Postgres. For every plain or prepared query an agent or human runs against production, hoop.dev decides to pass, mask, block, or escalate it for review.
When a tool or agent sends SQL, hoop.dev Postgres controls block banned statements before execution or hold risky ones for human approval via an AI Analyzer you configure. 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
Can I grant an AI agent read access to specific columns only?
Yes, Postgres lets you grant the select privilege on specific columns of a table. The role will return an error if the agent queries any other column on that table.
Why can my read-only agent role still run database functions?
Postgres grants the special public role execute privileges on functions and procedures by default. Every database user inherits rights from public until the object owner revokes them.
How do I stop an agent from creating objects in the public schema?
Postgres 15 and later block public schema object creation for standard roles by default. On older or upgraded databases, an admin must revoke create on the public schema from public.
Related guides
In this post