MCQs on User Management and Security | PostgreSQL Database

Boost your PostgreSQL expertise with this curated set of 30 multiple-choice questions on user management and security. Learn about roles, permissions, privileges, and security best practices to ensure database protection.


Topics Covered:

  • Creating and Managing Roles
  • Role Inheritance and Permissions
  • Granting and Revoking Privileges
  • Security Best Practices

MCQs on User Management and Security

Creating and Managing Roles

  1. Which command is used to create a role in PostgreSQL?
    • A) CREATE ROLE <role_name>;
    • B) NEW ROLE <role_name>;
    • C) CREATE USER <role_name>;
    • D) ROLE CREATE <role_name>;
  2. In PostgreSQL, roles can function as:
    • A) Users
    • B) Groups
    • C) Both A and B
    • D) Neither A nor B
  3. What option allows the created role to log into the database?
    • A) WITH LOGIN
    • B) ALLOW LOGIN
    • C) ENABLE LOGIN
    • D) LOGIN TRUE
  4. How do you delete a role in PostgreSQL?
    • A) DROP USER <role_name>;
    • B) REMOVE ROLE <role_name>;
    • C) DELETE ROLE <role_name>;
    • D) DROP ROLE <role_name>;
  5. Which command is used to alter an existing role’s attributes?
    • A) MODIFY ROLE <role_name>;
    • B) ALTER ROLE <role_name>;
    • C) UPDATE ROLE <role_name>;
    • D) CHANGE ROLE <role_name>;

Role Inheritance and Permissions

  1. What does the INHERIT attribute in PostgreSQL roles do?
    • A) Allows roles to inherit permissions from other roles
    • B) Allows roles to inherit schema ownership
    • C) Allows roles to create child roles
    • D) Allows roles to inherit database connections
  2. How do you grant a role the ability to inherit privileges?
    • A) GRANT INHERIT TO <role_name>;
    • B) ALTER ROLE <role_name> WITH INHERIT;
    • C) GRANT PERMISSIONS TO <role_name>;
    • D) ENABLE INHERIT FOR <role_name>;
  3. What happens when a role does not have the NOINHERIT attribute?
    • A) It inherits all granted privileges automatically
    • B) It requires explicit permission for privileges
    • C) It cannot access any database objects
    • D) It becomes a superuser
  4. How can a role be allowed to bypass all access controls in PostgreSQL?
    • A) Assign SUPERUSER attribute
    • B) Assign BYPASS attribute
    • C) Assign ADMIN attribute
    • D) Assign CONTROL attribute
  5. Which command grants the ability to inherit privileges to a role?
    • A) ALTER ROLE <role_name> INHERIT;
    • B) GRANT PRIVILEGES TO <role_name>;
    • C) CREATE INHERIT ROLE <role_name>;
    • D) ENABLE INHERIT ROLE <role_name>;

Granting and Revoking Privileges

  1. Which SQL command grants permissions on a table to a role?
    • A) PERMIT <role_name> ON <table_name>;
    • B) ALLOW <role_name> ON <table_name>;
    • C) GRANT <permissions> ON <table_name> TO <role_name>;
    • D) GIVE <permissions> TO <role_name>;
  2. How do you revoke a specific privilege from a role?
    • A) REMOVE <privilege> FROM <role_name>;
    • B) REVOKE <privilege> ON <object> FROM <role_name>;
    • C) DELETE <privilege> FROM <role_name>;
    • D) RESET PRIVILEGES <role_name>;
  3. What does the GRANT option WITH GRANT OPTION allow?
    • A) Allows the role to create databases
    • B) Allows the role to revoke granted privileges
    • C) Allows the role to grant the privilege to others
    • D) Allows the role to drop database objects
  4. If a role has privileges on a table, how can they be checked?
    • A) LIST PRIVILEGES <role_name>;
    • B) \dp <table_name> in psql
    • C) SHOW PERMISSIONS <table_name>;
    • D) DESCRIBE GRANTS <role_name>;
  5. What is the default behavior when GRANT is used on a table without specifying permissions?
    • A) Grants all privileges
    • B) Grants SELECT privilege
    • C) Grants SELECT and INSERT privileges
    • D) Grants no privileges
  6. How do you revoke ALL privileges from a role on a specific table?
    • A) RESET PRIVILEGES <role_name>;
    • B) REVOKE ALL ON <table_name> FROM <role_name>;
    • C) REMOVE ALL <role_name>;
    • D) RESET PERMISSIONS <role_name>;
  7. Which privilege is required to modify data in a table?
    • A) SELECT
    • B) UPDATE
    • C) DELETE
    • D) INSERT
  8. Can a role with no LOGIN attribute be granted privileges?
    • A) Yes
    • B) No
    • C) Only if it has SUPERUSER attribute
    • D) Only if granted by a superuser
  9. What command allows revoking all privileges granted by a specific role?
    • A) REMOVE ALL GRANTS <role_name>;
    • B) REVOKE GRANTED BY <role_name>;
    • C) REVOKE ALL PRIVILEGES BY <role_name>;
    • D) RESET GRANTS BY <role_name>;
  10. What privilege is needed to create new objects in a schema?
    • A) CREATE
    • B) ALTER
    • C) OWNER
    • D) SUPERUSER

