Sunteți pe pagina 1din 34

5

Storage Enhancements

Copyright 2009, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to:


Use 4 KB sector disks
Employ data compression
Create a SQL Access Advisor analysis session using
Enterprise Manager
Create a SQL Access Advisor analysis session using
PL/SQL
Use deferred segment creation

5-2

Copyright 2009, Oracle. All rights reserved.

11.2

Supporting 4 KB Sector Disks

Emulation mode:
LBA0

LBA1

LBA2

LBA3

LBA4

LBA5

4096-byte physical sector

Native mode:

Logical sector

LBA0
4096-byte physical sector

Physical sector

5-3

Copyright 2009, Oracle. All rights reserved.

LBA6

LBA7

11.2

Using 4 KB Sector Disks

Emulation mode:
Native mode:
Recommended 4 KB block
Mandatory 4 KB block size
size for redo logs
for redo logs
Recommended 4 KB block
Mandatory 4 KB block size
size (or larger) for data files
(or larger) for data files
Not affected:
Control file block size: 16 KB

Data files

Control
files

Online redo
log files

Database
5-4

Copyright 2009, Oracle. All rights reserved.

Archived
log files

11.2

Specifying the Disk Sector Size


Specify the sector size for disk drives with the new
SECTOR_SIZE and BLOCKSIZE clauses of the following
commands:
CREATE DISKGROUP
ALTER DATABASE
CREATE DATABASE
CREATE CONTROL FILE

5-5

Copyright 2009, Oracle. All rights reserved.

11.2

Using the SECTOR_SIZE Clause

Create a disk group in ASM with a 4 KB sector size:


CREATE DISKGROUP mydgroup1 NORMAL REDUNDANCY
FAILGROUP mycontroller1 DISK
'/devices/diska1',
'/devices/diska2',
'/devices/diska3',
'/devices/diska4'
FAILGROUP mycontroller2 DISK
'/devices/diskb1',
'/devices/diskb2',
'/devices/diskb3',
'/devices/diskb4'
ATTRIBUTE 'sector_size'='4096';

5-6

Copyright 2009, Oracle. All rights reserved.

11.2

Creating a Database with 4 KB Sector Disks

No extra work
No GUI change
Default sector size based on hardware (not the earlier 512
bytes sectors)

CREATE DATABASE sample NORESETLOGS FORCE LOGGING


ARCHIVELOG
LOGFILE
GROUP 1 '$ORACLE_BASE/oradata/sample/redo01.log'
SIZE 100M BLOCKSIZE 4096,
GROUP 2 '$ORACLE_BASE/oradata/sample/redo02.log
SIZE 100M BLOCKSIZE 4096
DATAFILE
...

5-7

Copyright 2009, Oracle. All rights reserved.

11.2

Specifying BLOCKSIZE
ALTER DATABASE sample ADD LOGFILE GROUP 3
('$ORACLE_BASE/oradata/sample/redo03a.log',
'$ORACLE_BASE/oradata/sample/redo03b.log')
SIZE 500K BLOCKSIZE 4096;
CREATE CONTROLFILE REUSE DATABASE sample NORESETLOGS
FORCE LOGGING ARCHIVELOG

LOGFILE
GROUP 1 '$ORACLE_BASE/oradata/sample/redo01.log'
SIZE 100M BLOCKSIZE 4096,
GROUP 2 '$ORACLE_BASE/oradata/sample/redo02.log '
SIZE 100M BLOCKSIZE 4096
DATAFILE

5-8

Copyright 2009, Oracle. All rights reserved.

11.2

Determining Your Log File Block Size

Viewing the V$LOG or V$STANDBY_LOG views in the data


dictionary
New BLOCKSIZE column
SQL> desc v$log
Name
Null?
Type
--------------------------------- -------- -----------GROUP#
NUMBER
THREAD#
NUMBER
SEQUENCE#
NUMBER
BYTES
NUMBER
BLOCKSIZE
NUMBER
MEMBERS
NUMBER
ARCHIVED
VARCHAR2(3)
STATUS
VARCHAR2(16)
FIRST_CHANGE#
NUMBER
FIRST_TIME
DATE
5-9

Copyright 2009, Oracle. All rights reserved.

11.2

Performing an Offline Migration to 4 KB Disks

Premigration (4 KB disks, back up and shut down


Oracle Database 11g Release 2)
Migration:
1.
2.
3.
4.
5.
6.

5 - 10

Move backup files to 4 KB disks.


Mount database.
Add log file groups on 4 KB disks.
Confirm their status.
Open the database.
Switch logs to 4 KB log group.

Postmigration (Query log file status and drop old log


files)

Copyright 2009, Oracle. All rights reserved.

Quiz

You must use 4 KB log files on 4 KB native mode disks.


