GRANT (Grant Privileges)
Last updated: 2026-11-04
GRANT (Grant Privileges)
GRANT gives privileges on an object to a role. PostgreSQL's permission model is role-centric: privileges are granted to roles, and users gain them by becoming members of those roles. A role can also be granted to another role, which lets you build layers of privileges.
| Kind | command |
|---|---|
| Example Language | SQL |
📝 Syntax
GRANT { <privilege> | ALL [PRIVILEGES] } ON [TABLE] <table> [, ...]
TO <role> [, ...]
[WITH GRANT OPTION]
-- other object types work too
GRANT { SELECT | INSERT | UPDATE | DELETE } ON <table> TO <role>;
⚙️ Parameters
| SELECT / INSERT / UPDATE / DELETE | The specific table-level privileges |
|---|---|
| ON <object> | The table, sequence, or schema the privilege applies to |
| TO <role> | The role that receives the privilege |
| WITH GRANT OPTION | Lets the role grant the privilege onward |
Returns:No return value. The privilege takes effect immediately.
▶ Example
Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.
Output:
DROP TABLE
CREATE TABLE
INSERT 0 2
DO
GRANT
grantee | privilege_type
--------------+---------------
report_reader | SELECT
📌 Key Points
- Follow least privilege: a read-only reporting role needs SELECT, not INSERT and UPDATE handed out as well.
- GRANT ... TO role WITH GRANT OPTION lets that role pass the privilege on to others.
- Object privileges are not granted to PUBLIC by default; PUBLIC means every user, so be careful when revoking from it.
- Granting to a role that does not exist fails with role ... does not exist — create the role first.
- The table owner keeps full privileges no matter what you grant to other roles.
- Grants accumulate: with several grant paths on the same object, revoking one of them may not actually remove access.
💡 Related Cases
More case studies coming soon.
📚 Related Reference
❓ FAQ
QHow do I inspect the privileges on a table?
AQuery information_schema.role_table_grants to see every grantee and privilege on every table; in psql, \dp shows the same information.