Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 423

1

Oracle Architectural
Components

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Listing
Listing the
the structures
structures involved
involved in
in
connecting
connecting aa user
user to
to an
an Oracle
Oracle server
server
•• Listing
Listing the
the stages
stages in
in processing
processing aa query
query
•• Listing
Listing the
the stages
stages in
in processing
processing aa DML
DML
statement
statement
•• Listing
Listing the
the stages
stages in
in processing
processing
COMMITS
COMMITS

1-2 Copyright  Oracle Corporation, 1998. All rights reserved.


The Oracle Server
Oracle server
Application/
network
server

Server Users
1-3 Copyright  Oracle Corporation, 1998. All rights reserved.
Connecting to a Database
Server
Client
Client process Server
Server

User Oracle server


process

Use
Use
rr

1-4 Copyright  Oracle Corporation, 1998. All rights reserved.


User Process

•• Runs
Runs onon the
the client
client machine
machine
•• Is
Is spawned
spawned when
when aa tool
tool or
or an
an application
application
is
is invoked
invoked
•• Runs
Runs the
the tool
tool or
or application
application (SQL*Plus,
(SQL*Plus,
Server
Server Manager,
Manager, Oracle
Oracle Enterprise
Enterprise
Manager,
Manager, Developer/2000)
Developer/2000)
•• Includes
Includes the
the User
User Program
Program Interface
Interface (UPI)
(UPI)
•• Generates
Generates calls
calls to
to the
the Oracle
Oracle server
server

1-5 Copyright  Oracle Corporation, 1998. All rights reserved.


Server Process

•• Runs
Runs on
on the
the server
server machine
machine (host)
(host)
•• Services
Services aa single
single user
user process
process in
in the
the
dedicated
dedicated server
server configuration
configuration
•• Uses
Uses an
an exclusive
exclusive PGA
PGA
•• Includes
Includes the
the Oracle
Oracle Program
Program Interface
Interface
(OPI)
(OPI)
•• Processes
Processes calls
calls generated
generated by
by the
the client
client
•• Returns
Returns results
results to
to the
the client
client

1-6 Copyright  Oracle Corporation, 1998. All rights reserved.


Oracle Instance
Instance
SGA

Background processes

An
An Oracle
Oracle instance:
instance:
•• Is
Is aa means
means to
to access
access an
an Oracle
Oracle
database
database
•• Always
Always opens
opens one
one and
and only
only one
one
database
database
1-7 Copyright  Oracle Corporation, 1998. All rights reserved.
Oracle Database

Control
files
Parameter
file

Password Data files Redo log Archived


file files log files

Database

1-8 Copyright  Oracle Corporation, 1998. All rights reserved.


Other Key Physical Structures

Parameter
file

Password Archived
file log files
Database

1-9 Copyright  Oracle Corporation, 1998. All rights reserved.


Processing a Query
SELECT
SELECT ** Statement
FROM
FROM emp
emp Handle
ORDER
ORDER BY
BY ename;
ename;
Handle

User Server
process process

Results
OK

OK

Parse
Parse Execute
Execute Fetch
Fetch
1-10 Copyright  Oracle Corporation, 1998. All rights reserved.
The Shared Pool
Shared pool

Library
cache

Data
dictionary
cache

•• Size
Size defined
defined by
by SHARED_POOL_SIZE
SHARED_POOL_SIZE
•• Library
Library cache
cache contains
contains statement
statement text,
text,
parsed
parsed code,
code, and
and an
an execution
execution plan
plan
•• Data
Data dictionary
dictionary cache
cache contains
contains table
table
and
and column
column definitions
definitions and
and privileges
privileges
1-11 Copyright  Oracle Corporation, 1998. All rights reserved.
Database Buffer Cache

•• Number
Number of of buffers
buffers defined
defined by
by
DB_BLOCK_BUFFERS
DB_BLOCK_BUFFERS
•• Size
Size of
of aa buffer
buffer based
based on
on DB_BLOCK_SIZE
DB_BLOCK_SIZE
•• Stores
Stores the
the most
most recently
recently used
used blocks
blocks

1-12 Copyright  Oracle Corporation, 1998. All rights reserved.


Program Global Area (PGA)

Server PGA
process

•• Not
Not shared
shared and
and not
not writable
writable
•• Contains
Contains
–– Sort
Sort area
area
–– Session
Session information
information
–– Cursor
Cursor state
state
–– Stack
Stack space
space
1-13 Copyright  Oracle Corporation, 1998. All rights reserved.
Processing a DML Statement
UPDATE
UPDATE emp
emp 3
Instance
SET
SET sal=sal*1.1
sal=sal*1.1
SGA
WHERE
WHERE empno=7369
empno=7369 4 Shared pool

Library
cache

Server 5 Database
buffer
Redo log Data
buffer dictionary
cache
process cache

Control
files
Data files Redo log
1 Database
files

1-14 Copyright  Oracle Corporation, 1998. All rights reserved.


Rollback Segment
Old
image

New
Table image
Rollback
segment

DML
statement
1-15 Copyright  Oracle Corporation, 1998. All rights reserved.
Redo Log Buffer

•• Size
Size defined
defined by
by LOG_BUFFER
LOG_BUFFER
•• Records
Records changes
changes made
made through
through the
the
instance
instance
•• Used
Used sequentially
sequentially
•• Circular
Circular buffer
buffer
1-16 Copyright  Oracle Corporation, 1998. All rights reserved.
Database Writer (DBWR)
Instance
SGA Shared pool

Database
buffer
cache

DBWR

Data files Control Redo log


files files

1-17 Copyright  Oracle Corporation, 1998. All rights reserved.


Log Writer (LGWR)
Instance
SGA Shared pool

Redo log
buffer

LGWR

Data files Control Redo log


files files

1-18 Copyright  Oracle Corporation, 1998. All rights reserved.


COMMIT Processing
1 Instance
SGA Shared pool

Server Database
Redo log
buffer
process buffer
4 cache

LGWR
3
2
User
process Control
files
Data files Redo log
files
Database

1-19 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary
Instance
SGA Shared pool

Server
process
PGA

User
DBWR LGWR
process

Parameter Control
file files
Archived
log files
Data files Redo log
Password files
file
Database

1-20 Copyright  Oracle Corporation, 1998. All rights reserved.


2
1
Using Administration Tools

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Using
Using the
the Server
Server Manager
Manager Line
Line Mode
Mode
•• Identifying
Identifying administration
administration applications
applications
supplied
supplied with
with the
the Oracle
Oracle Enterprise
Enterprise
Manager
Manager
•• Using
Using Oracle
Oracle Enterprise
Enterprise Manager
Manager
components
components

1-22 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Administration
Tools: Examples
Tool Description
Server Manager Line A line mode utility used for
Mode administrative tasks like starting
up, shutting down or
recovering a database
Oracle Enterprise Graphical user interface to
Manager administer, monitor, and tune
multiple databases.

SQL*Loader Utility for loading data from


external files into Oracle tables

Export or Import utility Utility for exporting/importing


data in Oracle format
Utility for creating database
Password File utility password file
1-23 Copyright  Oracle Corporation, 1998. All rights reserved.
Starting Server Manager in
Line Mode

On
On UNIX
UNIX svrmgrl
svrmgrl

On
On NT
NT svrmgr30
svrmgr30

Starting
Starting and
and executing
executing aa script:
script:
svrmgrl command=@credb.sql
On
On UNIX
UNIX svrmgrl command=@credb.sql
svrmgrl
svrmgrl command=“CONNECT
command=“CONNECT scott/tiger”
scott/tiger”

On
On NT
NT svrmgr30
svrmgr30 command=@u16run.sql
command=@u16run.sql

1-24 Copyright  Oracle Corporation, 1998. All rights reserved.


Server Manager Commands
Category Commands
Command that do not need EXIT
database connection REMARK
SET
SHOW
SPOOL

Commands needing Oracle CONNECT/DISCONNECT


privileges DESCRIBE
EXECUTE
SHOW ERRORS
SHOW PARAMETER SHOW
SGA
Commands needing special CONNECT… AS SYSDBA
Oracle privileges CONNECT… AS SYSOPER
ARCHIVE LOG
RECOVER DATABASE
STARTUP/SHUTDOWN

1-25 Copyright  Oracle Corporation, 1998. All rights reserved.


Server Manager
Commands: Examples
Set the column display width SET
SET CHARWIDTH
CHARWIDTH 2020
for character or numeric data: SET NUMWIDTH
SET NUMWIDTH 88

Spool output to a file: SPOOL


SPOOL credb.log
credb.log

Display current settings: SHOW


SHOW ALL
ALL

SHOW
SHOW SPOOL
SPOOL

1-26 Copyright  Oracle Corporation, 1998. All rights reserved.


Oracle
Oracle Enterprise
Enterprise Manager
Manager (OEM)
(OEM)

Oracle
Integrated Integrated
system customer
3rd party
management
applications
applications applications Agent

Enterprise Manager Console


Job Event Discovery Security
system system service service

Agent
Repository

Managed
systems

1-27 Copyright  Oracle Corporation, 1998. All rights reserved.


Enterprise
Enterprise Manager
Manager Console
Console
1

2
3
4

5
6

1-28 Copyright  Oracle Corporation, 1998. All rights reserved.


OEM
OEM Common
Common Services
Services

•• Repository
Repository
•• Service
Service Discovery
Discovery
•• Security
Security

1-29 Copyright  Oracle Corporation, 1998. All rights reserved.


OEM
OEM Database
Database Administration
Administration Tools
Tools

Components needing console

1-30 Copyright  Oracle Corporation, 1998. All rights reserved.


OEM Performance Pack

1-31 Copyright  Oracle Corporation, 1998. All rights reserved.


Starting
Starting and
and Using
Using OEM
OEM

•• Create
Create repository
repository automatically
automatically by
by invoking
invoking
OEM
OEM
•• Define
Define services
services
–– Auto
Auto discovery
discovery
–– Manual
Manual
•• Set
Set up
up security
security using
using preferred
preferred credentials
credentials
•• Use
Use the
the navigator
navigator and
and launch
launch palette
palette to
to
invoke
invoke applications
applications

1-32 Copyright  Oracle Corporation, 1998. All rights reserved.


Using
Using Application
Application Interface
Interface
4

3
2

1-33 Copyright  Oracle Corporation, 1998. All rights reserved.


Using
Using SQL
SQL Worksheet
Worksheet
1

1-34 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Using Server Manager in Line Mode


• Using Oracle Enterprise Manager
components

1-35 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing an Oracle Instance

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
•• Setting
Setting up
up operating
operating system
system and
and
password
password file
file authentication
authentication
•• Creating
Creating the
the parameter
parameter file
file
•• Starting
Starting up
up an
an instance
instance and
and opening
opening the
the
database
database
•• Closing
Closing aa database
database and
and shutting
shutting down
down
the
the instance
instance
•• Getting
Getting and
and setting
setting parameter
parameter values
values
•• Managing
Managing sessions
sessions
•• Monitoring
Monitoring ALERT
ALERT and
and trace
trace files
files
1-37 Copyright  Oracle Corporation, 1998. All rights reserved.
Overview
Instance
SGA Shared pool

User Server
process process
PGA

ALERT Control
file files
Parameter
file
Data files Redo log
Password files
file

1-38 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Administrator Users

The two database administrator users


SYS and SYSTEM are:
• Automatically created
• Granted the DBA role

1-39 Copyright  Oracle Corporation, 1998. All rights reserved.


User SYS and SYSTEM

SYS
SYS SYSTEM
SYSTEM
•• Password:
Password: •• Password:
Password:
change_on_install
change_on_install manager
manager
•• Owner
Owner of
of the
the •• Owner
Owner of
of additional
additional
database
database data
data internal
internal tables
tables used
used
dictionary
dictionary by
by Oracle
Oracle tools
tools

1-40 Copyright  Oracle Corporation, 1998. All rights reserved.


Authentication Methods
Remote database Local database
administration administration

Do you Yes Do you want Yes


have a secure to use OS Use OS
connection? authentication? authentication

No N
o Use a
password file

1-41 Copyright  Oracle Corporation, 1998. All rights reserved.


Operating System
Authentication
• Set
Set up
up the
the user
user to
to be
be authenticated
authenticated by
by
the
the operating
operating system.
system.
• Set
Set REMOTE_LOGIN_PASSWORDFILE
REMOTE_LOGIN_PASSWORDFILE
to
to NONE.
NONE.
• Use
Use the
the following
following commands
commands to
to connect
connect
to
to aa database:
database:
CONNECT
CONNECT // AS
AS SYSDBA
SYSDBA
CONNECT
CONNECT // AS
AS SYSOPER
SYSOPER

1-42 Copyright  Oracle Corporation, 1998. All rights reserved.


Using Password File
Authentication
• Create
Create the
the password
password file
file using
using the
the
password
password utility:
utility:
$orapwd
$orapwd file=$ORACLE_HOME/dbs/orapwU15\
file=$ORACLE_HOME/dbs/orapwU15\
password=admin
password=admin entries=5
entries=5

• Set
Set REMOTE_LOGIN_PASSWORDFILE
REMOTE_LOGIN_PASSWORDFILE
to
to EXCLUSIVE
EXCLUSIVE or or SHARED
SHARED
• Use
Use the
the following
following command
command to
to connect
connect
to
to aa database:
database:
CONNECT
CONNECT INTERNAL/ADMIN
INTERNAL/ADMIN
1-43 Copyright  Oracle Corporation, 1998. All rights reserved.
Changing the Internal Password

• Use
Use the
the password
password utility
utility on
on NT
NT and
and UNIX
UNIX

to
to delete
delete and
and create
create the
the password
password file.
file.
or
or
• Use
Use the
the ORADIM80
ORADIM80 utility
utility on
on NT
NT to
to delete
delete

and
and create
create aa new
new password
password file.
file.

1-44 Copyright  Oracle Corporation, 1998. All rights reserved.


The Initialization Parameter File
Instance
SGA Shared pool

Library
cache
Database
Redo log Data
buffer
buffer dictionary
cache
cache

SMON DBWR PMON CKPT LGWR ARCH

initU15.ora

SVRMGR>
SVRMGR> CONNECT
CONNECT // AS
AS SYSDBA
SYSDBA
SVRMGR>
SVRMGR> STARTUP
STARTUP PFILE=/DISK1/initU15.ora
PFILE=/DISK1/initU15.ora

1-45 Copyright  Oracle Corporation, 1998. All rights reserved.


Parameter File Example
## Initialization
Initialization Parameter
Parameter File:
File: initU15.ora
initU15.ora
db_name
db_name == U15
U15
control_files
control_files == (/DISK1/control01.con,
(/DISK1/control01.con,
/DISK2/control02.con)
/DISK2/control02.con)
db_block_size
db_block_size == 8192
8192
db_block_buffers
db_block_buffers == 2000
2000
shared_pool_size
shared_pool_size == 30000000
30000000

log_buffer
log_buffer == 64K
64K
processes
processes == 50
50
db_files
db_files == 100
100
log_files
log_files == 10
10
max_dump_file_size
max_dump_file_size == 10240
10240
background_dump_dest
background_dump_dest == (/home/disk3/user15/BDUMP)
(/home/disk3/user15/BDUMP)
user_dump_dest
user_dump_dest == (/home/disk3/user15/UDUMP)
(/home/disk3/user15/UDUMP)
core_dump_dest
core_dump_dest == (/home/disk3/user15/CDUMP)
(/home/disk3/user15/CDUMP)
rollback_segments
rollback_segments == (r01,r02,r03,r04,r05,r06,r07,r08)
(r01,r02,r03,r04,r05,r06,r07,r08)
...
...
1-46 Copyright  Oracle Corporation, 1998. All rights reserved.
Startup and Shutdown in Stages

OPEN
P All files opened as
U
RT described by the
T A control file for this
S MOUNT instance.

Control file
opened for this
instance.
NOMOUNT

N
W
O
TD
Instance

U
started.

SH
SHUTDOWN

1-47 Copyright  Oracle Corporation, 1998. All rights reserved.


STARTUP Command

Start up the instance, and


open the database.

STARTUP
STARTUP PFILE=/DISK1/initU15.ora
PFILE=/DISK1/initU15.ora

1-48 Copyright  Oracle Corporation, 1998. All rights reserved.


Shutdown Options

Shutdown Mode A I T N

Allow new connections

Wait until current sessions end

Wait until current transactions end

Force a checkpoint and close files

Shutdown mode:
A Abort I Immediate NO
T Transactional N Normal YES

1-49 Copyright  Oracle Corporation, 1998. All rights reserved.


Shutdown Time

1
Normal Transactional Immediate Abort
Time
1-50 Copyright  Oracle Corporation, 1998. All rights reserved.
Dynamic Performance Views

• Maintained
Maintained by
by the
the Oracle
Oracle Server
Server
and
and continuously
continuously updated
updated
• Contain
Contain data
data on
on disk
disk and
and memory
memory
structures
structures
• Contain
Contain data
data that
that is
is useful
useful for
for
performance
performance tuning
tuning
• Have
Have public
public synonyms
synonyms with
with the
the
prefix
prefix V$
V$

1-51 Copyright  Oracle Corporation, 1998. All rights reserved.


Accessing Dynamic
Performance Views
OPEN
Data dictionary

MOUNT
Dynamic
performance
views reading
NOMOUNT data from disk

Dynamic
performance
views reading
SHUTDOWN from memory

1-52 Copyright  Oracle Corporation, 1998. All rights reserved.


Example
V$PARAMETER
V$SGA
SGA V$OPTION
V$PROCESS
V$SESSION
V$VERSION
V$INSTANCE

Control file V$THREAD


V$CONTROLFILE
V$DATABASE
V$DATAFILE
V$DATAFILE_HEADER

V$LOGFILE
1-53 Copyright  Oracle Corporation, 1998. All rights reserved.
Displaying Current
Parameter Values
•• Use
Use the
the Server
Server Manager
Manager command:
command:
SHOW
SHOW PARAMETER
PARAMETER control
control

•• Query
Query the
the dynamic
dynamic performance
performance view
view
V$PARAMETER:
V$PARAMETER:

SELECT
SELECT name
name FROM
FROM v$parameter
v$parameter
WHERE
WHERE name
name LIKE
LIKE ‘%control%’;
‘%control%’;

1-54 Copyright  Oracle Corporation, 1998. All rights reserved.


Dynamic Initialization Parameters

Some initialization parameters can be


modified while an instance is running.
ALTER
ALTER SESSION
SESSION SET
SET SQL_TRACE=true;
SQL_TRACE=true;

ALTER
ALTER SYSTEM
SYSTEM SET
SET TIMED_STATISTICS=true;
TIMED_STATISTICS=true;

ALTER
ALTER SYSTEM
SYSTEM SET
SET SORT_AREA_SIZE=131072
SORT_AREA_SIZE=131072
DEFERRED;
DEFERRED;

1-55 Copyright  Oracle Corporation, 1998. All rights reserved.


Enable and Disable
Restricted Session
• Use
Use the
the STARTUP
STARTUP command
command to
to
restrict
restrict access
access to
to aa database:
database:

STARTUP
STARTUP RESTRICT
RESTRICT

• Use
Use the
the ALTER
ALTER SYSTEM
SYSTEM command
command to
to
place
place an
an instance
instance in
in restricted
restricted mode:
mode:

ALTER
ALTER SYSTEM
SYSTEM ENABLE
ENABLE RESTRICTED
RESTRICTED
SESSION;
SESSION;
1-56 Copyright  Oracle Corporation, 1998. All rights reserved.
Terminating Sessions
1. Identify which session to terminate
with the dynamic performance view

