0% found this document useful (0 votes)
5 views38 pages

D78846GC20 08

The document provides an overview of space management in Oracle Database, detailing automatic space management features, segment creation, and space reclamation techniques. It covers topics such as compression methods, deferred segment creation, and proactive monitoring of tablespace usage. Additionally, it discusses managing resumable space allocation and the use of the Segment Advisor for optimizing space utilization.

Uploaded by

ashupin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views38 pages

D78846GC20 08

The document provides an overview of space management in Oracle Database, detailing automatic space management features, segment creation, and space reclamation techniques. It covers topics such as compression methods, deferred segment creation, and proactive monitoring of tablespace usage. Additionally, it discusses managing resumable space allocation and the use of the Segment Advisor for optimizing space utilization.

Uploaded by

ashupin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Managing Space

Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Objectives

After completing this lesson, you should be able to:


• Describe how the Oracle Database server automatically
manages space
• Save space by using compression
• Proactively monitor and manage tablespace space usage
• Describe segment creation in the Oracle database
• Control deferred segment creation
• Use the Segment Advisor
• Reclaim wasted space from tables and indexes by using
the segment shrink functionality
• Manage resumable space allocation

8-2 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Space Management: Overview

Space is automatically managed by the Oracle Database


server. 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)

8-3 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Block Space Management

PCTFREE = 10

FS2

FS3

FS1
FS1

FS2
Inserts, Deletes Deletes
updates FS3

FS4
Full block Full block

8-4 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Row Chaining and Migration

Example:
• On update: Row length increases,
exceeding the available free space Old
in the block.
• Data needs to be stored in a new block. Original block
• Original physical identifier of row with pointer
(ROWID) is preserved. to migrated
row
• The Oracle Database server needs
to read two blocks to retrieve data.
• The Segment Advisor finds segments New data
containing the migrated rows.
• There is automatic coalescing of fragmented
free space inside the block.

8-5 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Quiz

When a row is chained or migrated, the I/O performance


associated with this row decreases because the Oracle
Database server must scan more than one data block to
retrieve the information for the row.
a. True
b. False

8-7 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Free Space Management Within Segments

BMB BMB BMB … BMB • Tracked by bitmaps in


segments
BMB BMB …
Benefits:
BMB …
• More flexible space
… utilization
• Runtime adjustment

• Multiple process
… … … … search of BMBs

Data
block …

Extent
Segment

8-8 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Types of Segments

• A segment is a set of extents allocated for a certain logical


structure. The different types of segments include:
– Table and cluster segments
– Index segment
– Undo segment
– Temporary segment
• Segments are dynamically allocated by the Oracle
Database server.

8-9 Copyright © 2014, Oracle and/or its affiliates. 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
• Viewing extent map
• Obtaining deallocation advice

8 - 10 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Understanding Deferred Segment Creation

• DEFERRED_SEGMENT_CREATION = TRUE is the default.


• Segment creation takes place as follows:
1. Table creation > Data dictionary operation
2. DML > Segment creation

CREATE TABLE INSERT INTO

• Saving disk space


• Improving installation time
of big applications

8 - 11 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Viewing Deferred Segment Information

SQL> SHOW PARAMETERS deferred_segment_creation


NAME TYPE VALUE
------------------------------------ ----------- ------
deferred_segment_creation boolean TRUE

SQL> CREATE TABLE seg_test(c number, d varchar2(500));


Table created.
SQL> SELECT segment_name FROM user_segments;
no rows selected

Inserting rows and creating segments:


SQL> INSERT INTO seg_test VALUES(1, 'aaaaaaa');
1 row created.

SQL> SELECT segment_name FROM user_segments;


SEGMENT_NAME
-------------------------------------------------------
SEG_TEST

8 - 12 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Controlling Deferred Segment Creation

With the DEFERRED_SEGMENT_CREATION parameter in the:


• Initialization file
• ALTER SESSION command
• ALTER SYSTEM command
With the SEGMENT CREATION clause:
• IMMEDIATE
• DEFERRED (default)
CREATE TABLE SEG_TAB3(C1 number, C2 number)
SEGMENT CREATION IMMEDIATE TABLESPACE SEG_TBS;
CREATE TABLE SEG_TAB4(C1 number, C2 number)
SEGMENT CREATION DEFERRED;

Note: Indexes inherit table characteristics.

8 - 13 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Restrictions and Exceptions

