How to Configure Gemini CLI Postgres Approval

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gemini cli postgres approval by pairing local tool prompts with strict database roles. This setup stops your AI agent from running bad SQL commands without a human check. Many teams start by giving the agent a shared login to test queries fast. That broad role lets the tool drop tables or read private rows by mistake. A safer plan splits read rights from write rights before the agent runs a task. How to set up gemini cli postgres approval with native roles First, you need to lock d

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 gemini cli postgres approval by pairing local tool prompts with strict database roles. This setup stops your AI agent from running bad SQL commands without a human check. Many teams start by giving the agent a shared login to test queries fast. That broad role lets the tool drop tables or read private rows by mistake. A safer plan splits read rights from write rights before the agent runs a task.

How to set up gemini cli postgres approval with native roles

First, you need to lock down what the database login can do on its own. PostgreSQL lets you set up group roles to manage rights for many users or tools. You can create a read role and grant it membership to the agent account. The SELECT right lets a role read all columns or just specific columns on a table by default. Note that this same SELECT right also allows the role to export data with COPY TO.

You should also check the default rights that every new role gets on your server. PostgreSQL uses a special role called PUBLIC that gives rights to every account by default. Out of the box, PUBLIC lets any account log in to databases and make temp tables. It also lets any account run functions and stored procedures unless the owner removes those rights. In older database versions, admins must also remove the right to create objects in the public schema.

Next, you pair this restricted database role with the local confirmation prompts in your terminal agent. When the AI agent wants to run a shell command or query, it pauses first. The user reads the proposed command on the screen and picks approve or reject. This step keeps a person in the loop before the tool runs any local command.

What native setup solves and where the gap remains

Combining a tight database role with local terminal prompts solves basic access problems well. It stops the agent from altering tables when it only needs to read schema details. It also forces the developer to look at shell actions before they run on the workstation.

Still, this native setup only controls who logs in and starts the local tool. Once the session starts, the database cannot pause a single statement to ask a team lead. If an agent needs a write role for one fix, that role stays active for all queries. A tired user might click approve on a risky delete statement without spotting a missing filter.

Approval Chains & Escalation + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native roles also struggle when tables hold sensitive fields like emails, phone numbers, or card numbers. You can grant SELECT on safe columns, but queries that join full tables will fail. Data masking solves this by rewriting matched fields like national IDs in the query results. Finally, local terminal prompts do not create a central audit log for your security team. When an agent runs queries from a laptop, nobody else sees which commands were approved.

Why query level checks beat broad database logins

Relying on local prompts puts all the safety burden on one busy developer. If the developer turns on auto-run flags to move faster, the approval step vanishes right away. Even with prompts on, the local machine still holds a raw database password in a file. Any script or terminal tool running under that user account can read that stored key.

Moving approval rules to the query level fixes these gaps for the whole engineering team. Instead of trusting a laptop prompt, the team checks the actual SQL text in flight. Read queries can run fast, while write statements wait for a peer to approve them. This approach keeps production data safe even when an AI agent writes an bad command.

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 a read-only PostgreSQL role still export table data?

Yes, the standard SELECT privilege in PostgreSQL also allows a role to run COPY TO commands. You must restrict sensitive columns or mask fields like emails and card numbers in results.

Why is the PostgreSQL PUBLIC role a risk for AI agents?

The PUBLIC role gives every user default rights to log in, make temp tables, and run functions. You must revoke these defaults so an AI agent cannot run custom code by mistake.

Do local terminal prompts create a central audit trail for compliance?

No, local CLI prompts only show up on the developer screen during that single terminal session. They do not send a tamper-proof record of approved SQL statements to a central log.

The query runs. The emails stay hidden.