V$SESSION:
SELECT
SELECT sid,
sid, serial#
serial# FROM
FROM v$session
v$session
WHERE
WHERE username=‘SCOTT’;
username=‘SCOTT’;

2. Execute the ALTER SYSTEM command:

ALTER
ALTER SYSTEM
SYSTEM KILL
KILL SESSION
SESSION ‘7,15’;
‘7,15’;

1-57 Copyright  Oracle Corporation, 1998. All rights reserved.


Trace Files
•• Trace
Trace files
files can
can bebe written
written by
by server
server
and
and background
background processes.
processes.
•• Oracle
Oracle dumps
dumps information
information about
about errors
errors
in
in trace
trace files.
files.
•• The
The ALERT
ALERT filefile consists
consists ofof aa
chronological
chronological log log of
of messages
messages and and
errors.
errors.
•• Server
Server process
process tracing
tracing can
can be
be enabled
enabled
or
or disabled
disabled by:by:
–– An
An ALTER
ALTER SESSION
SESSION command
command
–– The
The parameter
parameter SQL_TRACE
SQL_TRACE
1-58 Copyright  Oracle Corporation, 1998. All rights reserved.
Controlling the Trace File
Instance
SGA Shared pool

User Server
process process

ALERT file

USER_DUMP_DEST BACKGROUND_DUMP_DEST
1-59 Copyright  Oracle Corporation, 1998. All rights reserved.
Guidelines

Check
Check the
the ALERT
ALERT file
file periodically
periodically to:
to:
•• Detect
Detect internal
internal errors
errors (ORA-600)
(ORA-600)
and
and block
block corruption
corruption errors
errors
•• Monitor
Monitor database
database operations
operations
•• View
View the
the nondefault
nondefault initialization
initialization
parameter
parameter

1-60 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Starting
Starting up
up and
and shutting
shutting down
down an an
instance
instance
•• Understanding
Understanding the
the use
use of
of dynamic
dynamic
performance
performance views
views
•• Describing
Describing the
the use
use of
of trace
trace files
files

1-61 Copyright  Oracle Corporation, 1998. All rights reserved.


4
1
Creating a Database

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Preparing
Preparing the
the operating
operating system
system
•• Preparing
Preparing the
the parameter
parameter file
file
•• Creating
Creating the
the database
database

1-63 Copyright  Oracle Corporation, 1998. All rights reserved.


Overview
Instance

SGA Shared Pool

User Server
process process
PGA

Control
files
Parameter
file
Datafiles Redo log
Password files
file
Database
1-64 Copyright  Oracle Corporation, 1998. All rights reserved.
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

1-65 Copyright  Oracle Corporation, 1998. All rights reserved.


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 log
log 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
1-66 Copyright  Oracle Corporation, 1998. All rights reserved.
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
1-67 Copyright  Oracle Corporation, 1998. All rights reserved.
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
... ...

1-68 Copyright  Oracle Corporation, 1998. All rights reserved.


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

1-69 Copyright  Oracle Corporation, 1998. All rights reserved.


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.

1-70 Copyright  Oracle Corporation, 1998. All rights reserved.


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_NLS
ORA_NLS33
33
•• PATH
PATH

1-71 Copyright  Oracle Corporation, 1998. All rights reserved.


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

1-72 Copyright  Oracle Corporation, 1998. All rights reserved.


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.

1-73 Copyright  Oracle Corporation, 1998. All rights reserved.


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 = 1000 # LARGE
db_files = 1000 # 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 == 550
550 ## 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
...
...
1-74 Copyright  Oracle Corporation, 1998. All rights reserved.
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.

1-75 Copyright  Oracle Corporation, 1998. All rights reserved.


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 100
100
MAXLOGHISTORY
MAXLOGHISTORY 100
100
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;

1-76 Copyright  Oracle Corporation, 1998. All rights reserved.


Oracle Database Assistant

1-77 Copyright  Oracle Corporation, 1998. All rights reserved.


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

1-78 Copyright  Oracle Corporation, 1998. All rights reserved.


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)
1-79 Copyright  Oracle Corporation, 1998. All rights reserved.
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

1-80 Copyright  Oracle Corporation, 1998. All rights reserved.


5
1
Creating Data Dictionary Views
and Standard Packages

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Constructing
Constructing the
the data
data dictionary
dictionary views
views
•• Using
Using the
the data
data dictionary
dictionary
•• Preparing
Preparing the
the PL/SQL
PL/SQL environment
environment
using
using the
the administrative
administrative scripts
scripts
•• Administering
Administering stored
stored procedures
procedures
and
and packages
packages

1-82 Copyright  Oracle Corporation, 1998. All rights reserved.


Using the Data Dictionary
The
The data
data dictionary
dictionary provides
provides information
information
about:
about:
•• Logical
Logical and
and physical
physical database
database structure
structure
•• Names,
Names, definitions,
definitions, and
and space
space
allocation
allocation of
of schema
schema objects
objects
•• Integrity
Integrity constraints
constraints
•• Database
Database users
users and
and privileges
privileges
•• Auditing
Auditing

1-83 Copyright  Oracle Corporation, 1998. All rights reserved.


Base Tables and Data
Dictionary Views

Data dictionary views:


- Views simplify the base table information
- Created with the catalog.sql script

Base tables:
- Normalized
- Created with the sql.bsq script

1-84 Copyright  Oracle Corporation, 1998. All rights reserved.


Data Dictionary Views

DBA_xxx
objects of the entire database

ALL_xxx
objects can be accessed by the user

USER_xxx

objects owned by the user

1-85 Copyright  Oracle Corporation, 1998. All rights reserved.


Data Dictionary: Views
Examples and Categories
Views Description
dictionary General overview
dict_columns
dba_tables Information related to the user
dba_objects objects such as tables, constraints,
dba_lobs large objects and columns
dba_tab_columns
dba_constraints
dba_users Information about user privileges
dba_sys_privs and roles
dba_roles
1-86 Copyright  Oracle Corporation, 1998. All rights reserved.
Data Dictionary Views:
Examples and Categories
Views Description

dba_extents Space allocation for database


dba_free_space objects
dba_segments

dba_rollback_segs General database structures


dba_data_files
dba_tablespaces

dba_audit_trail
Auditing information
dba_audit_objects
dba_audit_obj_opts
1-87 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating Data Dictionary Views

Script Purpose

catalog.sql Creates commonly used data dictionary


views

catproc.sql Runs all scripts required for PL/SQL on the


server

1-88 Copyright  Oracle Corporation, 1998. All rights reserved.


Administrative Scripts
The following naming conventions exist
for the sql scripts:
Convention Description
cat*.sql Catalog and data dictionary information

dbms*.sql Database package specifications

prvt*.plb Wrapped database package code

utl*.sql Views and tables for database utilities

1-89 Copyright  Oracle Corporation, 1998. All rights reserved.


Stored Procedures
and Packages
Instance
Database applications
Shared pool
DBMS_SESSION
SGA
begin
begin SET_ROLE
... begin...
...
end;
dbms_session.set_role(..)
dbms_session.set_role(..)
...
...
end;
end;

PLUS>execute
PLUS>execute dbms_session.set_role(..)
dbms_session.set_role(..)

SVRMGR>execute
SVRMGR>execute dbms_session.set_role(..)
dbms_session.set_role(..)

1-90 Copyright  Oracle Corporation, 1998. All rights reserved.


What Are Stored Procedures?
•• Are
Are procedures
procedures oror functions
functions
•• Are
Are stored
stored in
in the
the data
data dictionary
dictionary
•• Can
Can be
be used
used by
by many
many users
users
•• Can
Can accept
accept and
and return
return parameters
parameters
•• Can
Can be
be used
used in
in SQL
SQL functions
functions

1-91 Copyright  Oracle Corporation, 1998. All rights reserved.


What Are Packages?

•• Group
Group logically
logically related
related PL/SQL
PL/SQL types,
types,
items,
items, and
and subprograms
subprograms
•• Have
Have two
two parts:
parts:
–– A
A specification
specification
–– A
A body
body
•• Allow
Allow Oracle
Oracle to
to read
read multiple
multiple objects
objects
into
into memory
memory at
at once
once

1-92 Copyright  Oracle Corporation, 1998. All rights reserved.


Package

Package Procedure A
specification declaration

Procedure B
Package definition
body
Procedure A
definition
Local
variable

1-93 Copyright  Oracle Corporation, 1998. All rights reserved.


Example
Package create or replace package
specification dbms_session is
from procedure set_role
(role_cmd varchar2);
dbmsutil.sql

create or replace package body


dbms_session wrapped
Package 0
body from abcd
prvtutil.plb abcd
abcd
abcd ...

1-94 Copyright  Oracle Corporation, 1998. All rights reserved.


Oracle-Supplied Packages
•• DBMS_LOB—Provides
DBMS_LOB—Provides routines
routines for
for operations
operations on
on
BLOB
BLOB and
and CLOB
CLOB datatypes
datatypes
•• DBMS_SESSION—Generates
DBMS_SESSION—Generates SQLSQL commands
commands like like
ALTER
ALTER SESSION
SESSION or
or SET
SET ROLE
ROLE
•• DBMS_UTILITY—Provides
DBMS_UTILITY—Provides various
various utility
utility routines
routines
•• DBMS_SPACE—Provides
DBMS_SPACE—Provides segment
segment space
space
availability
availability information
information
•• DBMS_ROWID—Provides
DBMS_ROWID—Provides ROWIDROWID information
information
•• DBMS_SHARED_POOL—Keeps
DBMS_SHARED_POOL—Keeps and
and unkeeps
unkeeps
information
information in
in the
the shared
shared pool
pool

1-95 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information About
Stored Objects
• Data
Data dictionary
dictionary view
view DBA_OBJECTS:
DBA_OBJECTS:
–– OWNER
OWNER
–– OBJECT_NAME
OBJECT_NAME
–– OBJECT_TYPE
OBJECT_TYPE
–– STATUS
STATUS (VALID,
(VALID, INVALID)
INVALID)
• DESCRIBE
DESCRIBE command:
command:
describe
describe dbms_session.set_role
dbms_session.set_role
1-96 Copyright  Oracle Corporation, 1998. All rights reserved.
Troubleshooting

The
The status
status of
of dependent
dependent objects
objects may
may be
be
INVALID:
INVALID:
•• If
If DDL
DDL commands
commands are are executed
executed on
on
referenced
referenced objects
objects
•• After
After creating
creating the
the objects
objects using
using the
the
IMPORT
IMPORT utility
utility

1-97 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Creating
Creating and
and using
using the
the data
data dictionary
dictionary
views
views
• Using
Using the
the administrative
administrative scripts
scripts
• Obtaining
Obtaining information
information about
about stored
stored
procedures
procedures and
and packages
packages

1-98 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Maintaining the Control File

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Explaining
Explaining the
the uses
uses of
of the
the control
control file
file
•• Examining
Examining the
the contents
contents ofof the
the control
control
file
file
•• Obtaining
Obtaining the
the control
control file
file information
information
•• Multiplexing
Multiplexing the
the control
control file
file

1-100 Copyright  Oracle Corporation, 1998. All rights reserved.


Using the Control File

Control
files

Redo log
Data files
files
Database
Database

1-101 Copyright  Oracle Corporation, 1998. All rights reserved.


The Contents of the Control File

Database name
Data file location
Redo log file location
Tablespace names
Current log sequence number
Checkpoint information
Log history
Backup information

1-102 Copyright  Oracle Corporation, 1998. All rights reserved.


Parameters Affecting the Size of
the Control File
The
The size
size of
of the
the control
control file
file is
is influenced
influenced by
by
the
the following
following parameters:
parameters:
• MAXLOGFILES
MAXLOGFILES
• MAXLOGMEMBERS
MAXLOGMEMBERS
• MAXLOGHISTORY
MAXLOGHISTORY
• MAXDATAFILES
MAXDATAFILES
• MAXINSTANCES
MAXINSTANCES

1-103 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information
• V$CONTROLFILE
V$CONTROLFILE
-- NAME
NAME
• V$PARAMETER
V$PARAMETER
-- NAME
NAME (( control_file)
control_file)
-- VALUE
VALUE
• V$CONTROLFILE_RECORD_SECTION
V$CONTROLFILE_RECORD_SECTION
-- TYPE
TYPE
-- RECORDS_SIZE
RECORDS_SIZE
-- RECORDS_TOTAL
RECORDS_TOTAL
-- RECORDS_USED
RECORDS_USED

1-104 Copyright  Oracle Corporation, 1998. All rights reserved.


Multiplexing the Control File
control_files=(/DISK1/control01.con,/DISK2/control02.con)

Disk 1 Disk 2

control01.con control02.con

1-105 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary
Multiplexing
Multiplexing the
the control
control file
file helps
helps to
to avoid
avoid
aa single
single point
point of
of database
database failure.
failure.

1-106 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Maintaining Redo Log Files

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
•• Explaining
Explaining the
the use
use of
of online
online redo
redo log
log
files
files
•• Obtaining
Obtaining log
log and
and archive
archive information
information
•• Controlling
Controlling log
log switches
switches and
and
checkpoints
checkpoints
•• Multiplexing
Multiplexing and
and maintaining
maintaining online
online
redo
redo log
log files
files
•• Planning
Planning online
online redo
redo log
log files
files
•• Troubleshooting
Troubleshooting common
common redo
redo log
log file
file
problems
problems
1-108 Copyright  Oracle Corporation, 1998. All rights reserved.
Using Redo Log Files

Control
files

Data files Redo log


files

Database

1-109 Copyright  Oracle Corporation, 1998. All rights reserved.


Redo Log Groups and Members

Group 1 Group 2 Group 3


Disk 1
Member Member Member

Member
Member Member
Disk 2

1-110 Copyright  Oracle Corporation, 1998. All rights reserved.


Oracle Architecture
Instance
SGA

Database
Redo log
buffer
buffer
cache

DBWR CKPT LGWR ARCH

Control
files
Parameter
file Archived
Data files Redo log
files log files
Password
file
Database
1-111 Copyright  Oracle Corporation, 1998. All rights reserved.
Without Archiving

Backup Disk failure

Data files Control


files

101
50 51 100

t1 t2

1-112 Copyright  Oracle Corporation, 1998. All rights reserved.


With Archiving

Archived
Backup redo logs
Disk failure
50
Data files Control
files

50 51 99 101
100

t1 t2

1-113 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information
About Archiving
•• Server
Server Manager
Manager command:
command:
ARCHIVE
ARCHIVE LOG
LOG LIST;
LIST;

•• V$DATABASE:
V$DATABASE:
–– NAME
NAME
–– LOG_MODE
LOG_MODE
•• V$INSTANCE
V$INSTANCE
–– ARCHIVER
ARCHIVER
1-114 Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Information
About Groups

V$THREAD:
V$THREAD:
•• GROUPS
GROUPS
•• CURRENT_GROUP#
CURRENT_GROUP#
•• SEQUENCE#
SEQUENCE#

1-115 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information About
Groups and Members

V$LOG:
• GROUP#
• MEMBERS
• STATUS
• SEQUENCE#
• BYTES

1-116 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information About
Groups and Members
V$LOGFILE:
• GROUP#
• STATUS
• MEMBER

1-117 Copyright  Oracle Corporation, 1998. All rights reserved.


Log Switches and Checkpoints

•• Force
Force log
log switches
switches with
with the
the command:
command:

ALTER
ALTER SYSTEM
SYSTEM SWITCH
SWITCH LOGFILE;
LOGFILE;

•• Control
Control checkpoints
checkpoints with
with the
the
initialization
initialization parameters:
parameters:
–– LOG_CHECKPOINT_INTERVAL
LOG_CHECKPOINT_INTERVAL
–– LOG_CHECKPOINT_TIMEOUT
LOG_CHECKPOINT_TIMEOUT

1-118 Copyright  Oracle Corporation, 1998. All rights reserved.


Adding Online Redo Log Groups

ALTER
ALTER DATABASE
DATABASE ADD
ADD LOGFILE
LOGFILE
(‘/DISK3/log3a.rdo’,
(‘/DISK3/log3a.rdo’,
‘/DISK4/log3b.rdo’)
‘/DISK4/log3b.rdo’) size
size 1M;
1M;

log1a.rdo
log2b.rdo log3a.rdo
log1b.rdo log3b.rdo

Group 1 Group 2 Group 3


1-119 Copyright  Oracle Corporation, 1998. All rights reserved.
Adding Online Redo
Log Members

ALTER
ALTER DATABASE
DATABASE ADD
ADD LOGFILE
LOGFILE MEMBER
MEMBER
‘/DISK4/log1b.rdo’
‘/DISK4/log1b.rdo’ TO
TO GROUP
GROUP 1,
1,
‘/DISK4/log2b.rdo’
‘/DISK4/log2b.rdo’ TO
TO GROUP
GROUP 2;
2;

log1a.rdo log1b.rdo log2a.rdo log2b.rdo

Group 1 Group 2
1-120 Copyright  Oracle Corporation, 1998. All rights reserved.
How to Relocate
Online Redo Log Files
11.. Shut
Shut down
down the
the database.
database.
22.. Copy
Copy the
the online
online redo
redo log
log files
files to
to the
the
new
new location.
location.
33.. Mount
Mount the
the database.
database.
44.. Execute
Execute the
the ALTER
ALTER DATABASE
DATABASE
RENAME
RENAME FILE
FILE command.
command.
55.. Open
Open the
the database.
database.

1-121 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Online Redo
Log Groups

ALTER
ALTER DATABASE
DATABASE DROP
DROP LOGFILE
LOGFILE
GROUP
GROUP 3;
3;

log1a.rdo log3a.rdo
log2a.rdo
log3b.rdo
log1b.rdo
log2b.rdo

Group 1 Group 2 Group 3

1-122 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Online Redo
Log Members

ALTER
ALTER DATABASE
DATABASE DROP
DROP LOGFILE
LOGFILE MEMBER
MEMBER
‘/DISK4/log2b.dbf’;
‘/DISK4/log2b.dbf’;

log1a.rdo
log1b.rdo
log2a.rdo log2b.rdo

Group 1 Group 2

1-123 Copyright  Oracle Corporation, 1998. All rights reserved.


Clearing Online Redo Log Files

Example
ALTER
ALTER DATABASE
DATABASE CLEAR
CLEAR LOGFILE
LOGFILE
‘/DISK3/log2a.rdo’;
‘/DISK3/log2a.rdo’;

1-124 Copyright  Oracle Corporation, 1998. All rights reserved.


Online Redo Log Configuration

Group 1 Group 2 Group 3


Member
Member Member

Member

Member

Disk 1 Disk 2 Disk 3


1-125 Copyright  Oracle Corporation, 1998. All rights reserved.
Possible LGWR Errors

•• One
One member
member of of aa group
group of
of two
two or
or more
more
is
is not
not available.
available.
•• All
All members
members of of the
the next
next group
group are
are not
not
available.
available.
•• All
All members
members of of the
the current
current group
group are
are
not
not available.
available.

1-126 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Controlling
Controlling log
log switches
switches and
and
checkpoints
checkpoints
• Administering
Administering online
online redo
redo log
log files
files

1-127 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Tablespaces
and Data Files

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Describing
Describing the
the logical
logical structure
structure of
of the
the
database
database
•• Creating
Creating tablespaces
tablespaces
•• Changing
Changing the
the size
size of
of tablespaces
tablespaces using
using
different
different methods
methods
•• Changing
Changing the
the status
status and
and storage
storage settings
settings of
of
tablespaces
tablespaces
•• Relocating
Relocating tablespaces
tablespaces
•• Preparing
Preparing necessary
necessary tablespaces
tablespaces

