How to Integrate Mode and Postgres Safely

Published
Length
3 min read

Luis Felipe Dias

All posts

Integrating Mode and Postgres lets analytics teams run SQL reports and build charts from live data. You connect the reporting app to a read-only database role so analysts can query tables safely. This setup helps product and finance teams explore business metrics in real time. At the same time, database admins must protect private user records and prevent slow queries. How Mode and Postgres share data and permissions Mode connects to a Postgres database using a dedicated database user and pa

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.

Integrating Mode and Postgres lets analytics teams run SQL reports and build charts from live data. You connect the reporting app to a read-only database role so analysts can query tables safely.

This setup helps product and finance teams explore business metrics in real time. At the same time, database admins must protect private user records and prevent slow queries.

How Mode and Postgres share data and permissions

Mode connects to a Postgres database using a dedicated database user and password. When an analyst runs a report, Mode sends the SQL query over an encrypted network path.

Postgres checks the role permissions before it reads any table or view. You can grant the SELECT privilege on whole tables or on specific columns only. This column rule stops the reporting role from reading private fields like emails or phone numbers.

Database admins often create a group role for analytics tools and assign specific permissions to it. Then, they add the Mode database user into that group role to keep management simple.

By default, Postgres gives the special PUBLIC role permission to connect and create temp tables. It also lets PUBLIC run functions and procedures unless the object owner revokes those rights. In Postgres 15 and newer, the default setup blocks general users from creating objects in the public schema. On older or upgraded databases, admins must revoke that create right from PUBLIC by hand.

Common failure modes in analytics database setups

Many teams make the mistake of sharing one broad database account across multiple reporting tools. If that account has write permissions, a bad query can change or delete production records.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Shared accounts also ruin your audit logs when a security review happens. When ten analysts use Mode at once, Postgres only logs the single shared service account name. You cannot tell which team member ran an expensive query or exported customer card numbers.

Overly broad read rights create another major risk for engineering and data teams. If the reporting role can read every table, anyone with report access can query national IDs. Admins should scope the database role to specific views or non-sensitive columns instead.

Steps to scope roles and network paths

Start by creating a dedicated read-only role just for your analytics workspace. Revoke default PUBLIC rights on sensitive databases so the new role starts with zero access. Next, grant usage on the target schema and grant SELECT only on safe columns.

You should also set query timeouts on that database role to stop runaway reports. A heavy join without an index can lock up CPU and slow down your main app. Finally, restrict network rules so only known IP addresses can reach the database port.

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 I limit Mode to read-only queries in Postgres?

Create a new Postgres role and grant it the SELECT privilege on approved tables or views. Do not grant insert, update, delete, or schema creation rights to this user.

Can I hide sensitive columns from Mode analysts in Postgres?

Yes, Postgres lets you grant SELECT on specific columns instead of the entire table. You can leave out columns that hold emails, phone numbers, or card numbers.

Why do upgraded Postgres databases let read-only users create objects?

Databases created before Postgres 15 allowed the PUBLIC role to create objects in the public schema. You must revoke the CREATE right on the public schema from PUBLIC to fix this.

The query runs. The emails stay hidden.