Introduction
Roles help control who can do what in a database. They keep data safe and organized.
Jump into concepts and practice - no test required
Roles help control who can do what in a database. They keep data safe and organized.
CREATE ROLE role_name [WITH option [option ...]]; ALTER ROLE role_name [WITH option [option ...]]; DROP ROLE role_name;
Use CREATE ROLE to make a new role.
Use ALTER ROLE to change role settings.
Use DROP ROLE to remove a role.
CREATE ROLE read_only; -- Creates a role named read_only with no special permissions.
CREATE ROLE admin WITH LOGIN PASSWORD 'secret'; -- Creates a role that can log in with a password.
ALTER ROLE read_only NOLOGIN; -- Prevents the role from logging in directly.
DROP ROLE read_only; -- Deletes the role from the database.
This creates a role named analyst that can log in and create databases. Then it shows the role details.
CREATE ROLE analyst WITH LOGIN PASSWORD 'data123'; ALTER ROLE analyst CREATEDB; -- Allows analyst to create databases -- Check roles SELECT rolname, rolcanlogin, rolcreatedb FROM pg_roles WHERE rolname = 'analyst';
Roles can represent users or groups.
Use strong passwords for roles with login rights.
Always check existing roles before creating new ones to avoid duplicates.
Roles control access and permissions in PostgreSQL.
Use CREATE ROLE, ALTER ROLE, and DROP ROLE to manage roles.
Roles can have login rights and other options like creating databases.
CREATE ROLE analyst NOLOGIN; ALTER ROLE analyst CREATEDB;
analyst?CREATE ROLE manager LOGIN PASSWORD 'secret';
developer that can log in, create databases, and also inherit permissions from another role team_member. Which command correctly achieves this?