1-129 Copyright  Oracle Corporation, 1998. All rights reserved.


Overview

Control
files

Redo log
Data files files

Database

1-130 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Structure

Database

Tablespace Data file

Logical Segment Physical

Extent

Oracle
O/S Block
block
1-131 Copyright  Oracle Corporation, 1998. All rights reserved.
SYSTEM and
Non-SYSTEM Tablespaces
SYSTEM
SYSTEM Tablespace
Tablespace Non-SYSTEM
Non-SYSTEM
contains:
contains: Tablespace
Tablespace contains:
contains:
–– Data
Data dictionary
dictionary –– Rollback
Rollback segments
segments
information
information –– Temporary
Temporary
–– SYSTEM
SYSTEM rollback
rollback segments
segments
segment
segment –– Application
Application data
data
–– Application
Application indexes
indexes

1-132 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Tablespaces

Example
CREATE
CREATE TABLESPACE
TABLESPACE app_data
app_data
DATAFILE
DATAFILE ‘/DISK4/app01.dbf’
‘/DISK4/app01.dbf’ SIZE
SIZE 100M,
100M,
‘/DISK5/app02.dbf’
‘/DISK5/app02.dbf’ SIZE
SIZE 100M
100M
MINIMUM
MINIMUM EXTENT
EXTENT 500K
500K
DEFAULT
DEFAULT STORAGE
STORAGE (INITIAL
(INITIAL 500K
500K NEXT
NEXT 500K
500K
MAXEXTENTS
MAXEXTENTS 500
500 PCTINCREASE
PCTINCREASE 0);
0);

1-133 Copyright  Oracle Corporation, 1998. All rights reserved.


Storage Parameters

The
The following
following parameters
parameters influence
influence the
the
segment
segment storage
storage allocation:
allocation:
• INITIAL
INITIAL
• NEXT
NEXT
• MAXEXTENTS
MAXEXTENTS
• MINEXTENTS
MINEXTENTS
• PCTINCREASE
PCTINCREASE

1-134 Copyright  Oracle Corporation, 1998. All rights reserved.


Temporary Tablespace

• Used
Used for
for sort
sort operations
operations
• Cannot
Cannot contain
contain any
any permanent
permanent objects
objects

CREATE
CREATE TABLESPACE
TABLESPACE sort
sort
DATAFILE
DATAFILE ‘/DISK2/sort01.dbf’
‘/DISK2/sort01.dbf’ SIZE
SIZE 50M
50M
MINIMUM
MINIMUM EXTENT
EXTENT 1M
1M
DEFAULT
DEFAULT STORAGE
STORAGE (INITIAL
(INITIAL 2M
2M NEXT
NEXT 2M
2M
MAXEXTENTS
MAXEXTENTS 500
500 PCTINCREASE
PCTINCREASE 0)
0)
TEMPORARY;
TEMPORARY;
1-135 Copyright  Oracle Corporation, 1998. All rights reserved.
Adding Data Files
to a Tablespace
Example
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data
ADD
ADD DATAFILE
DATAFILE
‘/DISK5/app03.dbf’
‘/DISK5/app03.dbf’ SIZE
SIZE 200M;
200M;

Tablespace APP_DATA

app01.dbf app03.dbf
app02.dbf
2M
1M 1M

1-136 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling Automatic Extension
of Data Files
Example
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data
ADD
ADD DATAFILE
DATAFILE
‘/DISK6/app04.dbf’
‘/DISK6/app04.dbf’ SIZE
SIZE 200M
200M
AUTOEXTEND
AUTOEXTEND ON
ON NEXT
NEXT 10M
10M
MAXSIZE
MAXSIZE 500M;
500M;

Tablespace APP_ DATA

app04.dbf
app01.dbf app02.dbf app03.dbf
2M
1M 1M 2M

1-137 Copyright  Oracle Corporation, 1998. All rights reserved.


Changing the Size
of Data Files Manually
Example
ALTER
ALTER DATABASE
DATABASE DATAFILE
DATAFILE
‘/DISK5/app02.dbf’
‘/DISK5/app02.dbf’ RESIZE
RESIZE 200M;
200M;

Tablespace APP_DATA

app01.dbf app02.dbf
1M 1M

1M

1-138 Copyright  Oracle Corporation, 1998. All rights reserved.


Changing the Storage Settings

Example
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data
MINIMUM
MINIMUM EXTENT
EXTENT 2M;
2M;

ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data
DEFAULT
DEFAULT STORAGE
STORAGE
(INITIAL
(INITIAL 2M
2M NEXT
NEXT 2M
2M
MAXEXTENTS
MAXEXTENTS 999);
999);

1-139 Copyright  Oracle Corporation, 1998. All rights reserved.


OFFLINE Status

• The
The tablespace
tablespace that
that is
is offline
offline is
is not
not
available
available for
for data
data access.
access.
• The
The SYSTEM
SYSTEM tablespace
tablespace and
and any
any
tablespace
tablespace with
with active
active rollback
rollback
segments
segments cannot
cannot be
be taken
taken offline.
offline.
Example
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data OFFLINE;
OFFLINE;

1-140 Copyright  Oracle Corporation, 1998. All rights reserved.


Moving Data Files:
ALTER TABLESPACE
•• The
The tablespace
tablespace APP_DATA
APP_DATA mustmust be
be
offline.
offline.
•• The
The target
target data
data files
files must
must exist.
exist.
Example
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data RENAME
RENAME
DATAFILE
DATAFILE ‘/DISK4/app01.dbf’
‘/DISK4/app01.dbf’ TO
TO
‘/DISK5/app01.dbf’;
‘/DISK5/app01.dbf’;

1-141 Copyright  Oracle Corporation, 1998. All rights reserved.


Moving Data Files:
ALTER DATABASE
•• The
The database
database must
must bebe mounted.
mounted.
•• The
The target
target data
data file
file must
must exist.
exist.
Example
ALTER
ALTER DATABASE
DATABASE RENAME
RENAME FILE
FILE
‘/DISK1/system01.dbf’
‘/DISK1/system01.dbf’ TO
TO
‘/DISK2/system01.dbf’;
‘/DISK2/system01.dbf’;

1-142 Copyright  Oracle Corporation, 1998. All rights reserved.


The READ-ONLY
Tablespace Status
Example
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data READ
READ
ONLY;
ONLY;

The tablespace APP_DATA is only available


for read operations.

1-143 Copyright  Oracle Corporation, 1998. All rights reserved.


Making Tablespace Read-Only

• The
The tablespace
tablespace must
must be
be online.
online.
• No
No active
active transactions
transactions are
are allowed.
allowed.
• The
The tablespace
tablespace must
must not
not contain
contain active
active
rollback
rollback segments.
segments.
• The
The tablespace
tablespace must
must not
not currently
currently be
be
involved
involved in
in an
an online
online backup.
backup.

1-144 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Tablespaces

The following statement removes the


APP_DATA tablespace and all its
contents.
Example
DROP
DROP TABLESPACE
TABLESPACE app_data
app_data
INCLUDING
INCLUDING CONTENTS;
CONTENTS;

1-145 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Tablespace Information

DBA_TABLESPACES
DBA_TABLESPACES
•• TABLESPACE_NAME
TABLESPACE_NAME
•• NEXT_EXTENT
NEXT_EXTENT
•• MAX_EXTENTS
MAX_EXTENTS
•• PCT_INCREASE
PCT_INCREASE
•• MIN_EXTLEN
MIN_EXTLEN
•• STATUS
STATUS
•• CONTENTS
CONTENTS
1-146 Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Data File Information

DBA_DATA_FILES
DBA_DATA_FILES
•• FILE_NAME
FILE_NAME
•• TABLESPACE_NAME
TABLESPACE_NAME
•• BYTES
BYTES
•• AUTOEXTENSIBLE
AUTOEXTENSIBLE
•• MAXBYTES
MAXBYTES
•• INCREMENT_BY
INCREMENT_BY

1-147 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Data File and Tablespace
Information from the Control File

V$DATAFILE V$TABLESPACE
- TS# - TS#
- NAME - NAME
- FILE#
- RFILE#
- STATUS
- ENABLED
- BYTES
- CREATE_BYTES

1-148 Copyright  Oracle Corporation, 1998. All rights reserved.


Guidelines

•• Use multiple tablespaces.


•• Specify storage
storage parameters
parameters for
for
tablespaces.
•• Assign tablespace quotas to users.
users.

1-149 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Understanding
Understanding the
the logical
logical database
database
structure
structure
• Administering
Administering tablespaces
tablespaces

1-150 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Storage Structure and
Relationships

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
•• Listing
Listing the
the different
different segment
segment types
types and
and
their
their uses
uses
•• Controlling
Controlling thethe use
use of
of extents
extents byby
segments
segments
•• Stating
Stating the
the use
use of
of block
block space
space
utilization
utilization parameters
parameters by by objects
objects
•• Obtaining
Obtaining information
information about
about storage
storage
structures
structures from
from the
the data
data dictionary
dictionary
•• Locating
Locating thethe segments
segments by by considering
considering
fragmentation
fragmentation and and life-spans
life-spans
1-152 Copyright  Oracle Corporation, 1998. All rights reserved.
Database Storage Hierarchy
Database

Tablespace Data file

Logical Segment Physical

Extent

Oracle
O/S block
block
1-153 Copyright  Oracle Corporation, 1998. All rights reserved.
Types of Segments

Table Table
partition

Cluster Index

1-154 Copyright  Oracle Corporation, 1998. All rights reserved.


Types of Segments

Index-organized
Index
table
partition

Rollback
Temporary
segment
segment

1-155 Copyright  Oracle Corporation, 1998. All rights reserved.


Types of Segments

LOB
LOB index
segment

Nested table Bootstrap


segment
1-156 Copyright  Oracle Corporation, 1998. All rights reserved.
Storage Clause Precedence

Oracle default
Tablespace
Segment

1-157 Copyright  Oracle Corporation, 1998. All rights reserved.


Extent Allocation and Deallocation
•• Allocated
Allocated when
when the
the segment
segment isis
++ Created
Created
++ Extended
Extended
++ Altered
Altered
•• Deallocated
Deallocated when
when the
the segment
segment is is
–– Dropped
Dropped
–– Altered
Altered
–– Truncated
Truncated
–– Automatically
Automatically resized
resized (rollback
(rollback segments
segments
only)
only)

1-158 Copyright  Oracle Corporation, 1998. All rights reserved.


Used and Free Extents

Data file

File header Used extent Free extent

1-159 Copyright  Oracle Corporation, 1998. All rights reserved.


Coalescing Free Space

Before

ALTER
ALTER TABLESPACE
TABLESPACE data01
data01 COALESCE;
COALESCE;

After

File header Used extent Free extent

1-160 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Block: Review

•• Minimum
Minimum unit
unit of
of I/O
I/O
•• Consists
Consists of
of one
one or
or more
more O/S
O/S blocks
blocks
•• Set
Set by
by DB_BLOCK_SIZE
DB_BLOCK_SIZE
•• Set
Set at
at database
database creation
creation

1-161 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Block Contents

Header

Free space

Data

1-162 Copyright  Oracle Corporation, 1998. All rights reserved.


Block Space
Utilization Parameters

INITRANS

MAXTRANS

PCTFREE

PCTUSED

1-163 Copyright  Oracle Corporation, 1998. All rights reserved.


Block Space Usage
PCTFREE=20 PCTUSED=40

Inserts 80% Inserts

1 2

80%
Inserts Inserts
40%

3 4
1-164 Copyright  Oracle Corporation, 1998. All rights reserved.
Data Dictionary Views

Used extents Free extents


DBA_EXTENTS DBA_FREE_SPACE

Segments Data files


DBA_SEGMENTS DBA_DATA_FILES

Tablespaces
DBA_TABLESPACES

1-165 Copyright  Oracle Corporation, 1998. All rights reserved.


Querying Segment Information

DBA_SEGMENTS
DBA_SEGMENTS
–– General
General information
information
–– OWNER
OWNER
SEGMENT_NAME
SEGMENT_NAME
–– SEGMENT_TYPE
SEGMENT_TYPE
–– TABLESPACE_NAME
TABLESPACE_NAME
– Size – Storage settings
– EXTENTS – INITIAL_EXTENT
– BLOCKS – NEXT_EXTENT
– MIN_EXTENTS
– MAX_EXTENTS
– PCT_INCREASE
1-166 Copyright  Oracle Corporation, 1998. All rights reserved.
Getting Used Extent Information

DBA_EXTENTS
DBA_EXTENTS
–– Identification
Identification
–– OWNER
OWNER
–– SEGMENT_NAME
SEGMENT_NAME
–– EXTENT_ID
EXTENT_ID
–– Location
Location and
and size
size
–– TABLESPACE_NAME
TABLESPACE_NAME
–– RELATIVE_FNO
RELATIVE_FNO
–– FILE_ID
FILE_ID
–– BLOCK_ID
BLOCK_ID
–– BLOCKS
BLOCKS

1-167 Copyright  Oracle Corporation, 1998. All rights reserved.


Checking Free
Extent Information

DBA_FREE_SPACE
DBA_FREE_SPACE
–– Location
Location and
and size
size
–– TABLESPACE_NAME
TABLESPACE_NAME
–– RELATIVE_FNO
RELATIVE_FNO
–– FILE_ID
FILE_ID
–– BLOCK_ID
BLOCK_ID
–– BLOCKS
BLOCKS

1-168 Copyright  Oracle Corporation, 1998. All rights reserved.


Organizing Tablespaces Based
on Fragmentation Propensity
Tablespace Usage Fragmentation

SYSTEM Zero
Data dictionary
TOOLS Very low
Applications
DATAn Low
Data segments
INDEXn Low
Index segments
RBSn High
Rollback segments
Very high*
TEMPn
Temporary segments
* Relevant only if tablespace PERMANENT
1-169 Copyright  Oracle Corporation, 1998. All rights reserved.
Summary
• Allocation
Allocation and
and deallocation
deallocation of
of extents
extents
for
for different
different types
types of
of segments
segments
• Block
Block space
space utilization
utilization parameters
parameters

1-170 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Rollback Segments

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Planning
Planning the
the number
number and
and size
size of
of
rollback
rollback segments
segments
•• Creating
Creating rollback
rollback segments
segments using
using
appropriate
appropriate storage
storage settings
settings
•• Maintaining
Maintaining rollback
rollback segments
segments
•• Obtaining
Obtaining rollback
rollback segment
segment information
information
from
from the
the data
data dictionary
dictionary
•• Troubleshooting
Troubleshooting rollback
rollback segment
segment
problems
problems

1-172 Copyright  Oracle Corporation, 1998. All rights reserved.


Rollback Segment
Old
image

New
Table image
Rollback
segment

Update
transaction
1-173 Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segments: Purpose

Transaction
rollback

Transaction Rollback Read


recovery segment consistency
1-174 Copyright  Oracle Corporation, 1998. All rights reserved.
Types of Rollback Segments

•• SYSTEM
SYSTEM
•• Non-SYSTEM
Non-SYSTEM
–– Private
Private
–– Public
Public

1-175 Copyright  Oracle Corporation, 1998. All rights reserved.


Transactions and Rollback
Segments

1 2

Transaction 1 Transaction 2
4 3

Active extent Inactive extent


1-176 Copyright  Oracle Corporation, 1998. All rights reserved.
Growth of Rollback Segments

1 2
1 2

4 3 5 3
4

Active extent New extent


Inactive extent
1-177 Copyright  Oracle Corporation, 1998. All rights reserved.
Shrinkage of Rollback Segments

6 1
1 2
5 2
6 3
4 3

Active extent
Optimal Inactive extent
1-178 Copyright  Oracle Corporation, 1998. All rights reserved.
Read-Consistency
SELECT *
Table FROM table

New image
Image at statement
commencement
1-179 Copyright  Oracle Corporation, 1998. All rights reserved.
Planning Rollback Segments:
Number
•• OLTP
OLTP
–– Small,
Small, but
but many
many segments
segments
–– One
One RBS/4
RBS/4 transactions
transactions
•• Batch
Batch
–– Large,
Large, but
but few
few

1-180 Copyright  Oracle Corporation, 1998. All rights reserved.


Planning Rollback Segments:
Number of Extents
0.50
0.50

0.40
0.40
Probability 0.30
0.30
of extending
0.20
0.20

0.10
0.10

0.00
0.00
00 10
10 20
20 30
30 40
40
Number
Number of
of extents
extents
1-181 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating Rollback Segments

Example
CREATE
CREATE ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01
rbs01
TABLESPACE
TABLESPACE rbs
rbs
STORAGE
STORAGE ((
INITIAL
INITIAL 100K
100K NEXT
NEXT 100K
100K OPTIMAL
OPTIMAL 4M
4M
MINEXTENTS
MINEXTENTS 20
20 MAXEXTENTS
MAXEXTENTS 100);
100);

1-182 Copyright  Oracle Corporation, 1998. All rights reserved.


Bringing Rollback Segments
Online
•• Use
Use the
the following
following command
command to to make
make aa
rollback
rollback segment
segment available:
available:
ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01
rbs01 ONLINE;
ONLINE;

•• Specify
Specify the
the following
following initialization
initialization
parameter
parameter toto ensure
ensure rollback
rollback segments
segments
are
are brought
brought online
online at
at STARTUP:
STARTUP:
ROLLBACK_SEGMENTS=(rbs01)
ROLLBACK_SEGMENTS=(rbs01)

1-183 Copyright  Oracle Corporation, 1998. All rights reserved.


How Instances Acquire Rollback
Segments
Acquire Compute
named required
Are there No
enough
private number
RBS ?
RBS of RBS

Yes
Acquire
public
RBS
Bring all
acquired
RBSs
ONLINE
1-184 Copyright  Oracle Corporation, 1998. All rights reserved.
Changing Rollback Segment
Storage Settings

Use
Use ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT
ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01
rbs01
STORAGE(
STORAGE( MAXEXTENTS
MAXEXTENTS 200
200 );
);

1-185 Copyright  Oracle Corporation, 1998. All rights reserved.


Deallocating Space from
Rollback Segments

Use
Use ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT
ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01
rbs01
SHRINK
SHRINK TO
TO 4M;
4M;

1-186 Copyright  Oracle Corporation, 1998. All rights reserved.


Taking Rollback Segment
Offline

Take
Take aa rollback
rollback segment
segment offline
offline to
to make
make
it
it unavailable.
unavailable.
ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01
rbs01
OFFLINE;
OFFLINE;

1-187 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Rollback Segments

A
A rollback
rollback segment
segment must
must be
be offline
offline before
before
it
it can
can be
be dropped.
dropped.

DROP
DROP ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01;
rbs01;

1-188 Copyright  Oracle Corporation, 1998. All rights reserved.


Rollback Segments in the
Database
DBA_ROLLBACK_SEGS
DBA_ROLLBACK_SEGS
•• Identification
Identification
–– SEGMENT_ID
SEGMENT_ID
–– SEGMENT_NAME
SEGMENT_NAME
•• Location,
Location, type,
type, and
and status
status
–– TABLESPACE_NAME
TABLESPACE_NAME
–– OWNER
OWNER (PUBLIC
(PUBLIC or
or SYS)
SYS)
–– STATUS
STATUS (ONLINE
(ONLINE or
or OFFLINE)
OFFLINE)
1-189 Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segment Statistics

V$ROLLNAME
V$ROLLNAME V$ROLLSTAT
V$ROLLSTAT
USN
USN USN
USN
NAME
NAME EXTENTS
EXTENTS
RSSIZE
RSSIZE
XACTS
XACTS
OPTSIZE
OPTSIZE
HWMSIZE
HWMSIZE
AVEACTIVE
AVEACTIVE
STATUS
STATUS
CUREXT
CUREXT
CURBLK
CURBLK
1-190 Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segment: Current Activity

