PostgreSQL Column Privileges: Grant Access and Test Limits
Grant PostgreSQL access to selected columns and test with a separate role. Check table-level grants, inherited privileges and expected permission errors.
By jackey.ye · Updated 2026-11-30
Column-level privileges in PostgreSQL let you expose only named columns of a table: grant SELECT on those columns, grant USAGE on the containing schema, then prove the boundary with SET ROLE. The trap is that a table-level grant overrides column restrictions, so a role holding SELECT on the whole table reads every column regardless of narrower grants.
This walkthrough pins the PostgreSQL 19 GRANT reference as its authority. Confirm your deployed server version with SHOW server_version; before trusting any result, because behavior and error text can differ across releases. Every expected error below is hand-derived from documented rules and was not executed; run the script only in an isolated schema you created for the purpose, never against shared objects.
How Do Column Privileges Work in PostgreSQL?
Privileges attach to objects, and column granularity exists for only four of them: SELECT, INSERT, UPDATE and REFERENCES. The GRANT synopsis shows the column form as GRANT { { SELECT | INSERT | UPDATE | REFERENCES } ( column_name [, ...] ) ... ON [ TABLE ] table_name, so DELETE, TRUNCATE and TRIGGER have no column-level variant at all.
Schema access is a separate gate. By default users cannot access objects in schemas they do not own, and the schema owner must grant USAGE for lookups to succeed, as described in Schemas and Privileges. A column grant without schema USAGE therefore fails before column checks even run.
The rule that explains every later test result is the sum of privileges: any role holds privileges granted directly to it, privileges granted to any role it is presently a member of, and privileges granted to PUBLIC. The Privileges chapter adds that no privileges are granted to PUBLIC by default on tables or table columns, so a fresh table starts closed.
What Does the Sandbox Fixture Look Like?
The names below are fixed, not generated, so they may already exist on your server. Run this script only inside a disposable database you can throw away, and check the names are unused first with \dn and \du. If any CREATE statement fails, stop and start over in a clean database rather than reusing partially created objects. This exact script needs a superuser: ALTER TABLE ... OWNER TO and SET ROLE both demand authority that CREATEROLE plus CREATE alone doesn't reliably provide. Confirm the server version first.
-- Disposable database only. Fixed names: verify they are unused,
-- and stop on any CREATE failure instead of retrying.
SHOW server_version;
CREATE SCHEMA colpriv_lab;
CREATE ROLE colpriv_owner NOLOGIN;
CREATE ROLE colpriv_reader NOLOGIN;
CREATE TABLE colpriv_lab.accounts (
account_id integer PRIMARY KEY,
display_name text NOT NULL,
balance_cents bigint NOT NULL,
tax_id text
);
ALTER TABLE colpriv_lab.accounts OWNER TO colpriv_owner;
INSERT INTO colpriv_lab.accounts VALUES
(1, 'Ada', 125000, 'TAX-001'),
(2, 'Grace', 98000, 'TAX-002');
colpriv_reader has no LOGIN attribute, so it cannot connect on its own; it exists to be assumed with SET ROLE during testing. tax_id and balance_cents are the sensitive columns the reader should never reach. The owner is deliberately distinct from the reader, because an owner bypasses column restrictions entirely.
How Do You Grant SELECT on Specific Columns and Prove the Limits?
Work through the steps in order; each one depends on the previous. Run the grants as a role that owns the table or holds grant options, then switch identity with SET ROLE for the tests.
Grant schema
USAGE. Without it, object lookup fails regardless of column grants.
GRANT USAGE ON SCHEMA colpriv_lab TO colpriv_reader;
Grant column-level
SELECTon the allowed columns only.
GRANT SELECT (account_id, display_name)
ON colpriv_lab.accounts TO colpriv_reader;
Test the allowed columns. Expect two rows.
SET ROLE colpriv_reader;
SELECT account_id, display_name FROM colpriv_lab.accounts;
Test a forbidden column. Expect failure:
ERROR: permission denied for table accounts. The pgsql-bugs report #16942 documents exactly this: a denied column produces a table-level message, so do not rely on the text to tell you which column failed.
SELECT tax_id FROM colpriv_lab.accounts;
Test
SELECT *. Expect the same table-level denial, because the star expands to columns the role cannot read.
SELECT * FROM colpriv_lab.accounts;
Add a table-level grant, re-test, then revoke and re-test. Run the whole block as the superuser; each
RESET ROLEreturns you to the original session role.
RESET ROLE;
GRANT SELECT ON colpriv_lab.accounts TO colpriv_reader;
SET ROLE colpriv_reader;
SELECT tax_id FROM colpriv_lab.accounts;
-- Expect success here: the table-level grant covers every column.
RESET ROLE;
REVOKE SELECT ON colpriv_lab.accounts FROM colpriv_reader;
SET ROLE colpriv_reader;
SELECT tax_id FROM colpriv_lab.accounts;
-- Expect ERROR: permission denied for table accounts again.
RESET ROLE;
The middle query succeeding is the subject of the next section; the final error is the point of it.
Why Does a Table-Level GRANT Override a Column Restriction?
The documented rule is permissive, not restrictive: a user may perform SELECT on a column if they hold that privilege for either the specific column or its whole table. Once the table-level grant exists, every column qualifies, and the narrower column grant adds nothing.
The same asymmetry breaks the common REVOKE misconception. The REVOKE reference states that if a role has been granted privileges on a table, revoking the same privileges from individual columns has no effect, and the GRANT notes say the table-level grant is unaffected by a column-level operation. So REVOKE SELECT (tax_id) ON colpriv_lab.accounts FROM colpriv_reader; removes only the column grant; the table grant survives and access continues.
Remediation is to remove the broader privilege, never to assume a column revoke narrows it:
RESET ROLE;
REVOKE SELECT ON colpriv_lab.accounts FROM colpriv_reader;
After that, re-grant only the columns you intend to expose and re-run the SET ROLE tests. Treat any table-level SELECT on a table with sensitive columns as a decision to disclose all of it.
How Do Inheritance, PUBLIC and Ownership Change the Result?
Three mechanisms widen effective access without touching the column grants you wrote, so audit each before trusting a passing test.
Inheritance. Roles default to the INHERIT attribute, and a member automatically has use of privileges granted to roles it is directly or indirectly a member of, per Role Membership. If colpriv_reader belongs to a group that holds table-level SELECT, the column restriction is already void.
SET ROLE swaps the identity, it doesn't strip inheritance. Effective privileges after the switch are those of the assumed role plus the memberships that role itself holds under its INHERIT and SET options — so a reader that is a member of a permissive group stays permissive when assumed. What changes is the starting point: privileges held only by your original session role, or only by groups that role belongs to, no longer apply. In a login session where that original role INHERITs a permissive group, the same query can succeed while the SET ROLE test fails, or the other way around. Record which identity you tested as, and check pg_roles.rolinherit for both roles plus the SET option on each membership path on your deployed version before drawing conclusions.
PUBLIC. A grant to PUBLIC applies to all roles, including ones created later. No table or column privileges go to PUBLIC by default, but a single GRANT SELECT ... TO PUBLIC reopens every column.
Ownership. The owner has all privileges by default and can re-grant anything it revokes, so column grants cannot fence in the owning role. Keeping colpriv_owner separate from application roles is what makes the restriction meaningful.
Audit sequence: check pg_auth_members for memberships of the reader, check the table ACL for a =r/ entry (the empty grantee field means PUBLIC), and confirm the reader is not the owner.
How Do Column Privileges Compare With Row-Level Security?
They are independent controls, and neither substitutes for the other. Column privileges decide which columns a role may read or write; row-level security decides which rows are visible or modifiable. A role can hold SELECT on tax_id and still see zero rows, or see every row while being denied tax_id. A multi-tenant system layers tenant deletion and security boundaries on top of both controls, so a grant fix doesn't settle isolation on its own.
Row security is enabled with ALTER TABLE ... ENABLE ROW LEVEL SECURITY, and per the Row Security Policies chapter a table with row security on and no policy uses default-deny, so no rows are visible or modifiable. The table owner typically bypasses row security, superusers and BYPASSRLS roles always do, and whole-table operations such as TRUNCATE and REFERENCES are not subject to it. RLS neither grants nor denies column access.
Dimension | Column privileges | Row-level security |
|---|---|---|
What it controls | Which columns a role may read or write | Which rows a role may see or modify |
How it is enabled | GRANT ... (column) plus schema USAGE | ALTER TABLE ... ENABLE ROW LEVEL SECURITY plus CREATE POLICY |
Who bypasses it | Superusers; the table owner, who holds all privileges | Superusers, BYPASSRLS roles, and normally the table owner |
Behavior when unconfigured | No access beyond the owner | Default-deny once enabled with no policy |
What a failed check looks like | ERROR: permission denied for table ... | Empty result set, or a WITH CHECK OPTION violation on write |
How Do You Inspect Which Column Privileges Are Actually in Effect?
Verify rather than assume. In psql, dp colpriv_lab.accounts shows an "Access privileges" column and a "Column privileges" column; the Privileges chapter notes that column entries appear only for columns with nondefault privileges, and that an empty access-privileges column means built-in defaults apply.
Read the aclitem format grantee=privilege-abbreviation[*].../grantor. For tables and columns the relevant letters are r (SELECT), a (INSERT), w (UPDATE) and x (REFERENCES), with * marking a grant option. A table-level grant appears in the access-privileges column as something like colpriv_reader=r/colpriv_owner; a column-only grant appears under column privileges as account_id: colpriv_reader=r/colpriv_owner.
The information schema view column_privileges gives a queryable form, but it has a known flattening: a privilege granted on the whole table shows up as a grant for each column, for the four column-capable privilege types. Use it to confirm presence, not to distinguish a table grant from a column grant.
SELECT grantee, column_name, privilege_type
FROM information_schema.column_privileges
WHERE table_schema = 'colpriv_lab'
AND table_name = 'accounts'
ORDER BY grantee, column_name;
If tax_id appears for colpriv_reader, a broader grant is in play; go back to the ACL column to find it. Column grants make the same definition reachable by BI tools and notebooks, which is why governed semantic metrics belong in the same audit conversation.
Frequently Asked Questions
Short answers to the questions that come up most often when testing column grants.
Does GRANT SELECT(col) work without schema USAGE?
No. Schema USAGE gates object lookup, so the query fails on the schema before column privileges are evaluated. Grant USAGE on the schema first, as step 1 of the workflow does.
Why does REVOKE SELECT(col) not block access?
Because a table-level grant is unaffected by a column-level revoke, so the broader privilege still applies. This is documented behavior, not a bug; revoke SELECT at the table level instead.
Can the table owner be restricted by column grants?
No. The owner holds all privileges by default and can re-grant anything it revokes, so column restrictions apply to other roles. That is why the fixture separates colpriv_owner from the application role.
Does row-level security replace column privileges?
No. RLS filters rows and column grants filter columns; they are independent controls, and a complete design usually needs both. Enabling RLS with no policy denies all rows without changing column access.
How do I confirm the deployed server behaves as documented?
Run SHOW server_version; and compare it with the version whose documentation you are reading, then repeat the SET ROLE tests in an isolated schema on that server. The GRANT reference is pinned to PostgreSQL 19; if your server reports a different major version, read the matching page for that release before you trust any expected outcome.
What Should You Verify Before Applying This to a Shared Database?
Treat the sandbox result as evidence only after each item below passes on the target server, not just on the machine where you built the fixture. Run the checks as the restricted role, because that is the identity whose access you are actually asserting.
Check | How to confirm it | Pass condition |
|---|---|---|
Server version | SHOW server_version; | Matches the documentation version you validated against |
Schema USAGE | has_schema_privilege('role','schema','USAGE') | Returns true |
Column grants present | Query information_schema.column_privileges for the role and table | Only the intended columns and privilege types appear |
No table-level grant | Inspect dp access privileges for the table | No arwdDxtm entry naming the restricted role |
No PUBLIC grant | Same dp output | No empty grantee field covering the table |
No inherited path | pg_auth_members joined to the role, plus rol.inherit and the membership SET option | No membership chain carries the table privilege, and the assumed role's own INHERIT/SET options are recorded |
Owner separated | Table owner versus application role | Different roles |
RLS status recorded | pg_class.relrowsecurity for the table | Value documented alongside the column design |
Two of these deserve emphasis because they are the ones most often skipped. A table-level grant is unaffected by a column-level operation, so a clean column_privileges result means nothing if dp still shows the role holding r on the whole table. And because a role holds the sum of privileges granted directly, through memberships, and to PUBLIC, a passing test as one role does not prove the application's login role is equally constrained — say explicitly whether you tested as the original session role or as an assumed role, since the two can inherit different memberships.
Record the outcome of each check with the date and server version. Privilege state drifts as roles are added and grants accumulate, so a result captured once is a snapshot, not a standing guarantee.
Platforms that consolidate PostgreSQL alongside lakehouse workloads under a single permission model still depend on these same PostgreSQL semantics being tested rather than assumed; Singdata's lakehouse is one example of a platform where that governance question arises, and the checks above remain the ones that decide the answer.