5Copyright © 2009, Oracle. All rights reserved.
Storage Enhancements
Copyright © 2009, Oracle. All rights reserved.5 - 2
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
Copyright © 2009, Oracle. All rights reserved.5 - 3
Supporting 4 KB Sector Disks
• Emulation mode:LBA0 LBA1 LBA2 LBA3 LBA4 LBA5 LBA6 LBA7
4096-byte physical sector
• Native mode:
LBA0
4096-byte physical sector
Logical sector
Physical sector
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 4
Using 4 KB Sector Disks
Emulation mode:• Recommended 4 KB block
size for redo logs • Recommended 4 KB block
size (or larger) for data files
Native mode:• Mandatory 4 KB block size
for redo logs • Mandatory 4 KB block size
(or larger) for data filesNot affected:• Control file block size: 16 KB
Database
Data filesControl
filesOnline redo
log filesArchived log files
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 5
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
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 6
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';
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 7
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 ARCHIVELOGLOGFILE GROUP 1 '$ORACLE_BASE/oradata/sample/redo01.log'
SIZE 100M BLOCKSIZE 4096, GROUP 2 '$ORACLE_BASE/oradata/sample/redo02.log‘
SIZE 100M BLOCKSIZE 4096DATAFILE...
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 8
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 4096DATAFILE
…
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 9
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
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 10
Performing an Offline Migration to 4 KB Disks
• Premigration (4 KB disks, back up and shut down Oracle Database 11g Release 2)
• Migration:1. Move backup files to 4 KB disks.
2. Mount database.
3. Add log file groups on 4 KB disks.
4. Confirm their status.
5. Open the database.
6. Switch logs to 4 KB log group.
• Postmigration (Query log file status and drop old log files)
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 12
Quiz
You must use 4 KB log files on 4 KB native mode disks.
1. True
2. False
Copyright © 2009, Oracle. All rights reserved.5 - 13
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.
Copyright © 2009, Oracle. All rights reserved.5 - 14
Table Compression Concepts
Header
Un
com
pre
ssed
dat
aCompressed
data
Freespace Inserts are
uncompressed.
PCTFREE reachedtriggers compression.
Inserts are againuncompressed.
PCTFREE reachedtriggers compression.
Data block
PCTFREElimit
Copyright © 2009, Oracle. All rights reserved.5 - 15
Compressing Table Data
Compression Method
Compression Ratio
CPU Overhead
CREATE and ALTER TABLE Syntax
Typical Apps
Basic compression
High Minimal COMPRESS [BASIC] DSS
OLTP table compression
High Minimal COMPRESS FOR OLTP
OLTP, DSS
11.2 update
Copyright © 2009, Oracle. All rights reserved.5 - 17
Using OLTP Compression
• 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:
• Enable compression on an existing table:
– Does not trigger compression on existing rows
CREATE TABLE t1 COMPRESS FOR OLTP;
ALTER TABLE t2 COMPRESS FOR OLTP;
11.2 changes
Copyright © 2009, Oracle. All rights reserved.5 - 18
Using the Compression Advisor
• A compression advisor helps to determine optimal compression ratios.
• The DBMS_COMPRESSION package includes the GET_COMPRESSION_RATIO procedure.
11.2
BEGINDBMS_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');
Copyright © 2009, Oracle. All rights reserved.5 - 19
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
Copyright © 2009, Oracle. All rights reserved.5 - 20
SQL Access Advisor: Overview
Workload
SQL Access Advisor
Solution
Component of CBO
Provides implementation
script
No expertiserequired
DBA
Whatpartitions, indexes, and MVs do I need
to optimizemy entire
workload?
Copyright © 2009, Oracle. All rights reserved.5 - 21
SQL Access Advisor: Usage Model
Indexes Materializedviews
Materializedviews log
SQL Access Advisor
Hypothetical
SQL cache
Filter Options
STS
Workload
Partitionedobjects
Copyright © 2009, Oracle. All rights reserved.5 - 22
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
Copyright © 2009, Oracle. All rights reserved.5 - 23
Using SQL Access Advisor
Copyright © 2009, Oracle. All rights reserved.5 - 24
SQL Access Advisor: PL/SQL Procedure Flow
SQLAccess Advisor
task
CREATE_TASKUPDATE_TASK_ATTRIBUTESDELETE_TASKQUICK_TUNE
SET_TASK_PARAMETERRESET_TASK
ADD_STS_REFDELETE_STS_REFEXECUTE_TASKINTERRUPT/CANCEL_TASKMARK_RECOMMENDATIONUPDATE_REC_ATTRIBUTES GET_TASK_REPORTGET_TASK_SCRIPT
Step 1
Step 2
Step 3
Report/Scripts
Task-dependent
Advisor-dependent
Copyright © 2009, Oracle. All rights reserved.5 - 25
SQL Access Advisor: PL/SQL Example
BEGIN dbms_advisor.create_task(dbms_advisor.sqlaccess_advisor,'MYTASK'); 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;
1
3
BEGINdbms_advisor.set_task_parameter('MYTASK','ANALYSIS_SCOPE','ALL'); dbms_advisor.set_task_parameter('MYTASK','MODE','COMPREHENSIVE'); END;
2
Copyright © 2009, Oracle. All rights reserved.5 - 26
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 UNLIMITEDEXTENT MANAGEMENT LOCAL UNIFORM SIZE 1m;
ALTER TABLESPACE temp SHRINK SPACE [KEEP 200m];
ALTER TABLESPACE temp SHRINK TEMPFILE 'tbs_temp.dbf';
Copyright © 2009, Oracle. All rights reserved.5 - 27
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
Copyright © 2009, Oracle. All rights reserved.5 - 28
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 UNLIMITEDEXTENT MANAGEMENT LOCAL UNIFORM SIZE 1m;
CREATE GLOBAL TEMPORARY TABLE temp_table (c varchar2(10)) ON COMMIT DELETE ROWS TABLESPACE temp;
Copyright © 2009, Oracle. All rights reserved.5 - 29
Segment Creation on Demand
• Segment creation is deferred until the first row is inserted.
• DEFERRED_SEGMENT_CREATION = TRUE (default)
CREATE TABLE INSERT INTO
• Save disk space
• Improve installation time
of applications with
large schemas
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 30
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
SQL> INSERT INTO seg_test VALUES(1, 'aaaaaaa');1 row created.
SQL> SELECT segment_name FROM user_segments;
SEGMENT_NAME
-------------------------------------------------------
SEG_TEST
Inserting rows and creating segments:
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 31
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.
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 32
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.
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 33
Additional Automatic Functionality
• No segments for unusable indexes and index partitions
• Creating an index without a segmentCREATE INDEX test_i1 ON seg_test(c) UNUSABLE;
• Removing any allocated space for an indexALTER INDEX test_i UNUSABLE;
• Creating the segment for an index: ALTER INDEX test_i REBUILD;
11.2
Copyright © 2009, Oracle. All rights reserved.5 - 34
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.
Copyright © 2009, Oracle. All rights reserved.5 - 35
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
Copyright © 2009, Oracle. All rights reserved.5 - 36
Practice 5: Overview
This practice covers using table compression.
Top Related