1. True
2. False

5 - 12

Copyright 2009, Oracle. All rights reserved.

Table Compression: Overview

Oracle Database 11g extends compression for OLTP


data.
Support for conventional DML operations
(INSERT, UPDATE, DELETE)

New algorithm significantly reduces write overhead.


Batched compression ensures no impact for most OLTP
transactions.

No impact on reads
Reads may actually see improved performance due to
fewer I/Os and enhanced memory efficiency.

5 - 13

Copyright 2009, Oracle. All rights reserved.

Table Compression Concepts

Inserts are again


uncompressed.

Uncompressed
data

Compressed
data

Data block

Header

PCTFREE reached
triggers compression.

PCTFREE
limit

Free
space

5 - 14

Inserts are
uncompressed.

Copyright 2009, Oracle. All rights reserved.

PCTFREE reached
triggers compression.

11.2
update

Compressing Table Data


Compression
Method

Compression
Ratio

CPU
Overhead

CREATE and
ALTER TABLE
Syntax

Basic
compression

High

Minimal

COMPRESS [BASIC] DSS

OLTP table
compression

High

Minimal

COMPRESS FOR
OLTP

5 - 15

Copyright 2009, Oracle. All rights reserved.

Typical
Apps

OLTP, DSS

Using OLTP Compression

11.2
changes

Requires database compatibility level at 11.1 or greater


New syntax extends the COMPRESS keyword:
COMPRESS [BASIC | FOR OLTP]
BASIC is the default: Refers to bulk-load operations from
prior releases
FOR OLTP: OLTP + direct loads

Enable compression for new tables:


CREATE TABLE t1 COMPRESS FOR OLTP;

Enable compression on an existing table:


ALTER TABLE t2 COMPRESS FOR OLTP;

Does not trigger compression on existing rows


5 - 17

Copyright 2009, Oracle. All rights reserved.

11.2

Using the Compression Advisor


A compression advisor helps to determine optimal
compression ratios.
The DBMS_COMPRESSION package includes the
GET_COMPRESSION_RATIO procedure.
BEGIN
DBMS_COMPRESSION.GET_COMPRESSION_RATIO ('USERS','SH','SALES',
NULL,DBMS_COMPRESSION.COMP_FOR_OLTP, blkcnt_cmp, blkcnt_uncmp,
rowcnt_cmp, rowcnt_uncmp, 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 = '||
blkcnt_uncmp/blkcnt_cmp||' to 1');
5 - 18

Copyright 2009, Oracle. All rights reserved.

Viewing Table Compression Information

*_TABLES views have new columns:


COMPRESSION: Indicates whether table compression is
enabled (ENABLED) or not (DISABLED)
COMPRESS_FOR: Type of compression

5 - 19

Copyright 2009, Oracle. All rights reserved.

SQL Access Advisor: Overview


What
partitions, indexes,
and MVs do I need
to optimize
my entire
workload?

Solution

SQL
Access
Advisor

DBA
Workload

No expertise
required

Component
of CBO
Provides
implementation
script

5 - 20

Copyright 2009, Oracle. All rights reserved.

SQL Access Advisor: Usage Model

SQL Access
Advisor
SQL cache
Workload

Hypothetical
STS
Filter
Options

Indexes

5 - 21

Materialized
views

Copyright 2009, Oracle. All rights reserved.

Materialized Partitioned
views log
objects

Possible Recommendations
Recommendation

Comprehensive

Limited

Add new (partitioned) index on table or materialized view.

YES

YES

Drop an unused index.

YES

NO

Modify an existing index by changing the index type.

YES

NO

Modify an existing index by adding columns at the end.

YES

YES

Add a new (partitioned) materialized view.

YES

YES

Drop an unused materialized view (log).

YES

NO

Add a new materialized view log.

YES

YES

Modify an existing materialized view log to add new


columns or clauses.

YES

YES

Partition an existing unpartitioned table or index.

YES

YES

5 - 22

Copyright 2009, Oracle. All rights reserved.

Using SQL Access Advisor

5 - 23

Copyright 2009, Oracle. All rights reserved.

SQL Access Advisor: PL/SQL Procedure Flow


Step 3
ADD_STS_REF
DELETE_STS_REF
EXECUTE_TASK
INTERRUPT/CANCEL_TASK
MARK_RECOMMENDATION
UPDATE_REC_ATTRIBUTES
GET_TASK_REPORT
GET_TASK_SCRIPT

Step 1
CREATE_TASK
UPDATE_TASK_ATTRIBUTES
DELETE_TASK
QUICK_TUNE
Task-dependent

Advisor-dependent

SQL
Access Advisor
task

Report/Scripts
SET_TASK_PARAMETER
RESET_TASK
Step 2
5 - 24

Copyright 2009, Oracle. All rights reserved.

SQL Access Advisor: PL/SQL Example

BEGIN
dbms_advisor.create_task(dbms_advisor.sqlaccess_advisor,'MYTASK');
END;

BEGIN
dbms_advisor.set_task_parameter('MYTASK','ANALYSIS_SCOPE','ALL');
dbms_advisor.set_task_parameter('MYTASK','MODE','COMPREHENSIVE');
END;

BEGIN
dbms_advisor.add_sts_ref('MYTASK','SH','MYSTS');
dbms_advisor.execute_task('MYTASK');
dbms_output.put_line(dbms_advisor.get_task_script('MYTASK'));
END;

5 - 25

Copyright 2009, Oracle. All rights reserved.

Temporary Tablespace Shrink

Sort segment extents are managed in memory after


being physically allocated.
This method can be an issue after big sorts are done.
To release physical space from your disks, you can
shrink temporary tablespaces:
Locally managed temporary tablespaces
Online operation
CREATE TEMPORARY TABLESPACE temp
TEMPFILE 'tbs_temp.dbf' SIZE 600m REUSE AUTOEXTEND ON MAXSIZE
UNLIMITED
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1m;
ALTER TABLESPACE temp SHRINK SPACE [KEEP 200m];
ALTER TABLESPACE temp SHRINK TEMPFILE 'tbs_temp.dbf';
5 - 26

Copyright 2009, Oracle. All rights reserved.

DBA_TEMP_FREE_SPACE
Lists temporary space usage information
Central point for temporary tablespace space usage
Column name

Description

TABLESPACE_NAME

Name of the tablespace

TABLESPACE_SIZE

Total size of the tablespace, in bytes

ALLOCATED_SPACE

Total allocated space, in bytes, including space that is currently


allocated and used and space that is currently allocated and
available for reuse

FREE_SPACE

Total free space available, in bytes, including space that is


currently allocated and available for reuse and space that is
currently unallocated

5 - 27

Copyright 2009, Oracle. All rights reserved.

Tablespace Option for Creating Temporary Table

Specify which temporary tablespace to use for your


global temporary tables.
Decide a proper temporary extent size.
CREATE TEMPORARY TABLESPACE temp
TEMPFILE 'tbs_temp.dbf' SIZE 600m REUSE AUTOEXTEND ON MAXSIZE
UNLIMITED
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1m;
CREATE GLOBAL TEMPORARY TABLE temp_table (c varchar2(10))
ON COMMIT DELETE ROWS TABLESPACE temp;

5 - 28

Copyright 2009, Oracle. All rights reserved.

11.2

Segment Creation on Demand

Segment creation is deferred until the first row is


inserted.
DEFERRED_SEGMENT_CREATION = TRUE (default)

CREATE TABLE

5 - 29

INSERT INTO
Save disk space
Improve installation time
of applications with
large schemas
Copyright 2009, Oracle. All rights reserved.

11.2

Creating Tables Without Segments


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
5 - 30

Copyright 2009, Oracle. All rights reserved.

11.2

Controlling Deferred Segment Creation


With DEFERRED_SEGMENT_CREATION parameter in the:
Initialization parameter file
ALTER SESSION command
ALTER SYSTEM command
With SEGMENT CREATION clause:
IMMEDIATE
DEFERRED (default in Oracle Database 11g Release 2)
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.


5 - 31

Copyright 2009, Oracle. All rights reserved.

11.2

Restrictions and Exceptions


Segment creation on demand:
Only for nonpartitioned heap tables and nonpartitioned
indexes
Not for IOTs, clustered tables, or other special tables
Not for tables in dictionary-managed tablespaces
Note: 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.

5 - 32

Copyright 2009, Oracle. All rights reserved.

11.2

Additional Automatic Functionality


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;

5 - 33

Copyright 2009, Oracle. All rights reserved.

Quiz
Which of the following statements are true for Oracle
Database 11g Release 2?
1. Deferred segment creation is always enabled. You
cannot control it.
2. You can control the deferred segment creation with the
SEGMENT CREATION clause of the CREATE TABLE
command.
3. Segment creation on demand is available for all types
of tables, including those owned by the SYS user.
4. Segment creation on demand is available for
nonpartitioned tables.

5 - 34

Copyright 2009, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:


Use 4 KB sector disks
Employ data compression
Create a SQL Access Advisor analysis session using
Enterprise Manager
Create a SQL Access Advisor analysis session using
PL/SQL
Use deferred segment creation

5 - 35

Copyright 2009, Oracle. All rights reserved.

Practice 5: Overview

This practice covers using table compression.

5 - 36

Copyright 2009, Oracle. All rights reserved.

S-ar putea să vă placă și