Professional Documents
Culture Documents
Oracle Architecture
Oracle Architecture
Oracle Architectural
Components
•• 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
Server Users
1-3 Copyright Oracle Corporation, 1998. All rights reserved.
Connecting to a Database
Server
Client
Client process Server
Server
Use
Use
rr
•• 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
•• 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
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
Database
Parameter
file
Password Archived
file log files
Database
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
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
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
Redo log
buffer
LGWR
Server Database
Redo log
buffer
process buffer
4 cache
LGWR
3
2
User
process Control
files
Data files Redo log
files
Database
Server
process
PGA
User
DBWR LGWR
process
Parameter Control
file files
Archived
log files
Data files Redo log
Password files
file
Database
•• 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
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
SHOW
SHOW SPOOL
SPOOL
Oracle
Integrated Integrated
system customer
3rd party
management
applications
applications applications Agent
Agent
Repository
Managed
systems
2
3
4
5
6
•• Repository
Repository
•• Service
Service Discovery
Discovery
•• Security
Security
•• 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
3
2
User Server
process process
PGA
ALERT Control
file files
Parameter
file
Data files Redo log
Password files
file
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
No N
o Use a
password file
• 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.
Library
cache
Database
Redo log Data
buffer
buffer dictionary
cache
cache
initU15.ora
SVRMGR>
SVRMGR> CONNECT
CONNECT // AS
AS SYSDBA
SYSDBA
SVRMGR>
SVRMGR> STARTUP
STARTUP PFILE=/DISK1/initU15.ora
PFILE=/DISK1/initU15.ora
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
STARTUP
STARTUP PFILE=/DISK1/initU15.ora
PFILE=/DISK1/initU15.ora
Shutdown Mode A I T N
Shutdown mode:
A Abort I Immediate NO
T Transactional N Normal YES
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$
MOUNT
Dynamic
performance
views reading
NOMOUNT data from disk
Dynamic
performance
views reading
SHUTDOWN from memory
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%’;
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;
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’;
ALTER
ALTER SYSTEM
SYSTEM KILL
KILL SESSION
SESSION ‘7,15’;
‘7,15’;
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
•• 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
•• Preparing
Preparing the
the operating
operating system
system
•• Preparing
Preparing the
the parameter
parameter file
file
•• Creating
Creating the
the database
database
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
•• 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
... ...
• 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.
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.
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
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
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.
## 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.
•• 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
Base tables:
- Normalized
- Created with the sql.bsq script
DBA_xxx
objects of the entire database
ALL_xxx
objects can be accessed by the user
USER_xxx
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
PLUS>execute
PLUS>execute dbms_session.set_role(..)
dbms_session.set_role(..)
SVRMGR>execute
SVRMGR>execute dbms_session.set_role(..)
dbms_session.set_role(..)
•• 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
Package Procedure A
specification declaration
Procedure B
Package definition
body
Procedure A
definition
Local
variable
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
• 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
•• 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
Control
files
Redo log
Data files
files
Database
Database
Database name
Data file location
Redo log file location
Tablespace names
Current log sequence number
Checkpoint information
Log history
Backup information
Disk 1 Disk 2
control01.con control02.con
Control
files
Database
Member
Member Member
Disk 2
Database
Redo log
buffer
buffer
cache
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
101
50 51 100
t1 t2
Archived
Backup redo logs
Disk failure
50
Data files Control
files
50 51 99 101
100
t1 t2
•• 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#
V$LOG:
• GROUP#
• MEMBERS
• STATUS
• SEQUENCE#
• BYTES
•• 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
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
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;
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.
ALTER
ALTER DATABASE
DATABASE DROP
DROP LOGFILE
LOGFILE
GROUP
GROUP 3;
3;
log1a.rdo log3a.rdo
log2a.rdo
log3b.rdo
log1b.rdo
log2b.rdo
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
Example
ALTER
ALTER DATABASE
DATABASE CLEAR
CLEAR LOGFILE
LOGFILE
‘/DISK3/log2a.rdo’;
‘/DISK3/log2a.rdo’;
Member
Member
•• 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.
• Controlling
Controlling log
log switches
switches and
and
checkpoints
checkpoints
• Administering
Administering online
online redo
redo log
log files
files
•• 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
Control
files
Redo log
Data files files
Database
Database
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
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);
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
• 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
app04.dbf
app01.dbf app02.dbf app03.dbf
2M
1M 1M 2M
Tablespace APP_DATA
app01.dbf app02.dbf
1M 1M
1M
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);
• 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;
• 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.
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
V$DATAFILE V$TABLESPACE
- TS# - TS#
- NAME - NAME
- FILE#
- RFILE#
- STATUS
- ENABLED
- BYTES
- CREATE_BYTES
• Understanding
Understanding the
the logical
logical database
database
structure
structure
• Administering
Administering tablespaces
tablespaces
Extent
Oracle
O/S block
block
1-153 Copyright Oracle Corporation, 1998. All rights reserved.
Types of Segments
Table Table
partition
Cluster Index
Index-organized
Index
table
partition
Rollback
Temporary
segment
segment
LOB
LOB index
segment
Oracle default
Tablespace
Segment
Data file
Before
ALTER
ALTER TABLESPACE
TABLESPACE data01
data01 COALESCE;
COALESCE;
After
•• 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
Header
Free space
Data
INITRANS
MAXTRANS
PCTFREE
PCTUSED
1 2
80%
Inserts Inserts
40%
3 4
1-164 Copyright Oracle Corporation, 1998. All rights reserved.
Data Dictionary Views
Tablespaces
DBA_TABLESPACES
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
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
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
•• 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
New
Table image
Rollback
segment
Update
transaction
1-173 Copyright Oracle Corporation, 1998. All rights reserved.
Rollback Segments: Purpose
Transaction
rollback
•• SYSTEM
SYSTEM
•• Non-SYSTEM
Non-SYSTEM
–– Private
Private
–– Public
Public
1 2
Transaction 1 Transaction 2
4 3
1 2
1 2
4 3 5 3
4
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
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);
•• 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)
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 );
);
Use
Use ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT
ALTER
ALTER ROLLBACK
ROLLBACK SEGMENT
SEGMENT rbs01
rbs01
SHRINK
SHRINK TO
TO 4M;
4M;
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;
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;
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
•• 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
•• Creating
Creating adequate
adequate rollback
rollback segments
segments
•• Troubleshooting
Troubleshooting rollback
rollback segment
segment
problems
problems
•• 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
SORT_AREA_SIZE
Data file
Permanent Temporary
tablespace 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
•• 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
V$SORT_SEGMENT
V$SORT_USAGE
DBA_SEGMENTS
V$SESSION V$SORT_USAGE
SADDR SESSION_ADDR
USERNAME TABLESPACE
SID CONTENTS
EXTENTS
BLOCKS
• Sorting
Sorting segments
segments in
in permanent
permanent and
and
temporary
temporary tablespaces
tablespaces
• Storage
Storage parameters
parameters for
for temporary
temporary
segments
segments
Regular Partitioned
table table
Index-organized
table Cluster
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
Up to 2 gigabytes Up to 4 gigabytes
•• 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
•• Can
Can identify
identify rows
rows within
within aa segment
segment
•• Needs
Needs less
less space
space
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;
• 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.
•• Compute
Compute PCTFREE
PCTFREE
(Average Row Size Initial Row Size) * 100
•• Compute
Compute PCTUSED
PCTUSED
Average Row Size * 100
100 PCTFREE
Available Data Space
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;
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);
ALTER
ALTER TABLE
TABLE scott.employees
scott.employees
ALLOCATE
ALLOCATE EXTENT(SIZE
EXTENT(SIZE 500K
500K
DATAFILE
DATAFILE ‘/DISK3/DATA01.DBF’);
‘/DISK3/DATA01.DBF’);
Extent ID 0 1 2 3 4
UNUSED_BLOCKS
Extent ID 0 1 2 3 4
ALTER
ALTER TABLE
TABLE scott.employees
scott.employees High water mark
DEALLOCATE
DEALLOCATE UNUSED;
UNUSED;
After
deallocation
TRUNCATE
TRUNCATE TABLE
TABLE scott.employees;
scott.employees;
Extent ID 0 1
Free space
DROP
DROP TABLE
TABLE scott.departments
scott.departments
CASCADE
CASCADE CONSTRAINTS;
CONSTRAINTS;
ANALYZE
ANALYZE TABLE
TABLE scott.employees
scott.employees
VALIDATE
VALIDATE STRUCTURE;
STRUCTURE;
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
Commonly
Commonly used
used functions:
functions:
Function Name Description
•• 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
•• 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
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)
Root
Branch
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 ... ... ... ...
... ... ... ... ... ...
... ...
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
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;
•• 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
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;
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;
ALTER
ALTER INDEX
INDEX scott.emp_lname_idx
scott.emp_lname_idx
STORAGE(NEXT
STORAGE(NEXT 400K
400K
MAXEXTENTS
MAXEXTENTS 100);
100);
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;
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;
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
•• Creating
Creating different
different types
types of
of indexes
indexes
•• Reorganizing
Reorganizing indexes
indexes
•• 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
Application
code
Table
DML
DML statement
statement
Check
Check nondeferred
nondeferred
constraints
constraints
COMMIT
COMMIT
Check
Check deferred
deferred
constraints
constraints
No No Use existing
index
Constraint Yes
deferrable?
No
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
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;
•• 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.
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;
•• 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;
DROP
DROP TRIGGER
TRIGGER scott.audit_dept;
scott.audit_dept;
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
•• Implementing
Implementing constraints
constraints and
and triggers
triggers
•• Using
Using appropriate
appropriate strategy
strategy for
for creating
creating
and
and maintaining
maintaining constraints
constraints
•• 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
Ordering of Rows
Hash function
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
Key 21
Key 12
Key 11
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;
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
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
DBA_TABLES DBA_INDEXES
OWNER OWNER
TABLE_NAME TABLE_NAME
IOT_TYPE INDEX_NAME
IOT_NAME INDEX_TYPE
TABLESPACE_NAME PCT_THRESHOLD
INCLUDE_COLUMN
• Identifying
Identifying situations
situations where
where clusters
clusters are
are
useful
useful
• Using
Using index-organized
index-organized tables
tables
• 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
Oracle
database
Export
SQL*Loader
Import
Oracle
database
Direct-load insert
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
EMP table
Parameter file
SQL*Loader Rejected
(optional)
Field processing
Discarded Accepted
Record selection
Bad
Selected file
Database files
Array
insert Extent
management
Conventional
Data Direct
Table path
save
High water
Space used only by conventional load mark
load1.dat SQL*Loader
load1.ctl
load2.dat SQL*Loader
load2.ctl
SQL*Loader
load3.dat
load3.ctl
Table
High water
mark
$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-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
•• 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
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
•• 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
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
•• 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
Account Default
locking tablespace
Authentication Temporary
mechanism tablespace
Security
domain
Role Tablespace
privileges quotas
Direct Resource
privileges limits
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;
OS_ OS_USER15
No
OPS$ OPS$USER15
(default) (default) Yes
ALTER
ALTER USER
USER peter
peter
IDENTIFIED
IDENTIFIED BY
BY hisgrandpa
hisgrandpa
PASSWORD
PASSWORD EXPIRE;
EXPIRE;
ALTER
ALTER USER
USER peter
peter
QUOTA
QUOTA 00 ON
ON data01;
data01;
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;
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
•• 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
•• 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
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.
Resource Description
ALTER
ALTER USER
USER scott
scott
PROFILE
PROFILE developer_prof;
developer_prof;
•• 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;
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;
DROP
DROP PROFILE
PROFILE developer_prof;
developer_prof;
DROP
DROP PROFILE
PROFILE developer_prof
developer_prof
CASCADE;
CASCADE;
DBA_USERS DBA_PROFILES
- profile - profile
- username - resource_name
- resource_type
(KERNEL)
- limit
Password Account
history locking
User Setting up
profiles
Password Password
expiration verification
and aging
•• 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.
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;
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
• Controlling
Controlling resource
resource usage
usage
• Administering
Administering passwords
passwords
•• 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
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
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;
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
REVOKE
REVOKE CREATE
CREATE TABLE
TABLE FROM
FROM user1;
user1;
REVOKE
REVOKE CREATE
CREATE SESSION
SESSION FROM
FROM scott;
scott;
GRANT
REVOKE DBA
DBA USER
USER 11 SCOTT
SCOTT
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;
DBA_TAB_PRIVS DBA_COL_PRIVS
GRANTEE GRANTEE
OWNER OWNER
TABLE_NAME TABLE_NAME
GRANTOR COLUMN_NAME
PRIVILEGE GRANTOR
GRANTABLE PRIVILEGE
GRANTABLE
REVOKE
REVOKE execute
execute ON
ON dbms_pipe
dbms_pipe
FROM
FROM scott;
scott;
GRANT
REVOKE SCOTT
SCOTT USER
USER 11 USER
USER 22
RESULT
SCOTT
SCOTT USER
USER 11 USER
USER 22
Controlling
Controlling system
system and
and object
object privileges
privileges
Users A C
B
• 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
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;
ALTER
ALTER ROLE
ROLE hr_clerk
hr_clerk
IDENTIFIED
IDENTIFIED EXTERNALLY;
EXTERNALLY;
ALTER
ALTER ROLE
ROLE hr_manager
hr_manager
NOT
NOT IDENTIFIED;
IDENTIFIED;
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;
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;
•• 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;
REVOKE
REVOKE sales_clerk
sales_clerk FROM
FROM scott;
scott;
REVOKE
REVOKE hr_manager
hr_manager FROM
FROM PUBLIC;
PUBLIC;
DROP
DROP ROLE
ROLE hr_manager;
hr_manager;
User
roles HR_CLERK HR_MANAGER PAY_CLERK
Application
roles BENEFITS PAYROLL
Application
privileges
Benefits privileges Payroll privileges
PAY_CLERK PAY_CLERK_RO
• 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
•• 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
Audit options
AUDIT_TRAIL Parameter
file
DBA
DB Instance NONE
AUD$
table
OS audit OS
OS No trail
trail
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;
•• Differentiating
Differentiating between
between database
database
auditing
auditing and
and value-based
value-based auditing
auditing
•• Maintaining
Maintaining the
the audit
audit trail
trail
• 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.
Initialization parameter
Environment variable
ALTER SESSION
command
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 ,.
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>
...
...
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’’’) ;;
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
------
------
ää
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;
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
•• 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