408-Oracle Essentials Database
408-Oracle Essentials Database
Creating a Database
Objectives
•• Preparing
Preparing the
the operating
operating system
system
•• Preparing
Preparing the
the parameter
parameter file
file
•• Creating
Creating the
the database
database
4-2
Overview
Instance
User Server
process process
PGA
Control
files
Parameter
file
Datafiles Redo log
Password files
file
Database
4-3
Creation Prerequisites
• AA privileged
privileged account
account authenticated
authenticated in
in
one
one ofof the
the following
following ways:
ways:
-- By
By the
the operating
operating system
system
-- Using
Using aa password
password file
file
• Memory
Memory to to start
start the
the instance
instance
• Sufficient
Sufficient disk
disk space
space for
for the
the planned
planned
database
database
4-4
Planning Database File Locations
•• Keep
Keep at
at least
least two
two active
active copies
copies ofof aa database
database
control
control file
file on
on at
at least
least two
two different
different devices.
devices.
•• Multiplex
Multiplex the
the redo
redo loglog files
files and
and put
put group
group
members
members on on different
different disks.
disks.
•• Separate
Separate data
data files
files whose
whose data:
data:
–– Will
Will participate
participate in
in disk
disk resource
resource contention
contention
across
across different
different physical
physical disk
disk resources
resources
–– Have
Have different
different life-spans
life-spans
–– Have
Have different
different administrative
administrative characteristics
characteristics
4-5
Oracle Software Locations
/u01/app/oracle /u02/app/applmgr
/product /product
/8.0.3
/bin
/dbs
/orainst
/sqlplus
...
/7.3.3
/admin /admin
/local /local
4-6
Oracle Database Files
/u02/ /u03/
oradata/ oradata/
db01/ db01/
system01.dbf tools01.dbf
control01.ctl control02.ctl
redo0101.rdo redo0102.rdo
... ...
db02/ db02/
system01.dbf users01.dbf
control01.ctl control02.ctl
redo0101.rdo redo0102.rdo
... ...
4-7
Creating a Database: Considerations
• On
On UNIX:
UNIX:
–– Created
Created automatically
automatically during
during an
an
installation
installation
–– Created
Created manually
manually after
after installation
installation
• On
On NT:
NT:
–– Created
Created using
using the
the Oracle
Oracle Database
Database
Assistant
Assistant
–– Created
Created manually
manually
4-8
File Management Methods
Files
Files controlled
controlled byby the
the file
file management
management method
method
are
are control
control files,
files, data
data files,
files, and
and redo
redo log
log files
files
Determines
Determines how
how files
files are
are located
located to
to help
help with:
with:
•• Multiplexing
Multiplexing of
of control
control and
and redo
redo log
log files
files
•• I/O
I/O load
load balancing
balancing
Determines
Determines how
how files
files are
are added,
added, extended,
extended, or
or
deleted
deleted
4-9
User-Managed File Management
Type
Type of
of File
File Management
Management (first
(first of
of two
two methods)
methods)
Pros:
Pros:
•• DBA
DBA has
has complete
complete control
control of
of names,
names, locations,
locations,
and
and sizes
sizes of
of all
all files
files
•• Compatible
Compatible with
with older
older versions
versions
Cons:
Cons:
•• DBA
DBA must
must manually
manually delete
delete files
files after
after their
their
associated
associated tablespace
tablespace is
is dropped
dropped
•• DBA
DBA must
must monitor
monitor and
and adjust
adjust file
file sizes
sizes over
over
time
time
4-10
User-Managed File Management
How
How to
to implement:
implement:
•• For
For user-managed
user-managed control
control files,
files, set
set
CONTROL_FILES
CONTROL_FILES to to aa list
list of
of files.
files. For
For example:
example:
•• For
For user-managed
user-managed redo
redo log
log files,
files, use
use the
the LOGFILE
LOGFILE
clause
clause in
in the
the CREATE
CREATE DATABASE
DATABASE command.
command.
•• For
For user-managed
user-managed data
data files,
files, use
use the
the DATAFILE
DATAFILE
clause
clause in
in the
the CREATE
CREATE DATABSE
DATABSE command
command or
or the
the
CREATE
CREATE TABLESPACE
TABLESPACE command
command
4-11
User-Managed File Management
Example
Example
Initialization
Initialization parameter:
parameter:
CONTROL_FILES
CONTROL_FILES == (/d1/oracle/control01.ctl,
(/d1/oracle/control01.ctl, /d2/oracle/control02.ctl)
/d2/oracle/control02.ctl)
CREATE
CREATE DATABASE
DATABASE command:
command:
CREATE
CREATE DATABASE
DATABASE TECHNO92
TECHNO92
MAXDATAFILES
MAXDATAFILES 100
100
DATAFILE
DATAFILE ‘C:\ora\oradata\system01.dbf'
‘C:\ora\oradata\system01.dbf' SIZE
SIZE 325M
325M
AUTOEXTEND
AUTOEXTEND ON
ON NEXT
NEXT 10240K
10240K MAXSIZE
MAXSIZE UNLIMITED
UNLIMITED
LOGFILE
LOGFILE GROUP
GROUP 11 (‘C:\ora\oralogs\redo01.log')
(‘C:\ora\oralogs\redo01.log') SIZE
SIZE 50M,
50M,
GROUP
GROUP 22 (‘D:\ora\oralogs\redo02.log')
(‘D:\ora\oralogs\redo02.log') SIZE
SIZE 50M;
50M;
4-12
Oracle Managed File Management
Type
Type of
of File
File Management
Management (second
(second of
of two
two methods)
methods)
Pros:
Pros:
•• Automated
Automated control
control of
of control
control of
of names
names and
and sizes
sizes of
of
all
all files
files
•• DBA
DBA only
only has
has to
to determine
determine the
the locations
locations
•• Less
Less monitoring
monitoring required
required due
due to
to automated
automated size
size
adjustment
adjustment and
and deleting
deleting of
of appropriate
appropriate files
files
Cons:
Cons:
•• File
File names
names can
can be
be somewhat
somewhat cryptic
cryptic
•• No
No control
control over
over exact
exact sizes
sizes and
and names
names of
of files
files
4-13
Oracle Managed File Management
How
How to
to implement:
implement:
•• For
For user-managed
user-managed data
data files,
files, set
set the
the
DB_CREATE_FILE_DEST
DB_CREATE_FILE_DEST to to aa valid
valid directory
directory
•• For
For user-managed
user-managed control
control files
files and
and redo
redo log
log
files,
files, set
set DB_CREATE_ONLINE_LOG_DEST_n
DB_CREATE_ONLINE_LOG_DEST_n
to
to aa valid
valid directory
directory
•• When
When thethe database
database is
is created,
created, insert
insert the
the
control_files
control_files parameter
parameter back
back into
into the
the init.ora
init.ora
file
file so
so that
that db
db can
can be
be started
started and
and stopped
stopped later
later
4-14
Oracle Managed File
Management
Example
Example
Initialization
Initialization parameters:
parameters:
DB_CREATE_FILE_DEST
DB_CREATE_FILE_DEST == ‘C:\ora\oradata'
‘C:\ora\oradata'
DB_CREATE_ONLINE_LOG_DEST_1=
DB_CREATE_ONLINE_LOG_DEST_1= ‘C:\ora\oralogs’
‘C:\ora\oralogs’
DB_CREATE_ONLINE_LOG_DEST_2=
DB_CREATE_ONLINE_LOG_DEST_2= ‘D:\ora\oralogs’
‘D:\ora\oralogs’
CREATE
CREATE DATABASE
DATABASE command:
command:
CREATE
CREATE DATABASE
DATABASE TECHNO92
TECHNO92
MAXDATAFILES
MAXDATAFILES 100;
100;
4-15
Creating a Database
Two
Two distinct
distinct methods:
methods:
•• Automated:
Automated: Database
Database Configuration
Configuration Assistant
Assistant
–– Better
Better for
for novice
novice DBA
DBA
–– Will
Will create
create aa parameter
parameter file
file for
for you
you
–– May
May not
not be
be able
able to
to use
use OFM
OFM methods
methods
–– Easier
Easier to
to use
use due
due to
to the
the many
many pre-defined
pre-defined settings
settings
•• Manual:
Manual: CREATE
CREATE DATABASE
DATABASE command
command
–– More
More flexible
flexible
–– Useful
Useful when
when using
using script
script for
for creating
creating multiple
multiple
identical
identical (or
(or similar)
similar) databases
databases on
on several
several sites
sites
–– Can
Can work
work off
off of
of aa parameter
parameter file
file
––
4-16 Must
Must run
run other
other scripts
scripts later
later (catalog.sql,etc.)
(catalog.sql,etc.)
Creating a Database Manually
1.
1. Decide
Decide onon aa unique
unique instance
instance and
and
database
database name
name and
and database
database character
character
set.
set.
2.
2. Set
Set the
the operating
operating system
system variables.
variables.
3.
3. Prepare
Prepare the
the parameter
parameter file.
file.
4.
4. Create
Create aa password
password file
file (recommended).
(recommended).
5.
5. Start
Start the
the instance.
instance.
6.
6. Create
Create the
the database.
database.
7.
7. Run
Run scripts
scripts to
to generate
generate the
the data
data dictionary
dictionary
and
and accomplish
accomplish postcreation
postcreation steps.
steps.
4-17
Operating System Environment
On
On UNIX
UNIX set
set the
the following
following environment
environment
variables:
variables:
•• ORACLE_HOME
ORACLE_HOME
•• ORACLE_SID
ORACLE_SID
•• ORACLE_BASE
ORACLE_BASE
•• ORA_NLS33
ORA_NLS33
•• PATH
PATH
4-18
Operating System Environment
On
On NTNT
•• Set
Set the
the variable
variable ORACLE_SID
ORACLE_SID toto use
use
SVRMGR30.
SVRMGR30.
•• Create
Create the
the service
service and
and the
the password
password
file
file with
with ORADIM80.
ORADIM80.
C:\>
C:\> ORADIM80
ORADIM80 -NEW
-NEW -SID
-SID u16
u16
-INTPWD
-INTPWD password
password -STARTMODE
-STARTMODE auto
auto
-PFILE
-PFILE ORACLE_HOME\DATABASE\initU16.ora
ORACLE_HOME\DATABASE\initU16.ora
4-19
Preparing the Parameter File
11.. Create
Create the
the new
new init<SID>.ora.
init<SID>.ora.
$cp
$cp init.ora
init.ora $ORACLE_HOME/dbs/initU16.ora
$ORACLE_HOME/dbs/initU16.ora
22.. Modify
Modify the
the initU16.ora
initU16.ora by
by editing
editing
the
the parameters.
parameters.
4-20
Editing the Parameter File
db_name
db_name == U16
U16
db_files
db_files == 100
100
## db_files
db_files == 400
400 ## MEDIUM
MEDIUM
## db_files
db_files == 1000
1000 ## LARGE
LARGE
db_file_multiblock_read_count
db_file_multiblock_read_count == 88
## db_file_multiblock_read_count
db_file_multiblock_read_count == 16 16 ## MEDIUM
MEDIUM
## db_file_multiblock_read_count
db_file_multiblock_read_count == 32 32 ## LARGE
LARGE
control_files
control_files == (/disk1/control01.con,/disk2/control02.con)
(/disk1/control01.con,/disk2/control02.con)
db_block_size
db_block_size == 8192
8192
db_block_buffers
db_block_buffers == 2000
2000 ## SMALL
SMALL
## db_block_buffers
db_block_buffers == 550550 ## MEDIUM
MEDIUM
## db_block_buffers
db_block_buffers == 3200
3200 ## LARGE
LARGE
shared_pool_size
shared_pool_size == 30000000
30000000
## shared_pool_size
shared_pool_size == 5000000
5000000 ## MEDIUM
MEDIUM
## shared_pool_size
shared_pool_size == 9000000
9000000 ## LARGE
LARGE
log_buffer
log_buffer == 65536
65536
## log_buffer
log_buffer == 32768
32768 ## MEDIUM
MEDIUM
## log_buffer
log_buffer == 163840
163840 ## LARGE
LARGE
...
...
4-21
Starting the Instance
11.. Connect
Connect asas SYSDBA.
SYSDBA.
22.. Start
Start the
the instance
instance in
in NOMOUNT
NOMOUNT stage.
stage.
SVRMGR>
SVRMGR> STARTUP
STARTUP NOMOUNT
NOMOUNT \\
2>
2> PFILE=initU16.ora
PFILE=initU16.ora
ORACLE
ORACLE instance
instance started.
started.
4-22
Creating the Database
SPOOL
SPOOL creU16.log
creU16.log
STARTUP
STARTUP NOMOUNT
NOMOUNT PFILE=initU16.ora
PFILE=initU16.ora
CREATE
CREATE DATABASE
DATABASE U16
U16
MAXLOGFILES
MAXLOGFILES 55
MAXLOGMEMBERS
MAXLOGMEMBERS 55
MAXDATAFILES
MAXDATAFILES 100100
MAXLOGHISTORY
MAXLOGHISTORY 100100
LOGFILE
LOGFILE
GROUP
GROUP 11 ('/DISK3/log1a.rdo',/DISK4/log1b.rdo’)
('/DISK3/log1a.rdo',/DISK4/log1b.rdo’) SIZE
SIZE 11 M,
M,
GROUP
GROUP 22 ('/DISK3/log2a.rdo',/DISK4/log2b.rdo’)
('/DISK3/log2a.rdo',/DISK4/log2b.rdo’) SIZE
SIZE 11 MM
DATAFILE
DATAFILE
'/DISK1/system01.dbf'
'/DISK1/system01.dbf' size
size 50M
50M autoextend
autoextend on
on
CHARACTER
CHARACTER SET
SET WE8ISO8859P1;
WE8ISO8859P1;
4-23
Oracle Database Assistant
4-24
Troubleshooting
Creation
Creation of
of the
the database
database fails
fails if:
if:
• There
There are
are syntax
syntax errors
errors in
in the
the
SQL
SQL script
script
• Files
Files that
that should
should be
be created
created
already
already exist
exist
• Operating
Operating system
system errors
errors such
such as as file
file or
or
directory
directory permission
permission or
or insufficient
insufficient
space
space errors
errors occur
occur
4-25
After Creation of the Database
The
The database
database contains:
contains:
• Data
Data files
files which
which make
make up
up the
the SYSTEM
SYSTEM
tablespace
tablespace
• Control
Control files
files and
and redo
redo log
log files
files
• User
User SYS/change_on_install
SYS/change_on_install
• User
User SYSTEM/manager
SYSTEM/manager
• Rollback
Rollback segment
segment SYSTEM
SYSTEM
• Internal
Internal tables
tables (but
(but no
no data
data
dictionary
dictionary views)
views)
4-26
OMF
•• Oracle-Managed
Oracle-Managed Files
Files
•• feature
feature introduced
introduced in
in Oracle9i
Oracle9i
•• Allows
Allows Oracle
Oracle RDBMSto
RDBMSto manage
manage datafiles
datafiles for
for
you.
you. Oracle
Oracle hashas been
been making
making significant
significant strides
strides
in
in making
making the the database
database easier
easier to
to manage
manage and and
OMF
OMF falls
falls into
into this
this category
category of
of features.
features.
••For
For example,
example, in in Oracle
Oracle databases
databases prior
prior to
to 9i,
9i,
when
when youyou dropped
dropped aa tablespace,
tablespace, you
you would
would also
also
have
have toto remove
remove the the physical
physical datafile
datafile associated
associated
with
with that
that tablespace.
tablespace. With
With Oracle9i,
Oracle9i, youyou can
can
leave
leave physical
physical file
file management
management to to the
the database
database
itself
itself by
by using
using OMFs
OMFs
4-27
OMF (Cont.)
•• Very
Very useful
useful in
in low-use
low-use // smaller
smaller databases
databases in
in order
order to
to
reduce
reduce the
the administrative
administrative overhead.
overhead.
•• OMF
OMF reduces
reduces the the overall
overall administrative
administrative overhead
overhead
required
required for
for such
such smaller
smaller databases.
databases.
••OMF
OMF feature
feature cancan bebe particularly
particularly useful
useful for
for development
development
and
and test
test databases.
databases.
••OMF
OMF simplifies
simplifies management
management of of aa standby
standby database.
database. In In
pre-Oracle9i
pre-Oracle9i databases,
databases, when
when youyou added
added aa tablespace
tablespace or or
datafile
datafile to
to the
the primary
primary database,
database, human
human intervention
intervention waswas
required
required onon the
the standby
standby database
database to to perform
perform the the same
same
operation.
operation.
••With
With OMF,
OMF, iffiff the
the standby
standby database
database is is configured
configured to to use
use
OMF,
OMF, then
then thethe creation
creation of
of aa tablespace
tablespace or or addition
addition ofof aa
datafile
datafile to
to the
the primary
primary database
database willwill result
result inin the
the
automated
automated creation
creation of of that
that tablespace
tablespace or or datafile
datafile on
on the
the
standby
standby server.
server. No No other
other administrative
administrative activity
activity is
is
required!
required!
4-28
OMF (Cont.)
• OMF
OMF is
is also
also useful
useful in
in aa large
large database
database environment
environment
that
that is
is using
using large
large disk
disk arrays.
arrays. (i.e.
(i.e. RAID-0).
RAID-0).
•OMF
OMF is is not
not an
an appropriate
appropriate choice
choice forfor use
use with
with aa
high-volume
high-volume or or mission-critical
mission-critical database
database thatthat is
is not
not
using
using high-end
high-end striped
striped disk
disk arrays.
arrays.
•For
For example,
example, OMFOMF isis not
not recommended
recommended on on systems
systems
with
with many
many smaller
smaller file
file systems,
systems, or or systems
systems running
running
RAID-5.
RAID-5. This
This is
is because
because thethe nature
nature of of managed
managed
datafiles
datafiles isis such
such that
that the
the DBA
DBA isis not
not able
able to
to
distribute
distribute I/O
I/O as
as required.
required.
•Also,
Also, the
the managed
managed datafile
datafile feature
feature does
does not
not support
support
the
the use
use of
of raw
raw disk
disk devices.
devices.
4-29
OMF (Cont.)
• Example
Example Create
Create Database
Database Command:
Command:
CREATE
CREATE DATABASE
DATABASE mydb
mydb
DATAFILE
DATAFILE SIZE
SIZE 500M
500M
LOGFILE
LOGFILE
GROUP
GROUP 11 SIZE
SIZE 10M
10M ,, GROUP
GROUP 22 SIZE
SIZE 10M
10M
DEFAULT
DEFAULT TEMPORARY
TEMPORARY TABLESPACE
TABLESPACE temp
temp
TEMPFILE
TEMPFILE SIZE
SIZE 100M
100M
UNDO
UNDO TABLESPACE
TABLESPACE undotbs1
undotbs1
DATAFILE
DATAFILE SIZE
SIZE 50M
50M
MAXLOGFILES
MAXLOGFILES == 55 MAXLOGMEMBERS
MAXLOGMEMBERS == 55
MAXDATAFILES
MAXDATAFILES == 600
600
NOARCHIVELOG;
NOARCHIVELOG;
4-30
OMF (Cont.)
•• Oracle9i
Oracle9i Release
Release 22 (9.2)
(9.2) changes:
changes:
File
File Type
Type Naming
Naming Convention
Convention Example
Example
Datafile
Datafile o1_mf_%t_%u_.dbf
o1_mf_%t_%u_.dbf o1_mf_tbs1_2ixfh90q_.dbf
o1_mf_tbs1_2ixfh90q_.dbf
Tempfile
Tempfile o1_mf_%t_%u_.tmp
o1_mf_%t_%u_.tmp o1_mf_temp1_6dygh80r_.tmp
o1_mf_temp1_6dygh80r_.tmp
Redo
Redo logfile
logfile o1_mf_%g_%u_.log
o1_mf_%g_%u_.log o1_mf_1_wo94n2xi_.log
o1_mf_1_wo94n2xi_.log
Control
Control file
file o1_mf_%u_.ctl
o1_mf_%u_.ctl o1_mf_cmr7t90p_.ctl
o1_mf_cmr7t90p_.ctl
Where:
Where:
%t
%t isis the
the tablespace
tablespace name
name (possibly
(possibly truncated)
truncated)
%u
%u is is an
an eight
eight character
character string
string that
that guarantees
guarantees
uniqueness
uniqueness
%g
%g is is the
the online
online redo
redo log
log file
file group
group number
number
A
A file
file is
is now
now considered
considered OMF OMF ifif its
its base
base file
file name
name has:
has: -- aa
"o1_mf_"
"o1_mf_" prefix
prefix -- and
and aa ".dbf",
".dbf", ".tmp",
".tmp", ".log",
".log", or
or ".ctl"
".ctl"
extension
extension -- andand an
an "_"
"_" character
character immediately
immediately preceding
preceding
the
the
4-31extension
extension
Summary
• Planning
Planning the
the database
database structure
structure
• Preparing
Preparing the
the operating
operating system
system
environment
environment
• Creating
Creating the
the database
database
4-32