Security Best Practices

  1. Which role attribute should be minimized to reduce security risks?
    • A) LOGIN
    • B) SUPERUSER
    • C) CREATE ROLE
    • D) NOINHERIT
  2. What is a key benefit of using role inheritance in PostgreSQL?
    • A) Centralized management of permissions
    • B) Automatic database backups
    • C) Improved query performance
    • D) Simplified schema creation
  3. What should be done to secure database connections over a network?
    • A) Use SSL/TLS encryption
    • B) Enable SUPERUSER for all roles
    • C) Use default passwords
    • D) Allow public IP connections
  4. What is the purpose of the pg_hba.conf file?
    • A) To manage role privileges
    • B) To configure database authentication
    • C) To set the PostgreSQL version
    • D) To define the schema structure
  5. How can you enforce password complexity in PostgreSQL?
    • A) Using password_encryption configuration
    • B) Using a custom password policy function
    • C) Adding constraints to the role creation
    • D) All of the above
  6. Why is it important to regularly audit user roles and privileges?
    • A) To improve database performance
    • B) To detect unauthorized access
    • C) To create new schemas
    • D) To enable faster queries
  7. Which command ensures that passwords are stored securely?
    • A) SET password_encryption TO ‘md5’;
    • B) SET password_encryption TO ‘scram-sha-256’;
    • C) SET password_security TO ‘true’;
    • D) ENCRYPT PASSWORDS;
  8. What is the best practice for default roles after installation?
    • A) Remove or restrict default roles
    • B) Grant all permissions to public
    • C) Change superuser to read-only
    • D) Enable all default privileges
  9. Which PostgreSQL log file setting is useful for monitoring failed login attempts?
    • A) log_connections
    • B) log_disconnections
    • C) log_min_error_statement
    • D) log_line_prefix
  10. How can you prevent SQL injection in PostgreSQL?
    • A) Use parameterized queries
    • B) Sanitize user inputs
    • C) Limit user privileges
    • D) All of the above

Answer Key

QnoAnswer
1A) CREATE ROLE <role_name>;
2C) Both A and B
3A) WITH LOGIN
4D) DROP ROLE <role_name>;
5B) ALTER ROLE <role_name>;
6A) Allows roles to inherit permissions
7B) ALTER ROLE <role_name> WITH INHERIT;
8A) It inherits all granted privileges
9A) Assign SUPERUSER attribute
10A) ALTER ROLE <role_name> INHERIT;
11C) GRANT <permissions> ON <table_name> TO <role_name>;
12B) REVOKE <privilege> ON <object> FROM <role_name>;
13C) Allows the role to grant the privilege to others
14B) \dp <table_name> in psql
15A) Grants all privileges
16B) REVOKE ALL ON <table_name> FROM <role_name>;
17B) UPDATE
18A) Yes
19C) REVOKE ALL PRIVILEGES BY <role_name>;
20A) CREATE
21B) SUPERUSER
22A) Centralized management of permissions
23A) Use SSL/TLS encryption
24B) To configure database authentication
25D) All of the above
26B) To detect unauthorized access
27B) SET password_encryption TO ‘scram-sha-256’;
28A) Remove or restrict default roles
29A) log_connections
30D) All of the above

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top