Managing Storage
Copyright © 2006, Oracle. All rights reserved.
• Space
Objectives
•
•
•
•
Management
Proactive
Monitoring
Seg. Advisor
& Seg.Shrink
Resumable
Allocation
Transportable
TBS and DB
After completing this lesson, you should be
able to:
• Describe how the Oracle database automatically
manages space
• Proactively monitor and manage tablespace space
usage
• Use the Segment Advisor
• Reclaim wasted space from tables and indexes by
using the segment shrink functionality
• Manage resumable space allocation
• Describe the concepts of transportable
tablespaces and databases
11-2
Copyright © 2006, Oracle. All rights reserved.
Space Management: Overview
Space is automatically managed by the Oracle
database. It generates alerts about potential problems
and recommends possible solutions. Features include:
• Oracle Managed Files (OMF)
• Free-space management with bitmaps (“locally
managed”) and automatic data file extension
• Proactive space management (default thresholds
and server-generated alerts)
• Space reclamation (shrinking segments, online
table redefinition)
• Capacity planning (growth reports)
11-3
Copyright © 2006, Oracle. All rights reserved.
Free Space Management
BMB
BMB
BMB
BMB
BMB
…
BMB
…
…
BMB
…
…
…
…
…
…
…
Data
block
…
Extent
•
•
Automatic
Enabled by the use
of locally managed
tablespaces
• Tracked by bitmaps
in segments
Benefits:
• More flexible space
utilization
• Run-time adjustment
• Multiple process
search of BMBs
Segment
11-4
Copyright © 2006, Oracle. All rights reserved.
Types of Segments
A segment is a set of extents allocated for a certain
logical structure. The different types of segments are:
• Data segment
• Index segment
• Temporary segment
Segments are dynamically allocated by the database.
11-5
Copyright © 2006, Oracle. All rights reserved.
Allocating Extents
•
•
Searching the data file’s bitmap for the required
number of adjacent free blocks
Sizing extents with storage clauses:
– UNIFORM
– AUTOALLOCATE
•
•
11-6
Viewing extent map
Obtaining deallocation
advice
Copyright © 2006, Oracle. All rights reserved.
Block Space Management
PCTFREE = 10
FS2
FS3
FS1
FS1
FS2
Inserts,
updates
FS3
Deletes
Deletes
FS4
Full block
11-7
Full block
Copyright © 2006, Oracle. All rights reserved.
Row Chaining and Migration
Example:
• On update: Row length increases,
exceeding the available free space in
the block.
• Data needs to be stored in a new
block.
• Original physical identifier of row
(ROWID) is preserved.
•
•
11-8
The Oracle database needs to read two
blocks to retrieve data.
The Segment Advisor finds segments
containing the migrated rows.
Copyright © 2006, Oracle. All rights reserved.
Old
Original block
with pointer
to migrated
row
New data
Proactive Tablespace Monitoring
11-9
Copyright © 2006, Oracle. All rights reserved.
Space
Management
> Proactive
.
Monitoring
Seg. Advisor
& Seg.Shrink
Resumable
Allocation
Transportable
TBS and DB
.
Thresholds and
Resolving Space Problems
97% full or 5 MB left
critical
Alert
85% full or 100 MB left
warning
Locally managed tablespace
DBA
Resolve space
problem
Resolve space problem by:
• Adding or resizing data file
• Setting AUTOEXTEND ON
11-10
•
•
Shrinking objects
Reducing UNDO_RETENTION
•
Checking for long-running queries in temporary
tablespaces
Copyright © 2006, Oracle. All rights reserved.
Monitoring Tablespace Space Usage
Check every 10 min.
Alert
97% Critical
Cleared
85% Warning
Cleared
Alert
MMON
•
•
•
•
11-11
Read-only and offline tablespaces: Do not set up alerts.
Temporary tablespace: Threshold corresponds to
space currently used by sessions.
Undo tablespace: Threshold corresponds to space
used by active and unexpired extents.
Autoextensible files: Threshold is based on the
maximum file size.
Copyright © 2006, Oracle. All rights reserved.
Shrinking Segments
Space
Management
Proactive
Monitoring
> Seg. Advisor
& Seg.Shrink
Resumable
Allocation
Transportable
TBS and DB
HWM
1
ALTER TABLE employees SHRINK SPACE COMPACT;
HWM
DML operations and queries can be issued during compaction.
2
ALTER TABLE employees SHRINK SPACE;
HWM
DML operations are blocked when the HWM is adjusted.
11-12
Copyright © 2006, Oracle. All rights reserved.
Results of Shrink Operation
•
•
•
•
•
Improved performance and space utilization
Indexes maintained
Triggers not executed
Number of migrated rows may be reduced
Rebuilding secondary indexes on IOTs
recommended
Index
Table
Shrink
Triggers not executed
11-13
Copyright © 2006, Oracle. All rights reserved.
DBA
Space Reclamation with ASSM
•
•
•
Online and in-place operation
Applicable only to segments residing in ASSM
tablespaces
Candidate segment types:
–
–
–
–
11-14
Heap-organized tables and index-organized tables
Indexes
Partitions and subpartitions
Materialized views and materialized view logs
Copyright © 2006, Oracle. All rights reserved.
Segment Advisor: Overview
11-15
Copyright © 2006, Oracle. All rights reserved.
Segment Advisor
11-16
Copyright © 2006, Oracle. All rights reserved.
Implementing Recommendations
11-18
Copyright © 2006, Oracle. All rights reserved.
Database Control and Segment Shrink
11-19
Copyright © 2006, Oracle. All rights reserved.
Shrinking Segments by Using SQL
ALTER … SHRINK SPACE [CASCADE]
TABLE [OVERFLOW]
INDEX
MODIFY PARTITION
MATERIALIZED VIEW
MATERIALIZED VIEW LOG
MODIFY SUBPARTITION
MODIFY LOB
ALTER TABLE employees ENABLE ROW MOVEMENT;
1
ALTER TABLE employees SHRINK SPACE CASCADE;
2
ALTER TABLE employees MODIFY LOB(resume) (SHRINK SPACE);3
ALTER TABLE employees OVERFLOW SHRINK SPACE;
11-20
Copyright © 2006, Oracle. All rights reserved.
4
Managing Resumable
Space Allocation
Space
Management
Proactive
Monitoring
Seg. Advisor
& Seg.Shrink
> Resumable
Allocation
Transportable
TBS and DB
A resumable statement:
• Enables you to suspend large operations instead
of receiving an error
• Gives you a chance to fix the problem while the
operation is suspended, rather than starting over
• Is suspended for the following conditions:
– Out of space
– Maximum extents reached
– Space quota exceeded
11-21
Copyright © 2006, Oracle. All rights reserved.
Using Resumable Space Allocation
•
•
•
Queries, DML operations, and certain DDL
operations can be resumed if they encounter an
out-of-space error.
A resumable statement can be issued through
SQL, PL/SQL, SQL*Loader, or the Oracle Call
Interface (OCI).
To run a resumable statement, you must first
enable resumable statements for your session.
ALTER SESSION ENABLE RESUMABLE;
INSERT INTO sales_new SELECT * FROM sh.sales;
ALTER SESSION DISABLE RESUMABLE;
11-22
Copyright © 2006, Oracle. All rights reserved.
Resuming Suspended Statements
1
SQL statement
Full table
2
Suspended
Continue
SQL
operation
5
11-24
3
Table
with free
space
Optionally
AFTER
SUSPEND
trigger
Copyright © 2006, Oracle. All rights reserved.
4
Abort
Transporting Tablespaces
…
Resumable
Allocation
.
> Transportable TBS
Transportable DB
Concept: Cross-platform transportable tablespaces:
• Simplify data distribution between data warehouse
and data marts
• Allow database migration from one platform to
another
• Supported platforms:
Solaris[tm] OE (32-bit)
HP-UX (64-bit)
Microsoft Windows IA (64-bit)
Solaris[tm] OE (64-bit)
HP Tru64 UNIX
IBM zSeries Based Linux
Microsoft Windows IA (32-bit)
HP-UX IA (64-bit) Linux 64-bit for AMD
Linux IA (32-bit)
Linux IA (64-bit)
Apple Mac OS
AIX-Based Systems (64-bit)
HP Open VMS
Microsoft Windows 64-bit for AMD
Solaris Operating System (x86)
11-26
Copyright © 2006, Oracle. All rights reserved.
Concept: Minimum Compatibility Level
•
Both source and target databases must have
COMPATIBLE set to 10.0.0 or higher.
•
•
Data file headers are platform-aware.
Before transporting, make sure that all read-only
and offline files are platform-aware.
Read/
write
Read/
write
Readonly
Readonly
COMPATIBLE=9.2.0
11-27
Read/
write
Readonly
COMPATIBLE=10.0.0
Copyright © 2006, Oracle. All rights reserved.
Transportable Tablespace Procedure
Source
Make tablespaces read-only.
Use Data Pump to extract metadata.
Target
uses the same
endian format?
Yes
No
Convert data files
by using RMAN.
Ship data files and dump file to target.
Use Data Pump to import metadata.
Target
11-28
Make tablespaces read/write.
Copyright © 2006, Oracle. All rights reserved.
Determining the Endian Format
of a Platform
SELECT tp.endian_format
FROM
v$transportable_platform tp,
v$database d
WHERE tp.platform_name = d.platform_name;
Source
11-29
Target
Copyright © 2006, Oracle. All rights reserved.
Transporting Databases
•
•
•
…
Resumable
Allocation
Transportable TBS
> Transportable DB
Generalize the transportable tablespace feature.
Data can easily be distributed from a data
warehousing environment to data marts, which are
usually on smaller platforms.
A database can be migrated from one platform to
another very quickly.
Platform X
Platform Y
Same “endianness”
Database files transfer
Existing database
11-30
New database
Copyright © 2006, Oracle. All rights reserved.
Database Transportation Procedure:
Source System Conversion
Open database in READ ONLY mode
and COMPATIBLE=10.0.0
Readonly
CONVERT
DATABASE
TO PLATFORM
Readonly
Ship
files
Readonly
Source
system
11-31
Readonly
Target
system
Copyright © 2006, Oracle. All rights reserved.
Database Transportation Procedure:
Target System Conversion
Open database in READ ONLY mode
and COMPATIBLE=10.0.0
CONVERT
DATABASE
ON TARGET
Readonly
Ship
files
Readonly
Readonly
Target
system
Source
system
11-32
Readonly
Copyright © 2006, Oracle. All rights reserved.
Database Transportation: Considerations
•
•
•
•
11-33
Create the password file on the target platform.
Transport the BFILEs used in the source
database.
The generated pfile and transport script use OMF.
Use DBNEWID to change the DBID.
Copyright © 2006, Oracle. All rights reserved.
Summary
In this lesson, you should have learned how to:
• Use the Oracle database to automatically manage
space
• Proactively monitor and manage tablespace space
usage
• Use the Segment Advisor
• Reclaim wasted space from tables and indexes by
using the segment shrink functionality
• Manage resumable space allocation
• Describe the concepts of transportable
tablespaces and databases
11-34
Copyright © 2006, Oracle. All rights reserved.
Practice Overview:
Managing Storage
This practice covers the following topics:
• Using threshold alerts to proactively manage
tablespaces
• Using the Segment Advisor to shrink space
• Viewing alerts and alert history in SQL*Plus and
Enterprise Manager
11-35
Copyright © 2006, Oracle. All rights reserved.