Sample Exam Questions

From the objective of OSS-DB Exam Silver
- Operation and Management - Installation Method (Template Database)

Sample Question


Choose the two most accurate statements regarding the template databases.

  1. Tables can be added to the template database template0  like a normal (non template) database.
  2. Tables can be added to the template database template1 like a normal (non template) database.
  3. When you create a new database with CREATE DATABASE, unless specified in the option, template0 is used as a template database. 
  4. To create a new template database called template2, add the TEMPLATE option when executing the CREATE DATABASE command.
  5. By default, no users can connect to the template database template0. 

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

Answer and Explanation

When creating a new database with CREATE DATABASE in PostgreSQL,  a copy of either the default or specified template database  is made.

Immediately after the database cluster is initialized by initdb, there are two  template databases, one called template0 and one called template1. 

Template0 is includes only standard objects that the base PostgreSQL provides, you will not be able to add or update either data or objects. template1, together with normal (non template) databases, allow you to add or update data and objects. 

CREATE DATABASE uses template1 as the template database by default. If you want to use another database as a template database, specify that database using the TEMPLATE option. The database specified with the TEMPLATE option does not necessarily need to be a template database, but if you specify a database that is not a template database, you must be either a superuser or the owner of that database. To make the database a template database, set the datistemplate of the system catalog pg_database to true.

In order to prevent template0 from being accidentally updated, datallowconn of pg_database is false, so that no one can connect, including superuser.

Therefore, the correct answer is B and E.