GRANT PRIVILEGE
View as MarkdownGRANT PRIVILEGE grants privileges to database
role(s).
Syntax
The syntax supports the ALL [PRIVILEGES] shorthand to refer to all
applicable privileges for the
object type.
For PostgreSQL compatibility, you can reference views, materialized views,
and sources with the TABLE keyword. With ON TABLE, the ALL [PRIVILEGES]
shorthand expands to the full table privilege set
(SELECT, INSERT, UPDATE, DELETE), even if some of those privileges aren’t
meaningful for the object type. The non-applicable privileges have no
runtime effect. They’re stored so that a later REVOKE ALL ON TABLE can
clear every privilege previously granted through the same shorthand.
For specific cluster(s):
GRANT <USAGE | CREATE | ALL [PRIVILEGES]> [, ... ]
ON CLUSTER <name> [, ...]
TO <role_name> [, ... ];
For all clusters:
GRANT <USAGE | CREATE | ALL [PRIVILEGES]> [, ... ]
ON ALL CLUSTERS
TO <role_name> [, ... ];
For specific connection(s):
GRANT <USAGE | ALL [PRIVILEGES]>
ON CONNECTION <name> [, ...]
TO <role_name> [, ... ];
For all connections or all connections in specific schema(s) or in database(s):
GRANT <USAGE | ALL [PRIVILEGES]>
ON ALL CONNECTIONS
[ IN <SCHEMA | DATABASE> <name> [, <name> ...] ]
TO <role_name> [, ... ];
For specific database(s):
GRANT <USAGE | CREATE | ALL [PRIVILEGES]> [, ... ]
ON DATABASE <name> [, ...]
TO <role_name> [, ... ];
For all database:
GRANT <USAGE | CREATE | ALL [PRIVILEGES]> [, ... ]
ON ALL DATABASES
TO <role_name> [, ... ];
SELECT privileges
on the view/materialized views. That is, having SELECT privileges on the
underlying objects defining the view/materialized view is insufficient.
For specific materialized view(s)/view(s)/source(s):
GRANT <SELECT | ALL [PRIVILEGES]>
ON <name> [, <name> ...]
TO <role_name> [, ... ];
For PostgreSQL compatibility, the TABLE keyword is also accepted. With the
TABLE syntax, you can name INSERT, UPDATE, and DELETE explicitly, and
ALL [PRIVILEGES] expands to the full table privilege set
(SELECT, INSERT, UPDATE, DELETE). The non-applicable privileges have no
runtime effect, but they’re stored so a matching REVOKE ALL can clear them.
GRANT <SELECT | INSERT | UPDATE | DELETE | ALL [PRIVILEGES]> [, ...]
ON TABLE <name> [, <name> ...]
TO <role_name> [, ... ];
For specific network policies:
GRANT <USAGE | ALL [PRIVILEGES]>
ON NETWORK POLICY <name> [, ...]
TO <role_name> [, ... ];
For all network policies:
GRANT <USAGE | ALL [PRIVILEGES]>
ON ALL POLICIES
TO <role_name> [, ... ];
For specific query policies:
GRANT <USAGE | ALL [PRIVILEGES]>
ON QUERY POLICY <name> [, ...]
TO <role_name> [, ... ];
For all query policies:
GRANT <USAGE | ALL [PRIVILEGES]>
ON ALL QUERY POLICIES
TO <role_name> [, ... ];
For specific schema(s):
GRANT <USAGE | CREATE | ALL [PRIVILEGES]> [, ... ]
ON SCHEMA <name> [, ...]
TO <role_name> [, ... ];
For all schemas or all schemas in a specific database(s):
GRANT <USAGE | CREATE | ALL [PRIVILEGES]> [, ... ]
ON ALL SCHEMAS [IN DATABASE <name> [, <name> ...]]
TO <role_name> [, ... ];
For specific secret(s):
GRANT <USAGE | ALL [PRIVILEGES]> [, ... ]
ON SECRET <name> [, ...]
TO <role_name> [, ... ];
For all secrets or all secrets in a specific database(s):
GRANT <USAGE | ALL [PRIVILEGES]> [, ... ]
ON ALL SECRET [IN DATABASE <name> [, <name> ...]]
TO <role_name> [, ... ];
GRANT <CREATEROLE | CREATEDB | CREATECLUSTER | CREATENETWORKPOLICY | CREATEQUERYPOLICY | ALL [PRIVILEGES]> [, ... ]
ON SYSTEM
TO <role_name> [, ... ];
For specific view(s):
GRANT <USAGE | ALL [PRIVILEGES]>
ON TYPE <name> [, <name> ...]
TO <role_name> [, ... ];
For all types or all types in a specific schema(s) or in a specific database(s):
GRANT <USAGE | ALL [PRIVILEGES]>
ON ALL TYPES
[ IN <SCHEMA|DATABASE> <name> [, <name> ...] ]
TO <role_name> [, ... ];
For specific table(s):
GRANT <SELECT | INSERT | UPDATE | DELETE | ALL [PRIVILEGES]> [, ...]
ON [TABLE] <name> [, <name> ...]
TO <role_name> [, ... ];
For all tables or all tables in a specific schema(s) or in a specific database(s):
ALL TABLES [...] also applies to sources, views, and
materialized views (for the applicable privileges).
GRANT <SELECT | INSERT | UPDATE | DELETE | ALL [PRIVILEGES]> [, ...]
ON ALL TABLES
[ IN <SCHEMA|DATABASE> <name> [, <name> ...] ]
TO <role_name> [, ... ];
Details
Available privileges
| Privilege | Description | Abbreviation | Applies to |
|---|---|---|---|
| SELECT | Permission to read rows from an object. |
r
|
|
| INSERT | Permission to insert rows into an object. |
a
|
|
| UPDATE |
Permission to modify rows in an object. Modifying rows may also require SELECT if a read is needed to determine which rows to update. |
w
|
|
| DELETE |
Permission to delete rows from an object. Deleting rows may also require SELECT if a read is needed to determine which rows to delete. |
d
|
|
| CREATE | Permission to create a new objects within the specified object. |
C
|
|
| USAGE |
Permission to use or reference an object (e.g., schema/type lookup).
WARNING!
USAGE on a secret lets a role read the secret’s value. Materialize does not
return secret contents in query results, but a role with USAGE can reference
the secret in a connection or source that sends it to an endpoint the role
controls. Grant USAGE on a secret only to roles you would trust with the
secret itself.
|
U
|
|
| CREATEROLE |
Permission to create/modify/delete roles and manage role memberships for any role in the system.
WARNING! Roles with the
CREATEROLE privilege can obtain the privileges of any other
role in the system by granting themselves that role. Avoid granting
CREATEROLE unnecessarily.
|
R
|
|
| CREATEDB | Permission to create new databases. |
B
|
|
| CREATECLUSTER | Permission to create new clusters. |
N
|
|
| CREATENETWORKPOLICY | Permission to create network policies to control access at the network layer. |
P
|
|
| CREATEQUERYPOLICY | Permission to create query policies. |
Q
|
|
| Object | Privileges |
|---|---|
CLUSTER
|
|
CONNECTION
|
|
DATABASE
|
|
MATERIALIZED VIEW
|
|
QUERY POLICY
|
|
SCHEMA
|
|
SECRET
|
|
SOURCE
|
|
SYSTEM
|
|
TABLE
|
|
TYPE
|
|
VIEW
|
|
Privileges
The privileges required to execute this statement are:
- Ownership of affected objects.
USAGEprivileges on the containing database if the affected object is a schema.USAGEprivileges on the containing schema if the affected object is namespaced by a schema.- superuser status if the privilege is a system privilege.
Examples
GRANT SELECT ON mv_quarterly_sales TO data_analysts, reporting;
GRANT USAGE, CREATE ON DATABASE materialize TO data_analysts;
GRANT ALL ON CLUSTER dev_cluster TO data_analysts, developers;
GRANT CREATEDB ON SYSTEM TO source_owners;
Useful views
mz_internal.mz_show_system_privilegesmz_internal.mz_show_my_system_privilegesmz_internal.mz_show_cluster_privilegesmz_internal.mz_show_my_cluster_privilegesmz_internal.mz_show_database_privilegesmz_internal.mz_show_my_database_privilegesmz_internal.mz_show_schema_privilegesmz_internal.mz_show_my_schema_privilegesmz_internal.mz_show_object_privilegesmz_internal.mz_show_my_object_privilegesmz_internal.mz_show_all_privilegesmz_internal.mz_show_all_my_privileges