USERS, ROLES, GROUPS

Let me explain it with some "Roles and Permissions" qns

QN: 1

Create a login role report_user that can only read from film table.

ANS:
CREATE ROLE report_user LOGIN;
GRANT SELECT ON film TO report_user;

since, we are creating a new user called report_user.. and giving only SELECT access to film table.. so it can only read data.

QN: 2

Try to access customer table and fix permission denied.

ANS:
GRANT SELECT ON customer TO report_user;

since, report_user does not have access to customer table.. so it gives error.. so we give SELECT permission to fix it.

QN: 3

Allow report_user to see only some columns in customer table.

ANS:
REVOKE SELECT ON customer FROM report_user;
GRANT SELECT (customer_id, first_name, last_name) ON customer TO report_user;

since, we remove full access first.. then give access only to specific columns.

QN: 4

Create support_user with limited permissions.

ANS:
CREATE ROLE support_user LOGIN;
GRANT SELECT ON customer TO support_user;
GRANT UPDATE (email) ON customer TO support_user;

since, support_user can read full table.. but can update only email column.. and no delete is given.

QN: 5

Remove film access from report_user.

ANS:
REVOKE SELECT ON film FROM report_user;

since, we remove previously given permission.

QN: 6

Create readonly_group with SELECT on all tables.

ANS:
CREATE ROLE readonly_group;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly_group;

since, this group can read all tables.

QN: 7

Create analyst1 and analyst2 and add to group.

ANS:
CREATE ROLE analyst1 LOGIN;
CREATE ROLE analyst2 LOGIN;
GRANT readonly_group TO analyst1;
GRANT readonly_group TO analyst2;

since, both users are added to group.. so they get read-only access automatically.

 

Comments

Popular posts from this blog

THE DELIVERY MAN

EC2 LAUNCHING

SORT A LINKED LIST USING MERGE SORT