Sample Exam Questions

From the objective of OSS-DB Exam Silver
S2.2 Usage of server management tools (createuser/dropuser)

Sample Question

2.01

You want to create a new user, john, in a PostgreSQL database running on port 5432 of the server pgserver and grant the database creation privilege.
Which of the underlined parts of the following command is incorrect?
It is assumed that the user executing createuser has appropriate access privileges.

createuser -h pgserver -p 5432 -d -U john

 
  1.  -h
  2. -p
  3. -d
  4. -U
  5. There is no incorrect option.

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

Answer and Explanation

To create a database user, connect to the database with a user with privileges and issue SQL's CREATE USER.
PostgreSQL provides the createuser command, which is executed from the OS command line, and this internally connects to the database and executes CREATE USER (or more precisely, CREATE ROLE).
To connect to the database, specify the hostname where the target database is running, the port number, the username to use for the connection, etc. (if omitted, the default value is used, so it is not always necessary to specify).
The destination host is specified with the -h option, and the port number is specified with the -p option. The -U option is used to specify the connection username.
Also, to create a user, specify the username to create, the privileges to grant, etc.
The username to create is specified at the end of the command without options. The database privileges that can be granted include superuser privileges, database creation privileges, and user creation privileges. The -d option is specified to grant database creation privileges.
In the example command, the hostname (-h), port number (-p), and database creation privilege (-d) are correctly specified; however, '-U john' means to connect to the database as john, which is incorrect. If you delete ""-U"", it will be the correct command.

Therefore, the correct answer is D.

The options used for database connection are common to other client commands such as psql and createdb, so let's remember them all together.