0
0
PostgreSQLquery~20 mins

Role creation and management in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Role Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this role creation query?
Consider the following SQL command executed in PostgreSQL:

CREATE ROLE analyst LOGIN PASSWORD 'secure123' NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT;

What will be the result when you run \du analyst to list this role's attributes?
PostgreSQL
CREATE ROLE analyst LOGIN PASSWORD 'secure123' NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT;
ARole name: analyst, Attributes: Cannot create DB, Can create role, Can inherit, Can login
BRole name: analyst, Attributes: Superuser, Can create DB, Can create role, Can inherit, Can login
CRole name: analyst, Attributes: Cannot login, Can create DB, Can create role, Can inherit
DRole name: analyst, Attributes: Cannot create DB, Cannot create role, Cannot inherit, Can login
Attempts:
2 left
💡 Hint
Look carefully at the keywords NOSUPERUSER, NOCREATEDB, NOCREATEROLE, NOINHERIT and LOGIN.
📝 Syntax
intermediate
1:30remaining
Which option correctly grants a role the ability to create databases?
You want to grant the role 'developer' the permission to create databases. Which of the following SQL commands is syntactically correct and achieves this?
AALTER ROLE developer WITH CREATEDB;
BALTER ROLE developer SET CREATEDB;
CALTER ROLE developer CREATEDB;
DALTER ROLE developer GRANT CREATEDB;
Attempts:
2 left
💡 Hint
Remember the syntax for altering role attributes in PostgreSQL.
🔧 Debug
advanced
2:00remaining
Why does this role creation command fail?
You run the following command:

CREATE ROLE manager PASSWORD 'pass123' LOGIN;

But PostgreSQL returns an error. What is the cause?
PostgreSQL
CREATE ROLE manager PASSWORD 'pass123' LOGIN;
AThe PASSWORD clause is deprecated; use ENCRYPTED PASSWORD instead.
BThe PASSWORD clause must come after LOGIN keyword.
CThe LOGIN keyword must come before PASSWORD clause.
DThe PASSWORD clause requires the keyword ENCRYPTED before it.
Attempts:
2 left
💡 Hint
Check PostgreSQL documentation for role creation syntax regarding passwords.
🧠 Conceptual
advanced
1:30remaining
What is the effect of the NOINHERIT attribute on a role?
In PostgreSQL, what does setting the NOINHERIT attribute on a role do?
AThe role cannot grant privileges to other roles.
BThe role cannot inherit privileges from roles it is a member of.
CThe role cannot login to the database.
DThe role cannot be a member of any other role.
Attempts:
2 left
💡 Hint
Think about what inheritance means in role membership.
optimization
expert
2:30remaining
Efficiently revoking multiple privileges from a role
You want to revoke the privileges to create databases and create roles from the role 'temp_admin'. Which single SQL command correctly and efficiently revokes both privileges?
AALTER ROLE temp_admin NOCREATEDB NOCREATEROLE;
BREVOKE CREATEDB, CREATEROLE FROM temp_admin;
CREVOKE ALL PRIVILEGES ON DATABASE temp_admin;
DALTER ROLE temp_admin REVOKE CREATEDB, CREATEROLE;
Attempts:
2 left
💡 Hint
Remember that CREATEDB and CREATEROLE are role attributes, not privileges on objects.