Professional Documents
Culture Documents
Fundamentals
Tulsi ocp
Database structure
Tulsi ocp
Physical Structures
Data files
Redo log files
Control files
Tulsi ocp
Physical structures
Tulsi ocp
datfile1
datfile3
datfile4
datfile 2
A
Tulsi ocp
Overview
Instance
User
process
Shared pool
Library
cache
Data dict.
cache
Server
process
SGA
Data buffer
cache
Redo log
buffer
PGA
SMON DBW0 PMON CKPT
Parameter
file
Password
file
Data
files
Control
files
LGWR Others
Redo
log
files
Archived
log files
Database
Tulsi ocp
Logical structure
Database
Tablespace
Segment
Extent
datablock
Tulsi ocp
Tablespace(contd)
Tulsi ocp
Schema Objects
z
z
z
z
z
z
z
z
Tables
Indexes - for faster access
Synonyms - to mask owner(security)
Sequences -used to automatically generate
numbers
Views - virtual tables
Triggers
Stored Procedures and Functions
Clusters - faster access
Tulsi ocp
user2.tab2
user1.tab1.ind
user3.tab1
Tulsi ocp
Space Allocation
z
z
Tulsi ocp
ORACLE Database
user1.tbl1
Data Dictionary
usr3.tbl1
usr2.vw1
usr2.tbl1
SYSTEM tablespace
TRAINING tablespace
Data1.ora
4 MB
Data2.ora
1 MB
Tulsi ocp
Data3.ora
4 MB
Data Block
Extents
Tulsi ocp
Data Blocks
z
z
z
z
z
z
Tulsi ocp
Segments
Segment
Tulsi ocp
Types of Segments
Data Segment
Index Segment
Tulsi ocp
Types of Segments(contd)
Rollback Segment
Temporary Segment
Tulsi ocp
Oracle Instance
SGA
ORACLE Background processes
Tulsi ocp
Oracle Instance
An Oracle instance:
Is a means to access an Oracle database
Always opens one and only one database
Instance
Shared pool
SGA
Data buffer
cache
Redo log
buffer
Tulsi ocp
Memory
structures
Background
processes
Memory Structures:
Processes
User Process
ORACLE Processes
z
z
Server Processes
Background Processes
Tulsi ocp
User
User
User
User
DBWR
LGWR
SMON
Tulsi ocp
PMON
RECO
Memory Structures
System Global Area
Library cache
Database
buffer
cache
Data dictionary
cache
shared
pool
Tulsi ocp
Redo log
buffer
Tulsi ocp
Tulsi ocp
Tulsi ocp
Processes
z
User processes
ORACLE Processes
Server processes
Background processes
Tulsi ocp
Server Process
Handle requests from Client Process
z Communicate to ORACLE to carry out
requests from Client Process
z Ex: Reading data from data file into SGA if
data is not present in the SGA database
buffer
z
Tulsi ocp
Tulsi ocp
Tulsi ocp
Background Processes
Database writer(DBWR)
z Log writer(LGWR)
z Archiver(ARCH)
z System Monitor(SMON)
z Process Monitor(PMON)
z Checkpoint(CKPT)
z
Tulsi ocp
DBWR
The database writer process writes the
modified data base buffer blocks on to
the database files on disk
z Keeps most frequently used blocks in
memory
z
Tulsi ocp
Tulsi ocp
DBWR(contd)
Tulsi ocp
LGWR
z
Tulsi ocp
Tulsi ocp
Tulsi ocp
SMON
Detection of deadlocks and termination of
one of the transactions
z Free fragmented space
z Release temporary segments
z Automatic Instance recovery when an
instance failure has occurred(by using Redo
Log)
z
Tulsi ocp
PMON
z
Tulsi ocp
CKPT
Optional process
z Signals DBWR to write at checkpoints
z DBWR writes contents of DB buffer to disk
z Updates headers of data files and control
files to reflect the most recent checkpoint
z
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
SGA Buffers
z
Tulsi ocp
Tulsi ocp
Tulsi ocp
PGA
Data and control info for one single server
process
z Allocated only when user gets connected
z
Tulsi ocp
Tulsi ocp
Mount database
Open database
Close database
Dismount database
Remove SGA
fromocp
memory
Tulsi
T
i t b k
d
Overview
User
process
Server
process
PGA
Instance
SGA
Shared pool
ALERT
file
Trace
files
Data
files
Control
files
Parameter
file
Password
file
Database
Tulsi ocp
Redo
log
files
Overview
Database
Tablespace
Logical
Data file
Physical
Segment
Extent
Oracle
block
OS block
Tulsi ocp
Block Space
Utilization Parameters
INITRANS
MAXTRANS
PCTFREE
PCTUSED
Tulsi ocp
Inserts
PCTUSED=40
80%
Inserts
80%
Inserts
40%
Inserts
Tulsi ocp
Tulsi ocp
Row chaining
z
Tulsi ocp
Row Migration
z
Tulsi ocp
Tulsi ocp
Creating a Database
Tulsi ocp
Tulsi ocp
Tuning questions
who tunes?
z
application designers
z
application developers
z
database administrators
z
system administrators
Tulsi ocp
Why tune?
How much tuning ?
There are basically two forms of tuning
speed : short response time
high throughput scalability: higher load at a
comparable response time or throughput
Tulsi ocp
Tuning goals
z
z
z
z
z
z
z
Tulsi ocp
z
z
z
z
z
Tulsi ocp
z
z
z
Tulsi ocp
z
z
z
z
z
z
Tulsi ocp
z
z
z
z
Tulsi ocp
z
z
B-tree
Bitmap
Reverse key
Clusters
Histograms
Tulsi ocp
Tulsi ocp
Tulsi ocp
Bitmap indexes
z
z
z
z
z
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
clusters
Tulsi ocp
Cluster types
Tulsi ocp
Histograms
z
z
Tulsi ocp
Tulsi ocp
Tulsi ocp
parser
The parser performs two functions:
z Syntax analysis: This checks SQL statements
for correct syntax.
z Semantic analysis: This checks, for example,
that the current database objects and object
attributes referenced are correct.
Tulsi ocp
optimizer
The optimizer uses internal rules or costing
methods to determine the most efficient way of
producing the result of the query.
z The Oracle server provides two
z methods of optimization:
z cost-based optimizer (CBO)
z rule-based optimizer (RBO).
Tulsi ocp
z
z
Tulsi ocp
Tulsi ocp
z
z
z
z
z
z
Tulsi ocp
Explain plan
Tulsi ocp
Tulsi ocp
Tulsi ocp
Optimization approaches
z
z
Tulsi ocp
CBO
z
z
z
Tulsi ocp
RBO
z
z
z
Tulsi ocp
z
z
z
z
Tulsi ocp
Tulsi ocp
Query transformer
Tulsi ocp
Estimator
Selectivity
Cardinality
z
z
z
z
Effective cardinality
Group cardinality
Join cardinality
Distinct cardinality
Cost
z
z
z
Disk I/O
Cpu usage
Memory usage as units of work
Tulsi ocp
z
z
z
z
z
z
Tulsi ocp
Hash join
Sort-merge join
Tulsi ocp
Tulsi ocp
Tulsi ocp
Important Columns
in the Plan Table
statement_id
timestamp
operation
the
options
operation,
object name
optimizer
id
parent_id
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
trace file
output file
explain=
sys=n
Tulsi ocp
cpu
elapsed
disk
query
current
-------- ---------- ---------- ---------- ---------0.05
0.02
0
0
0
0.00
0.00
0
0
0
0.00
0.00
8
8
0
-------- ---------- ---------- ---------- ---------0.05
0.02
8
8
0
Tulsi ocp
rows
---------0
0
1
---------1
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Report heading
TKPROF version, date run, sort option, trace file
One entry for each distinct SQL statement in trace file
Listing of SQL statement
OCI call statistics: count of parse, execute, and fetch
calls, rows processed, and time and I/O used
Parse information: parsing user, recursive depth,
library cache misses, and optimizer mode
Row source operation listing
Execution plan listing (optional)
Wait event listing (optional)
Tulsi ocp
Tulsi ocp
cpu
elapsed
disk
query
current
-------- ---------- --------- --------- --------0.01
0.02
0
0
0
0.00
0.00
0
0
0
0.59
0.99
0
33633
0
-------- ---------- --------- --------- --------0.60
1.01
0
33633
0
Tulsi ocp
rows
--------0
0
194
--------194
Tulsi ocp
Tulsi ocp
Tulsi ocp
Execution Plan
--------------------------------------------------SELECT STATEMENT
GOAL: CHOOSE
SORT (ORDER BY)
NESTED LOOPS
NESTED LOOPS (OUTER)
NESTED LOOPS (OUTER)
NESTED LOOPS
TABLE ACCESS (BY INDEX ROWID) OF 'OBJ$'
INDEX (RANGE SCAN) OF 'I_OBJ2' (UNIQUE)
TABLE ACCESS (CLUSTER) OF 'TAB$'
INDEX (UNIQUE SCAN) OF 'I_OBJ#' (NON-UNIQUE)
INDEX (UNIQUE SCAN) OF 'I_OBJ1' (UNIQUE)
TABLE ACCESS (CLUSTER) OF 'SEG$'
INDEX (UNIQUE SCAN) OF 'I_FILE#_BLOCK#' (NON-UNIQUE)
TABLE ACCESS (CLUSTER) OF 'TS$'
INDEX (UNIQUE SCAN) OF 'I_TS#' (NON-UNIQUE)
Tulsi ocp
z
z
z
Tulsi ocp
STATSPACK
Installing of statspack
C:/ORACLE/ORA92/RDBMS/ADMIN/SPCREATE.SQL
z Collection of statistics
EXECUTE STATSPACK.SNAP
z Automatic collection of statistics
C:/ORACLE/ORA92/RDBMS/ADMIN/SPAUTO.SQL
z Produce a report
C:/ORACLE/ORA92/RDBMS/ADMIN/SPREPORT.SQL
To collect timing information
set timed_statistics=TRUE
z
Tulsi ocp
Statspack output
zInformation
Tulsi ocp
UTLBSTAT AND
UTLESTAT
zTHESE
UTILITIES
zGATHER PERFORMANCE FIGUES OVER
A DEFINED PERIOD
zRun the scripts form sql*plus as sysdba
zStatspack provide clearer statistics
Tulsi ocp
Sql*plus autotrace
zCreate
autotrace on
Tulsi ocp
Database Administration
Tools: Examples
Tool
Description
SQL*Loader
Tulsi ocp
Created automatically
Granted the DBA role
Tulsi ocp
Password:
change_on_instalSYSTEM
l
z Password:
manager
Owner of the
database data
z Owner of additional
dictionary
internal tables and views
used by Oracle tools
Tulsi ocp
Tulsi ocp
Tulsi ocp
Configuration Assistant
Tulsi ocp
Enterprise Manager
Console
1
Tulsi ocp
Instance Manager
Security Manager
Storage Manager
Schema Manager
SQL*Plus Worksheet
Tools and wizards for data management
and backup
Tulsi ocp
Overview
User
process
Server
process
PGA
Instance
SGA
Shared pool
ALERT
file
Trace
files
Data
files
Control
files
Parameter
file
Password
file
Database
Tulsi ocp
Redo
log
files
Redo log
buffer
Shared pool
Library
cache
Data dict.
cache
initU15.ora
SQL>
SQL>
SQL>
SQL>
CONNECT
CONNECT
STARTUP
STARTUP
// AS
AS SYSDBA
SYSDBA
PFILE=/DISK1/initU15.ora
PFILE=/DISK1/initU15.ora
Tulsi ocp
Uses of Parameters
z
z
z
z
z
Tulsi ocp
Tulsi ocp
STARTUP Command
Tulsi ocp
ALTER DATABASE
Command
Tulsi ocp
Opening a Database in
Read-Only Mode
z
z
Execute queries
Execute disk sorts using locally managed
tablespaces
Take data files offline and online, not
tablespaces
Perform recovery of offline data files and
tablespaces
Tulsi ocp
Shutdown Options
Shutdown Mode
Shutdown mode:
A Abort
I Immediate
NO
T Transactional
N Normal
YES
Tulsi ocp
Example
V$PARAMETER
V$SGA
V$OPTION
V$PROCESS
V$SESSION
V$VERSION
V$INSTANCE
SGA
V$THREAD
V$CONTROLFILE
V$DATABASE
V$DATAFILE
V$DATAFILE_HEADER
V$LOGFILE
Control file
Tulsi ocp
Displaying Current
Parameter Values
z
Tulsi ocp
Dynamic Initialization
Parameters
z
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;
Tulsi ocp
Creating a Database
Overview
User
process
Server
process
PGA
Instance
SGA
Shared pool
ALERT
file
Trace
files
Data
files
Control
files
Parameter
file
Password
file
Database
Tulsi ocp
Redo
log
files
Creation Prerequisites
z
z
z
Tulsi ocp
z
z
Tulsi ocp
On Windows NT
/oracle_base
\oracle_base
/product
\oracle_home
/release_number
/bin
/dbs
/orainst
/sqlplus
...
/8.1.5
/admin
/local
Tulsi ocp
\admin\db_name
\admin\v815
\oradata\db_name
\bin
\database
/u03/
oradata/
db01/
tools01.dbf
control02.ctl
redo0102.rdo
...
Tulsi ocp
db02/
users01.dbf
control02.ctl
redo0102.rdo
...
Creating a Database
z
z
Tulsi ocp
Tulsi ocp
Pretuned Databases
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
1.
1. Connect
Connect as
as SYSDBA.
SYSDBA.
2.
Start
the
in
2.SQL>
Start
the instance
instance
in NOMOUNT
NOMOUNT stage.
stage.
STARTUP
NOMOUNT
SQL>
STARTUP
NOMOUNT PFILE=initU16.ora
PFILE=initU16.ora
ORACLE
ORACLE instance
instance started.
started.
Tulsi ocp
Tulsi ocp
Overview
Other objects created with the
database:
z Data dictionary
Base tables
Views
System
tablespace
Other
database
files
Database
Data Dictionary
z
z
z
z
z
z
DDL
Some DML
System
tablespace
Other
database
files
Database
Normalized
Created with database using sql.bsq script
Tulsi ocp
z
z
Users
Schema objects
Storage structures
DBA_xxx
All of the objects in the database
ALL_xxx
Objects accessible by the current user
USER_xxx
Objects owned by the current user
Tulsi ocp
General overview
Schema objects
DBA_TABLES
DBA_OBJECTS
Space allocation
DICTIONARY
DBA_ SEGMENTS
DBA_FREE_SPACE
DICT_COLUMNS
DBA_TAB_COLUMNS
DBA_CONSTRAINTS
DBA_EXTENTS
Database structure
DBA_DATA_FILES
DBA_ROLLBACK_SEGS
DBA_TABLESPACES
Tulsi ocp
Virtual tables
Information accessed from:
z
z
z
z
Memory
Control file
PL/SQL
Java
External procedures
Written in C
Stored in a shared library
To execute, publish the call specification
Tulsi ocp
Tulsi ocp
Example: DBMS_SESSION.SET_ROLE
Package: DBMS_SESSION
Procedure: SET_ROLE
Tulsi ocp
Purpose
catalog.sql
catproc.sql
Tulsi ocp
Data
files
Control
files
Redo log
files
z
z
Database
z
z
z
At mount
To operate
Linked to a single
database
Should be multiplexed
Loss may require recovery
Tulsi ocp
Tulsi ocp
Disk 1
Disk 2
control01.con
control02.con
Tulsi ocp
Data
files
Control
files
Redo log
files
Database
Tulsi ocp
Group 1
Group 2
Group 3
Disk 1
Member
Member
Member
Member
Member
Member
Tulsi ocp
Disk 2
Oracle Architecture
SGA
Instance
Data buffer
cache
DBWR
Redo log
buffer
CKPT
ARCH
Control
files
Parameter
file
Password
file
LGWR
Redo
log
files
Data
files
Database
Tulsi ocp
Archived
log files
Without Archiving
Backup
Data files
Disk failure
Control
files
51
50
t1
100
t2
Tulsi ocp
101
With Archiving
Backup
Data files
Control
files
Disk failure
50
99
100
51
50
t1
t2
Tulsi ocp
101
Obtaining Information
About Archiving
z
SQL command:
ARCHIVE
ARCHIVE LOG
LOG LIST;
LIST;
V$DATABASE:
NAME
LOG_MODE
V$INSTANCE:
ARCHIVER
Tulsi ocp
Obtaining Information
About Groups
V$THREAD:
z GROUPS
z CURRENT_GROUP#
z SEQUENCE#
Tulsi ocp
Tulsi ocp
Tulsi ocp
LOG_CHECKPOINT_INTERVAL
LOG_CHECKPOINT_TIMEOUT
FAST_START_IO_TARGET
Tulsi ocp
ALTER
ALTER DATABASE
DATABASE ADD
ADD LOGFILE
LOGFILE
(/DISK3/log3a.rdo,
(/DISK3/log3a.rdo,
/DISK4/log3b.rdo)
/DISK4/log3b.rdo) size
size 1M;
1M;
log1b.rdo
log2b.rdo
Group 1
Group 2
Tulsi ocp
log3b.rdo
Group 3
ALTER
ALTER DATABASE
DATABASE ADD
ADD
/DISK4/log1b.rdo
/DISK4/log1b.rdo
/DISK4/log2b.rdo
/DISK4/log2b.rdo
log1a.rdo
LOGFILE
LOGFILE MEMBER
MEMBER
TO
TO GROUP
GROUP 1,
1,
TO
TO GROUP
GROUP 2;
2;
log1b.rdo
log2a.rdo
Group 1
log2b.rdo
Group 2
Tulsi ocp
Tulsi ocp
ALTER
ALTER DATABASE
DATABASE DROP
DROP LOGFILE
LOGFILE GROUP
GROUP 3;
3;
log3a.rdo
log1b.rdo
log1b.rdo
log1b.rdo
log2b.rdo
Group 1
Group 2
Tulsi ocp
log3b.rdo
Group 3
ALTER
ALTER DATABASE
DATABASE DROP
DROP LOGFILE
LOGFILE MEMBER
MEMBER
/DISK4/log2b.dbf;
/DISK4/log2b.dbf;
log1b.rdo
log1b.rdo
log1b.rdo
log2b.rdo
Group 1
Group 2
Tulsi ocp
Example:
Example:
ALTER DATABASE
Tulsi ocp
Group 1
Group 2
Group 3
Member
Member
Member
Member
Member
Disk 1
Disk 2
Tulsi ocp
Disk 3
Tulsi ocp
Overview
Control
files
Data files
Redo log
files
Database
Tulsi ocp
Tablespace
Logical
Data file
Physical
Segment
Extent
Oracle
block
OS block
Tulsi ocp
SYSTEM tablespace:
Non-SYSTEM tablespaces:
Separate segments
Ease space administration
Control amount of space allocated to a user
Tulsi ocp
Creating Tablespaces
CREATE
CREATE TABLESPACE
TABLESPACE app_data
app_data
DATAFILE
DATAFILE '/DISK4/app_data_01.dbf'
'/DISK4/app_data_01.dbf'
SIZE
SIZE 100M,
100M,
'/DISK5/app
'/DISK5/app data_
data_ 02.dbf'
02.dbf'
SIZE
SIZE 100M
100M
MINIMUM
MINIMUM EXTENT
EXTENT 500K
500K
DEFAULT
500K
DEFAULT STORAGE
STORAGE (( INITIAL
INITIAL
500K
NEXT
500K
NEXT
500K
MAXEXTENTS
500
MAXEXTENTS
500
PCTINCREASE
00 );
PCTINCREASE
);
Tulsi ocp
Dictionary-managed tablespaces:
Default technique
Free extents recorded in data dictionary tables
Tulsi ocp
z
z
z
z
Tulsi ocp
Temporary Tablespace
z
z
z
z
Tulsi ocp
app_data
app_data
2M;
2M;
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data
DEFAULT
DEFAULT STORAGE
STORAGE ((
INITIAL
2M
INITIAL
2M
NEXT
2M
NEXT
2M
MAXEXTENTS
MAXEXTENTS 999
999 );
);
Tulsi ocp
Offline Status
z
z
SYSTEM
Tablespaces with active rollback segments
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data OFFLINE;
OFFLINE;
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data ONLINE;
ONLINE;
Tulsi ocp
Read-Only Tablespaces
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data READ
READ ONLY;
ONLY;
z
z
z
Tulsi ocp
Dropping Tablespaces
z
z
z
Tulsi ocp
Resizing a Tablespace
z
Automatically
Manually
app_data_01.dbf
100M
app_data_02.dbf
100M
100M
Tulsi ocp
app_data_03.dbf
200M
Tablespace APP_DATA
app_data_01.dbf
100M
app_data_02.dbf
100M
app_data_03.dbf
200M
Tulsi ocp
app_data_04.dbf
200M
app_data_01.dbf
100M
app_data_02.dbf
100M
app_data_03.dbf
200M
100M
Tulsi ocp
app_data_04.dbf
200M
ALTER
ALTER TABLESPACE
TABLESPACE app_data
app_data
ADD
ADD DATAFILE
DATAFILE '/DISK5/app_data_03.dbf'
'/DISK5/app_data_03.dbf'
SIZE
SIZE 200M;
200M;
Tablespace APP_DATA
app_data_01.dbf
100M
app_data_02.dbf
100M
app_data_03.dbf
200M
Tulsi ocp
z
z
Tulsi ocp
Tablespace information:
DBA_TABLESPACES
V$TABLESPACE
DBA_DATA_FILES
V$DATAFILE
Tempfile information:
DBA_TEMP_FILES
V$TEMPFILE
Tulsi ocp
Overview
Database
Tablespace
Logical
Data file
Physical
Segment
Extent
Oracle
block
OS block
Tulsi ocp
Types of Segments
Table
Table
partition
Cluster
Index
Tulsi ocp
Types of Segments
Index-organized
table
Index
partition
Rollback
segment
Temporary
segment
Tulsi ocp
Types of Segments
LOB
segment
LOB index
Nested table
Bootstrap
segment
Tulsi ocp
Oracle default
Tablespace
Segment
Tulsi ocp
Created
Extended
Altered
Dropped
Altered
Truncated
Automatically resized (rollback segments only)
Tulsi ocp
File header
Used extent
Tulsi ocp
Free extent
Tulsi ocp
Header
Free space
Data
Tulsi ocp
Block Space
Utilization Parameters
INITRANS
MAXTRANS
PCTFREE
PCTUSED
Tulsi ocp
Inserts
PCTUSED=40
80%
Inserts
80%
Inserts
40%
Inserts
Tulsi ocp
Free extents
DBA_EXTENTS
DBA_FREE_SPACE
Segments
Data files
DBA_SEGMENTS
DBA_DATA_FILES
Tablespaces
DBA_TABLESPACES
Tulsi ocp
Querying DBA_SEGMENTS
z
General information
OWNER
SEGMENT_NAME z
SEGMENT_TYPE
TABLESPACE_NAME
Size
EXTENTS
BLOCKS
BYTES
Storage settings
INITIAL_EXTENT
NEXT_EXTENT
MIN_EXTENTS
MAX_EXTENTS
PCT_INCREASE
Other information
Location
Tuning
Tulsi ocp
Querying DBA_EXTENTS
z
Identification
OWNER
SEGMENT_NAME
EXTENT_ID
Size
BLOCKS
BYTES
Location
TABLESPACE_NAME
RELATIVE_FNO
FILE_ID
BLOCK_ID
Tulsi ocp
Querying
DBA_FREE_SPACE
z
Location
TABLESPACE_NAME
RELATIVE_FNO
FILE_ID
BLOCK_ID
Size
BYTES
BLOCKS
Tulsi ocp
New
image
Table
Rollback segment
Update transaction
Tulsi ocp
Transaction rollback
Transaction
recovery
Rollback segment
Tulsi ocp
Read consistency
Read Consistency
Table
SELECT *
FROM table
New image
Image at start of statement
Tulsi ocp
Types of Rollback
Segments
z
z
Tulsi ocp
AUTOMATIC UNDO
MANAGEMENT
Undo_management (auto/manual)
Undo_tablespace (undotbs)
Tulsi ocp
Transaction 1 Transaction 2
Active extent
Inactive extent
Tulsi ocp
Growth of Rollback
Segments
1
4
2
5
3
4
Active extent
New extent
Inactive extent
Tulsi ocp
5
4
3
Active extent
OPTIMAL
Inactive extent
Tulsi ocp
Managing Tables
Regular
table
Partitioned
table
Index-organized
table
Cluster
Tulsi ocp
Structure of a Row
Row header
Column length
Database block
Column value
Tulsi ocp
Built-in
Scalar
Collection
CHAR(N), NCHAR(N)
VARCHAR2(N),
NVARCHAR2(N)
NUMBER(P,S)
DATE
RAW(N)
BLOB, CLOB,
NCLOB, BFILE
LONG, LONG RAW
ROWID, UROWID
VARRAY
TABLE
Tulsi ocp
Relationship
REF
LOB
Up to 2 gigabytes
Up to 4 gigabytes
Tulsi ocp
z
z
FFF
BBBBBB
RRR
Data object
number
Relative file
number
Block number
Row number
Tulsi ocp
Restricted ROWID
z
z
z
z
Can
Can identify
identify rows
rows within
within aa segment
segment
Needs
Needs less
less space
space
BBBBBBBB
Block number
RRRR
Row number
Tulsi ocp
FFFF
File number
Collections
z
z
z
VARRAY
Nested
table
Tulsi ocp
Creating a Table
CREATE
CREATE TABLE
TABLE employee(
employee(
id
NUMBER(7),
id
NUMBER(7),
last_name
last_name VARCHAR2(25),
VARCHAR2(25),
dept_id
NUMBER(7))
dept_id
NUMBER(7))
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 data;
data;
Tulsi ocp
After update
Pointer
Tulsi ocp
Managing Indexes
Classification of Indexes
z
Logical
Physical
Partitioned or nonpartitioned
B-tree
Normal or reverse key
Bitmap
Tulsi ocp
B-Tree Index
Index entry
Root
Branch
Leaf
Tulsi ocp
KEY
ID
----1257
2877
4567
6657
8967
9637
9947
...
...
EMPLOYEE table
ROWID
(BLOCK# ROW# FILE#)
------------------0000000F.0002.0001
0000000F.0006.0001
0000000F.0004.0001
0000000F.0003.0001
0000000F.0005.0001
0000000F.0001.0001
0000000F.0000.0001
...
...
ID
----7499
7369
7521
7566
7654
7698
7782
...
FIRST_NAME JOB
---------- -------ALLEN
SALESMAN
SMITH
CLERK
WARD
SALESMAN
JONES
MANAGER
MARTIN
SALESMAN
BLAKE
MANAGER
CLARK
MANAGER
...
...
...
...
...
...
Tulsi ocp
Dramatically
Dramatically improves
improves query
query performance
performance
CREATE
CREATE INDEX
INDEX summit.item_quantity_to_deliver_idx
summit.item_quantity_to_deliver_idx
ON
ON summit.item(quantity
summit.item(quantity -- quantity_shipped);
quantity_shipped);
SELECT
ord_id,
item_id
z
expressions
SELECT
ord_id,using
item_id
z Queries
Queries
using
expressions can
can use
use the
the
FROM
ITEM
FROMindex
ITEM
index
WHERE
WHERE (quantity
(quantity -- quantity_shipped)
quantity_shipped) >> 0;
0;
Tulsi ocp
Bitmap Index
File 3
Block 10
Table
Block 11
Block 12
Index
start
end
key ROWID ROWID
<Blue,
<Green,
<Red,
<Yellow,
10.0.3,
10.0.3,
10.0.3,
10.0.3,
12.8.3,
12.8.3,
12.8.3,
12.8.3,
Tulsi ocp
bitmap
1000100100010010100>
0001010000100100000>
0100000011000001001>
0010001000001000010>
Bitmap
Tulsi ocp
CREATE
CREATE INDEX
INDEX summit.employee_last_name_idx
summit.employee_last_name_idx
ON
ON summit.employee(last_name)
summit.employee(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 indx;
indx;
Tulsi ocp
CREATE
CREATE UNIQUE
UNIQUE INDEX
INDEX summit.orders_id_idx
summit.orders_id_idx
ON
ON summit.orders(id)
summit.orders(id) 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 indx;
indx;
Tulsi ocp
Tulsi ocp
Rebuilding Indexes
Use the ALTER INDEX command to:
z Move an index to a different tablespace
z Improve space utilization by removing
deleted entries
z Change a reverse key index to a normal
B-tree index and vice versa
ALTER
ALTER INDEX
INDEX summit.orders_region_id_idx
summit.orders_region_id_idx REBUILD
REBUILD
TABLESPACE
TABLESPACE indx02;
indx02;
Tulsi ocp
Dropping Indexes
Drop and re-create an index before bulk loads.
Drop indexes that are infrequently needed and build
them when necessary.
Drop and re-create invalid indexes.
DROP
DROP INDEX
INDEX summit.deptartment_name_idx;
summit.deptartment_name_idx;
Tulsi ocp
NLS Features
Language support
Territory support
Character set support
Linguistic sorting
Message support
Date and time formats
Numeric formats
Monetary formats
Database
Tulsi ocp
Different Types
of Encoding Schemes
Oracle supports different classes of
character encoding schemes:
z Single-byte character sets
z
z
z
7-bit
8-bit
Tulsi ocp
Tulsi ocp
Specifying Language-Dependent
Behavior
Initialization parameter
Environment variable
ALTER SESSION
command
Tulsi ocp
Specifying Language-Dependent
Behavior for the Server
z
NLS_LANGUAGE specifies:
- The language for messages
- Day and month names
- Symbols for A.D, B.C, A.M, P.M.
- The default sorting mechanism
NLS_TERRITORY specifies:
- Day and week numbering
- Default date format, decimal character,
group separator, and the default ISO
and local currency symbols
Tulsi ocp
VALUES
NLS_LANGUAGE
AMERICAN
NLS_DATE_LANGUAGE
AMERICAN
NLS_SORT
BINARY
AMERICA
NLS_TERRITORY
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_DATE_FORMAT
NLS_NUMERIC_CHARACTERS
AMERICA
DD-MON-YY
,.
Tulsi ocp
Environment variable:
NLS_LANG=<language>_<territory>.<charse
t>
Additional environment variables:
z
z
z
z
z
z
z
NLS_DATE_FORMAT
NLS_DATE_LANGUAGE
NLS_SORT
NLS_NUMERIC_CHARACTERS
NLS_CURRENCY
NLS_ISO_CURRENCY
NLS_CALENDAR
Tulsi ocp
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>
...
...
Tulsi ocp
Tulsi ocp
Obtaining Information
About Character Sets
NLS_DATABASE_PARAMETERS:
PARAMETER
(NLS_CHARACTERSET,
NLS_NCHAR_CHARACTERSET)
VALUE
Tulsi ocp
Managing Privileges
Managing Privileges
Two types of privileges:
z System: Enables users to perform
particular actions in the database
z Object: Enables users to access and
manipulate a specific object
Tulsi ocp
System Privileges
z
z
z
z
Tulsi ocp
System Privileges:
Examples
Category
Examples
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
Tulsi ocp
GRANT
GRANT CREATE
CREATE SESSION,
SESSION, CREATE
CREATE TABLE
TABLE TO
TO managers;
managers;
GRANT
GRANT CREATE
CREATE SESSION
SESSION TO
TO scott
scott
WITH
WITH ADMIN
ADMIN OPTION;
OPTION;
Tulsi ocp
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
Tulsi ocp
Database Level
Session Level
DBA_SYS_PRIVS
SESSION_PRIVS
GRANTEE
PRIVILEGE
PRIVILEGE
ADMIN OPTION
Tulsi ocp
REVOKE
REVOKE CREATE
CREATE TABLE
TABLE FROM
FROM karen;
karen;
REVOKE
REVOKE CREATE
CREATE SESSION
SESSION FROM
FROM scott;
scott;
Tulsi ocp
KAREN
KAREN
SCOTT
SCOTT
DBA
DBA
KAREN
KAREN
SCOTT
SCOTT
GRANT
GRANT
REVOKE
REVOKE
Tulsi ocp
KAREN
KAREN
Tulsi ocp
SCOTT
SCOTT
Object Privileges
Object priv.
Table View
ALTER
DELETE
Sequence
Procedure
EXECUTE
INDEX
INSERT
REFERENCES
SELECT
UPDATE
Tulsi ocp
GRANT
GRANT EXECUTE
EXECUTE ON
ON dbms_pipe
dbms_pipe TO
TO public;
public;
GRANT
GRANT UPDATE(first_name,
UPDATE(first_name, salary)
salary) ON
ON
employee
employee TO
TO karen
karen WITH
WITH GRANT
GRANT OPTION;
OPTION;
Tulsi ocp
DBA_TAB_PRIVS
DBA_COL_PRIVS
GRANTEE
OWNER
TABLE_NAME
GRANTOR
PRIVILEGE
GRANTABLE
GRANTEE
OWNER
TABLE_NAME
COLUMN_NAME
GRANTOR
PRIVILEGE
GRANTABLE
Tulsi ocp
REVOKE
REVOKE execute
execute ON
ON dbms_pipe
dbms_pipe FROM
FROM scott;
scott;
Tulsi ocp
USER
USER 11
USER
USER 22
SCOTT
SCOTT
USER
USER 11
USER
USER 22
GRANT
REVOKE
Tulsi ocp
Revoking Object
Privileges
Using WITH GRANT
OPTION
RESULT
SCOTT
SCOTT
USER
USER 11
Tulsi ocp
USER
USER 22
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
Tulsi ocp
SIDE
zORCLE NET CONFIGURATION SERVER
SIDE
Tulsi ocp
SIDE
z LISTENER PROCESS NEED TO EXIST
zLISTENER PROCESS: LISTENS FOR
INCOMING CONNECTIONS ON BEHALF
OF A DATABASE OR A NUMBER OF
DATASES
Tulsi ocp
LISTENER PROCESS
zA
Tulsi ocp
zWhen
Tulsi ocp
zLISTENER
=
z (DESCRIPTION_LIST =
z (DESCRIPTION =
z
(ADDRESS_LIST =
z
(ADDRESS = (PROTOCOL = IPC)(KEY =
EXTPROC0))
z
)
z
(ADDRESS_LIST =
z
(ADDRESS = (PROTOCOL = TCP)(HOST =
sprinttechnolog)(PORT = 1521))
z
)
z )
z )
Tulsi ocp
lsnrctl
zPrompt syntax
zLsnrctl> set current_listener listener2
Tulsi ocp
LSNRCTL commands
zUse
Tulsi ocp
Tulsi ocp
zFirst
Tulsi ocp