• Segment creation on demand is:


– Only for nonpartitioned tables and indexes
– Not for IOTs, clustered tables, or other special tables
– Not for tables in dictionary-managed tablespaces
• If you were to migrate a table without segments from a
locally managed to a dictionary-managed tablespace, you
must drop and re-create it.

8 - 14 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Additional Automatic Functionality

Without user intervention:


• No segments for unusable indexes and index partitions
• Creating an index without a segment:
CREATE INDEX test_i1 ON seg_test(c) UNUSABLE;
• Removing any allocated space for an index:
ALTER INDEX test_i UNUSABLE;
• Creating the segment for an index:
ALTER INDEX test_i REBUILD;

SELECT segment_name, partition_name, segment_type


FROM user_segments
WHERE segment_name like '%DEMO';

8 - 15 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Quiz

Which of the following statements are true?


a. Deferred segment creation is always enabled. You cannot
control it.
b. You can control the deferred segment creation with the
SEGMENT CREATION clause of the CREATE TABLE
command.
c. Segment creation on demand is available for all types of
tables, including those owned by the SYS user.
d. Segment creation on demand is available for
nonpartitioned tables.

8 - 16 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Table Compression: Overview

Reducing storage costs by compressing all data:


• Basic compression for direct-path insert operations: 10x
• Advanced row compression for all DML operations: 2–4x

Compression Compression CPU CREATE and ALTER Typical


Method Ratio Overhead TABLE Syntax Applications

Basic table High Minimal COMPRESS [BASIC] DSS


compression

Advanced row High Minimal ROW STORE COMPRESS OLTP, DSS


compression ADVANCED

8 - 17 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Compression for Direct-Path Insert Operations

• Is enabled with CREATE TABLE … COMPRESS BASIC …;


• Is recommended for bulk loading data warehouses
• Maximizes contiguous free space in blocks

Header
PCTFREE
=0
Uncompressed

Free
data

space

Compressed
data

Data block
Inserts are PCTFREE reached Inserts are again PCTFREE reached
uncompressed. triggers compression. uncompressed. triggers compression.

8 - 18 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Advanced Row Compression for DML Operations

• Is enabled with
CREATE TABLE … ROW STORE COMPRESS ADVANCED
…;
• Is recommended for active OLTP environments

G Y
Y Y Y Y Y Y
G Y G G Y G
G Y Y G G Y Y G
Uncompressed OLTP compression with symbol table at
block the beginning of the block

8 - 20 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Specifying Table Compression

You can specify table You cannot :


compression for: • Specify basic and
• An entire heap-organized advanced row compression
table on tables with more than
• A partitioned table (Each 255 columns
partition can have a • Drop a column if a table is
different type or level of compressed for direct-
compression.) loads, but you can drop it if
• The storage of a nested the table is advance row
table compressed

8 - 21 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Using the Compression Advisor

The Compression Advisor:


• Analyzes objects to give an estimate of space savings for
different compression methods
• Helps in deciding the correct compression level for an
application
• Recommends various strategies for compression
– Picks the right compression algorithm for a particular data
set
– Sorts on a particular column for increasing the compression
ratio
– Presents tradeoffs between different compression algorithms
• Works for OLTP compression (via Enterprise Manager)

8 - 22 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Using the DBMS_COMPRESSION Package

To determine optimal compression ratios:


BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO ('USERS','SH','SALES',
NULL,DBMS_COMPRESSION.COMP_FOR_OLTP, blkcnt_cmp, blkcnt_uncmp,
rowcnt_cmp, rowcnt_uncmp, comp_ration, comptype);
DBMS_OUTPUT.PUT_LINE('Blk count compressed = ' || blkcnt_cmp);
DBMS_OUTPUT.PUT_LINE('Blk count uncompressed = ' ||
blkcnt_uncmp);
DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' ||
rowcnt_cmp);
DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' ||
rowcnt_uncmp);
DBMS_OUTPUT.PUT_LINE('Compression type = ' || comptype);
DBMS_OUTPUT.PUT_LINE('Compression ratio = '||comp_ratio||' to
1');

8 - 23 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Proactive Tablespace Monitoring

8 - 24 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Thresholds and Resolving Space Problems

97% full or 5 MB left


critical
Alert
85% full or 100 MB left DBA
warning
Resolve space
Locally managed tablespace problem
Resolve space problem by:
• Adding or resizing data file
• Setting AUTOEXTEND ON
• Shrinking objects
• Reducing UNDO_RETENTION
• Checking for long-running queries in temporary
tablespaces

8 - 25 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Monitoring Tablespace Space Usage

97% Critical Cleared


Alert
85% Warning Cleared
Alert

MMON

• 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.
• Auto-extensible files: Threshold is based on the maximum
file size.
8 - 26 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Shrinking Segments

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.

8 - 27 Copyright © 2014, Oracle and/or its affiliates. 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
DBA

Triggers not executed

8 - 28 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Reclaiming Space Within ASSM Segments

• Online and in-place operation


• Applicable only to segments residing in ASSM tablespaces
• Candidate segment types:
– Heap-organized tables and index-organized tables
– Indexes
– Partitions and subpartitions
– Materialized views and materialized view logs

8 - 29 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Using the Segment Advisor

8 - 30 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Automatic Segment Advisor

The Automatic Segment Advisor:


• Is started by a Scheduler job set to run during the default
maintenance window:
– Weeknights, Monday–Friday, from 10:00 PM to 2:00 AM
– Saturday and Sunday, both windows start at 6:00 AM and
last for 20 hours
• Examines database statistics, samples segment data, and
then selects the following objects to analyze:
– Tablespaces that have exceeded a critical or warning
threshold
– Segments that have the most activity
– Segments that have the highest growth rate

8 - 31 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Shrinking Segments by Using SQL

ALTER … SHRINK SPACE [CASCADE][COMPACT]

TABLE [OVERFLOW] INDEX MATERIALIZED VIEW MATERIALIZED VIEW LOG

MODIFY PARTITION MODIFY SUBPARTITION MODIFY LOB

1 ALTER TABLE employees ENABLE ROW MOVEMENT;

2 ALTER TABLE employees SHRINK SPACE CASCADE;

ALTER TABLE employees MODIFY LOB(resume) (SHRINK


3 SPACE);

4 ALTER TABLE employees OVERFLOW SHRINK SPACE;

8 - 32 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Shrinking Segments by Using Enterprise Manager

8 - 33 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Managing Resumable Space Allocation

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
• A resumable statement can be suspended and resumed
multiple times.

8 - 34 Copyright © 2014, Oracle and/or its affiliates. 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, and Data Pump utilities, or the
Oracle Call Interface (OCI).
• A statement executes in resumable mode only if its
session has been enabled by one of the following actions:
– The RESUMABLE_TIMEOUT initialization parameter is set to a
nonzero value.
– An ALTER SESSION ENABLE RESUMABLE statement is
issued:
ALTER SESSION ENABLE RESUMABLE;
INSERT INTO sales_new SELECT * FROM sh.sales;
ALTER SESSION DISABLE RESUMABLE;

8 - 35 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Resuming Suspended Statements

1 SQL statement

Full table

2 Suspended

Continue
SQL 3 4
Optionally
operation

5 Table AFTER
with free SUSPEND Abort
space trigger

8 - 37 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


What Operations Are Resumable?

The following operations are resumable:


• Queries: SELECT statements that run out of temporary
space (for sort areas)
• DML: INSERT, UPDATE, and DELETE statements
• The following DDL statements:
– CREATE TABLE ... AS SELECT
– CREATE INDEX
– ALTER INDEX ... REBUILD
– ALTER TABLE ... MOVE PARTITION
– ALTER TABLE ... SPLIT PARTITION
– ALTER INDEX ... REBUILD PARTITION
– ALTER INDEX ... SPLIT PARTITION
– CREATE MATERIALIZED VIEW

8 - 39 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Quiz

Select the true statements about space management:


a. Segment creation in Oracle Database 12c is deferred for
all tables. There are no exceptions.
b. All UNUSABLE indexes and index partitions are created
without a segment.
c. Shrinking segment space is a nonresumable operation.
d. You can set thresholds by tablespace.

8 - 40 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Summary

In this lesson, you should have learned how to:


• Describe how the Oracle Database server automatically
manages space
• Save space by using compression
• Proactively monitor and manage tablespace space usage
• Describe segment creation in the Oracle database
• Control deferred segment creation
• Use the Segment Advisor
• Reclaim wasted space from tables and indexes by using
the segment shrink functionality
• Manage resumable space allocation

8 - 41 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.


Practice: Overview

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

8 - 42 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.

You might also like