V$SESSION
V$SESSION V$TRANSACTION
V$TRANSACTION
SADDR
SADDR SES_ADDR
SES_ADDR
USERNAME
USERNAME XIDUSN
XIDUSN
SID
SID UBAFIL
UBAFIL
SERIAL#
SERIAL# UBABLK
UBABLK
UBASQN
UBASQN
UBAREC
UBAREC
STATUS
STATUS
USED_UBLK
USED_UBLK
USED_UREC
USED_UREC
1-191 Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segment Problems

•• Insufficient
Insufficient space
space for
for transactions
transactions
•• Read-consistency
Read-consistency error
error
•• Blocking
Blocking transaction
transaction
•• Error
Error in
in taking
taking tablespace
tablespace offline
offline

1-192 Copyright  Oracle Corporation, 1998. All rights reserved.


Insufficient Space for Transactions

•• No
No space
space in
in tablespace
tablespace
–– Extend
Extend data
data files
files
–– Allow
Allow automatic
automatic extension
extension of
of data
data
files
files
–– Add
Add data
data files
files
•• MAXEXTENTS
MAXEXTENTS reachedreached for
for segment
segment
–– Increase
Increase MAXEXTENTS
MAXEXTENTS
–– Recreate
Recreate segments
segments with
with larger
larger extent
extent
sizes
sizes
1-193 Copyright  Oracle Corporation, 1998. All rights reserved.
Read-Consistency Error
SELECT * Reused
Table FROM table block

New image
Image at statement
commencement
1-194 Copyright  Oracle Corporation, 1998. All rights reserved.
Blocking Session
Blocking
session
1 2
4 1
Extent 3

3 2 5 3
4

Existing extent
New extent
1-195 Copyright  Oracle Corporation, 1998. All rights reserved.
Error in Taking a
Tablespace Offline
Cannot
Cannot take
take tablespace
tablespace containing
containing active
active
RBS
RBS offline
offline
•• Check
Check rollback
rollback segments
segments in in the
the
tablespace
tablespace
•• Find
Find active
active transactions
transactions using
using these
these
rollback
rollback segments
segments
•• Find
Find session
session IDID and
and serial
serial number
number
•• Terminate
Terminate the
the session,
session, if
if necessary
necessary

1-196 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Creating
Creating adequate
adequate rollback
rollback segments
segments
•• Troubleshooting
Troubleshooting rollback
rollback segment
segment
problems
problems

1-197 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Temporary Segments

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Distinguishing
Distinguishing the
the different
different types
types of
of
temporary
temporary segments
segments
•• Allocating
Allocating space
space for
for temporary
temporary
segments
segments within
within aa database
database
•• Obtaining
Obtaining temporary
temporary segment
segment
information
information for
for aa database
database oror instance
instance

1-199 Copyright  Oracle Corporation, 1998. All rights reserved.


Temporary Segment
Memory

SORT_AREA_SIZE

Data file

1-200 Copyright  Oracle Corporation, 1998. All rights reserved.


Types of Temporary Segments
Memory

Permanent Temporary
tablespace tablespace

1-201 Copyright  Oracle Corporation, 1998. All rights reserved.


Temporary Segments
in a Permanent Tablespace

•• Created
Created when
when needed
needed on
on aa per
per
transaction
transaction basis
basis
•• Reclaimed
Reclaimed by
by SMON
SMON when
when thethe
statement
statement completes
completes execution
execution

1-202 Copyright  Oracle Corporation, 1998. All rights reserved.


Temporary Segments
in a Temporary Tablespace

•• Known
Known as as sort
sort segments
segments
•• Only
Only one
one segment
segment per per tablespace
tablespace per
per
instance
instance
•• Created
Created when
when the
the first
first disk
disk sort
sort occurs
occurs
in
in the
the instance
instance after
after startup
startup
•• Reused
Reused by by several
several transactions
transactions based
based
on
on information
information inin the
the Sort
Sort Extent
Extent Pool
Pool
•• Released
Released onon instance
instance shutdown
shutdown
1-203 Copyright  Oracle Corporation, 1998. All rights reserved.
Guidelines
for Temporary Segments
•• Set
Set upup different
different TEMPORARY
TEMPORARY tablespaces
tablespaces
based
based on on sorting
sorting needs
needs
•• Specify
Specify DEFAULT
DEFAULT STORAGE
STORAGE for for these
these
tablespaces
tablespaces as as shown:
shown:
–– INITIAL=
INITIAL= NEXT
NEXT == (multiple
(multiple of
of
SORT_AREA_SIZE)
SORT_AREA_SIZE) ++ DB_BLOCK_SIZE
DB_BLOCK_SIZE
–– PCTINCREASE
PCTINCREASE == 00

1-204 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information for a
Database Instance

V$SORT_SEGMENT

V$SORT_USAGE

DBA_SEGMENTS

1-205 Copyright  Oracle Corporation, 1998. All rights reserved.


Sort Segment Statistics
V$SORT_SEGMENT
V$SORT_SEGMENT
•• TABLESPACE_NAME
TABLESPACE_NAME
•• EXTENT_SIZE
EXTENT_SIZE
•• TOTAL_EXTENTS
TOTAL_EXTENTS
•• TOTAL_BLOCKS
TOTAL_BLOCKS
•• USED_EXTENTS
USED_EXTENTS
•• USED_BLOCKS
USED_BLOCKS
•• FREE_EXTENTS
FREE_EXTENTS
•• FREE_BLOCKS
FREE_BLOCKS
•• MAX_SORT_SIZE
MAX_SORT_SIZE
•• MAX_SORT_BLOCKS
MAX_SORT_BLOCKS
1-206 Copyright  Oracle Corporation, 1998. All rights reserved.
Temporary Segment Activity

V$SESSION V$SORT_USAGE
SADDR SESSION_ADDR
USERNAME TABLESPACE
SID CONTENTS
EXTENTS
BLOCKS

1-207 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Sorting
Sorting segments
segments in
in permanent
permanent and
and
temporary
temporary tablespaces
tablespaces
• Storage
Storage parameters
parameters for
for temporary
temporary
segments
segments

1-208 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Tables

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
•• Distinguishing
Distinguishing between
between different
different Oracle
Oracle
data
data types
types
•• Creating
Creating tables
tables using
using appropriate
appropriate
storage
storage settings
settings
•• Controlling
Controlling the
the space
space used
used byby tables
tables
•• Analyzing
Analyzing tables
tables to
to check
check integrity
integrity and
and
migration
migration
•• Retrieving
Retrieving information
information about
about tables
tables
from
from the
the data
data dictionary
dictionary
•• Converting
Converting between
between different
different formats
formats of
of
ROWID
ROWID
1-210 Copyright  Oracle Corporation, 1998. All rights reserved.
Storing User Data

Regular Partitioned
table table

Index-organized
table Cluster

1-211 Copyright  Oracle Corporation, 1998. All rights reserved.


Structure of a Row

Row header
Database Column length
Column value
block
1-212 Copyright  Oracle Corporation, 1998. All rights reserved.
Oracle Data Types
Data
Datatype
type

User-defined
User-defined Built-in
Built-in

Scalar
Scalar Collection
Collection Relationship
Relationship
CHAR(N), NCHAR(N) VARRAY REF
VARCHAR2(N),
NVARCHAR2(N) TABLE
NUMBER(P,S)
DATE
RAW(N)
BLOB, CLOB,
NCLOB, BFILE
LONG, LONG RAW
ROWID

1-213 Copyright  Oracle Corporation, 1998. All rights reserved.


Data Types for Storing
Large Objects

LONG, LONG RAW LOB

Single column per table Multiple columns per table

Up to 2 gigabytes Up to 4 gigabytes

SELECT returns data SELECT returns locator

Data stored in-line Data stored in-line or out-of-line

No object type support Supports object types

Sequential access to chunks Random access to chunks

1-214 Copyright  Oracle Corporation, 1998. All rights reserved.


ROWID Data Type

•• Unique
Unique identifier
identifier for
for aa row
row
•• Used
Used to
to locate
locate aa row
row

ROWID Format
OOOOOO FFF BBBBBB RRR
Data object Relative file Block number Row number
number number

1-215 Copyright  Oracle Corporation, 1998. All rights reserved.


Restricted ROWID

•• Can
Can identify
identify rows
rows within
within aa segment
segment
•• Needs
Needs less
less space
space

BBBBBBBB . RRRR . FFFF


Block number Row number File number

1-216 Copyright  Oracle Corporation, 1998. All rights reserved.


Collections
•• Collections
Collections are
are objects
objects that
that contain
contain
objects.
objects.
•• VARRAYs
VARRAYs are are ordered
ordered sets
sets ofof elements
elements
containing
containing aa count
count and
and aa limit.
limit.
•• Nested
Nested tables
tables are
are tables
tables with
with aa column
column
or
or variable
variable of
of the
the TABLE
TABLE datadata type.
type.

VARRAY Nested
table
1-217 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating a Table

CREATE
CREATE TABLE
TABLE employees(
employees(
empno
empno NUMBER(4),
NUMBER(4),
last_name
last_name VARCHAR2(30)
VARCHAR2(30)
deptno
deptno NUMBER(2))
NUMBER(2))
PCTFREE
PCTFREE 20
20 PCTUSED
PCTUSED 50
50
STORAGE(INITIAL
STORAGE(INITIAL 200K
200K NEXT
NEXT 200K
200K
PCTINCREASE
PCTINCREASE 00 MAXEXTENTS
MAXEXTENTS 50)
50)
TABLESPACE
TABLESPACE data01;
data01;

1-218 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating a Table: Guidelines

• Use
Use aa few
few standard
standard extent
extent sizes
sizes for
for
tables
tables to
to reduce
reduce tablespace
tablespace
fragmentation.
fragmentation.
• Use
Use the
the CACHE
CACHE clause
clause for
for frequently
frequently
used,
used, small
small tables.
tables.

1-219 Copyright  Oracle Corporation, 1998. All rights reserved.


Setting PCTFREE and PCTUSED

•• Compute
Compute PCTFREE
PCTFREE
(Average Row Size  Initial Row Size) * 100

Average Row Size

•• Compute
Compute PCTUSED
PCTUSED
Average Row Size * 100
100  PCTFREE 
Available Data Space

1-220 Copyright  Oracle Corporation, 1998. All rights reserved.


Row Migration and Chaining
Before After
update update

1-221 Copyright  Oracle Corporation, 1998. All rights reserved.


Copying an Existing Table

CREATE
CREATE TABLE
TABLE new_emp
new_emp
STORAGE(INITIAL
STORAGE(INITIAL 200K
200K NEXT
NEXT 200K
200K
PCTINCREASE
PCTINCREASE 00 MAXEXTENTS
MAXEXTENTS 50)
50)
NOLOGGING
NOLOGGING
TABLESPACE
TABLESPACE data01
data01
AS
AS
SELECT
SELECT ** FROM
FROM scott.employees;
scott.employees;

1-222 Copyright  Oracle Corporation, 1998. All rights reserved.


Changing Storage and Block
Utilization Parameters

ALTER
ALTER TABLE
TABLE scott.employees
scott.employees
PCTFREE
PCTFREE 30
30
PCTUSED
PCTUSED 50
50
STORAGE(NEXT
STORAGE(NEXT 500K
500K
MINEXTENTS
MINEXTENTS 22
MAXEXTENTS
MAXEXTENTS 100);
100);

1-223 Copyright  Oracle Corporation, 1998. All rights reserved.


Manually Allocating Extents

ALTER
ALTER TABLE
TABLE scott.employees
scott.employees
ALLOCATE
ALLOCATE EXTENT(SIZE
EXTENT(SIZE 500K
500K
DATAFILE
DATAFILE ‘/DISK3/DATA01.DBF’);
‘/DISK3/DATA01.DBF’);

1-224 Copyright  Oracle Corporation, 1998. All rights reserved.


High Water Mark
After inserts
Extent ID 0 1 2 3 4

After deletes High water mark

Extent ID 0 1 2 3 4

Used block Unused block Free space after delete

1-225 Copyright  Oracle Corporation, 1998. All rights reserved.


Finding the High Water Mark:
DBMS_SPACE.UNUSED_SPACE
TOTAL_BLOCKS

UNUSED_BLOCKS

Extent ID 0 1 2 3 4

High water mark


LAST_USED_EXTENT_FILE_ID,
LAST_USED_EXTENT_BLOCK_ID

1-226 Copyright  Oracle Corporation, 1998. All rights reserved.


Deallocation of Unused Space
Before
deallocation

ALTER
ALTER TABLE
TABLE scott.employees
scott.employees High water mark
DEALLOCATE
DEALLOCATE UNUSED;
UNUSED;

After
deallocation

Used block Unused block Free space after delete

1-227 Copyright  Oracle Corporation, 1998. All rights reserved.


Truncating a Table

TRUNCATE
TRUNCATE TABLE
TABLE scott.employees;
scott.employees;

Extent ID 0 1

High water mark

Free space

1-228 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Tables

DROP
DROP TABLE
TABLE scott.departments
scott.departments
CASCADE
CASCADE CONSTRAINTS;
CONSTRAINTS;

1-229 Copyright  Oracle Corporation, 1998. All rights reserved.


Validating Table Structure
•• The
The Oracle
Oracle server
server verifies
verifies the
the integrity
integrity
of
of each
each data
data block.
block.
•• Use
Use the
the CASCADE
CASCADE option
option to
to validate
validate the
the
structure
structure of
of all
all indexes
indexes on
on the
the table,
table, and
and
perform
perform cross-referencing
cross-referencing between
between thethe
table
table and
and its
its indexes.
indexes.

ANALYZE
ANALYZE TABLE
TABLE scott.employees
scott.employees
VALIDATE
VALIDATE STRUCTURE;
STRUCTURE;

1-230 Copyright  Oracle Corporation, 1998. All rights reserved.


Detecting Row Migration
•• The
The Oracle
Oracle server
server gathers
gathers statistics
statistics
based
based on
on sample
sample data
data and
and updates
updates data
data
dictionary.
dictionary.
ANALYZE
ANALYZE TABLE
TABLE scott.employees
scott.employees
ESTIMATE
ESTIMATE STATISTICS;
STATISTICS;
•• Check
Check CHAIN_CNT
CHAIN_CNT
SELECT
SELECT chain_cnt
chain_cnt
FROM
FROM DBA_TABLES
DBA_TABLES
WHERE
WHERE table_name=‘EMPLOYEES’
table_name=‘EMPLOYEES’
AND
AND owner=‘SCOTT’;
owner=‘SCOTT’;
1-231 Copyright  Oracle Corporation, 1998. All rights reserved.
Retrieving Table Information
DBA_OBJECTS DBA_TABLES

OWNER OWNER
OBJECT_NAME TABLE_NAME
OBJECT_ID PCT_FREE
DATA_OBJECT_ID PCT_USED
CREATED INITIAL_EXTENT
NEXT_EXTENT
DBA_SEGMENTS MIN_EXTENTS
MAX_EXTENTS
OWNER PCT_INCREASE
SEGMENT_NAME CACHE
TABLESPACE_NAME BLOCKS
HEADER_FILE EMPTY_BLOCKS
HEADER_BLOCK CHAIN_CNT
1-232 Copyright  Oracle Corporation, 1998. All rights reserved.
Retrieving Extent Information

DBA_EXTENTS
DBA_EXTENTS
•• OWNER
OWNER
•• SEGMENT_NAME
SEGMENT_NAME
•• EXTENT_ID
EXTENT_ID
•• FILE_ID
FILE_ID
•• BLOCK_ID
BLOCK_ID
•• BLOCKS
BLOCKS

1-233 Copyright  Oracle Corporation, 1998. All rights reserved.


DBMS_ROWID Package

Commonly
Commonly used
used functions:
functions:
Function Name Description

ROWID_CREATE Creates a ROWID from individual components

ROWID_OBJECT Returns the object identifier for a ROWID

ROWID_RELATIVE_FNO Returns the relative file number for a ROWID

ROWID_BLOCK_NUMBER Returns the block number for a ROWID

ROWID_ROW_NUMBER Returns the row number for a ROWID

ROWID_TO_ABSOLUTE_FNO Returns the absolute file number for a ROWID

ROWID_TO_EXTENDED Converts a ROWID from restricted to extended

ROWID_TO_RESTRICTED Converts a ROWID from extended to restricted

1-234 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Creating
Creating aa table
table with
with appropriate
appropriate
storage
storage and
and block
block utilization
utilization
parameters
parameters
•• Controlling
Controlling table
table storage
storage
•• Using
Using of
of DBMS_ROWID
DBMS_ROWID package
package

1-235 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Indexes

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Listing
Listing the
the different
different types
types of
of indexes
indexes
and
and their
their uses
uses
•• Creating
Creating B-tree
B-tree and
and Bitmap
Bitmap indexes
indexes
•• Reorganizing
Reorganizing indexes
indexes
•• Dropping
Dropping indexes
indexes
•• Getting
Getting index
index information
information from
from the
the data
data
dictionary
dictionary

1-237 Copyright  Oracle Corporation, 1998. All rights reserved.


Classification of Indexes

Logical
Logical
•• Single
Single column
column or
or concatenated
concatenated
•• Unique
Unique or
or nonunique
nonunique
Physical
Physical
•• Partitioned
Partitioned oror nonpartitioned
nonpartitioned
•• B-tree
B-tree or
or bitmap
bitmap
–– Normal
Normal or
or reverse
reverse key
key (B-tree
(B-tree only)
only)

1-238 Copyright  Oracle Corporation, 1998. All rights reserved.


B-Tree Index
Index entry

Root

Branch

Index entry header


Leaf Key column length
Key column value
ROWID

1-239 Copyright  Oracle Corporation, 1998. All rights reserved.


Reverse Key Index
Index on EMP (EMPNO) EMP table

