Sample Exam Questions
Connect to a database in psql and execute:
create role cdbuser login createdb
Connect to a database in psql and execute:
create user cdbuser db
Connect to a database in psql and execute:
create user name=cdbuser grant=dbcreate
From the OS command line, execute:
createuser -d cdbuser
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
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.
© EDUCO All Rights Reserved.