0
0
PostgreSQLquery~5 mins

Role creation and management in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a role in PostgreSQL?
A role in PostgreSQL is an entity that can own database objects and have database privileges. It can represent a user or a group of users.
Click to reveal answer
beginner
How do you create a new role with login capability?
Use the command: CREATE ROLE role_name LOGIN; This creates a role that can be used to connect to the database.
Click to reveal answer
intermediate
What command grants a role the ability to create databases?
Use: ALTER ROLE role_name CREATEDB; to allow the role to create new databases.
Click to reveal answer
intermediate
How can you assign one role to another role (role membership)?
Use: GRANT role_name TO member_role; to make member_role inherit privileges of role_name.
Click to reveal answer
intermediate
How do you remove a role from the database?
Use: DROP ROLE role_name; to delete the role. Make sure the role owns no database objects or is not connected.
Click to reveal answer
Which command creates a role that can log in to the database?
ACREATE ROLE user1 NOCREATE;
BCREATE ROLE user1 LOGIN;
CALTER ROLE user1 LOGIN;
DGRANT LOGIN TO user1;
How do you allow a role to create new databases?
AGRANT CREATEDB TO role_name;
BCREATE ROLE role_name CREATEDB;
CALTER ROLE role_name CREATEDB;
DSET role_name CREATEDB;
What does the command GRANT admin TO user; do?
AGives user the privileges of admin role.
BCreates a new role named admin for user.
CRemoves admin role from user.
DChanges user role to admin.
Which command removes a role from PostgreSQL?
AREMOVE ROLE role_name;
BDROP USER role_name;
CDELETE ROLE role_name;
DDROP ROLE role_name;
Can a role in PostgreSQL represent a group of users?
AYes, roles can be groups or individual users.
BNo, roles are only individual users.
COnly if the role has LOGIN privilege.
DOnly if the role is a superuser.
Explain how to create a new PostgreSQL role that can log in and create databases.
Think about the commands to create a role and then grant it database creation rights.
You got /3 concepts.
    Describe how role membership works in PostgreSQL and how to grant one role to another.
    Consider how roles can be grouped by granting one role to another.
    You got /3 concepts.