Professional Documents
Culture Documents
3
List of Main Components
Instance
Client process
Shared pool SGA
Library cache
Redo
Database Buffer
Data dict. log buffer
Cache
Server process cache
Parameter file Data file Control file Redo data File log file
file
Password file
Database
4
Oracle Server
5
Oracle Instance
An Oracle instance:
A basic way of access to the Oracle database
Always opens and uses only one database at a time
Consists of the memory structure and the background processes
Instance
6
Create a Connection and Session
Create a session
Database user
7
Oracle Database
Oracle database:
Is data set treated as a unit
Consists of three file types
Oracle database
Password file
8
Physical Structure
Control files
Title
Data files Control
files
Data files
Redo log files (including data
Online redo
dictionary)
log files
9
Memory Structure
10
System Global Area (SGA)
11
SGA
12
Shared Pool
The shared pool is used to store the most recently
executed SQL statements and the most recently used data
definitions.
It consists of mainly of two memory structures:
Library cache
Data dictionary cache
Its size is determined by the value of the parameter
Shared pool
SHARED_POOL_SIZE.
Library
cache
ALTER SYSTEM SET Data dictionary
SHARED_POOL_SIZE = 64M; cache
13
Library Cache
The library cache stores the most recent SQL and PL/SQL
statements:
It allows commonly used statements to be shared
It is managed by LRU (least recently used) algorithm
It consists of two structures:
14
Data Dictionary Cache
15
Database Buffer Cache
The database buffer cache stores the copies of data blocks previously
extracted from the data file.
When you get or modify data, this buffer cache helps improve the
performance.
It is managed by LRU algorithm.
DB_BLOCK_SIZE determines the primary block size.
Database buffer
cache
16
Database Buffer Cache
17
Redo Log Buffer Cache
The redo log buffer cache contains all the changes made
to data blocks.
This cache is primary used for recovery.
The records can be used to redo changes.
Its size is defined by LOG_BUFFER.
Redo log
buffer cache
18
Large Pool
19
Java Pool
20
Program Global Area
PGA is an area allocated for every user process to connect the Oracle database.
21
Process Structure
22
User Process
Server
process
User
process
Connection
established
Database user
23
Service Process
A service process is a program that directly interacts with the Oracle server.
In response to user requests, it makes a call to the server, and returns the
result to the user.
A session can be created in either the dedicated or shared server mode.
Server
process
Connection
established Session created
Database user
24
Background Processes
25
Database Writer
26
Log Writer
Instance
SGA
LGWR begins to write:
Redo log When a transaction
buffer commits
When one third of the
DBWn LGWR buffer cache is full
When there is an 1MB
log
Data
files
Control
files
Redo log
files
Every 3 seconds
Before DBWn writes
Database
27
System Monitor Process
Instance Used for:
Instance recovery:
SGA
Rolling forward changes
made to the log file
Opening the database
so that users can log on
Rolling back
SMON uncommitted
transactions
It coalesces free space every 3
Data Control Redo log seconds
files files files It de-allocates temporary
segments
Database
28
Process Monitor
Instance
SGA
Clean up after failed
processes by:
Rolling back a transaction
Releasing a lock
Freeing other resources
PMON
Restarting dead
dispatches
PGA area
29
Checkpoint
30
Archiver Process
ARCn
ARCn
Data Control Redo log Archived
files files files Redo log
files
31
Logical Structure
Tablespace
Data file
Segment Segment
Extent Blocks
32
RAC Mode
Schematic Diagram
33
RAC Mode
Advantages
Good scalability
High availability
State-of-the-art Cache Fusion technology
Lower hardware cost
Brief switching
Disadvantages
Difficult to manage
High demand on the network
34
HOTSTANDBY (Failover)
Schematic Diagram
35
HOTSTANDBY( Failover)
Advantages
Easy to manage
Running steadily
Disadvantages
Lengthy switching
During system switching, the database connection
between the client and the server will go down, and
thus a reconnection attempt is required.
The standby system is idle, making it impossible to
achieve a load balance.
36
Summary
37
Managing Tablespaces and Data Files
Objectives
39
Overview
Database
40
Database Architecture
Database
Extent
Oracle
OS block
block
41
System and Non-System Tablespaces
System tablespace:
Created with the database
Contains the data dictionary
Contains the SYSTEM undo segment
Non-System Tablespaces:
Different segments stored separately (e.g., undo
segments, temporary segments, application data)
Control the amount of space allocated to users objects
42
Tablespace Management
Locally managed tablespaces:
Free extents are contained in their own bitmap
Each bit in the bitmap corresponds to a block or a group of
blocks
Flag bit in the bitmap shows the free or used status of
blocks.
Dictionary-Managed Tablespaces:
Default tablespace management method
Free extents recorded in the data dictionary
43
Locally Management Tablespaces
44
Dictionary Managed Tablespaces
45
Undo Tablespace
46
Temporary Tablespaces
47
Restrictions on Default Temporary Tablespaces
You cannot:
Drop the default temporary tablespace until after a new
default is made available
Take the default temporary tablespace offline.
Can not change the default temporary tablespace to a
permanent tablespace
48
Drop Tablespace
49
Resize Tablespaces
Tablespace APP_DATA
100M
100M 200M
100M
app_data_01.dbf app_data_02.dbf app_data_03.dbf
50
Manually Resize Data Files
ALTER DATABASE
DATAFILE '/u03/oradata/userdata02.dbf'
RESIZE 200M;
Tablespace APP_DATA
100M
100M 200M 200M
100M
51
Add a Data File to the Tablespace
Tablespace APP_DATA
52
Move Data Files (Modify Tablespace)
53
Obtain Tablespace Information
Tablespace info:
DBA_TABLESPACES
V$TABLESPACE
Data file info:
DBA_DATA_FILES
V$DATAFILE
Temporary file info:
DBA_TEMP_FILES
V$TEMPFILE
54
Summary
55
Practice
56
56
Managing Redo Log Files
Objectives
58
Use the Redo Log Files
Redo log files record all data changes and provide the means to redo
transactions in the event of a database failure.
Manage redo log files in groups.
An Oracle database requires a minimum of two groups of redo log files.
Each log file in the group is called a group member.
Database
Redo log
files
59
Structure of a Redo Log File
60
How Redo Logs Work
61
Forcing Log Switches and Checkpoints
62
Adding Redo Log Groups
63
Adding Online Redo Log Group Members
64
Dropping a Redo Log Group
65
Dropping an Online Redo Log Group Member
log1a.rdo log1a.rdo
log1b.rdo log1b.rdo
log1c.rdo log2c.rdo
Group 1 Group 2
66
Clearing, Relocating or Renaming Online Redo Log Files
67
Obtaining Log Group and Member Information
68
Archived Redo Log Files
69
Archived Log Files
70
Summary
71
Practice
72
Managing Users and Privileges
Objectives
74
Database Schema
75
About Creating a User
76
Creating a User: Database Level Identification
77
Dropping a User
78
Obtaining User Information
79
System Privileges
80
System Privileges: Examples
Category Examples
INDEX CREATE ANY INDEX
ALTER ANY INDEX
DROP ANY INDEX
TABLE CREATE TABLE
CREATE ANY TABLE
ALTER ANY TABLE
DROP ANY TABLE
SELECT ANY TABLE
UPDATE ANY TABLE
DELETE ANY TABLE
SESSION CREATE SESSION
ALTER SESSION
RESTRICTED SESSION
TABLESPACE CREATE TABLESPACE
ALTER TABLESPACE
DROP TABLESPACE
UNLIMITED TABLESPACE
81
Granting System Privileges
82
Revoking System Privileges
83
Granting Object Privileges
84
Revoking Object Privileges
85
Obtaining Privileges Information
86
Summary
87
Practice
88
Managing an ORACLE Instance
Objectives
90
Initialization Parameter Files
Oracle Instance
spfiledb01.ora
91
Initialization Parameter Files
92
PFILE
initSID.ora
93
An Example of PFILE
# Initialization Parameter File: initdb01.ora
db_name = db01
instance_name = db01
control_files = ( /u03/oradata/db01/control01db01.ctl,
/u03/oradata/db01/control02db01.ctl)
db_block_size = 4096
db_block_buffers = 500
shared_pool_size = 31457280 # 30M Shared Pool
db_files = 1024
max_dump_file_size = 10240
background_dump_dest = /u05/oracle9i/admin/db01/bdump
user_dump_dest = /u05/oracle9i/admin/db01/udump
core_dump_dest = /u05/oracle9i/admin/db01/cdump
undo_management = auto
undo_tablespace = undtbs
...
94
SPFILE
spfileSID.ora
The SPFILE file is a binary file in which the modification can take
effect without the need of restarting the database.
The file resides on the ORACLE server side.
The ALTER SYSTEM command can be used to change the value of
parameters directly.
It can determine whether the modification will take effect
temporarily in the memory or the modification will take effect
persistently from now on.
Modified values can be deleted and reset to default value of
instances.
95
Creating an SPFILE File
96
96
An Example of SPFILE
*.background_dump_dest='$ORACLE_HOME/admin/db01/bdump'
*.compatible='9.0.0'
*.control_files='/u03/oradata/db01/ctrl01db01.ctl','/u03/oradata/db01/ctrl02db01.ctl'
*.core_dump_dest='$ORACLE_HOME/admin/db01/cdump'
*.db_block_buffers=500
*.db_block_size=4096
*.db_files=40
*.db_name='db01'
*.instance_name='db01'
*.remote_login_passwordfile='exclusive'
*.shared_pool_size=31457280 # 30M Shared Pool
*.undo_management='AUTO'
db01.undo_tablespace='UNDOTBS01'
db02.undo_tablespace='UNDOTBS02'
...
97
Starting Up a Database
NOMOUNT
OPEN
STARTUP
MOUNT
NOMOUNT
Starting the
Instance
SHUTDOWN
SHUTDOWN
98
Starting Up a Database
MOUNT
OPEN
STARTUP
MOUNT
Opening the
Control File
NOMOUNT
Starting the
Instance
SHUTDOWN
SHUTDOWN
99
Starting Up a Database
OPEN
OPEN
STARTUP Opening All Files Described in
the Control File of the Instance
MOUNT
Opening the
Control File
NOMOUNT
Starting the
Instance
SHUTDOWN
SHUTDOWN
100
STARTUP Command
STARTUP
STARTUP PFILE=$ORACLE_HOME/dbs/initdb01.ora
101
The ALTER DATABASE Command
Open an database:
ALTER DATABASE db01 OPEN;
102
Shutting Down the Database
Shutdown mode A I T N
Allowing new access x x x x
Waiting till all current sessions are terminated
x x x o
Waiting till all current transactions are terminated
x x o o
Forced execution of checkpoint and closing all files
x o o o
Shutdown Mode:
NORMAL
x NO
TRANSACTIONAL
o YES
IMMEDIATE
ABORT
103
Shutting Down an Object
During a
Shutdown Normal,
Shutdown Transactional
In this shutdown mode: or After that, restarting
Shutdown Immediate
the database:
Data block buffer
content written into Instance recovery
data file not required
Un-submitted
transactions rolled
back
Resource released
Consistent Database
(Clean Database)
104
Shutting Down an Object
During a
Shutdown Abort
After that, restarting the
or database:
In this shutdown mode: Instance Failure
or
Startup Force Modified information is
Modified data block
written to the redo log
buffer content are not
file
written into data file
Uncommitted changes
Uncommitted
must be rolled back with
transactions are not
the rollback segment
rolled back
Resource released
Inconsistent Database
(Dirty Database)
105
Managing Instances by Checking Diagnostic Files
106
Alert Log File
107
Background Trace File
108
User Trace File
The user trace file is created when user process is connected to the
Oracle server through the server process.
A user trace file contains traced SQL statements or user
communication error messages.
A user trace file is created when an error occurs during a user
session.
Its path is defined in the initialization parameter USER_DUMP_DEST.
It size is defined in the parameter MAX_DUMP_FILE_SIZE and the
default value is 10M.
109
Opening or Closing a User Trace File
110
Summary
111
Practice
112
ctice
112
Introduction to the Use of SQL*Plus
Objectives
114
Main Contents of SQL*Plus
Log in to SQL*Plus.
Describe table structure.
Edit SQL statements.
Execute SQL in the SQL*Plus.
Save or insert SQL statements to or into a file
115
Logging In to SQL*Plus
sqlplus [username[/password
[@database]]]
116
Displaying Table Structure
117
SQL*Plus Editing Commands
A[PPEND] text
C[HANGE] / old / new
C[HANGE] / text /
CL[EAR] BUFF[ER]
DEL
DEL n
DEL m n
118
SQL*Plus Editing Commands
I[NPUT]
I[NPUT] text
L[IST]
L[IST] n
L[IST] m n
R[UN]
n
n text
0 text
119
Using LIST, n, and APPEND
SQL> LIST
1 SELECT last_name
2* FROM employees
SQL> 1
1* SELECT last_name
SQL> A , job_id
1* SELECT last_name, job_id
SQL> L
120
Using the CHANGE Command
SQL> L
1* SELECT * from employees
SQL> c/employees/departments
1* SELECT * from departments
SQL> L
1* SELECT * from departments
121
SQL*Plus File Commands
SAVE filename
GET filename
START filename
@ filename
EDIT filename
SPOOL filename
EXIT
122
Using the SAVE and START Commands
SQL> L
1 SELECT last_name, manager_id, department_id
2* FROM employees
SQL> SAVE my_query
123
Summary
124
Exercise
125
Introduction to Logical Backup and Recovery
Objectives
127
Database Backup and Recovery
Two backup modes for ORACLE database:
Physical backup: It supports full recovery of database, but the database
must run in archivelog mode. Moreover, the backup is rather complicated,
and it requires the assistance of the recovery manager RMAN in backup
and recovery as well as mass external storage devices, for example, tape
library.
Logical backup: It does not require that the database run in the archivelog
mode. The backup work is simple, and no mass external storage devices
are required.
Logical backup of ORACLE database consists of three modes: table mode,
user mode, and full-database mode.
Closely related to backup, the recovery also consists of three modes: table
mode, user mode, and full-database mode.
128
Backup Tools
Backup Tool
EXPORT (Using the EXP command)
Recovery Tool
IMPORT (Using the IMP command)
129
Database Backup and Recovery
EXPORT Backup
In principle, the version of the backup program and recovery program (exp
and imp) must be same with the version of Server. We recommend the
backup shall be performed on the Server to ensure the consistency of
character set and software version. The following sample backup and
recovery statements directly run on the database server.
The backup or recovery operation cannot happen at the time when any
timing task of the database is going on; otherwise, the contention of
rollback segment or temp segment may lead to the failure of backup or
recovery operation.
We recommend that the backup operation be performed on the time when
the system is not busy to avoid the period when database writing
operations are frequent, for example, the backup operation can be
performed at 2:00 in the morning.
130
The Export Command
Syntax
exp keyword = (value, value2, ,valuen)
Example
exp hr/hr TABLES=(employees,departments) rows=y
file=exp1.dmp
131
Database Backup and Recovery
Table Mode
Table mode is used to back up a designated object in a certain user
mode (such as table, index, constraint, and so on).
To back up the object to the local hard disk of the host, use the
following command:
exp ring/ring rows=y indexes=n compress=n buffer=1024000
direct=y feedback=100000 file=exp_ring_tables_yyyymmdd.dmp
log=exp_ring_tables_yyyymmdd.log
tables=RBT_ADMININFO,RBT_CONFIG
132
Database Backup and Recovery
User Mode
User mode is used to back up all objects under a certain
user mode.
To back up the objects to the local hard disk of the host,
use the following command:
exp ring/ring rows=y indexes=n compress=n
buffer=1024000 direct=y feedback=100000
file=exp_ring_yyyymmdd.dmp
log=exp_ring_yyyymmdd.log
133
Command Line of the Import Tool
Syntax
imp keyword = value or keyword = (value, value2, value n)
Example
imp hr/hr TABLES=(employees,departments) rows=y
file=exp1.dmp
134
Database Backup and Recovery
IMPORT Recovery
Table Mode
It is to recover from the data backed up in the table
mode.
To recover from a local file, use the following command:
imp ring/ring rows=y indexes=n ignore=n commit=y
buffer=1024000 feedback=100000
file=exp_ring_tables_yyyymmdd.dmp
log=imp_ring_tables_yyyymmdd.log
tables=RBT_ADMININFO,RBT_CONFIG
135
Database Backup and Recovery
IMPORT Recovery
User Mode
It is to recover from the data backed up in the user
mode.
To recover from a local file, use the following command:
imp ring/ring rows=y indexes=n ignore=n commit=y
buffer=1024000 file=exp_ring_yyyymmdd.dmp
log=imp_ring_yyyymmdd.log
136
Database Backup and Recovery
IMPORT Recovery
The ignore parameter
During the recovery of Oracle database, if it is to recover a table that
already exists, the Oracle server will then determine the operation
according to the settings of the ignore parameter.
If ignore=y, Oracle server will not execute the CREATE TABLE
statement, and it will insert data in the table instead. If records to be
inserted are against the constraints, for example, primary key
constraint, the error record will not be inserted, but conforming
records will be added to the table.
If ignore=n, Oracle server will not execute the CREATE TABLE
statement, nor will it insert data in the table. It will ignore the table
error and recover the next table.
The indexes parameter
During data recovery, if indexes=n the indexes of the table will
not be recovered, but the unique index corresponding to the primary
key will be recovered unconditionally to ensure data integrity.
137
Database Backup and Recovery
Regular Backup of cron Scripts
Set the backup time for the cron scripts to 2:00 each morning. It will
perform backup for all application data.
Definition steps:
Assign timing task authority to an Oracle user
Execute the crontab e command as an Oracle user to add a timing
task
Create the task script exp_cron.sh in the backup directory and note
to set such environment variables as ORACLE_HOME,
ORACLE_SID and PATH
Add execution authority to exp_cron.sh
Check whether the setting is correct with the crontab l command
after modification
138
Summary
139
Practice
140
Daily Database Check
Objectives
142
Daily Database Check
143
Daily Database Check
144
Daily Database Check
View SGA
The sum of individual buffers in the SGA must be less than half the physical memory
of the system.
Check the SGA of the database:
SQL>show sga
Check physical memory of the system:
Solaris:
$ /usr/sbin/prtconf |grep -i "Memory size"
HP:
$ grep Physical /var/adm/syslog/syslog.log
AIX:
$ /usr/sbin/lsattr -E -l sys0 -a realmem
145
Daily Database Check
Check rollback section competition
8i: The return value must be less than 2%. If this value is excessively
high, 8i needs manual creation of more rollback segments.
SQL> select 'The average of waits/gets is '||
round((sum(waits) / sum(gets)) * 100,2)||'%'
From v$rollstat;
9i: The Nospace value must be 0. If the non-zero values exist
continuously, it is recommended that the size of the rollback tablespace
be increased.
SQL>select distinct nospaceerrcnt as nospace
From v$undostat
Where begin_time>sysdate-(1/12);
146
Daily Database Check
Check Log File
During database running, query v$log_history to observe the
switching time of the log switch.
It is recommended that the online log be better switched every one
hour at non-peak period, and be switched every 20 minutes at
service summit.
SQL>select to_char(first_time,'yyyy-mm-dd hh24:mi:ss') change_time
from v$log_history;
CHANGE_TIME
-------------------
2004-04-06 10:02:52
2004-04-06 10:10:45
2004-04-06 10:17:01
147
Daily Database Check
Check tablespace
Check such information as the size, left space and used space
percentage of each tablespace
Especially when the left space of the service tablespace is less than
50M or the used space percentage is greater than 90%, consider
increasing the size of the tablespace.
SQL> select a.tablespace_name, a.bytes totalbytes, sum(b.bytes)
freebytes
from dba_data_files a, dba_free_space b
where a.file_id = b.file_id
group by a.tablespace_name, a.bytes ;
TABLESPACE_NAME TOTALBYTES FREEBYTES
-----------------------------------------
CWMLITE 20971520 11141120
148
Daily Database Check
149
Daily Database Check
150
Summary
151
Practice
152
Network Configuration
Objectives
Listener Management
Local Service Name Configuration
Handle Simple Connection Faults
154
Listener Process
Client Server
Listener
tnsnames.ora
sqlnet.ora
listener.ora
155
Configuring the listener.org File
156
Example of listener.ora
1. LISTENER =
2. (ADDRESS_LIST =
3. (ADDRESS= (PROTOCOL= TCP)(Host= stc-sun02)(Port= 1521))
)
4. SID_LIST_LISTENER =
5. (SID_LIST =
6. (SID_DESC =
7. (ORACLE_HOME= /home/oracle)
8. (GLOBAL_DBNAME = ORCL.us.oracle.com)
9. (SID_NAME = ORCL)
)
157
Listener Tool (LSNRCTL)
DOS prompt:
158
Listener Program Management
159
Configuring Local Network Service Name
160
Adding Service Name
161
Specifying Oracle Version
162
Inputting Database Service name
163
Network Protocol
164
Host Name and Listener Port
165
Test and Connection
166
Connection Test Result
167
Name Network Service
168
Saving
169
tnsnames.ora
MY_SERVICE.US.ORACLE.COM =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = stc-sun02.us.oracle.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = TEST.us.oracle.com)
)
)
170
sqlnet.ora
NAMES.DEFAULT_DOMAIN = us.oracle.com
NAMES.DIRECTORY_PATH= (TNSNAMES, HOSTNAME)
SQLNET.EXPIRE_TIME=0
sqlplus system/manager@MY_SERVICE
SQL*Plus: Release 9.0.0.0.0 - Beta on Tue Feb 27 10:11:00 2001
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Connected to:
Oracle9i Enterprise Edition Release 9.0.0.0.0 - Beta
JServer Release 9.0.0.0.0 - Beta
SQL>
171
Troubleshooting for Client
Common Faults:
172
Summary
Listener Management
Local Service Name Configuration
Three important configuration files:
listener.ora
Tnsnames.ora
Sqlnet.ora
173
Practice
174
Emergency Database Fault Handling
Objectives
176
Emergency Database Fault Handling
177
Emergency Database Fault Handling
178
Emergency Database Fault Handling
179
Emergency Database Fault Handling
180
Emergency Database Fault Handling
181
Emergency Database Fault Handling
Use ORACLE RDA to collect on-site information
RDA is a shell program developed by ORACLE. It is used to completely collect
environmental information of Oracle software, for reference of engineers in remote
fault diagnosis.
RDA installation: Set up an independent directory for RDA. Do not include the RDA of
the old version in the same directory.
After script execution, pack information reports in htm and txt form under the
RDA_Output directory and a .tar.Z of these files.
Precautions on the Use of RDA:
Confirm whether the database is started and can be connected.
Confirm the FTP process is in BIN mode, and no error occurs to download.
Confirm whether the sell file after decompression of tar has executable right.
182
Summary
183
Practice
184
Questions and Answers
185
Recommended Database References
186
Recommended Database Websites
187