KEY ROWID
EMPNO ENAME JOB ...
EMPNO (BLOCK# ROW# FILE#) ----- ----- --------
----- ------------------- 7499 ALLEN SALESMAN
1257 0000000F.0002.0001 7369 SMITH CLERK
2877 0000000F.0006.0001 7521 WARD SALESMAN ...
4567 0000000F.0004.0001 7566 JONES MANAGER
6657 0000000F.0003.0001 7654 MARTIN SALESMAN
8967 0000000F.0005.0001 7698 BLAKE MANAGER
9637 0000000F.0001.0001 7782 CLARK MANAGER
9947 0000000F.0000.0001 ... ... ... ...
... ... ... ... ... ...
... ...

1-240 Copyright  Oracle Corporation, 1998. All rights reserved.


Bitmap Index

Table File 3
Block 10

Block 11

Index Block 12

start end
key ROWID ROWID bitmap
<Blue, 10.0.3, 12.8.3, 1000100100010010100>
<Green, 10.0.3, 12.8.3, 0001010000100100000>
<Red, 10.0.3, 12.8.3, 0100000011000001001>
<Yellow, 10.0.3, 12.8.3, 0010001000001000010>
1-241 Copyright  Oracle Corporation, 1998. All rights reserved.
Comparing B-Tree and
Bitmap Indexes
B-tree Bitmap

Suitable for high-cardinality Suitable for low-cardinality


columns columns

Updates on keys relatively Updates to key columns very


inexpensive expensive

Inefficient for queries Efficient for queries


using OR predicates using OR predicates

Useful for OLTP Useful for DSS

1-242 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Normal B-Tree Indexes

CREATE
CREATE INDEX
INDEX scott.emp_lname_idx
scott.emp_lname_idx
ON
ON scott.employees(last_name)
scott.employees(last_name)
PCTFREE
PCTFREE 30
30
STORAGE(INITIAL
STORAGE(INITIAL 200K
200K NEXT
NEXT 200K
200K
PCTINCREASE
PCTINCREASE 00 MAXEXTENTS
MAXEXTENTS 50)
50)
TABLESPACE
TABLESPACE indx01;
indx01;

1-243 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Indexes: Guidelines

•• Balance
Balance query
query and
and DML
DML needs
needs
•• Place
Place in
in separate
separate tablespace
tablespace
•• Use
Use uniform
uniform extent
extent sizes:
sizes: multiples
multiples of
of
five
five blocks
blocks or
or MINIMUM
MINIMUM EXTENT
EXTENT size
size
for
for tablespace
tablespace
•• Consider
Consider NOLOGGING
NOLOGGING for for large
large indexes
indexes
•• Set
Set high
high PCTFREE
PCTFREE if if new
new key
key values
values are
are
likely
likely to
to be
be within
within the
the current
current range
range

1-244 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Reverse Key Indexes

CREATE
CREATE UNIQUE
UNIQUE INDEX
INDEX scott.ord_ord_no_idx
scott.ord_ord_no_idx
ON
ON scott.ord(ord_no)
scott.ord(ord_no) REVERSE
REVERSE
PCTFREE
PCTFREE 30
30
STORAGE(INITIAL
STORAGE(INITIAL 200K
200K NEXT
NEXT 200K
200K
PCTINCREASE
PCTINCREASE 00 MAXEXTENTS
MAXEXTENTS 50)
50)
TABLESPACE
TABLESPACE indx01;
indx01;

1-245 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Bitmap Indexes

CREATE
CREATE BITMAP
BITMAP INDEX
INDEX scott.ord_region_id_idx
scott.ord_region_id_idx
ON
ON scott.ord(region_id)
scott.ord(region_id)
PCTFREE
PCTFREE 30
30
STORAGE(INITIAL
STORAGE(INITIAL 200K
200K NEXT
NEXT 200K
200K
PCTINCREASE
PCTINCREASE 00 MAXEXTENTS
MAXEXTENTS 50)
50)
TABLESPACE
TABLESPACE indx01;
indx01;

1-246 Copyright  Oracle Corporation, 1998. All rights reserved.


Changing Storage Parameters
for Indexes

ALTER
ALTER INDEX
INDEX scott.emp_lname_idx
scott.emp_lname_idx
STORAGE(NEXT
STORAGE(NEXT 400K
400K
MAXEXTENTS
MAXEXTENTS 100);
100);

1-247 Copyright  Oracle Corporation, 1998. All rights reserved.


Allocating and Deallocating
Index Space

ALTER
ALTER INDEX
INDEX scott.ord_region_id_idx
scott.ord_region_id_idx
ALLOCATE
ALLOCATE EXTENT
EXTENT (SIZE
(SIZE 200K
200K
DATAFILE
DATAFILE ‘/DISK6/indx01.dbf’);
‘/DISK6/indx01.dbf’);

ALTER
ALTER INDEX
INDEX scott.ord_ord_no_idx
scott.ord_ord_no_idx
DEALLOCATE
DEALLOCATE UNUSED;
UNUSED;

1-248 Copyright  Oracle Corporation, 1998. All rights reserved.


Rebuilding Indexes
Use
Use this
this command
command to:to:
•• Move
Move an
an index
index to
to aa different
different tablespace
tablespace
•• Improve
Improve space
space utilization
utilization by
by removing
removing
deleted
deleted entries
entries
•• Change
Change aa reverse
reverse key
key index
index to
to aa normal
normal
B-tree
B-tree index
index and
and vice
vice versa
versa
ALTER
ALTER INDEX
INDEX scott.ord_region_id_idx
scott.ord_region_id_idx
REBUILD
REBUILD
TABLESPACE
TABLESPACE indx02;
indx02;
1-249 Copyright  Oracle Corporation, 1998. All rights reserved.
Checking Index Validity

ANALYZE
ANALYZE INDEX
INDEX scott.ord_region_id_idx
scott.ord_region_id_idx
VALIDATE
VALIDATE STRUCTURE;
STRUCTURE;

INDEX_STATS
1-250 Copyright  Oracle Corporation, 1998. All rights reserved.
Dropping Indexes

•• Drop
Drop and
and re-create
re-create an
an index
index before
before bulk
bulk
loads.
loads.
•• Drop
Drop indexes
indexes that
that are
are infrequently
infrequently
needed
needed and
and build
build them
them when
when necessary.
necessary.
•• Drop
Drop and
and recreate
recreate invalid
invalid indexes.
indexes.

DROP
DROP INDEX
INDEX scott.dept_dname_idx;
scott.dept_dname_idx;

1-251 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Index Information

DBA_INDEXES
DBA_INDEXES DBA_IND_COLUMNS
DBA_IND_COLUMNS
OWNER
OWNER INDEX_OWNER
INDEX_OWNER
INDEX_NAME
INDEX_NAME INDEX_NAME
INDEX_NAME
INDEX_TYPE
INDEX_TYPE TABLE_OWNER
TABLE_OWNER
TABLE_OWNER
TABLE_OWNER TABLE_NAME
TABLE_NAME
TABLE_NAME
TABLE_NAME COLUMN_NAME
COLUMN_NAME
UNIQUENESS
UNIQUENESS COLUMN_POSITION
COLUMN_POSITION
TABLESPACE_NAME
TABLESPACE_NAME COLUMN_LENGTH
COLUMN_LENGTH
LOGGING
LOGGING
STATUS
STATUS

1-252 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Creating
Creating different
different types
types of
of indexes
indexes
•• Reorganizing
Reorganizing indexes
indexes

1-253 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Maintaining Data Integrity

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Implementing
Implementing data
data integrity
integrity constraints
constraints
and
and triggers
triggers
•• Maintaining
Maintaining integrity
integrity constraints
constraints and
and
triggers
triggers
•• Obtaining
Obtaining constraint
constraint and
and trigger
trigger
information
information from
from the
the data
data dictionary
dictionary

1-255 Copyright  Oracle Corporation, 1998. All rights reserved.


Data Integrity
Database Integrity
trigger constraint
Data

Application
code

Table

1-256 Copyright  Oracle Corporation, 1998. All rights reserved. 256


Types of Constraints
Constraint Description
NOT NULL Specifies that a column cannot contain
null values
UNIQUE Designates a column or combination of
columns as unique
PRIMARY Designates a column or combination of
KEY columns as the table’s primary key

FOREIGN Designates a column or combination of


KEY columns as the foreign key in a
referential integrity constraint

CHECK Specifies a condition that each row of


the table must satisfy

1-257 Copyright  Oracle Corporation, 1998. All rights reserved.


Constraint States
Disabled
Disabled Enabled
Enabled Enabled
Enabled
novalidate
novalidate validate
validate

New data Existing data

1-258 Copyright  Oracle Corporation, 1998. All rights reserved.


Deferred Constraints

DML
DML statement
statement

Check
Check nondeferred
nondeferred
constraints
constraints

COMMIT
COMMIT

Check
Check deferred
deferred
constraints
constraints

1-259 Copyright  Oracle Corporation, 1998. All rights reserved.


Primary/Unique Key
Enforcement
Yes Is an index Yes
Key enabled? available
for use?

No No Use existing
index

Constraint Yes
deferrable?

No

Do not use Create Create nonunique


index unique index index

1-260 Copyright  Oracle Corporation, 1998. All rights reserved.


Foreign Key Considerations

To Perform
Drop parent table Cascade constraints
Truncate parent table Disable/drop foreign key
Drop tablespace Use CASCADE CONSTRAINTS
containing parent clause
table
Avoid locks on child Create index on foreign key
table while performing
DML on parent table
Perform DML on child Ensure tablespace containing
table parent key index online

1-261 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Triggers

DML action

Trigger

Table
Trigger
Trigger types
types
•• INSERT
INSERT or
or UPDATE
UPDATE or
or DELETE
DELETE
•• BEFORE
BEFORE or
or AFTER
AFTER
•• ROW
ROW or
or STATEMENT
STATEMENT
1-262 Copyright  Oracle Corporation, 1998. All rights reserved.
Defining Constraints While
Creating a Table
CREATE
CREATE TABLE
TABLE scott.employees(
scott.employees(
empno
empno NUMBER(4)
NUMBER(4)
CONSTRAINT
CONSTRAINT emp_pk
emp_pk PRIMARY
PRIMARY KEY
KEY
DEFERRABLE
DEFERRABLE
USING
USING INDEX
INDEX
STORAGE(INITIAL
STORAGE(INITIAL 100K
100K NEXT
NEXT 100K)
100K)
TABLESPACE
TABLESPACE indx01,
indx01,
last_name
last_name VARCHAR2(30)
VARCHAR2(30)
CONSTRAINT
CONSTRAINT emp_ln_nn
emp_ln_nn NOT
NOT NULL,
NULL,
deptno
deptno NUMBER(2))
NUMBER(2))
TABLESPACE
TABLESPACE data01;
data01;
1-263 Copyright  Oracle Corporation, 1998. All rights reserved.
Guidelines for
Defining Constraints
•• Primary
Primary and
and unique
unique constraints:
constraints:
–– Place
Place indexes
indexes in
in aa separate
separate
tablespace
tablespace
–– Use
Use nonunique
nonunique indexes
indexes if
if bulk
bulk loads
loads
are
are frequent
frequent
•• Self-referencing
Self-referencing foreign
foreign keys:
keys:
–– Define
Define or
or enable
enable foreign
foreign keys
keys after
after
initial
initial load
load
–– Defer
Defer constraint
constraint checking
checking
1-264 Copyright  Oracle Corporation, 1998. All rights reserved.
Disabling Constraints

•• Disable
Disable before
before bulk
bulk load,
load, especially
especially
self-referencing
self-referencing foreign
foreign keys.
keys.
•• Disable
Disable referencing
referencing foreign
foreign keys
keys before
before
disabling
disabling parent
parent keys.
keys.

ALTER
ALTER TABLE
TABLE scott.departments
scott.departments
DISABLE
DISABLE CONSTRAINT
CONSTRAINT dept_pk
dept_pk CASCADE;
CASCADE;

•• Unique
Unique indexes
indexes are
are dropped,
dropped, but
but
nonunique
nonunique indexes
indexes are
are retained.
retained.
1-265 Copyright  Oracle Corporation, 1998. All rights reserved.
Enabling Constraints

•• No
No locks
locks on
on table
table
Enable
NOVALIDATE •• Primary/unique
Primary/unique keys
keys
must
must use
use nonunique
nonunique
indexes
indexes

ALTER
ALTER TABLE
TABLE scott.departments
scott.departments
ENABLE
ENABLE NOVALIDATE
NOVALIDATE CONSTRAINT
CONSTRAINT dept_pk;
dept_pk;

1-266 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling Constraints

•• Locks
Locks table
table
Enable •• Can
Can use
use unique
unique or
or
VALIDATE nonunique
nonunique indexes
indexes
•• Needs
Needs valid
valid table
table
data
data
ALTER
ALTER TABLE
TABLE scott.employees
scott.employees
ENABLE
ENABLE VALIDATE
VALIDATE CONSTRAINT
CONSTRAINT emp_dept_fk;
emp_dept_fk;

1-267 Copyright  Oracle Corporation, 1998. All rights reserved.


Using the EXCEPTIONS Table

1.
1. Create
Create EXCEPTIONS
EXCEPTIONS table
table
(utlexcpt.sql).
(utlexcpt.sql).
2.
2. Execute
Execute ALTER
ALTER TABLE
TABLE with
with
EXCEPTIONS
EXCEPTIONS clause.
clause.
3.
3. Use
Use subquery
subquery on
on EXCEPTIONS
EXCEPTIONS to
to
locate
locate rows
rows with
with invalid
invalid data.
data.
4.
4. Rectify
Rectify the
the errors.
errors.
5.
5. Reexecute
Reexecute ALTER
ALTER TABLE
TABLE to
to enable
enable
the
the constraint.
constraint.
1-268 Copyright  Oracle Corporation, 1998. All rights reserved.
Disabling and Enabling Triggers

•• Use
Use ALTER
ALTER TRIGGER
TRIGGER to
to disable
disable or
or
enable
enable one
one trigger.
trigger.
ALTER
ALTER TRIGGER
TRIGGER scott.emp_conv_ln
scott.emp_conv_ln
DISABLE;
DISABLE;
•• Use
Use ALTER
ALTER TABLE
TABLE to
to disable
disable or
or enable
enable
all
all triggers.
triggers.
ALTER
ALTER TABLE
TABLE scott.employees
scott.employees
ENABLE
ENABLE ALL
ALL TRIGGERS;
TRIGGERS;

1-269 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Constraints

•• Drop
Drop constraints
constraints using
using this
this command:
command:

ALTER
ALTER TABLE
TABLE scott.employees
scott.employees
DROP
DROP CONSTRAINT
CONSTRAINT emp_ln_uk;
emp_ln_uk;

•• Drop
Drop aa table
table and
and any
any referencing
referencing
foreign
foreign key
key using
using this
this command:
command:
DROP
DROP TABLE
TABLE departments
departments
CASCADE
CASCADE CONSTRAINTS;
CONSTRAINTS;

1-270 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping Triggers

DROP
DROP TRIGGER
TRIGGER scott.audit_dept;
scott.audit_dept;

1-271 Copyright  Oracle Corporation, 1998. All rights reserved.


Getting Constraint Information
DBA_CONSTRAINTS DBA_CONS_COLUMNS
OWNER OWNER
CONSTRAINT_NAME CONSTRAINT_NAME
CONSTRAINT_TYPE TABLE_NAME
TABLE_NAME COLUMN_NAME
SEARCH_CONDITION POSITION
R_OWNER
R_CONSTRAINT_NAME
DELETE_RULE
STATUS
DEFERRABLE
DEFERRED
VALIDATED
GENERATED
BAD
LAST_CHANGE
1-272 Copyright  Oracle Corporation, 1998. All rights reserved.
Getting Information on Triggers

DBA_TRIGGERS DBA_TRIGGER_COLS
OWNER TRIGGER_OWNER
TRIGGER_NAME TRIGGER_NAME
TRIGGER_TYPE TABLE_OWNER
TRIGGERING_EVENT TABLE_NAME
TABLE_OWNER COLUMN_NAME
TABLE_NAME
STATUS DBA_OBJECTS
DESCRIPTION OWNER
TRIGGER_BODY OBJECT_NAME
OBJECT_TYPE
STATUS

1-273 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Implementing
Implementing constraints
constraints and
and triggers
triggers
•• Using
Using appropriate
appropriate strategy
strategy for
for creating
creating
and
and maintaining
maintaining constraints
constraints

1-274 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Using Clusters and
Index-Organized Tables

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Creating
Creating and
and maintaining
maintaining clusters
clusters
•• Using
Using index-organized
index-organized tables
tables
•• Retrieving
Retrieving information
information about
about clusters
clusters
and
and tables
tables from
from the
the data
data dictionary
dictionary

1-276 Copyright  Oracle Corporation, 1998. All rights reserved.


Distribution of Rows Within a
Table

Table Cluster Index-organized


table

Ordering of Rows

Random Grouped Ordered

1-277 Copyright  Oracle Corporation, 1998. All rights reserved.


Clusters
ORD_NO PROD QTY ... Cluster Key
----- ------ ------ (ORD_NO)
101 A4102 20 101 ORD_DT CUST_CD
102 A2091 11 05-JAN-97 R01
102 G7830 20 PROD QTY
102 N9587 26 A4102 20
101 A5675 19 A5675 19
101 W0824 10 W0824 10
102 ORD_DT CUST_CD
07-JAN-97 N45
PROD QTY
ORD_NO ORD_DT CUST_CD A2091 11
------ ------ ------ G7830 20
101 05-JAN-97 R01 N9587 26
102 07-JAN-97 N45

Unclustered ORD Clustered ORD


and ITEM tables and ITEM tables
1-278 Copyright  Oracle Corporation, 1998. All rights reserved.
Cluster Types
Index cluster Hash cluster

Hash function

1-279 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Index Clusters
11.. Create
Create aa cluster.
cluster.
CREATE
CREATE CLUSTER
CLUSTER scott.ord_clu
scott.ord_clu
(ord_no
(ord_no NUMBER(3))
NUMBER(3))
SIZE
SIZE 200
200 TABLESPACE
TABLESPACE DATA01
DATA01
STORAGE(INITIAL
STORAGE(INITIAL 5M
5M NEXT
NEXT 5M
5M PCTINCREASE
PCTINCREASE 0);
0);

22.. Create
Create aa cluster
cluster index.
index.
CREATE
CREATE INDEX
INDEX scott.ord_clu_idx
scott.ord_clu_idx
ON
ON CLUSTER
CLUSTER scott.ord_clu
scott.ord_clu
TABLESPACE
TABLESPACE INDX01
INDX01
STORAGE(INITIAL
STORAGE(INITIAL 1M
1M NEXT
NEXT 1M
1M PCTINCREASE
PCTINCREASE 0);
0);
1-280 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating Index Clusters
33.. Create
Create tables
tables in
in the
the cluster.
cluster.
CREATE
CREATE TABLE
TABLE scott.ord
scott.ord
(ord_no
(ord_no NUMBER(3)
NUMBER(3)
CONSTRAINT
CONSTRAINT ord_pk
ord_pk PRIMARY
PRIMARY KEY,
KEY,
ord_dt
ord_dt DATE,
DATE, cust_cd
cust_cd VARCHAR2(3))
VARCHAR2(3))
CLUSTER
CLUSTER scott.ord_clu(ord_no);
scott.ord_clu(ord_no);
CREATE
CREATE TABLE
TABLE scott.item
scott.item
(ord_no
(ord_no NUMBER(3)
NUMBER(3) CONSTRAINT
CONSTRAINT item_ord_fk
item_ord_fk
REFERENCES
REFERENCES scott.ord,
scott.ord,
prod
prod VARCHAR2(5),
VARCHAR2(5), qty
qty NUMBER(3),
NUMBER(3),
CONSTRAINT
CONSTRAINT item_pk
item_pk PRIMARY
PRIMARY KEY(ord_no,prod))
KEY(ord_no,prod))
CLUSTER
CLUSTER scott.ord_clu(ord_no);
scott.ord_clu(ord_no);
1-281 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating Hash Clusters
11.. Create
Create aa cluster.
cluster.
CREATE
CREATE CLUSTER
CLUSTER scott.off_clu
scott.off_clu
(country
(country VARCHAR2(2),postcode
VARCHAR2(2),postcode VARCHAR2(8))
VARCHAR2(8))

SIZE
SIZE 500
500 HASHKEYS
HASHKEYS 1000
1000
TABLESPACE
TABLESPACE DATA01
DATA01
STORAGE(INITIAL
STORAGE(INITIAL 5M
5M NEXT
NEXT 5M
5M PCTINCREASE
PCTINCREASE 0);
0);
2 . Create tables in a cluster.
2 . Create tables in a cluster.
CREATE
CREATE TABLE
TABLE scott.office(
scott.office(
office_cd
office_cd NUMBER(3),
NUMBER(3), cost_ctr
cost_ctr NUMBER(3),
NUMBER(3),
country
country VARCHAR2(2),
VARCHAR2(2), postcode
postcode VARCHAR2(8))
VARCHAR2(8))

1-282CLUSTER
CLUSTER scott.off_clu(country,postcode);
scott.off_clu(country,postcode);
Copyright  Oracle Corporation, 1998. All rights reserved.
Defining SIZE for Clusters

•• Defines
Defines space
space used
used by
by all
all the
the rows
rows for
for aa
given
given key.
key.
•• Used
Used in in both
both types
types of
of cluster
cluster toto
estimate:
estimate:
–– The
The maximum
maximum number
number of of key
key values
values
per
per block
block for
for an
an index
index cluster
cluster
–– The
The exact
exact number
number of of key
key values
values per
per
block
block for
for aa hash
hash cluster
cluster

1-283 Copyright  Oracle Corporation, 1998. All rights reserved.


Parameters Specific to
Hash Clusters
•• HASHKEYS:
HASHKEYS: Number
Number of
of key
key values
values
•• HASH
HASH IS:
IS: Optional
Optional user-defined
user-defined hash
hash
function
function

Key 21
Key 12
Key 11

Key 1 Key 2 Key 3 Key 22

Overflow block
Preallocated blocks
1-284 Copyright  Oracle Corporation, 1998. All rights reserved.
Altering Clusters
Change
 Change storage
storage and
and block
block space
space usage
usage
parameters
parameters
Change
 Change SIZE
SIZE for
for index
index clusters
clusters
Allocate
 Allocate and
and deallocate
deallocate space
space

ALTER
ALTER CLUSTER
CLUSTER scott.ord_clu
scott.ord_clu
SIZE
SIZE 300
300 STORAGE
STORAGE (NEXT
(NEXT 2M);
2M);

 SIZE,
SIZE, HASH
HASH IS,
IS, or
or HASHKEYS
HASHKEYS cannot
cannot be
be
altered
altered for
for hash
hash clusters
clusters
1-285 Copyright  Oracle Corporation, 1998. All rights reserved.
Dropping Clusters
Use
Use INCLUDING
INCLUDING TABLES
TABLES to
to drop
drop tables
tables
and
and cluster
cluster
DROP
DROP CLUSTER
CLUSTER scott.ord_clu
scott.ord_clu
INCLUDING
INCLUDING TABLES;
TABLES;
or
or drop
drop tables
tables before
before dropping
dropping cluster.
cluster.
DROP
DROP TABLE
TABLE scott.ord;
scott.ord;
DROP
DROP TABLE
TABLE scott.item;
scott.item;
DROP
DROP CLUSTER
CLUSTER scott.ord_clu;
scott.ord_clu;

1-286 Copyright  Oracle Corporation, 1998. All rights reserved.


Situations Where Clusters
Are Useful

Criterion Index Hash

Uniform key distribution

Evenly spread key values

Rarely updated key

Often joined master-detail tables

Predictable number of key values

Queries using equality predicate on key

1-287 Copyright  Oracle Corporation, 1998. All rights reserved.


Retrieving Cluster Information
DBA_CLUSTERS DBA_TAB_COLUMNS
OWNER OWNER
CLUSTER_NAME TABLE_NAME
TABLESPACE_NAME COLUMN_NAME
KEY_SIZE DATA_TYPE
CLUSTER_TYPE DATA_LENGTH
FUNCTION DATA_PRECISION
HASHKEYS DATA_SCALE

DBA_CLU_COLUMNS DBA_CLUSTER_
OWNER HASH_EXPRESSIONS
CLUSTER_NAME OWNER
CLU_COLUMN_NAME CLUSTER_NAME
TABLE_NAME HASH_EXPRESSION
TAB_COLUMN_NAME
1-288 Copyright  Oracle Corporation, 1998. All rights reserved.
Index-Organized Tables
Indexed access Accessing index-
on table organized table

ROWID

Non-key columns
Key column
Row header
1-289 Copyright  Oracle Corporation, 1998. All rights reserved.
Index-Organized Tables
Compared with Regular Tables
Regular Table Index-Organized Table
Unique identifier—ROWID Identified by primary key

ROWID implicit No ROWID


Supports several indexes No secondary indexes

FTS returns rows in no specific Full index scans return


order rows in PK order

Unique constraints allowed No support for


unique constraints

Distribution, replication, and Distribution, replication, and


partitioning supported partitioning not supported
1-290 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating Index-Organized Tables

CREATE
CREATE TABLE
TABLE scott.sales
scott.sales
(( office_cd
office_cd NUMBER(3),
NUMBER(3),
qtr_end
qtr_end DATE,
DATE,
revenue
revenue NUMBER(10,2),
NUMBER(10,2),
review
review VARCHAR2(1000),
VARCHAR2(1000),
CONSTRAINT
CONSTRAINT sales_pk
sales_pk
PRIMARY
PRIMARY KEY(office_code,
KEY(office_code, qtr_end))
qtr_end))
ORGANIZATION
ORGANIZATION INDEX
INDEX TABLESPACE
TABLESPACE data01
data01
PCTTHRESHOLD
PCTTHRESHOLD 20
20
OVERFLOW
OVERFLOW TABLESPACE
TABLESPACE data02;
data02;
1-291 Copyright  Oracle Corporation, 1998. All rights reserved.
Row Overflow
IOT tablespace Overflow tablespace
Segment = PK Name Segment = SYS_IOT_OVER_n
Type = Index Type=Table

Row bigger than


Block PCTTHRESHOLD

Rows within PCTTHRESHOLD


1-292 Copyright  Oracle Corporation, 1998. All rights reserved.
Retrieving IOT Information from
Data Dictionary

DBA_TABLES DBA_INDEXES
OWNER OWNER
TABLE_NAME TABLE_NAME
IOT_TYPE INDEX_NAME
IOT_NAME INDEX_TYPE
TABLESPACE_NAME PCT_THRESHOLD
INCLUDE_COLUMN

1-293 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Identifying
Identifying situations
situations where
where clusters
clusters are
are

useful
useful
• Using
Using index-organized
index-organized tables
tables

1-294 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Loading and Reorganizing Data

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

• Loading
Loading data
data using
using direct-load
direct-load insert
insert
• Loading
Loading data
data into
into Oracle
Oracle tables
tables using
using
SQL*Loader
SQL*Loader conventional
conventional and
and direct
direct
paths
paths
• Reorganizing
Reorganizing data
data using
using export
export and
and
import
import

1-296 Copyright  Oracle Corporation, 1998. All rights reserved.


Overview
Other
applications

Oracle
database
Export
SQL*Loader

Import

Oracle
database
Direct-load insert

1-297 Copyright  Oracle Corporation, 1998. All rights reserved.


Using Direct-Load Inserts

INSERT
INSERT /*+APPEND
/*+APPEND */
*/ INTO
INTO scott.emp
scott.emp
NOLOGGING
NOLOGGING
SELECT
SELECT ** FROM
FROM scott.old_emp;
scott.old_emp;
Server
process

EMP table

Used block High water mark

Free space after delete Blocks used by inserted rows

1-298 Copyright  Oracle Corporation, 1998. All rights reserved.


Parallel Direct-Load Insert
ALTER
ALTER SESSION
SESSION ENABLE
ENABLE PARALLEL
PARALLEL DML;
DML;
INSERT
INSERT /*+PARALLEL(scott.emp,2)
/*+PARALLEL(scott.emp,2) */
*/
INTO
INTO scott.emp
scott.emp NOLOGGING
NOLOGGING
SELECT
SELECT ** FROM
FROM scott.old_emp;
scott.old_emp;
Slave Slave
process process

EMP table

Used block High water mark

Free space after delete Temporary segments

1-299 Copyright  Oracle Corporation, 1998. All rights reserved.


SQL*Loader
Control file Data files

Parameter file
SQL*Loader Rejected
(optional)
Field processing

Discarded Accepted
Record selection
Bad
Selected file

Discard file Oracle server


(optional) Rejected
Inserted
Log file

Database files

1-300 Copyright  Oracle Corporation, 1998. All rights reserved.


Conventional and Direct Loads
Instance
SGA Shared pool

Array
insert Extent
management
Conventional

Data Direct
Table path
save

High water
Space used only by conventional load mark

1-301 Copyright  Oracle Corporation, 1998. All rights reserved.


Comparing Direct and
Conventional Path Loads
Conventional Load Direct Path Load
Uses COMMITs to make Uses data saves
changes permanent
Redo log entries always Generates redo only under
generated specific conditions
Enforces all constraints Enforces only primary key,
unique, and NOT NULL
INSERT triggers fire INSERT triggers do not fire
Can load into clustered Cannot load into
tables clustered tables
Other users can make Other users cannot
changes to tables make changes to tables

1-302 Copyright  Oracle Corporation, 1998. All rights reserved.


Parallel Direct Loads
Temporary segments

load1.dat SQL*Loader
load1.ctl

load2.dat SQL*Loader
load2.ctl

SQL*Loader
load3.dat
load3.ctl

Table

High water
mark

1-303 Copyright  Oracle Corporation, 1998. All rights reserved.


Using SQL*Loader

$sqlldr
$sqlldr scott/tiger
scott/tiger \\
>> control=ulcase6.ctl
control=ulcase6.ctl \\
>> log=ulcase6.log
log=ulcase6.log direct=true
direct=true
ulcase6.ctl

SQL*Loader

EMP table
ulcase6.log

1-304 Copyright  Oracle Corporation, 1998. All rights reserved.


SQL*Loader: Input Files
• Parameter file • Data file
– Load options – Input records
• Control file
LOAD DATA
INFILE 'ulcase6.dat’
INSERT
INTO TABLE emp
(empno POSITION(01:04) INTEGER
EXTERNAL NULLIF empno=BLANKS,
...

)
1-305 Copyright  Oracle Corporation, 1998. All rights reserved.
Log File Contents
• Header information
• Global information: parameters and file
names
• Table information: table and column
specifications
• Data file information: records processed
• Table load information: errors and
discards
• Summary statistics

1-306 Copyright  Oracle Corporation, 1998. All rights reserved.


SQL*Loader: Other Output Files
•• Bad
Bad file
file
–– Rejected
Rejected records
records
–– Same
Same format
format as
as data
data files
files
•• Discard
Discard file
file
–– Records
Records not
not satisfying
satisfying conditions
conditions
–– Same
Same format
format as
as data
data files
files

1-307 Copyright  Oracle Corporation, 1998. All rights reserved.


SQL*Loader: Usage Guidelines

•• Use
Use aa parameter
parameter file
file to
to specify
specify
commonly
commonly used
used command
command lineline options
options
•• Place
Place data
data within
within the
the control
control file
file only
only for
for
aa small,
small, one-time
one-time load
load
•• Improve
Improve performance
performance by: by:
–– Allocating
Allocating sufficient
sufficient space
space
–– Sorting
Sorting the
the data
data on
on the
the largest
largest index
index
–– For
For parallel
parallel loads,
loads, specify
specify different
different
files
files for
for temporary
temporary segments
segments
1-308 Copyright  Oracle Corporation, 1998. All rights reserved.
SQL*Loader: Troubleshooting
•• Insufficient
Insufficient space
space for
for table
table or
or index
index
•• Instance
Instance failure
failure during
during the
the load
load
•• If
If the
the SORTED
SORTED INDEXES INDEXES clause clause is is used
used
and
and data
data is
is notnot in in the
the order order specified specified
•• Duplicate
Duplicate keyskeys found found in in aa unique unique index,
index,
unique
unique or or primary
primary key key duringduring aa direct direct
load
load
•• BINDSIZE
BINDSIZE for for conventional
conventional load load cannot
cannot
fit
fit one
one row
row
•• Errors
Errors oror discards
discards exceed exceed specified specified
1-309
limit
limit Copyright  Oracle Corporation, 1998. All rights reserved.
Moving Data Using EXP/IMP
Export

O/S file
Data files

Import

1-310 Copyright  Oracle Corporation, 1998. All rights reserved.


Uses of Export and Import
•• Reorganize
Reorganize tables
tables
•• Move
Move data
data owned
owned by by one
one user
user to
to
another
another user
user
•• Move
Move data
data between
between databases:
databases:
–– Development
Development to to production
production
–– OLTP
OLTP system
system to to aa data
data warehouse
warehouse
•• Migrate
Migrate toto aa different
different platform
platform or
or
release
release of
of Oracle
Oracle
•• Repeat
Repeat test
test runs
runs during
during development
development or
or
upgrade
upgrade
•• Perform
Perform aa logical
logical backup
backup
1-311 Copyright  Oracle Corporation, 1998. All rights reserved.
Export Modes
Table User Database

• Table • All objects • All objects in


• Indexes owned by the database
user, except (except
• Triggers indexes and objects
• Constraints triggers on owned by
tables owned SYS)
• Grants by other
• Analyze users
method
1-312 Copyright  Oracle Corporation, 1998. All rights reserved.
Conventional/Direct Path Export
Dump Export
Export
file

Evaluating SQL command


buffer processing

Private buffer Buffer cache


or buffer cache management
Read database
block

Direct
Conventional
1-313 Copyright  Oracle Corporation, 1998. All rights reserved.
Using Export

$exp
$exp scott/tiger
scott/tiger tables=(dept,emp)
tables=(dept,emp) \\
>> file=emp.dmp
file=emp.dmp log=exp.log
log=exp.log compress=n
compress=n \\
>> direct=y
direct=y recordlength=32768
recordlength=32768

emp.dmp

Export
Export

DEPT,EMP exp.log
tables
1-314 Copyright  Oracle Corporation, 1998. All rights reserved.
Using Import

$imp
$imp scott/tiger
scott/tiger tables=(dept,emp)
tables=(dept,emp) \\
>> file=emp.dmp
file=emp.dmp log=imp.log
log=imp.log ignore=y
ignore=y

imp.log

emp.dmp Import
Import

1-315 Copyright  Oracle Corporation, 1998. All rights reserved.


Import Behavior

•• Order
Order of
of Import
Import
–– Table
Table Data
Data B-tree
B-tree Indexes
Indexes
Constraints,
Constraints, Triggers,
Triggers, Bitmap
Bitmap indexes
indexes
•• Tablespace
Tablespace used
used for
for the
the object
object
–– Same
Same tablespace
tablespace as
as in
in the
the source
source
database,
database, if
if possible
possible
–– User’s
User’s default
default tablespace
tablespace

1-316 Copyright  Oracle Corporation, 1998. All rights reserved.


Guidelines on the Usage of
Export and Import
•• Use
Use aa parameter
parameter file
file to
to specify
specify
commonly
commonly used used command
command line line options.
options.
•• Use
Use CONSISTENT=Y
CONSISTENT=Y only only if
if exporting
exporting aa
small
small volume
volume ofof data.
data.
•• Do
Do not
not use
use COMPRESS=Y
COMPRESS=Y if if there
there are
are
many
many deleted
deleted rows.
rows.
•• Improve
Improve performance
performance by: by:
–– Allocating
Allocating large
large buffer
buffer size
size
–– Using
Using direct
direct path
path ifif using
using only
only 7.3.3
7.3.3 or
or
higher
higher
1-317 Copyright  Oracle Corporation, 1998. All rights reserved.
NLS Considerations in Export
and Import
Export client
Export
Export character set

Database
character set Import
Import

Import client
character set
Possible character set conversion
1-318 Copyright  Oracle Corporation, 1998. All rights reserved.
Summary

•• Using
Using Direct-Load
Direct-Load insert
insert to
to copy
copy tables
tables
•• Using
Using SQL*Loader
SQL*Loader to to migrate
migrate from
from
other
other applications
applications
•• Using
Using Export
Export and
and Import
Import utilities
utilities to
to
reorganize
reorganize data
data

1-319 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Users

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Creating
Creating new
new database
database users
users
•• Altering
Altering and
and dropping
dropping existing
existing database
database
users
users
•• Monitoring
Monitoring information
information about
about existing
existing
users
users

1-321 Copyright  Oracle Corporation, 1998. All rights reserved.


Users and Security

Account Default
locking tablespace

Authentication Temporary
mechanism tablespace
Security
domain
Role Tablespace
privileges quotas

Direct Resource
privileges limits

1-322 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Schema
Tables
- Triggers
- Constraints
Indexes
Views
Sequences
Stored program units
Synonyms
User-defined data types
Database links
1-323 Copyright  Oracle Corporation, 1998. All rights reserved.
Checklist for Creating Users
1.
1. Choose
Choose aa username
username and
and
authentication
authentication mechanism.
mechanism.
2.
2. Identify
Identify tablespaces
tablespaces inin which
which the
the
user
user needs
needs toto store
store objects.
objects.
3.
3. Decide
Decide on
on quotas
quotas for
for each
each
tablespace.
tablespace.
4.
4. Assign
Assign default
default tablespace
tablespace and
and
temporary
temporary tablespace.
tablespace.
5.
5. Create
Create aa user.
user.
6.
6. Grant
Grant privileges
privileges and
and roles
roles to
to the
the
user.
user.
1-324 Copyright  Oracle Corporation, 1998. All rights reserved.
Creating a New User:
Server Authentication
Set
Set the
the initial
initial password:
password:

CREATE
CREATE USER
USER peter
peter
IDENTIFIED
IDENTIFIED BY
BY my1stson
my1stson
DEFAULT
DEFAULT TABLESPACE
TABLESPACE data01
data01
TEMPORARY
TEMPORARY TABLESPACE
TABLESPACE temp
temp
QUOTA
QUOTA 15m
15m ON
ON data01
data01
PASSWORD
PASSWORD EXPIRE;
EXPIRE;

1-325 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating a New User: Operating
System Authentication
Use
Use OS_AUTHENT_PREFIX
OS_AUTHENT_PREFIX
Example:
Example: O/S
O/S User
User == user15
user15
OS_AUTHENT_ Database Remote Login
PREFIX User Possible

OS_ OS_USER15
No

empty string USER15


““ No

OPS$ OPS$USER15
(default) (default) Yes

1-326 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating a New
User: Guidelines
•• Choose
Choose aa standard
standard password
password initially;
initially;
use
use O/S
O/S authentication
authentication sparingly.
sparingly.
•• Use
Use the
the EXPIRE
EXPIRE keyword
keyword to
to force
force users
users
to
to reset
reset their
their passwords.
passwords.
•• Always
Always assign
assign temporary
temporary tablespace.
tablespace.
•• Restrict
Restrict quotas
quotas to
to few
few users;
users;
use
use QUOTA
QUOTA UNLIMITED
UNLIMITED with
with caution.
caution.
•• Educate
Educate users:
users:
–– To
To connect
connect
–– To
To change
change password
password
1-327 Copyright  Oracle Corporation, 1998. All rights reserved.
Controlling Account Lock
and Password

ALTER
ALTER USER
USER peter
peter
IDENTIFIED
IDENTIFIED BY
BY hisgrandpa
hisgrandpa
PASSWORD
PASSWORD EXPIRE;
EXPIRE;

1-328 Copyright  Oracle Corporation, 1998. All rights reserved.


Changing User Quota on
Tablespace

ALTER
ALTER USER
USER peter
peter
QUOTA
QUOTA 00 ON
ON data01;
data01;

1-329 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping a User

DROP
DROP USER
USER peter;
peter;

Use
Use the
the CASCADE
CASCADE clause
clause if
if the
the
schema
schema contains
contains objects.
objects.

DROP
DROP USER
USER peter
peter CASCADE;
CASCADE;

1-330 Copyright  Oracle Corporation, 1998. All rights reserved.


Monitoring Users

DBA_USERS
DBA_USERS DBA_TS_QUOTAS
DBA_TS_QUOTAS

USERNAME
USERNAME USERNAME
USERNAME
USER_ID
USER_ID TABLESPACE_NAME
TABLESPACE_NAME
CREATED
CREATED BYTES
BYTES
ACCOUNT_STATUS
ACCOUNT_STATUS MAX_BYTES
MAX_BYTES
LOCK_DATE
LOCK_DATE BLOCKS
BLOCKS
EXPIRY_DATE
EXPIRY_DATE MAX_BLOCKS
MAX_BLOCKS
DEFAULT_TABLESPACE
DEFAULT_TABLESPACE
TEMPORARY_TABLESPACE
TEMPORARY_TABLESPACE

1-331 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Creating
Creating users
users specifying
specifying the
the
appropriate
appropriate password
password mechanism
mechanism
•• Controlling
Controlling usage
usage of
of space
space by
by users
users

1-332 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Profiles

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Creating
Creating and
and assigning
assigning profiles
profiles to
to users
users
•• Controlling
Controlling use
use of
of resources
resources with
with
profiles
profiles
•• Altering
Altering and
and dropping
dropping profiles
profiles
•• Administering
Administering passwords
passwords using
using profiles
profiles
•• Obtaining
Obtaining information
information about
about profiles,
profiles,
assigned
assigned limits,
limits, and
and password
password
management
management

1-334 Copyright  Oracle Corporation, 1998. All rights reserved.


Profiles
•• Are
Are named
named sets
sets of
of resource
resource and
and
password
password limits
limits
•• Are
Are assigned
assigned to
to users
users by
by Tablespace Default
the
the CREATE/ALTER
CREATE/ALTER USER USER quotas tablespace

command
command Authentication Temporary
mechanism tablespace
•• Can
Can be
be enabled
enabled or
or disabled
disabled Security
domain
Role Account
•• Can
Can relate
relate to
to the
the DEFAULT
DEFAULT privileges locking

profile
profile Direct Resource
privileges limits
•• Can
Can limit
limit system
system resources
resources on
on
session
session or
or call
call level
level
1-335 Copyright  Oracle Corporation, 1998. All rights reserved.
Managing Resources
with Profiles

1.
1. Create
Create profiles.
profiles.
2.
2. Assign
Assign profiles
profiles to
to the
the user.
user.
3.
3. Enable
Enable resource
resource limits.
limits.

1-336 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating a Profile:
Resource Limit
CREATE
CREATE PROFILE
PROFILE developer_prof
developer_prof LIMIT
LIMIT
SESSIONS_PER_USER
SESSIONS_PER_USER 22
CPU_PER_SESSION
CPU_PER_SESSION 10000
10000
IDLE_TIME
IDLE_TIME 60
60
CONNECT_TIME
CONNECT_TIME 480;
480;

1-337 Copyright  Oracle Corporation, 1998. All rights reserved.


Setting Resource Limits
at Session Level
Resource Description
CPU_PER_SESSION Total CPU time measured in
hundredths of seconds
SESSIONS_PER_USER Number of concurrent sessions
allowed for each username
CONNECT_TIME Elapsed connect time measured
in minutes
IDLE_TIME Periods of inactive time
measured in minutes
LOGICAL_READS_PER Number of data blocks (physical
_SESSION and logical reads)
PRIVATE_SGA Private space in the SGA
measured in bytes (for MTS
only)

1-338 Copyright  Oracle Corporation, 1998. All rights reserved.


Setting Resources at Call Level

Resource Description

CPU_PER_CALL CPU time per call in hundredths


of seconds

LOGICAL_READS_PER Number of data blocks


_CALL

1-339 Copyright  Oracle Corporation, 1998. All rights reserved.


Assigning Profiles to a User
CREATE
CREATE USER
USER user3
user3 IDENTIFIED
IDENTIFIED BY
BY user3
user3
DEFAULT
DEFAULT TABLESPACE
TABLESPACE data01
data01
TEMPORARY
TEMPORARY TABLESPACE
TABLESPACE temp
temp
QUOTA
QUOTA unlimited
unlimited ON
ON data01
data01
PROFILE
PROFILE developer_prof;
developer_prof;

ALTER
ALTER USER
USER scott
scott
PROFILE
PROFILE developer_prof;
developer_prof;

1-340 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling Resource Limits

•• Set
Set the
the initialization
initialization parameter
parameter
RESOURCE_LIMIT
RESOURCE_LIMIT to to TRUE
TRUE
or
or
•• Enforce
Enforce the
the resource
resource limits
limits by
by enabling
enabling
the
the parameter
parameter with
with the
the ALTER
ALTER SYSTEM
SYSTEM
command
command
ALTER
ALTER SYSTEM
SYSTEM SET
SET RESOURCE_LIMIT=TRUE;
RESOURCE_LIMIT=TRUE;

1-341 Copyright  Oracle Corporation, 1998. All rights reserved.


Altering a Profile

ALTER
ALTER PROFILE
PROFILE default
default LIMIT
LIMIT
SESSIONS_PER_USER
SESSIONS_PER_USER 55
CPU_PER_CALL
CPU_PER_CALL 3600
3600
IDLE_TIME
IDLE_TIME 30;
30;

1-342 Copyright  Oracle Corporation, 1998. All rights reserved.


Dropping a Profile

DROP
DROP PROFILE
PROFILE developer_prof;
developer_prof;

DROP
DROP PROFILE
PROFILE developer_prof
developer_prof
CASCADE;
CASCADE;

1-343 Copyright  Oracle Corporation, 1998. All rights reserved.


Viewing Resource Limits

DBA_USERS DBA_PROFILES
- profile - profile
- username - resource_name
- resource_type
(KERNEL)
- limit

1-344 Copyright  Oracle Corporation, 1998. All rights reserved.


Password Management

Password Account
history locking

User Setting up
profiles

Password Password
expiration verification
and aging

1-345 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling Password Management

•• Set
Set up
up password
password management
management by by using
using
profiles
profiles and
and assigning
assigning them
them to
to users.
users.
•• Lock,
Lock, unlock,
unlock, and
and expire
expire accounts
accounts using
using
the
the CREATE
CREATE USER USER or or ALTER
ALTER USER
USER
command.
command.
•• Password
Password limits
limits are
are always
always enforced,
enforced,
even
even if
if RESOURCE_LIMIT
RESOURCE_LIMIT for for an
an
instance
instance isis set
set to
to FALSE.
FALSE.

1-346 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating a Profile:
Password Settings

CREATE
CREATE PROFILE
PROFILE grace_5
grace_5 LIMIT
LIMIT
FAILED_LOGIN_ATTEMPTS
FAILED_LOGIN_ATTEMPTS 33
PASSWORD_LIFE_TIME
PASSWORD_LIFE_TIME 30
30
PASSWORD_REUSE_TIME
PASSWORD_REUSE_TIME 30
30
PASSWORD_VERIFY_FUNCTION
PASSWORD_VERIFY_FUNCTION verify_function
verify_function
PASSWORD_GRACE_TIME
PASSWORD_GRACE_TIME 5;
5;

1-347 Copyright  Oracle Corporation, 1998. All rights reserved.


Password Settings
Parameter Description

FAILED_LOGIN_ATTEMPTS Number of failed login attempts


before lockout of the account

PASSWORD_LOCK_TIME Number of days for which the


account remains locked upon
password expiration
Lifetime of the password in days
PASSWORD_LIFE_TIME
after which the password expires
Grace period in days for changing
PASSWORD_GRACE_TIME the password after the first
successful login after the password
has expired

1-348 Copyright  Oracle Corporation, 1998. All rights reserved.


Password Settings
Parameter Description

PASSWORD_REUSE_TIME Number of days before a password can


be reused
Maximum number of times a password
PASSWORD_REUSE_MAX
can be reused

PASSWORD_VERIFY_FUNCTION PL/SQL function that makes a


password complexity check before a
password is assigned

1-349 Copyright  Oracle Corporation, 1998. All rights reserved.


User-Provided Password
Function
Function
Function must
must be
be created
created in
in the
the SYS
SYS
schema
schema and
and must
must have
have the
the following
following
specification:
specification:

function_name(
function_name(
userid_parameter
userid_parameter IN
IN VARCHAR2(30),
VARCHAR2(30),
password_parameter
password_parameter IN
IN VARCHAR2(30),
VARCHAR2(30),
old_password_parameter
old_password_parameter IN
IN VARCHAR2(30))
VARCHAR2(30))
RETURN
RETURN BOOLEAN
BOOLEAN

1-350 Copyright  Oracle Corporation, 1998. All rights reserved.


Password Verification Function
VERIFY_FUNCTION
•• Minimum
Minimum length
length is
is four
four characters
characters
•• Password
Password should
should not
not be
be equal
equal to
to
username
username
•• Password
Password should
should have
have at
at least
least one
one
alpha,
alpha, one
one numeric,
numeric, and
and one
one special
special
character
character
•• Password
Password should
should differ
differ from
from the
the
previous
previous password
password byby at
at least
least
three
three letters
letters Password
verification
1-351 Copyright  Oracle Corporation, 1998. All rights reserved.
Viewing Password Information
•• DBA_USERS
DBA_USERS
–– profile
profile
–– username
username
–– account_status
account_status
–– lock_date
lock_date
–– expiry_date
expiry_date
•• DBA_PROFILES
DBA_PROFILES
–– profile
profile
–– resource_name
resource_name
–– resource_type
resource_type (PASSWORD)
(PASSWORD)
–– limit
limit

1-352 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Controlling
Controlling resource
resource usage
usage
• Administering
Administering passwords
passwords

1-353 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Privileges

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives

•• Identifying
Identifying system
system and
and object
object privileges
privileges
•• Granting
Granting and
and revoking
revoking privileges
privileges
•• Controlling
Controlling operating
operating system
system or
or
password
password file
file authentication
authentication

1-355 Copyright  Oracle Corporation, 1998. All rights reserved.


Managing Privileges

Two
Two types
types ofof privileges:
privileges:
• SYSTEM:
SYSTEM: enables
enables users
users to
to perform
perform
particular
particular actions
actions in
in the
the database
database
• OBJECT:
OBJECT: enables
enables users
users to
to access
access and
and
manipulate
manipulate aa specific
specific object
object

1-356 Copyright  Oracle Corporation, 1998. All rights reserved.


System Privileges
•• There
There are
are about
about 8080 system
system privileges.
privileges.
•• The
The ANY-keyword
ANY-keyword in in the
the privileges
privileges
signifies
signifies that
that users
users have
have the
the privilege
privilege in
in
every
every schema.
schema.
•• The
The GRANT
GRANT command
command addsadds aa privilege
privilege
to
to aa user
user or
or aa group
group of
of users.
users.
•• The
The REVOKE
REVOKE command
command deletes
deletes the
the
privileges.
privileges.

1-357 Copyright  Oracle Corporation, 1998. All rights reserved.


System Privileges: Examples
Category Examples 
INDEX CREATE ANY INDEX
ALTER ANY INDEX
DROP ANY INDEX 
TABLE CREATE TABLE
CREATE ANY TABLE
ALTER ANY TABLE
DROP ANY TABLE
SELECT ANY TABLE
UPDATE ANY TABLE
DELETE ANY TABLE
SESSION CREATE SESSION
ALTER SESSION
RESTRICTED SESSION
TABLESPACE CREATE TABLESPACE
ALTER TABLESPACE
DROP TABLESPACE
UNLIMITED TABLESPACE
1-358 Copyright  Oracle Corporation, 1998. All rights reserved.
Granting System Privileges

GRANT
GRANT CREATE
CREATE SESSION,
SESSION, CREATE
CREATE TABLE
TABLE
TO
TO user1;
user1;

GRANT
GRANT CREATE
CREATE SESSION
SESSION TO
TO scott
scott
WITH
WITH ADMIN
ADMIN OPTION;
OPTION;

1-359 Copyright  Oracle Corporation, 1998. All rights reserved.


SYSDBA and SYSOPER
Privileges

Category Examples 


SYSOPER STARTUP
SHUTDOWN
ALTER DATABASE OPEN | MOUNT
ALTER DATABASE BACKUP CONTROLFILE
ALTER TABLESPACE BEGIN/END BACKUP
RECOVER DATABASE,
ALTER DATABASE ARCHIVELOG
RESTRICTED SESSION

SYSDBA SYSOPER privileges WITH ADMIN OPTION
CREATE DATABASE
RECOVER DATABASE UNTIL

1-360 Copyright  Oracle Corporation, 1998. All rights reserved.


Password File Authentication
11.. Create
Create the
the password
password file
file and
and set
set the
the
REMOTE_LOGIN_PASSWORDFILE
REMOTE_LOGIN_PASSWORDFILE
parameter.
parameter.
22.. Set
Set REMOTE_LOGIN_
REMOTE_LOGIN_
PASSWORD_FILE=EXCLUSIVE.
PASSWORD_FILE=EXCLUSIVE.
33.. Grant
Grant SYSOPER
SYSOPER andand SYSDBA
SYSDBA
privileges
privileges to
to users.
users.
44.. Query
Query V$PWFILE_USERS
V$PWFILE_USERS to to verify
verify the
the
password
password file
file members.
members.

1-361 Copyright  Oracle Corporation, 1998. All rights reserved.


Displaying System Privileges

Database Level Session Level


DBA_SYS_PRIVS SESSION_PRIVS
• GRANTEE • PRIVILEGE
• PRIVILEGE
• ADMIN OPTION

1-362 Copyright  Oracle Corporation, 1998. All rights reserved.


System Privilege Restrictions

O7_DICTIONARY_ACCESSIBILITY
O7_DICTIONARY_ACCESSIBILITY ==
TRUE
TRUE
•• Reverts
Reverts to
to Oracle7
Oracle7 behavior
behavior
•• Removes
Removes thethe restrictions
restrictions on
on system
system
privileges
privileges with
with the
the ANY
ANY keyword
keyword
•• Defaults
Defaults to
to TRUE
TRUE

1-363 Copyright  Oracle Corporation, 1998. All rights reserved.


Revoking System Privileges

REVOKE
REVOKE CREATE
CREATE TABLE
TABLE FROM
FROM user1;
user1;

REVOKE
REVOKE CREATE
CREATE SESSION
SESSION FROM
FROM scott;
scott;

1-364 Copyright  Oracle Corporation, 1998. All rights reserved.


Revoking System Privileges
Using WITH ADMIN OPTION
DBA
DBA USER
USER 11 SCOTT
SCOTT

GRANT

REVOKE DBA
DBA USER
USER 11 SCOTT
SCOTT

1-365 Copyright  Oracle Corporation, 1998. All rights reserved.


Revoking System Privileges
Using WITH ADMIN OPTION
RESULT
DBA
DBA USER
USER 11 SCOTT
SCOTT

1-366 Copyright  Oracle Corporation, 1998. All rights reserved.


Object Privileges
Object priv. Table View Sequence Procedure
ALTER 
DELETE 
EXECUTE 
INDEX 
INSERT 
REFERENCES 
SELECT 
UPDATE 

1-367 Copyright  Oracle Corporation, 1998. All rights reserved.


Granting Object Privileges

GRANT
GRANT EXECUTE
EXECUTE ON
ON dbms_pipe
dbms_pipe TO
TO
public;
public;

GRANT
GRANT UPDATE(ename,sal)
UPDATE(ename,sal) ON
ON emp
emp
TO
TO user1
user1 WITH
WITH GRANT
GRANT OPTION;
OPTION;

1-368 Copyright  Oracle Corporation, 1998. All rights reserved.


Displaying Object Privileges

DBA_TAB_PRIVS DBA_COL_PRIVS

GRANTEE GRANTEE
OWNER OWNER
TABLE_NAME TABLE_NAME
GRANTOR COLUMN_NAME
PRIVILEGE GRANTOR
GRANTABLE PRIVILEGE
GRANTABLE

1-369 Copyright  Oracle Corporation, 1998. All rights reserved.


Revoking Object Privileges

REVOKE
REVOKE execute
execute ON
ON dbms_pipe
dbms_pipe
FROM
FROM scott;
scott;

1-370 Copyright  Oracle Corporation, 1998. All rights reserved.


Revoking Object Privileges
Using WITH GRANT OPTION
SCOTT
SCOTT USER
USER 11 USER
USER 22

GRANT

REVOKE SCOTT
SCOTT USER
USER 11 USER
USER 22

1-371 Copyright  Oracle Corporation, 1998. All rights reserved.


Revoking Object Privileges
Using WITH GRANT OPTION

RESULT
SCOTT
SCOTT USER
USER 11 USER
USER 22

1-372 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

Controlling
Controlling system
system and
and object
object privileges
privileges

1-373 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Managing Roles

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
•• Creating
Creating and
and modifying
modifying roles
roles
•• Controlling
Controlling availability
availability of
of roles
roles
•• Removing
Removing roles
roles
•• Using
Using predefined
predefined roles
roles
•• Displaying
Displaying role
role information
information from
from the
the
data
data dictionary
dictionary

1-375 Copyright  Oracle Corporation, 1998. All rights reserved.


Roles

Users A C
B

Roles HR_MGR HR_CLERK

Privileges SELECT INSERT


ON EMP ON EMP

CREATE CREATE UPDATE


TABLE SESSION ON EMP

1-376 Copyright  Oracle Corporation, 1998. All rights reserved.


Benefits of Roles

• Reduced
Reduced granting
granting of
of privileges
privileges
• Dynamic
Dynamic privilege
privilege management
management
• Selective
Selective availability
availability of
of privileges
privileges
• Granted
Granted through
through the
the OS
OS
• No
No cascading
cascading revokes
revokes
• Improved
Improved performance
performance

1-377 Copyright  Oracle Corporation, 1998. All rights reserved.


Creating Roles

CREATE
CREATE ROLE
ROLE sales_clerk;
sales_clerk;

CREATE
CREATE ROLE
ROLE hr_clerk
hr_clerk
IDENTIFIED
IDENTIFIED BY
BY bonus;
bonus;

CREATE
CREATE ROLE
ROLE hr_manager
hr_manager
IDENTIFIED
IDENTIFIED EXTERNALLY;
EXTERNALLY;

1-378 Copyright  Oracle Corporation, 1998. All rights reserved.


Using Predefined Roles
Role Name Description
CONNECT These two roles are provided
RESOURCE for backward compatibility.
DBA All system privileges WITH
ADMIN OPTION
EXP_FULL_DATABASE Privileges to export the DB
IMP_FULL_DATABASE Privileges to import the DB
DELETE_CATALOG_ROLE DELETE privileges on
DD tables
EXECUTE_CATALOG_ROLE EXECUTE privilege on
DD packages
SELECT_CATALOG_ROLE SELECT privilege on DD tables

1-379 Copyright  Oracle Corporation, 1998. All rights reserved.


Modifying Roles
ALTER
ALTER ROLE
ROLE sales_clerk
sales_clerk
IDENTIFIED
IDENTIFIED BY
BY commission;
commission;

ALTER
ALTER ROLE
ROLE hr_clerk
hr_clerk
IDENTIFIED
IDENTIFIED EXTERNALLY;
EXTERNALLY;

ALTER
ALTER ROLE
ROLE hr_manager
hr_manager
NOT
NOT IDENTIFIED;
IDENTIFIED;

1-380 Copyright  Oracle Corporation, 1998. All rights reserved.


Assigning Roles

GRANT
GRANT sales_clerk
sales_clerk TO
TO scott;
scott;

GRANT
GRANT hr_clerk,
hr_clerk,
TO
TO hr_manager;
hr_manager;

GRANT
GRANT hr_manager
hr_manager TO
TO scott
scott
WITH
WITH ADMIN
ADMIN OPTION;
OPTION;

1-381 Copyright  Oracle Corporation, 1998. All rights reserved.


Establishing Default Roles
ALTER
ALTER USER
USER scott
scott
DEFAULT
DEFAULT ROLE
ROLE hr_clerk,
hr_clerk, sales_clerk;
sales_clerk;

ALTER
ALTER USER
USER scott
scott DEFAULT
DEFAULT ROLE
ROLE ALL;
ALL;

ALTER
ALTER USER
USER scott
scott DEFAULT
DEFAULT ROLE
ROLE ALL
ALL
EXCEPT
EXCEPT hr_clerk;
hr_clerk;

ALTER
ALTER USER
USER scott
scott DEFAULT
DEFAULT ROLE
ROLE NONE;
NONE;

1-382 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling and Disabling Roles

•• Disable
Disable aa role
role to
to temporarily
temporarily revoke
revoke the
the
role
role from
from aa user.
user.
•• Enable
Enable aa role
role to
to temporarily
temporarily grant
grant it.
it.
•• The
The SET
SET ROLE
ROLE command
command enables
enables and
and
disables
disables roles.
roles.
•• Default
Default roles
roles are
are enabled
enabled for
for aa user
user at
at
login.
login.
•• A
A password
password maymay be
be required
required to
to enable
enable aa
role.
role.
1-383 Copyright  Oracle Corporation, 1998. All rights reserved.
Enabling and Disabling Roles:
Examples
SET
SET ROLE
ROLE sales_clerk
sales_clerk
IDENTIFIED
IDENTIFIED BY
BY commission;
commission;

SET
SET ROLE
ROLE hr_clerk;
hr_clerk;

SET
SET ROLE
ROLE ALL
ALL EXCEPT
EXCEPT
sales_clerk;
sales_clerk;

SET
SET ROLE
ROLE NONE;
NONE;

1-384 Copyright  Oracle Corporation, 1998. All rights reserved.


Removing Roles from Users

REVOKE
REVOKE sales_clerk
sales_clerk FROM
FROM scott;
scott;

REVOKE
REVOKE hr_manager
hr_manager FROM
FROM PUBLIC;
PUBLIC;

1-385 Copyright  Oracle Corporation, 1998. All rights reserved.


Removing Roles

DROP
DROP ROLE
ROLE hr_manager;
hr_manager;

1-386 Copyright  Oracle Corporation, 1998. All rights reserved.


Guidelines for Creating Roles
Users

User
roles HR_CLERK HR_MANAGER PAY_CLERK

Application
roles BENEFITS PAYROLL

Application
privileges
Benefits privileges Payroll privileges

1-387 Copyright  Oracle Corporation, 1998. All rights reserved.


Guidelines for using Passwords
and Default Roles

Password protected Default role


non-default

PAY_CLERK PAY_CLERK_RO

Insert, update, delete Select privileges


and select privileges
1-388 Copyright  Oracle Corporation, 1998. All rights reserved.
Displaying Role Information
Role View Description
DBA_ROLES All roles which exist in the database
DBA_ROLE_PRIVS Roles granted to users and roles
ROLE_ROLE_PRIVS Roles which are granted to roles
DBA_SYS_PRIVS System privileges granted to users
and roles
ROLE_SYS_PRIVS System privileges granted to roles
ROLE_TAB_PRIVS Table privileges granted to roles
SESSION_ROLES Roles which the user currently has
enabled.

1-389 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

• Creating
Creating roles
roles
• Assigning
Assigning privileges
privileges toto roles
roles
• Assigning
Assigning roles
roles to
to users
users oror roles
roles
• Establishing
Establishing default
default roles
roles

1-390 Copyright  Oracle Corporation, 1998. All rights reserved.


1
Auditing

Copyright  Oracle Corporation, 1998. All rights reserved.


Session Objectives

•• Differentiating
Differentiating between
between database
database
auditing
auditing and
and value-based
value-based auditing
auditing
•• Using
Using database
database auditing
auditing
•• Viewing
Viewing enabled
enabled auditing
auditing options
options
•• Retrieving
Retrieving and
and maintaining
maintaining
auditing
auditing information
information

1-392 Copyright  Oracle Corporation, 1998. All rights reserved.


Auditing Categories
•• Auditing
Auditing privileged
privileged operations
operations
–– Always
Always audited
audited
–– Startup,
Startup, shutdown,
shutdown, and
and SYSDBA
SYSDBA connections
connections
•• Database
Database auditing
auditing
–– Enabled
Enabled by
by DBA
DBA
–– Cannot
Cannot record
record column
column values
values
•• Value-based
Value-based or
or application
application auditing
auditing
–– Implemented
Implemented through
through code
code
–– Can
Can record
record column
column values
values
–– Used
Used to
to track
track changes
changes to
to tables
tables
1-393 Copyright  Oracle Corporation, 1998. All rights reserved.
Value-Based Auditing:
An Example
CREATE
CREATE TRIGGER
TRIGGER scott.audit_employee
scott.audit_employee
AFTER
AFTER INSERT
INSERT OROR DELETE
DELETE OR
OR UPDATE
UPDATE
ON
ON scott.emp
scott.emp
FOR
FOR EACH
EACH ROW
ROW
BEGIN
BEGIN
INSERT
INSERT INTO
INTO scott.audit_employee
scott.audit_employee
VALUES
VALUES (( :OLD.empno,
:OLD.empno, :OLD.name,…,
:OLD.name,…,
:NEW.empno,
:NEW.empno, :NEW.name,…,
:NEW.name,…,
USER,
USER, SYSDATE);
SYSDATE);
END;
END;

1-394 Copyright  Oracle Corporation, 1998. All rights reserved.


Database Auditing
Enable DB auditing Execute command

DBA Parameter file User


Server
Specify process
audit options

Review audit Generate


information audit trail

Audit options

Audit trail Other tables


Database

1-395 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling Database Auditing

AUDIT_TRAIL Parameter
file
DBA

DB Instance NONE
AUD$
table

OS audit OS
OS No trail
trail

1-396 Copyright  Oracle Corporation, 1998. All rights reserved.


Enabling Auditing Options
•• Statement
Statement auditing
auditing
AUDIT
AUDIT user;
user;
•• Privilege
Privilege auditing
auditing
AUDIT
AUDIT select
select any
any table
table
BY
BY scott
scott BY
BY ACCESS;
ACCESS;
•• Schema
Schema object
object auditing
auditing
AUDIT
AUDIT LOCK
LOCK ON
ON scott.emp
scott.emp
BY
BY ACCESS
ACCESS WHENEVER
WHENEVER SUCCESSFUL;
SUCCESSFUL;

1-397 Copyright  Oracle Corporation, 1998. All rights reserved.


Auditing Schema Objects
Object Stored
Table View Seq- Pro- Snap-
Option uence gram shot
ALTER X X X
AUDIT X X X X X
COMMENT X X X
DELETE X X X
EXECUTE X
GRANT X X X X X
INDEX X X
INSERT X X X
LOCK X X X
READ
RENAME X X X
SELECT X X X X X
UPDATE X X X
1-398 Copyright  Oracle Corporation, 1998. All rights reserved.
Viewing Auditing Options

Data Dictionary View Description

ALL_DEF_AUDIT_OPTS Default audit options

DBA_STMT_AUDIT_OPTS Statement auditing options

DBA_PRIV_AUDIT_OPTS Privilege auditing options

DBA_OBJ_AUDIT_OPTS Schema object auditing


options

1-399 Copyright  Oracle Corporation, 1998. All rights reserved.


Disabling Auditing Options

NOAUDIT
NOAUDIT user
user WHENEVER
WHENEVER SUCCESSFUL;
SUCCESSFUL;

NOAUDIT
NOAUDIT create
create table
table BY
BY scott;
scott;

NOAUDIT
NOAUDIT LOCK
LOCK ON
ON emp;
emp;

1-400 Copyright  Oracle Corporation, 1998. All rights reserved.


The Audit Trail
•• Stores
Stores the
the records
records generated
generated by by statement,
statement,
privilege,
privilege, and
and object
object auditing
auditing
•• The
The audit
audit records
records are
are stored
stored inin the
the SYS.AUD$
SYS.AUD$
data
data dictionary
dictionary table
table or
or in
in the
the OS
OS audit
audit trail
trail
•• Each
Each record
record in
in the
the audit
audit trail
trail includes:
includes:
–– The
The user
user who
who executed
executed the
the statement
statement
–– The
The command
command issued
issued (action
(action code)
code)
–– Any
Any system
system or
or object
object privilege
privilege used
used
–– The
The objects
objects referenced
referenced in
in the
the statement
statement
–– The
The date
date and
and time
time the
the statement
statement was
was issued
issued

1-401 Copyright  Oracle Corporation, 1998. All rights reserved.


Viewing Auditing Results
Audit Trail View Description

DBA_AUDIT_TRAIL All audit trail entries

DBA_AUDIT_EXISTS Records for AUDIT EXISTS/NOT


EXISTS

DBA_AUDIT_OBJECT Records concerning schema


objects

DBA_AUDIT_SESSION All connect and disconnect entries

DBA_AUDIT_STATEMENT Statement auditing records

1-402 Copyright  Oracle Corporation, 1998. All rights reserved.


Auditing Guidelines
•• Focus
Focus auditing
auditing
–– Object
Object auditing,
auditing, where
where possible
possible
–– Only
Only specific
specific users
users
–– By
By session
session
–– Successful
Successful or
or unsuccessful
unsuccessful
•• Maintain
Maintain the
the audit
audit trail
trail
–– Monitor
Monitor the
the growth
growth of of the
the audit
audit trail
trail
–– Protect
Protect the
the audit
audit trail
trail from
from unauthorized
unauthorized
access
access
–– Cleaning
Cleaning OS
OS audit
audit files
files

1-403 Copyright  Oracle Corporation, 1998. All rights reserved.


Summary

•• Differentiating
Differentiating between
between database
database
auditing
auditing and
and value-based
value-based auditing
auditing
•• Maintaining
Maintaining the
the audit
audit trail
trail

1-404 Copyright  Oracle Corporation, 1998. All rights reserved.


22
1
Using National Language
Support

Copyright  Oracle Corporation, 1998. All rights reserved.


Objectives
•• Choosing
Choosing character
character setset and
and national
national
character
character set
set for
for aa database
database
•• Specifying
Specifying the
the language-dependent
language-dependent
behavior
behavior using
using initialization
initialization parameters,
parameters,
environment
environment variables
variables and
and the
the ALTER
ALTER
SESSION
SESSION command
command
•• Using
Using the
the different
different types
types of
of NLS
NLS
parameters
parameters
•• Explaining
Explaining the
the influence
influence onon language-
language-
dependent
dependent application
application behavior
behavior
•• Obtaining
Obtaining information
information about
about NLS
NLS usage
usage
1-406 Copyright  Oracle Corporation, 1998. All rights reserved.
NLS Features
• Language
Language support
support
• Territory
Territory support
support
• Character
Character setset support
support
• Linguistic
Linguistic sorting
sorting
• Message
Message support
support
• Date
Date and
and time
time formats
formats
• Numeric
Numeric formats
formats
• Monetary
Monetary formats
formats
Database
1-407 Copyright  Oracle Corporation, 1998. All rights reserved.
Different Types of
Encoding Schemes
Oracle
Oracle supports
supports different
different classes
classes of
of
character
character encoding
encoding schemes:
schemes:
-- Single-byte
Single-byte character
character sets
sets
-- 7-bit
7-bit
-- 8-bit
8-bit
-- Varying-width
Varying-width multibyte
multibyte character
character set
set
-- Fixed-width
Fixed-width multibyte
multibyte character
character set
set
-- Unicode
Unicode (UTF8,
(UTF8, AL24UTFFSS)
AL24UTFFSS)

1-408 Copyright  Oracle Corporation, 1998. All rights reserved.


Character Sets and National
Character Sets of a Database
Database Character Sets National Character Sets

Defined at creation time Defined at creation time


Cannot be changed without Cannot be changed without
re-creation re-creation
Store data columns of type Store data columns of type
CHAR, VARCHAR2, CLOB, NCHAR, NVARCHAR2 and
LONG NCLOB
Can store varying-width Can store fixed-width and
character sets varying-width multibyte
character sets

1-409 Copyright  Oracle Corporation, 1998. All rights reserved.


Guidelines

• Choose
Choose aa closely
closely related
related database
database
character
character set
set and
and national
national character
character set.
set.
• String
String operations
operations might
might be
be faster
faster with
with
fixed-width
fixed-width character
character sets.
sets.
• Variable-width
Variable-width character
character sets
sets use
use space
space
more
more efficiently.
efficiently.

1-410 Copyright  Oracle Corporation, 1998. All rights reserved.


Specifying Language-Dependent
Behavior

Initialization parameter
Environment variable

ALTER SESSION
command

1-411 Copyright  Oracle Corporation, 1998. All rights reserved.


Specifying Language-Dependent
Behavior for the Server
• NLS_LANGUAGE
NLS_LANGUAGE specifies:
specifies:
-- The
The language
language for
for messages
messages
-- Day
Day and
and month
month names
names
-- Symbols
Symbols for
for A.D,
A.D, B.C,
B.C, A.M,
A.M, P.M.
P.M.
-- The
The default
default sorting
sorting mechanism
mechanism
• NLS_TERRITORY
NLS_TERRITORY specifies:
specifies:
-- Day
Day and
and week
week numbering
numbering
-- Default
Default date
date format,
format, decimal
decimal character,
character,
group
group separator,
separator, and
and the
the default
default ISO
ISO
and
and local
local currency
currency symbols
symbols
1-412 Copyright  Oracle Corporation, 1998. All rights reserved.
Dependent Language and
Territory Default Values

PARAMETER VALUES

NLS_LANGUAGE AMERICAN
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY

NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_DATE_FORMAT DD-MON-YY
NLS_NUMERIC_CHARACTERS ,.

1-413 Copyright  Oracle Corporation, 1998. All rights reserved.


Specifying Language-Dependent
Behavior for the Session
• Environment
Environment variable:
variable:
–– NLS_LANG=<language>_<territory>.<charset>
NLS_LANG=<language>_<territory>.<charset>
• Additional
Additional environment
environment variables:
variables:
–– NLS_DATE_FORMAT
NLS_DATE_FORMAT
–– NLS_DATE_LANGUAGE
NLS_DATE_LANGUAGE
–– NLS_SORT
NLS_SORT
–– NLS_NUMERIC_CHARACTERS
NLS_NUMERIC_CHARACTERS
–– NLS_CURRENCY
NLS_CURRENCY
–– NLS_ISO_CURRENCY
NLS_ISO_CURRENCY
–– NLS_CALENDAR
NLS_CALENDAR
1-414 Copyright  Oracle Corporation, 1998. All rights reserved.
Character Sets in
Client-Server Architecture

NLS_LANG=<language>_<territory>.<charset>
NLS_LANG=<language>_<territory>.<charset>
NLS_NCHAR=<ncharset>
NLS_NCHAR=<ncharset>

CREATE
CREATE DATABASE
DATABASE ...
...
CHARACTER
CHARACTER SET
SET <charset>
<charset>
NATIONAL
NATIONAL CHARACTER
CHARACTER SET
SET
<ncharset>
<ncharset>
...
...

1-415 Copyright  Oracle Corporation, 1998. All rights reserved.


Specifying Language-Dependent
Behavior for the Session

ALTER
ALTER SESSION
SESSION SET
SET
NLS_DATE_FORMAT=‘DD.MM.YYYY’;
NLS_DATE_FORMAT=‘DD.MM.YYYY’;

DBMS_SESSION.SET_NLS(‘NLS_DATE_FORMAT’,
DBMS_SESSION.SET_NLS(‘NLS_DATE_FORMAT’,
’’’DD.MM.YYYY’’’)
’’’DD.MM.YYYY’’’) ;;

1-416 Copyright  Oracle Corporation, 1998. All rights reserved.


Sorting
• Oracle
Oracle provides
provides aa linguistic
linguistic sort.
sort.
• NLS_SORT
NLS_SORT specifies
specifies types
types of
of sort.
sort.
• The
The NLSSORT
NLSSORT function
function reflects
reflects
linguistic
linguistic comparison.
comparison.

ALTER
ALTER SESSION
SESSION SET
SET NLS_SORT=GERMAN;
NLS_SORT=GERMAN;
SELECT
SELECT letter
letter FROM
FROM letters
letters ORDER
ORDER BY
BY letter;
letter;
LETTER
LETTER

------
------

ää

1-417 Copyright  Oracle Corporation, 1998. All rights reserved.


Using NLS Parameters
in SQL-Functions

SELECT
SELECT TO_CHAR(hiredate,’DD.MON.YYYY’,
TO_CHAR(hiredate,’DD.MON.YYYY’,
‘NLS_DATE_LANGUAGE=GERMAN’)
‘NLS_DATE_LANGUAGE=GERMAN’) FROM
FROM emp;
emp;

SELECT
SELECT ename,
ename, TO_CHAR(sal,’9G999D99’,
TO_CHAR(sal,’9G999D99’,
‘NLS_NUMERIC_CHARACTERS=‘‘,.’’’)
‘NLS_NUMERIC_CHARACTERS=‘‘,.’’’)
FROM
FROM emp;
emp;

1-418 Copyright  Oracle Corporation, 1998. All rights reserved.


Import and Loading Data
Using NLS
• Data
Data will
will be
be converted
converted from
from NLS_LANG
NLS_LANG

to
to the
the database
database character
character set
set during
during the
the
IMPORT
IMPORT
• LOADER:
LOADER:
–– Conventional:
Conventional: data
data is
is converted
converted into
into
the
the session
session character
character set
set specified
specified by
by
NLS_LANG
NLS_LANG
–– DIRECT:
DIRECT: data
data is
is converted
converted directly
directly
into
into the
the database
database character
character set
set
1-419 Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Information
About Character Sets

NLS_DATABASE_PARAM
NLS_DATABASE_PARAM ETERS
ETERS
–– PARAMETER
PARAMETER
(NLS_CHARACTERSET,
(NLS_CHARACTERSET,
NLS_NCHAR_CHARACTERSET)
NLS_NCHAR_CHARACTERSET)
–– VALUE
VALUE

1-420 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information
About NLS Settings
• NLS_INSTANCE_PARAM
NLS_INSTANCE_PARAM ETERS
ETERS
–– PARAMETER
PARAMETER (( NLS-initialization
NLS-initialization parameters
parameters
that
that have
have been
been explicitly
explicitly set)
set)
–– VALUE
VALUE
• NLS_SESSION_PARAMETERS
NLS_SESSION_PARAMETERS
–– PARAMETER
PARAMETER (( NLS-session
NLS-session parameters)
parameters)
–– VALUE
VALUE

1-421 Copyright  Oracle Corporation, 1998. All rights reserved.


Obtaining Information About
NLS Settings
• V$NLS_VALID_VALUES
V$NLS_VALID_VALUES
–– PARAMETER
PARAMETER
(LANGUAGE,
(LANGUAGE, SORT,
SORT, TERRITORY,
TERRITORY,
CHARACTERSET)
CHARACTERSET)
–– VALUE
VALUE
• V$NLS_PARAM
V$NLS_PARAM ETERS
ETERS
–– PARAMETER
PARAMETER (NLS-session
(NLS-session
parameters,
parameters, NLS_CHARACTERSET)
NLS_CHARACTERSET)
–– VALUE
VALUE
1-422 Copyright  Oracle Corporation, 1998. All rights reserved.
Summary

•• Choosing
Choosing aa database
database character
character setset and
and
aa national
national character
character setset for
for the
the database
database
•• Using
Using the
the different
different types
types ofof NLS
NLS
parameters
parameters for
for the
the server,
server, for
for the
the
session,
session, and
and of
of the
the session
session

1-423 Copyright  Oracle Corporation, 1998. All rights reserved.

You might also like