Certification Objectives: Q&A Self-Test
Certification Objectives: Q&A Self-Test
2.01
Create a Database by Using the Database Configuration Assistant (DBCA)
2.02Generate Database Creation Scripts by Using DBCA
2.03Manage Database Design Templates by Using DBCA
2.04Configure Database Options by Using DBCA
2.05Certification Summary
Two-Minute Drill
Q&A Self-Test
T his chapter goes through the theory and practice of creating a database—through
the mechanics of creation using both the GUI and command line. This chapter also
provides a description of using database templates. However, one objective that must be
dealt with immediately is to demystify the process: creating a database is no big deal.
Furthermore, you really do not have to worry about getting it right. Hardly anything is
fixed at database-creation time. It certainly makes sense to think about how your
database will be structured, its purpose and environment, at creation time, but (with
one exception) everything can be changed afterward, although some changes may be
awkward. As a general rule, keep things as simple as possible at this stage.
CERTIFICATION OBJECTIVE 2.01
Create a Database by Using the Database Configuration Assistant (DBCA)
Although creating a database is not difficult (the process can be quick and simple—a
single two-word command will do it—and it may take less than 10 minutes), there are
some concepts you should understand before proceeding with the creation process—
namely, the instance, the database, and the data dictionary.
The Instance, the Database, and the Data Dictionary
An Oracle server is an instance and a database; the two are separate but connected. The
instance is composed of memory structures and processes, in your RAM and on your
CPU(s). Its existence is transient; it can be started and stopped. The database is
composed of files on disk; once created, it persists until it is deleted. Creating an
instance is nothing more than building the memory structures and starting the
processes. Creating a database is done by the instance as a once-off operation, and the
instance can then subsequently open and close the database many times. The database
is inaccessible without the instance.
Within the database is a set of tables and other objects called the data dictionary. The
data dictionary describes all the logical and physical structures in the database,
including all the segments that store user data. The database creation process involves
creating the bare minimum of physical structures needed to support the data dictionary
and then creating the data dictionary within them.
An instance is defined by an instance parameter file. The parameter file contains
directives that define (among other things) how the instance should be built in memory,
including the size of the memory structures and the behavior of the background
processes. After the instance has been built, it is said to be in “no mount” mode. In no
mount mode, the instance exists but has not connected to a database. Indeed, the
database may not have been created at this point.
All parameters, either specified by the parameter file or set implicitly, have defaults,
except for the DB_NAME parameter. This parameter names the database to which the
instance will connect. This name is also embedded in the controlfile. One parameter,
CONTROL_FILES, tells the instance the location of the controlfile. This parameter
defines the connection between the instance and the database. When the instance reads
the controlfile (which it will find by reading the CONTROL_FILES parameter or by
relying on the default value), if there is a mismatch in database names, the database will
not mount. In mount mode, the instance has successfully connected to the controlfile. If
the controlfile is damaged or nonexistent, it will be impossible to mount the database.
The controlfile is small, but vital.
Within the controlfile are pointers to the other files (the online redo log files and the
datafiles) that make up the rest of the database. Having mounted the database, the
instance can open the database by locating and opening these other files. An open
database is a database where the instance has opened all the available online redo log
files and datafiles. Also within the controlfile is a mapping of datafiles to tablespaces.
This lets the instance identify the datafile(s) that make(s) up the SYSTEM tablespace. In
the SYSTEM tablespace, it will find the data dictionary. The data dictionary lets the
instance resolve references to objects referred to in SQL code to the segments in which
they reside, and work out where, physically, the objects are.
The creation of a database server must therefore involve these steps:
1. Create the instance.
2. Create the database.
3. Create the data dictionary.
In practice, though, there is a fourth step:
4. Make the database usable.
The data dictionary, as initially created with the database, is fully functional but
unusable. It has the capability for defining and managing user data but cannot be used
by normal human beings because its structure is too abstruse. Before users (or DBAs)
can actually use the database, a set of views must be created on top of the data
dictionary that will present it in a human-understandable form. Also, many PL/SQL
packages are required to add functionality.
The data dictionary itself is created by running a set of SQL scripts that exist in the
ORACLE_HOME/rdbms/admin directory. These are called by the CREATE
DATABASE command. The first is sql.bsq, which then calls several other scripts. These
scripts issue a series of commands that create all the tables and other objects that make
up the data dictionary.
The views and other objects that make the database usable are generated with more
scripts in the ORACLE_HOME/rdbms/admin directory and have a “cat” prefix.
Examples of these are catalog.sql and catproc.sql, which should always be run
immediately after database creation. There are many other optional “cat” scripts that
will enable certain features—some of these can be run at creation time; others might be
run subsequently to install the features at a later date.
Using the DBCA to Create a Database
Here are the steps to follow to create a database:
1. Create a parameter file and (optionally) a password file.
2. Use the parameter file to build an instance in memory.
3. Issue the CREATE DATABASE command. This will generate, at a minimum, a
controlfile, two online redo log files, one datafile each for the SYSTEM and SYSAUX
tablespaces, and a data dictionary. The syntax does allow a lot more to be done at this
point.
4. Run SQL scripts to generate the data dictionary views and the supplied PL/SQL
packages.
5. Run SQL scripts to generate the Enterprise Manager Database Express as well as
any options (such as Java) the database will require.
6. On Windows systems, there is an additional step because Oracle runs as a Windows
service. Oracle provides a utility, oradim.exe, to assist you in creating this service.
These steps can be executed interactively from the SQL*Plus prompt or through a GUI
tool, the Database Configuration Assistant (DBCA). Alternatively, you can automate the
process by using scripts or the DBCA with a response file.
Regardless of the platform you are running on, the easiest way to create a database is
through the DBCA. It creates a parameter file and a password file and then generates
scripts that will start the instance, create the database, and generate the data dictionary
and the data dictionary views. Alternatively, you can create the parameter file and
password file by hand and then do the rest from a SQL*Plus session. Many DBAs
combine the two techniques: they use the DBCA to generate the files and scripts, and
then look at them and perhaps edit them before running them from SQL*Plus.
To launch the DBCA on Windows, take the shortcut on the Start menu. Here’s the
navigation path:
1. Start
2. Programs
3. Oracle – OraDB12Home1
4. Configuration and Migration Tools
5. Database Configuration Assistant
Note that the precise path will vary depending on the name given to the Oracle Home at
install time. Alternatively, run the dbca.bat script from a CMD prompt. Following a
standard installation, it will be included in your Windows search path.
To launch the DBCA on Linux, first set the environment variables that should always be
set for any Linux DBA session: DISPLAY, ORACLE_BASE, ORACLE_HOME, and
PATH. Here is an example of a script that will do this:
Note that the Base and Home will vary according to choices made at install time. The
variables also exist in a Windows environment, but are usually defined as registry
variables set by the Oracle Universal Installer (OUI) rather than shell variables. The
DISPLAY variable must, of course, be set to the address of your X server. To launch the
DBCA, run the dbca shell script, which is located in the $ORACLE_HOME/bin
directory.
The DBCA validation checks are not comprehensive. Errors may show up
only during step 13. Typical of these are memory issues. For instance, if at
step 9 you specify Automatic Memory Management with a total that is
more that the shared memory configured on your system, you will not get
an error at this point.
Step 12: Summary
The Summary window shows what DBCA intends to do. Scan through the report, and if
you see anything you do not like, this would be a good time to use the Back button and
make changes.
FIGURE 2-12 DBCA step 12
Step 13: Progress Page
The Progress Page window shows the creation of the scripts (if they were requested) and
then the various stages of database creation. This may take 10 minutes, or it may take an
hour or more. The difference is largely dependent on whether a template was used, what
options were selected, and the hardware specifications.
FIGURE 2-13 DBCA step 13
EXERCISE 2-1
Create a Database with DBCA
Using the graphical DBCA tool, create a database. Repeat the exercise as many times as
you can, deleting any previously created database(s) first if you are short on RAM or
disk space. It is important to become comfortable with the process and to experiment
with the various options presented by the dialog.
Some of the responses will vary depending on whether the platform is Windows, Linux,
or something else. The variations will be obvious and most commonly have to do with
directory naming conventions. Here are the steps to follow:
1. Log on to the server machine.
Connect to the server as the operating system user who did the installation. The
standard account name is oracle.
2. Launch the DBCA.
From a command shell, make sure that you have the appropriate environment variables
set. The following is a typical dialog on a Linux system using the bash shell:
The DISPLAY variable is set to point to the address of your X server (typically your PC).
Test it by running any X program, such as the X-Clock. If you are running on the
console, or perhaps in a VNC Desktop, this will not be necessary. Next, the
ORACLE_BASE is set and assumes an OFA installation (binaries owned by user oracle).
ORACLE_HOME and PATH continue the OFA standard. Using the “which” utility
confirms that dbca is on the search path, so launch it.
On Windows, it may be possible to find a link to the DBCA in the Start menu and run it
relying on variables set in the Registry. Alternatively, you could control everything
manually from a command prompt, again assuming an OFA install:
Whatever the platform, the scripts have the same structure. A shell script named after
the database (for example, orcl121.sh for Linux, orcl121.bat for Windows) does some OS
work and then launches SQL*Plus to run a SQL script (called oracle121.sql). The SQL
script drives the rest of the database creation. Studying these scripts and the scripts they
call is very instructive.
The Creation Scripts
The starting point is the shell script. Let’s take a look at a Linux example:
This creates a few directories, using values calculated from the ORACLE_BASE and
ORACLE_HOME environment variables, provided in the DBCA dialog, or from defaults
with appropriate access permissions. It then concludes with the call to SQL*Plus, to
launch the SQL script orcl121.sql. A variation on Windows will be calls to the ORADIM
utility (described later) that create the Windows service under which the instance will
run.
The driving SQL script will vary greatly, depending on the options taken in the DBCA
dialog. Here is one example:
The ACCEPT commands prompt for passwords for the SYS and SYSTEM schemas. Then
the script invokes a host shell to run the orapwd utility. This utility creates the external
password file, with a name that is platform specific. On Linux it will be
$ORACLE_HOME/dbs/orapw<DBNAME> (where <DBNAME> is the name of the
database), and on Windows it will be
%ORACLE_HOME%\database\PWD<DBNAME>.ora.
Following this is a set of calls to other SQL scripts, beginning with CreateDB.sql:
The second line connects as user SYS using the supplied password. The fifth line starts
the database in no mount mode using a parameter file named init.ora. This file will be
populated with parameters set by default or specified in the DBCA dialog. The next
command (which continues to the end of the file) creates the database.
Note: Remember the modes: nomount means “build the memory structures and start
the processes.”
Following the CREATE DATABASE “orcl121” line are some settings for limits (such as
MAXDATAFILES=100, meaning that this database will be restricted to 100 datafiles)
and then clauses for four tablespaces:
The SYSTEM tablespace (where the data dictionary lives) will be in a datafile named
system01.dbf with a size of 700MB.
The SYSAUX tablespace (objects that are not associated with the data dictionary but
are very closely related) will be in a datafile named sysaux01. dbf with a size of 550MB.
A default temporary tablespace (for temporary data—space needed by sessions for,
one hopes, only a brief period) named TEMP will be in tempfile temp01.dbf, with a size
of 20MB. An undo tablespace (used for undo segments, which are necessary to ensure
transactional consistency) named UNDOTBS1 will use the datafile undotbs01.dbf, with a
size of 200MB.
Then the character sets for the database and national language are specified. In the
example, they are Unicode. The LOGFILE section specifies that the database should
have three online log file groups, each consisting of one file (the log file member) that’s
50MB in size. Finally, the passwords for SYS and SYSTEM are set.
This database creation command takes only a couple minutes to run. All it does is create
the minimal structures necessary for a database, most importantly the data dictionary.
Control then returns to the calling SQL script, which (in the example) launches more
scripts:
CreateDBFiles.sql will create a tablespace called USERS, to be used as the default
tablespace for storing permanent objects (such as tables).
CreateDBCatalog.sql calls a set of scripts to generate the required views onto the data
dictionary and the various supplied PL/SQL packages.
A set of scripts (JServer.sql through apex.sql) then generate various options that were
selected in the DBCA dialog.
postDBCreation.sql runs anything necessary immediately after creation, such as
applying bundled patches and converting the pfile to an spfile.
lockAccount.sql locks all pre-seeded accounts (with a few exceptions) and finally
restarts the database.
The scripts generated and their contents vary greatly, depending on the DBCA dialog.
For example, if at step 3 you choose to create a database from a template, the whole
process is much simpler because the database does not need to be created, and most of
the work is done via calls to the RMAN Recovery Manager procedures, which in effect
restore a database from a backup in the template.
The Initialization Parameter File
In order to start the database instance, DBCA must create an initialization parameter
file. This is generated whether you take the option to create a database or to generate
scripts. The file is generated in the same directory as the other script and is nominated
on the STARTUP command in the CreateDB.sql script:
Here is the file generated by the dialog from Exercise 2-1 (comment lines removed for
brevity):
All these parameters will be covered in later chapters. The file has just 16 parameters
specified out of hundreds, and is the bare minimum needed to get a typical database
running. Many more parameters will usually be added subsequently according to the
requirements for the environment, scale, and performance.
EXERCISE 2-2
Generate Database Creation Scripts by Using DBCA
Use DBCA to generate several sets of database creation scripts. Perform as many
iterations of this as you wish, supplying a different database name and SID each time,
and selecting different options. Here are the steps to follow:
1. Launch the DBCA. Respond to the prompts as follows:
a. Select the Create Database radio button. Click Next.
b. Select the radio button for Advanced Mode. If you choose the button for “Create a
database with default configuration,” you do not get a prompt to generate scripts. Click
Next.
c. Select the radio button for General Purpose or Transaction Processing. Click Next.
d. Specify the value gpdb for both Global Database Name and SID. Click Next.
e. Deselect everything. Click Next.
f. Enter the passwords as Oracle121. Click Next.
g. Choose Storage Type: File System. Leave everything else at the default. Click Next.
h. Leave everything at the default. Click Next.
i. Leave everything at the default. Click Next.
j. Deselect the check boxes for Create Database and Save as a Database Template.
Select the check box for Generate Database Creation Scripts. Note the destination
directory. Click Next.
k. No input needed.
l. Study the summary. Note that the install from a template will include all the options
that were prompted for in the previous exercise, and will also have values for various
parameters. Click Finish.
m. The scripts will be generated. Click OK and then Close.
2. Study the scripts.
Attempt to reverse-engineer the creation process. Note that the process is much simpler
when using a template. Compare the scripts generated by this exercise with those
generated by the previous exercise.
3. Repeat.
And repeat again, with variations. It is vital to become familiar with the DBCA dialog,
and with the scripts that it generates.
SELF TEST
Create a Database by Using the Database Configuration Assistant (DBCA)
1. Which of these operations can be accomplished with the DBCA? (Choose all correct
answers.)
A. Create a database
B. Remove a database
C. Upgrade a database
D. Add database options
E. Remove database options
2. To create a database, in what mode must the instance be? (Choose the best
answer.)
A. Not started
B. Started in NOMOUNT mode
C. Started in MOUNT mode
D. Started in OPEN mode
3. Several actions are necessary to create a database. Place these in the correct order:
1. Create the data dictionary views.
2. Create the parameter file.
3. Create the password file.
4. Issue the CREATE DATABASE command.
5. Issue the STARTUP command. (Choose the best answer.)
A. 2, 3, 5, 4, 1
B. 3, 5, 2, 4, 1
C. 5, 3, 4, 2, 1
D. 2, 3, 1, 4, 5
4. What instance parameter cannot be changed after database creation? (Choose the
best answer.)
A. All instance parameters can be changed after database creation.
B. All instance parameters can be changed after database creation, if it is done while the
instance is in MOUNT mode.
C. CONTROL_FILES.
D. DB_BLOCK_SIZE.
5. What files are created by the CREATE DATABASE command? (Choose all
correct answers.)
A. The controlfile
B. The server parameter file
C. The online redo log files
D. The password file
E. The static initialization parameter file
F. The SYSAUX tablespace datafile
G. The SYSTEM tablespace datafile
6. What will happen if you do not run the CATALOG.SQL and CATPROC.SQL scripts
after creating a database? (Choose the best answer.)
A. It will not be possible to open the database.
B. It will not be possible to create any user tables.
C. It will not be possible to use PL/SQL.
D. It will not be possible to query the data dictionary views.
E. It will not be possible to connect as any user other than SYS.
Manage Database Design Templates by Using DBCA
7. What tools can be used to manage templates? (Choose all correct answers.)
A. The Database Configuration Assistant
B. The Database Upgrade Assistant
C. SQL*Plus
D. Database Express
E. The Oracle Universal Installer
8. At what point can you not choose or change the database character set? (Choose
the best answer.)
A. At database creation time, if you are using a DBCA template
B. At database creation time, if you are using a DBCA template that includes datafiles
C. At database creation time, if you are not using a DBCA template
D. After database creation, using DBCA to install options
Configure Database Options by Using DBCA
9. If there are several databases created off the same Oracle Home, how will Database
Express be configured? (Choose the best answer.)
A. Database Express will give access to all the databases created from the one Oracle
Home through one URL.
B. Database Express will give access to each database through different ports.
C. Database Express need only be configured in one database and can then be used to
connect to all of them.
D. Database Express can manage only one database per Oracle Home.
10. The SYSAUX tablespace is mandatory. What will happen if you attempt to issue
a CREATE DATABASE command that does not specify a datafile for the SYSAUX
tablespace? (Choose the best answer.)
A. The command will fail.
B. The command will succeed, but the database will be inoperable until the SYSAUX
tablespace is created.
C. A default SYSAUX tablespace and datafile will be created.
D. The SYSAUX objects will be created in the SYSTEM tablespace.
Generate Database Creation Scripts by Using DBCA
11. What files are generated when you choose the option to Generate Database
Creation Scripts in the Database Configuration Assistant? (Choose all correct answers.)
A. A shell script
B. SQL scripts
C. A parameter file
D. A password file
E. A response file
LAB QUESTION
Create a database manually by following these steps:
1. Create an initialization file with the bare minimum of parameters.
2. Issue a CREATE DATABASE command.
3. Run a few queries to see what has been created.
4. Delete the database.
Also, set your ORACLE_HOME and PATH variables as usual. On Windows, create the
service
and then launch SQL*Plus and issue a CREATE DATABASE command, relying on
defaults for everything:
To remove the database, run the DROP DATABASE command from within SQL*Plus: