How to Configure Postgres Column Level Security

Published
Length
3 min read

Luis Felipe Dias

All posts

You configure postgres column level security by revoking table-wide read rights and granting read grants on single columns. This setup restricts database roles so users can query approved fields. Sensitive columns remain blocked. Most engineering teams start by assigning broad read roles to analysts and developers for fixing. When roles stay too broad, every query returns personal data. Secrets, and billing details to anyone connected. How postgres column level security works in practice Post

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 configure postgres column level security by revoking table-wide read rights and granting read grants on single columns. This setup restricts database roles so users can query approved fields. Sensitive columns remain blocked. Most engineering teams start by assigning broad read roles to analysts and developers for fixing. When roles stay too broad, every query returns personal data. Secrets, and billing details to anyone connected.

How postgres column level security works in practice

PostgreSQL manages data visibility through its rights system instead of granting the SELECT rights on an entire table an admin grants SELECT on exact columns of a table, view, or materialized view. This rights also allows the user to export those exact columns using the COPY TO task.

Before granting column grants admins must check inherited and default access. The special role name PUBLIC grants rights to every role on the system by default, PUBLIC receives CONNECT and TEMPORARY rights on databases. Plus EXECUTE rights on functions and procedures. Object owners can revoke these default grants to lock down baseline access.

Schema grants also matter during setup in PostgreSQL 15 and later. The default config stops every user from creating objects in the public schema in earlier versions, or databases upgraded from them. An admin must revoke CREATE on the public schema from PUBLIC once baseline access is tight. Teams create group roles to manage column rights for many users at once. Admins grant exact column rights to the group role then grant users membership in that group.

Why static column grants create operational friction

Native column rights work well for static reporting. They break common developer workflows if a table has fifty columns and one contains sensitive data. The admin must grant access to the other forty-nine columns one by one. Whenever a developer adds a new column during a schema migration. Nobody with restricted roles can read it until an admin updates the grants.

Also, column grants reject broad queries outright if an engineer runs a standard wildcard query to inspect. A single row during an incident. The database blocks the entire statement because one restricted column is present. Teams often bypass this friction by granting full table read rights during emergencies. Leaves sensitive data exposed in query results.

Column-Level Encryption + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native database permissions leave open

Native database roles decide who can log in and which objects they can refuse or read altogether. They do not inspect or modify what single statements return in flight if a support engineer needs to see that a customer record exists. Needs to see a partial value to debug an issue. Native rights only offer an all-or-nothing choice.

Once a role has grants to read a column the database sends the raw text straight to the client tool. Native grants cannot mask values live. They do not attach external identity context to single queries. Managing column grants across dozens of microservices and databases also forces admins to maintain complex rights matrices inside every single database instance.

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

What happens when a user runs a wildcard query on a table with restricted columns?

PostgreSQL rejects the entire query with a grants error. The user must rewrite the query and list only the exact columns they have grants to read.

How do group roles simplify column permission management?

Instead of granting column rights to single user accounts. Admins create a group role and assign the column rights to that role users then receive membership in the group role to inherit those exact grants.

Does the PUBLIC role give all users read access to tables by default?

No, PUBLIC receives CONNECT and TEMPORARY on databases and EXECUTE on functions and procedures by default. Still, if someone grants table rights to PUBLIC every user on the system gains that access until the owner revokes it.

The query runs. The emails stay hidden.