Sample Exam Questions

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

Sample Question

2.40

Choose the three most appropriate descriptions for the createuser command.

 
  1. The same can be achieved by connecting to a database using psql etc., and executing the DROP DATABASE command.

  2. You can delete either a database created with the createdb command or a database created with the CREATE DATABASE command.

  3. You can also delete databases that are running on other hosts.

  4. You must be a superuser or have CREATEDB privileges to execute it.

  5. The database to be deleted must be empty, otherwise an error occurs.

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

Answer and Explanation

In PostgreSQL, there are multiple databases in a database cluster. To add a database to the cluster, execute the CREATE DATABASE command, or to drop one, execute the DROP DATABASE command. The createdb and dropdb commands are provided as wrappers so that these commands can be executed from the OS. Because it is a wrapper, anything that dropdb can do can also be done with DROP DATABASE. Also, there is no real distinction between these OS and SQL commands, so you can drop a database whether you used CREATE DATABASE or createdb to create it.

dropdb, like other PostgreSQL client utilities, allows you to specify the host to which you want to connect, the port number, and so on, allowing you to run commands against databases running on other hosts over the network.

You must have superuser or CREATEDB privileges to create a new database, but you must have superuser privileges or be the owner of the database to drop it. Even if you have the CREATEDB privilege, you must be the owner to drop it.

dropdb will drop the database even if it is not empty. This is also the same with DROP TABLE with which you can drop a table with data. If you drop it, you will not be able to undo it, so be very careful when you do so.

So the correct answers are A, B, and C.