0Pricing
SQL Academy · Lesson

Roles and Privileges

GRANT and REVOKE access.

What Are Roles and Privileges?

In SQL, roles are named groups of privileges that can be assigned to users. Privileges control what actions a user or role is allowed to perform on database objects such as tables, views, and functions.

Instead of granting permissions to each user individually, you create a role with the required privileges and then assign that role to many users at once. This makes access control much easier to manage at scale.

Creating a Role

Use CREATE ROLE to define a new role in PostgreSQL. A role can represent a single user or a group of users depending on how you configure it.

Roles are created without any privileges by default — you must explicitly grant them access to objects.

CREATE ROLE readonly_user;
CREATE ROLE app_writer;
CREATE ROLE db_admin;

All lessons in this course

  1. Roles and Privileges
  2. Row-Level Security Policies
  3. Column-Level Permissions
  4. Auditing Access
← Back to SQL Academy