Sample Exam Questions

From the objective of OSS-DB Exam Silver
S2.5 Basic server administration (Adding, deleting and modifying database role / user)

Sample Question

2.13

Choose two appropriate ways to create a user cdbuser with privileges to create databases. In either of these options, the user executing the command is assumed to have the necessary privileges.

 
  1. Connect to a database in psql and execute:
    create role cdbuser login createdb

  2. Connect to a database in psql and execute:
    create user cdbuser db

  3. Connect to a database in psql and execute:
    create user name=cdbuser grant=dbcreate

  4. From the OS command line, execute:
    createuser -d cdbuser

  5. From the OS command line, execute:
    createuser -D cdbuser

※This sample exam is different from those that appear in the actual OSS-DB Exam.
2024/05/07

Answer and Explanation

To create a user in the database, connect to the database and execute CREATE USER. In terms of syntax, you specify the user name to be created after CREATE USER, followed by the privileges to be granted (or not granted). To grant database creation privileges, specify the option CREATEDB.

Since PostgreSQL makes no distinction between users and roles, CREATE ROLE can still create users, but since the role created by default does not have access to the database, the LOGIN option is specified to grant access to the database.

Option A has this format. The options B and C are specified incorrectly.

PostgreSQL also allows database users to be created by executing the command createuser from the OS command line. This command interprets the specified options, connects to the database, and issues CREATE ROLE. The parameter specifications are in reverse order from SQL's CREATE USER: createuser is immediately followed by permission options, and the user name to be created at the end.

Specify the -d option to grant the database creation (CREATEDB) privilege. Uppercase -D means no database privileges are granted. The result is the same without -D, because it is not granted by default.

Similarly, the lowercase -l, -r, and -s grant connection (LOGIN), user creation (CREATEROLE), and superuser (SUPERUSER) privileges, respectively, while the uppercase -L, -R, and -S mean that these privileges are not granted. It would be beneficial to understand these collectively.

So the correct answers are A and D.