GRANT statement controls each role or user’s SQL privileges for interacting with specific databases, schemas, tables, or user-defined types. For privileges required by specific statements, see the documentation for the respective SQL statement.
You can use GRANT to directly grant privileges to a role or user, or you can grant membership to an existing role, which grants that role’s privileges to the grantee. Users granted a privilege with WITH GRANT OPTION can in turn grant that privilege to others. The owner of an object implicitly has the GRANT OPTION for all privileges, and the GRANT OPTION is inherited through role memberships.
For new databases, users with the following roles are automatically granted the ALL privilege:
- Every user who is part of the
adminrole (including therootuser) - Every user who is part of the
ownerrole for the new database
Syntax
Parameters
Grant all privileges.
A comma-separated list of privileges to grant. For guidelines, see Managing privileges.Supported privileges include:
SELECT- Read data from a tableINSERT- Insert data into a tableUPDATE- Update data in a tableDELETE- Delete data from a tableCREATE- Create objects in a database or schemaDROP- Drop objects from a databaseGRANT- Grant privileges to other usersUSAGE- Use a schema or typeEXECUTE- Execute a functionZONECONFIG- Modify replication zonesCONNECT- Connect to a database
A comma-separated list of database, table, sequence, or function names. The list should be preceded by the object type (e.g.,
DATABASE mydatabase).Grant privileges on all sequences in a schema or list of schemas.
Grant privileges on all tables and sequences in a schema or list of schemas.
Grant privileges on all user-defined functions in a schema or list of schemas.
A comma-separated list of roles.
Designate the user as a role admin. Role admins can grant or revoke membership for the specified role.
Allow the user to grant the specified privilege to others.
Required privileges
-
To grant privileges, the user granting the privileges must also have the privilege being granted on the target database or tables. For example, a user granting the
SELECTprivilege on a table to another user must have theSELECTprivileges on that table andWITH GRANT OPTIONonSELECT. -
To grant roles, the user granting role membership must be a role admin (i.e., members with the
WITH ADMIN OPTION) or a member of theadminrole. To grant membership to theadminrole, the user must haveWITH ADMIN OPTIONon theadminrole.
Details
Granting privileges
When a role or user is granted privileges for a table, the privileges are limited to the table. The user does not automatically get privileges to new or existing tables in the database.Granting roles
- Users and roles can be members of roles
- The
rootuser is automatically created as anadminrole and assigned theALLprivilege for new databases - All privileges of a role are inherited by all its members
- Membership loops are not allowed (direct or indirect)
Examples
Grant privileges on databases
Grant privileges on specific tables
Grant privileges on all tables in a database or schema
To grant all the privileges on existing tables to a user:ALTER DEFAULT PRIVILEGES:
Grant system-level privileges
System-level privileges live above the database level and apply to the entire cluster.root and admin users have system-level privileges by default, and are capable of granting it to other users and roles using the GRANT statement.
Make a table readable to every user
Grant privileges on schemas
Grant privileges on user-defined types
Grant the privilege to manage replication zones
max can then use the CONFIGURE ZONE statement to add, modify, reset, or remove replication zones for the table rides.
Grant role membership
Grant the admin option
See also
- REVOKE
- SHOW GRANTS
- CREATE ROLE
- ALTER ROLE
- DROP ROLE
- Privileges