Oracle DBA Workshop I - Introduction
Oracle DBA Workshop I - Introduction
Introduction
Contents
Architectural Components
Managing an Oracle Instance
Managing Control File
Creating Data Dictionary Views and Standard Packages
Managing Redo Log Files
ManagingTablespaces and Data Files
Storage Structure and Relationships
Managing Rollback Segments
Managing Tables
Managing Indexes
Reorganizing Data
Architectural
Components
Objectives
After completing this lesson, you should be able to do the following:
Data Control
Parameter files files Redo Archived
file log files log files
Password
file
Database
Oracle Database Files
Archived
log files
Password
file
Database
Other Key Physical
Structures
Parameter
file
Archived
log files
Password
file
Database
Oracle Instance
An oracle instance:
Is a means to access an Oracle database
Always opens one and only one database
Instance
Shared Pool
SGA Memory
structures
Data Redo Log
Buffer Buffer
Cache
Parse:
Search for identical statement
Check syntax, object names, and privileges
Lock objects used during parse
Create and store execution plan
Execute: Identify rows selected
Fetch: Return rows to user process
Shared Pool
Shared Pool
Library
Cache
Data
dictionary
cache
The library cache contains the SQL statement text, parsed code
and execution plan
The data dictionary cache contains table, Column, and other
object definitions and privileges
The shared pool is sized by SHARED_POOL_SIZE
Database Buffer Cache
Data buffer
Cache
PGA
Processing DML Statement
User Shared Pool
process SGA
4 1 2
Server
3
process
Data Control
Redo
files files
1 log files
Database
Redo Log Buffer
Redo log
buffer
New
Table
image
Rollback Segment
DML statement
Before making a change, the server process saves the old data value into
a rollback segment. This before image is used to:
Undo the changes if the transaction is rolled back
Provide read consistency by ensuring that other transactions do not
see uncommitted changes made b the DML statement
Recover the database to a consistent state in case of failures
COMMIT Processing
Instance
Shared Pool
1 SGA
Database
Log Writer (LGWR)
Instance
Shared Pool
SGA LGWR writes when:
There is a commit
The redo buffer log
Data Redo Log
Buffer Buffer
Cache is one_third full
There is more than
LGWR 1 MB of redo
Before DBW0 writes
Data Control
Redo
files files
log files
Database
Other Instance Processes
Shared Pool
SGA
DBW0
writes when:
Data Redo Log
Buffer Buffer
Cache There are many
dirty buffers
There are few
DBW0
free buffers
Timeout occurs
Data Control Checkpoint occurs
files files Redo
log files
Database
SMON: System Monitor
ALERT
file
Trace
files
Data Control
Parameter files files Redo
file log files
Password
file Database
The Initialization
Parameter File Instance
Shared Pool
SGA Library
cache
Data Redo log
buffer buffer Data dict.
cache cahe
initU15.ora
Parameter Description
IFILE Name of another parameter file to be embedded within
the current parameter file. Up to three levels of nesting is
possible
LOG_BUFFER Number of bytes allocated to the redo log buffer in the SGA
SQL_TRACE Enable or disables the SQL trace facility for every user
session.
STARTUP PFILE=%ORACLE_HOME%\database\initDB01.ora
ALTER DATABASE
Command
Change the state of the database from NOMOUNT to
MOUNT:
Shutdown Mode A I T N
Allow new connections X X X X
Wait until current sessions end X X X 0
Wait until current transactions end X X 0 0
Force a checkpoint and close files X 0 0 0
Shutdown mode:
X NO
A Abort I Immediate
T Transactional N Normal 0 YES
Different Types of
SHUTDOWN
Transfer Shutdown Shutdown Shutdown
of Funds Normal Immediate Transactional
Check account
1 balances
Insert new Database
2 funds down
Remove funds
3 from old account
Database
4 Commit down
Database
5 Log out down
Dynamic Performance
Views
V$THREAD
V$CONTROLFILE
V$DATABASE
V$DATAFILE
V$DATAFILE_HEADER
Control file V$LOGFILE
Example
Dynamic Performance View
Description
(accessible in the
NOMOUNT stage)
V$OPTION Lists options that are installed with the Oracle server
V$CONTROLFILE Lists the names of the control files (Even though available,
this view returns no rows in NOMOUNT state.)
V$DATAFILE_HEADER Displays data file header information from the control file
STARTUP RESTRICT
USER_DUMP_DEST BACKGROUND_DUMP_DEST
Location of ALERT File
and the Trace Files
BACKGROUND_DUMP_DEST Defines the location of the background trace file and ALERT
file
USER_DUMP_DEST Defines where trace files will be created at the request of the
users
MAX_DUMP_FILE_SIZE Specified in O/S blocks; Limits the size of user trace files,
not the ALERT file or background trace files.
Guidelines
Other
database
files
Database
Data Dictionary Contents
The data dictionary provides information about:
Logical and physical database structure
Definitions and space allocations of objects
Integrity constraints
Users
Roles
Privileges
Auditing
Other information
Base Tables and Data
Dictionary Views
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
Data Dictionary Examples
General overview
- DICTIONARY - DICT_COLUMNS
Schema objects
- DBA_TABLES - DBA_TAB_COLUMNS
- DBA_OBJECTS - DBA_CONSTRAINTS
Space Allocation
- DBA_SEGMENTS - DBA_EXTENTS
- DBA_FREE_SPACE
Database Structure
- DBA_DATA_FILES
- DBA_ROLLBACK_SEGS
- DBA_TABLESPACES
Dynamic Performance
Tables
Virtual tables
Information accessed from:
- Memory
- Control file
Synonyms begin with V$
DBA uses to monitor and tune the database
Listed in V$FIXED_TABLE
Example: V$DATAFILE for data file information
Stored Program Units
PL/SQL
- Oracles procedural language extension to SQL
- Stored in the data dictionary
Java
- Stored in the data dictionary
- To execute, publish its call specification
External procedures
- Written in C
- Stored in a shared library
- To execute, publish the call specification
Stored PL/SQL Program
Units
A Package
Groups logically related PL/SQL types, items, and
subprograms
Has two parts:
- A specification describes its components
- A body implements the logic
Example: DBMS_SESSION.SET_ROLE
- Package: DBMS_SESSION
- Procedure: SET_ROLE
Executing a PL/SQL Program Unit
SQL> EXECUTE dbms_session.set_role(.)
Instance
Server
SGA
Shared pool
DBMS_SESSION
System Control
tablespace files
SET ROLE
Databases BEGIN
END;
Other Redo log
data files files
Package Specification and Body
EMP_PKG
package PROCEDURE hire...
specification
g_empno NUMBER;
Script Purpose
Convention Description
Disk 1 Disk 2
Control01.ctl Control01.ctl
Guidelines for Control
Files
You should:
- Multiplex the control file
- Include the full pathname in CONTROL_FILES
- Back up the control file after the database structure
changes
Control files:
- Are sized by CREATE DATABASE keywords
- Have a reusable section that can expand due to Recovery
Manager updates
Obtaining Information
V$CONTROLFILE
V$CONTROLFILE_RECORD_SECTION
Performance views from the control file:
- V$DATAFILE
- V$TEMPFILE
- V$TABLESPACE
- V$LOG
- Others
Summary
Database
Redo Log Groups and
Members
Control
files
Parameter Redo
file Data Log Archived
log files
Password
file
Files files
Without Archiving
Data control
files files
50 51 100 101
11 12
With Archiving
Data control
files files 99
50 51 100 101
11 12
Obtaining Information
About Archiving
SQL Command:
ARCHIVE LOG LIST;
V$DATABASE:
- NAME
- LOG_MODE
V$INSTANCE:
ARCHIVER
Obtaining Information
About Groups
V$THREAD:
GROUPS
CURRENT_GROUP#
SEQUENCE#
Obtaining Information
About Groups and
Members
V$LOG:
GROUP#
MEMBERS
STATUS
SEQUENCE#
BYTES
Obtaining Information About
Groups and Members
V$LOGFILE:
GROUP#
STATUS
MEMBER
Log Switches and
Checkpoints
Group 1 Group 2
How to Relocate or Rename
Online Redo Log Files
redo0101 redo0201
Group 1 Group 2
Cleaning Online Redo Log
Files
Example:
Group 1 Group 2 Group 3
Member Member
Specify UTL_FILE_DIR
Create a dictionary file
EXECUTE DBMS_LOGMNR_D.BUILD(v815dict.ora,
C:\ora815\admin\v815\log);
Specifying Log Files to Be Analyzed
Set up the V$LOGMNR_CONTENTS view:
Initialize a new list and specify the first log file.
EXECUTE DBMS_LOGMNR.ADD_LOGFILE(
c:\ora815\oradata\v815\redo01a.log,
DBMS_LOGMNR.NEW);
EXECUTE
DBMS_LOGMNR.START_LOGMNR(
DICTFILENAME=>
c:\ora815\oradata\v815\log\v815dict.ora);
Tracking Changes to a
Table
View V$LOGMNR_CONTENTS to track changes for the EMP table:
EXECUTE
DBMS_LOGMNR.END_LOGMNR;
Obtaining Information
About Logs Being
Analyzed
V$LOGMNR_DICTIONARY
V$LOGMNR_PARAMETERS
V$LOGMNR_CONTENTS
Summary
Control
files
Redo log
Data files files
Database
Database Storage Hierarchy
Database
Extent
Oracle OS block
block
System and Non-SYSTEM
Tablespaces
SYSTEM tablespace :
- Created with the database
- Contains the data dictionary
- Contains the SYSTEM rollback segment
Non-SYSTEM tablespaces:
- Separate segments
- Ease space administration
- Control amount of space allocated to a user
Creating Tablespaces
Create TABLESPACE app_data
DATAFILE ..\DISK4\app_data_01.dbf
SIZE 100M,
..\disk5\app_data_02.dbf
SIZE 100M
MINIMUM EXTENT 500K
DEFAULT STORAGE (INITIAL 500K
NEXT 500K
MAXEXTENTS 500
PCTINCREASE 0 );
Space Management in
Tablespaces
Dictionary -Managed tablespaces:
- Default technique
- Free extents recorded in data dictionary tables
Locally Managed tablespaces:
- Free extents recorded in bitmap
- Each bit corresponds to a block or group of blocks
- Bit value indicated free or used
Locally Managed Tablespaces
Create TABLESPACE user_data
DATAFILE ..\DISK2\user_data_01.dbf
SIZE 5OOM
EXTENT MANGEMENT LOCAL
UNIFORM SIZE 10M;
App_data_02.dbf
100M
100M
App_data_o1.dbf App_data_03.dbf
100M 200M
Enabling Automatic Extension of
Data Files
ALTER TABLESPACE app_data
ADD DATAFILE ..\DISK6\app_data_04.DBF
SIZE 200M
AUTOEXTEND ON
NEXT 10M
MAXSIZE 500M;
Tablespace APP_DATA
Tablespace APP_DATA
App_data_02.dbf App_data_03.dbf
100M 200M
App_data_01.dbf App_data_04.dbf
100M 100M
100M
Adding Data Files to a Tablespace
ALTER TABLESPACE app_data
ADD DATAFILE ..\Disk5\app_data_03.dbf
SIZE 200M;
Tablespace APP_DATA
App_data_01.dbf App_data_02.dbf
100M 100M
App_data_02.dbf 100M
Moving Data Files:
ALTER TABLESPACE
The tablespace must be offline.
The Target data files must exist
ALTER DATABASE
RENAME FILE ..\\DISK1\system_01.dbf
TO ..\DISK2\system_01.dbf;
Obtaining Tablespace
Information
Tablespace Information:
- DBA_TABLESPACES
- V$TABLESPACE
Data file information :
- DBA_DATA_FILES
- V$DATAFILE
Tempfile Information :
- DBA_TEMP_FILES
- V$TEMPFILE
Guidelines
Extent
Table
Table partition
Cluster
Index
Types of Segments
Rollback segment
Temporary Segment
Types of Segments
Lob Segment
LOB index
Nested
table
Bootstrap
Segment
Storage Clause Precedence
Oracle Default
Tablespace
Segment
Extent Allocation and Deallocation
Allocated when the segment is :
- Created
- Extended
- Altered
Deallocated when the segment is :
- Dropped
- Altered
- Truncated
- Automatically resized(rollback segments only)
Used and Free Extents
Data file
Header
Free Space
Data
Block Space Utilization Parameters
INITRANS
MAXTRANS
PCTFREE
PCTUSED
BLOCK Space Usage
PCTFREE=20 PCTFREE=20
Inserts
80 %
Inserts
1 2
80 %
Inserts
Inserts 40 %
4
3
Data Dictionary Views
Tablespaces DBA_TABLESPACES
Querying DBA_SEGMENTS
General Information Storage Settings
- OWNER - INITIAL_EXTENT
- SEGMENT_NAME - NEXT_EXTENT
- SEGMENT_TYPE - MIN_EXTENTS
- - MAX_EXTENTS
TABLESPACE_NAME - PCT_INCREASE
SIZE
- EXTENTS Other Information
- BLOCKS - Location
- BYTES - Tuning
Querying DBA_EXTENTS
Location
Identification
-
- OWNER
TABLESPACE_NAME
- SEGMENT_NAME
- RELATIVE_FNO
- EXTENTS_ID
- FILE_ID
- BLOCK_ID
SIZE
- BLOCKS
- BYTES
Querying DBA_FREE_SPACE
Location
- TABLESPACE_NAME
- RELATIVE_FNO
- BLOCK_ID
SIZE
- BYTES
- BLOCKS
Organizing Tablespaces Based on
Fragmentation Propensity
Tablespace Usage Fragmentation
SYSTEM Data dictionary Zero
TOOLS Applications Very low
DATAN Data Segments Low
Indexn Index Segments Low
RBSn Rollback Segments High
New
Table
Image
Rollback Segment
Update transaction
Rollback Segments:
Purpose
Transaction rollback
Read
Rollback segment
consistency
Transaction
recovery
Read consistency
Table SELECT *
FROM TABLE
New image
Image at start of statement
Types of Rollback Segments
1 2
4 3
Transaction 1 Transaction 2
1 2 1 2
5 3
4 3
4
Inactive extent
Shrinkage of Rollback Segments
6 1 1 22
2
5
6 3
4 3
OPTIMAL
Active extent
Inactive extent
Creating Rollback Segments
ROLLBACK_SEGMENTS=(rbs01, rbs02)
How Instances Acquire Rollback
Segments
Acquire Compute
Are there
named required No
enough
private number
RBS ?
RBS of RBS
Yes
Acquire
public
rollback
segments
V$ROLLNAME V$ROLLSTAT
USN USN
NAME EXTENTS
RSSIZE
XACTS
OPTSIZE
HWMSIZE
AVEACTIVE
STATUS
CUREXT
CURBLK
Rollback Segment: Current
Activity
V$SESSION V$TRANSACTION
SADDR SES_ADDR
USERNAME XIDUSN
SID UBAFIL
SERIAL# UBABLK
UBASQN
UBAREC
STATUS
USED_UBLK
USED_UREC
Planning Rollback Segments:
Number
OLTP
- Many small rollback segments
- Four transactions per rollback segment
- Up to ten transactions per rollback segment
Batch
- Few Large rollback segments
- One per transaction
Planning Rollback
Segments:
Number of Extents
0.50
Probability
0.40
of extending
0.30
0.20
0.10
0.00
0 10 20 30 40
Number of extents
Rollback Segment
Problems
New image
Image at statement commencement
Blocking Session
Blocking
session
1 1 2
4
5 3
3 2 4
Existing Extent
New extent
Error in Taking a Tablespace
Offline
Cannot take tablespace containing active RBS offline
1. Determine which rollback segments are in the
tablespace
2. Take all of these rollback segments offline
3. Find active transactions using these rollback segments
4. Find the session ID and serial number
5. Terminate the session if necessary
6. Take the tablespace offline
Summary
Regular table
Partitioned table
User-defined Built-in
ROWID format
Nested Table
VARRAY
Creating a Table
CREATE TABLE employee(
id NUMBER(7),
last_name VARCHAR2(25),
dept_id NUMBER(7))
PCTFREE 20 PCTUSED 50
STORAGE (INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE DATA;
Temporary Tables
The rows are private to the session
Pointer
Changing Storage and Block
utilization Parameter
UNUSED_BLOCKS
Extents ID 0 1 2 3 4
High-water mark
LAST_USED_EXTENT_FILE_ID,
LAST_USED_EXTENT_BLOCK_ID
Deallocation of Unused Space
Before deallocation
Extents ID 0 1 2 3 4
Free Space
High- Water
Mark
Dropping a Table
OWNER
SEGMENT_NAME
EXTENT_ID
FILE_ID
BLOCK_ID
BLOCKS
Summary
In this lesson,you should have learned how to :
Logical
- Single column or concatenated
- Unique or nonunique
- Function-based
Physical
- Partitioned or nonpartitioned
- B-tree
- Normal or reverse key
- Bitmap
B-Tree Index
Index entry
Root
Branch
Leaf
Index entry header
Key column Length
Key Column Value
ROWID
Reverse key index
Key ROWID
ID FIRST_NAME JOB
ID (BLOCK ROW# FILE #)
7499 ALLEN SALESMAN
1257 0000000F.0002.0001
7369 SMITH CLERK
2877 0000000F.0006.0001 7521 WARD SALESMAN
7566 BLAKE MANAGER
4567 0000000F.0004.0001
7654 MARTIN SALESMAN
6657 0000000F.0003.0001 7698 BLAKE MANAGER
7782 CLARK MANAGER
8967 0000000F.0005.0001
9637 0000000F.0001.0001
. .
9947 0000000F.0000.0001
Creating Function-Based Indexes
Block 11
Block 12
start end
Key ROWID ROWID bitmap
< Blue, 10.03, 12.8.3, 1000100100010010100>
<Green, 10.0.3, 12.8.3, 0001010000100100000>
<Red, 10.0.3,12.8.3, 0100000011000001001>
<Yellow,10.03,12.8.3, 0010001000001000010>
Comparing B-tree and Bitmap Indexes
B-Tree Bitmap
CREATE INDEX
summit.employee_last_name_idx
ON summit.employee(last_name)
PCTREE 3O
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx;
Creating Indexes :Guidelines
Balance query and DML needs
Place in separate tablespace
Use uniform extent sizes:Multiples of five block
or MINIMUM EXTENT size for tablespace
Consider NOLOGGING for large indexes
Set high PCTFREE if new key values are likely
to be within the current range
Create Reverse Key Indexes
Create UNIQUE INDEX summit.orders_id_idx
ON summit.orders(id) REVERSE
PCTFREE 30
STORAGE(INITIAL 200K NEXT 200K
PCTINCREASE 0 MAXEXTENTS 50)
TABLESPACE indx
Creating Bitmap Indexes
Use the parameter CREATE_BITMAP_AREA_SIZE to
specify the amount of memory allocated for bitmap
creation.
ALTER INDEX
summit.employee_last_name_idx
STORAGE (NEXT 400k MAXEXTENTS 100);
Allocating and Deallocating Index
Space
DROP INDEX
summit.department_name_idx;
Obtaining Index Information
DBA_INDEXES DBA_IND_COLUMNS
OWNER INDEX_OWNER
INDEX_NAME INDEX_NAME
INDEX_TYPE TABLE_OWNER
TABLE_OWNER TABLE_NAME
TABLE_NAME COLUMN_NAME
UNIQUENESS COLUMN_POSITION
TABLESPACE_NAME COLUMN_LENGTH
LOGGING
STATUS
Summary
In this lesson,you should have learned how to :
Export
Data Files
OS File
Import
Uses of Export and Import
Reorganize tables
Move data owned by one user to another user
Move data between databases :
- Development to production
- OLTP system to a data warehouse
Migrate the database to a different
- OS platform
- Release of the Oracle database
Repeat test runs during development or
upgrade
Perform a logical backup
Export Modes
Database
Using Export
emp.dmp
export
DEPT and
EMP tables
Exp.log
Using Import
Imp.log
emp.dmp Import
Database
Import Behavior
Order of Import :
Table -> Data -> B-Tree indexes -> constraints,
triggers, bitmap indexes
Tablespace used for the object :
- Same tablespace as in the source database,
if possible
- Users default tablespace
Export and Import Guidelines
Database
Character Set Import
Import client
Character Set
Datawarehouse
staging
Information
Distribution
Transporting Tablespaces
System 1 System 2
/disk1
/u/d1 s980501.dmp
/u/d2 /disk2
SALES_TS SALES_TS
/u/d1/sales1.dbf \disk1\sales01.dbf
/u/d2/sales2.dbf \disk2\sales02.dbf
Read Only
Transportable Tablespaces :
Uses