How to Configure Amazon Q Postgres Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an amazon q postgres prevent delete rule by removing delete rights from the database role your agent uses. You also give that role read or insert rights on chosen tables only. Many teams start by giving an AI assistant their standard developer login. That login often holds full write and delete powers across the database. If the agent makes a mistake, it can wipe out production rows in seconds. Scoping down the database role stops destructive commands before they alter your tables.

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 amazon q postgres prevent delete rule by removing delete rights from the database role your agent uses. You also give that role read or insert rights on chosen tables only. Many teams start by giving an AI assistant their standard developer login. That login often holds full write and delete powers across the database. If the agent makes a mistake, it can wipe out production rows in seconds. Scoping down the database role stops destructive commands before they alter your tables.

How amazon q postgres prevent delete roles work

PostgreSQL controls table actions through role permissions. To stop an AI agent from deleting rows, you create a dedicated role for the agent. You grant the SELECT privilege so the role can read tables or views. PostgreSQL even lets you grant SELECT on specific columns of a table. If the agent needs to add or change data, you grant INSERT or UPDATE without granting DELETE.

Teams with many users often set up group roles to manage these permissions. You assign the right table privileges to the group role first. Then you add the agent role as a member of that group. This keeps your permission setup clean and easy to audit.

You must also check the special PUBLIC role in your database. In PostgreSQL, PUBLIC grants default rights to every role on the system. By default, PUBLIC gets rights to connect to databases and create temporary tables. It also gets rights to run functions and procedures. A stored function might delete rows when someone calls it. The object owner must revoke execute rights from PUBLIC on dangerous functions. On older databases upgraded from versions before PostgreSQL 15, admins also revoke CREATE on the public schema from PUBLIC.

Why native roles are only half the fix

Native database roles decide who can log in and which table permissions they hold. They work well when an agent only needs static read access. Yet real engineering work often requires more than static role boundaries.

First, static permissions apply to every query in the session. If a role has UPDATE rights to fix one row, an AI agent can still update every row by mistake by default. A careless update without a filter can blank out a whole column. The database sees a valid permission and runs the statement anyway.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Second, developers often run AI agents inside their own local terminals. The agent inherits the developer's local database keys and session rights. If the developer holds delete rights for daily work, the agent holds them too. Maintaining separate credentials for humans and local AI tools creates extra friction for the team.

What happens to sensitive data during queries

Blocking delete statements protects data integrity, but it does not protect data privacy. An agent with read access can still pull whole tables into its prompt context. Those tables often hold sensitive customer details like emails, phone numbers, card numbers, or national IDs.

You can limit column access in PostgreSQL by granting SELECT on safe columns only. Still, many apps store mixed data inside text or JSON columns. Column grants cannot filter out a phone number hidden inside a free-text note. They also break queries when an agent runs a broad select statement to inspect a table structure. Teams need a way to inspect each query in flight and rewrite matched fields in results.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres, inline in the Postgres wire protocol. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails refuse bad deletes or drops with a real Postgres error, or hold risky queries for approval. On the way back, hoop.dev data masking rewrites sensitive values in returned rows in memory, and every verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

Can PostgreSQL block deletes on specific rows only?

Standard table privileges apply to the whole table, not single rows. You can use row-level security policies to filter which rows a role can change or delete.

Why can my restricted Postgres role still run delete functions?

PostgreSQL grants EXECUTE rights on new functions to the PUBLIC role by default. You must revoke EXECUTE from PUBLIC so restricted roles cannot run functions that delete data.

Does revoking DELETE stop an agent from dropping tables?

Revoking DELETE only stops row removal. To stop table drops, ensure the agent role does not own the table or belong to the owner role.

The query runs. The emails stay hidden.