39
13 Copyright © 2004, Oracle. All rights reserved. Monitoring and Managing Storage

Monitoring and Managing Storage

  • Upload
    pilar

  • View
    34

  • Download
    3

Embed Size (px)

DESCRIPTION

Monitoring and Managing Storage. Objectives. After completing this lesson, you should be able to: Tune redo writing and archiving operations Issue statements that can be suspended when encountering space condition errors - PowerPoint PPT Presentation

Citation preview

Page 1: Monitoring and Managing Storage

13Copyright © 2004, Oracle. All rights reserved.

Monitoring and Managing Storage

Page 2: Monitoring and Managing Storage

13-2 Copyright © 2004, Oracle. All rights reserved.

Objectives

After completing this lesson, you should be able to:• Tune redo writing and archiving operations

• Issue statements that can be suspended when encountering space condition errors

• Reduce space-related error conditions through proactively managing tablespace space usage

• Reclaim wasted space from tables and indexes using the segment-shrink functionality

• Estimate the size of new tables and indexes

• Use different storage options to improve performance of queries

• Rebuild indexes online

Page 3: Monitoring and Managing Storage

13-3 Copyright © 2004, Oracle. All rights reserved.

Online Redo Log File Configuration

• Size redo log files to minimize contention.

• Provide enough groups to prevent waiting.

• Store redo log files on separate, fast devices.

• Monitor the redo log file configuration with:

– V$LOGFILE– V$LOG– V$INSTANCE_RECOVERY

Page 4: Monitoring and Managing Storage

13-5 Copyright © 2004, Oracle. All rights reserved.

Redo Logfile Sizing Advisor

Page 5: Monitoring and Managing Storage

13-6 Copyright © 2004, Oracle. All rights reserved.

Increasing the Performance of Archiving

• Allow the LGWR process to write to a disk different from the one the ARCn process is reading.

• Share the archiving work during a temporary increase in workload:

• Increase the number of archive processes.

• Change archiving speed:

– LOG_ARCHIVE_MAX_PROCESSES– LOG_ARCHIVE_DEST_n

ALTER SYSTEM ARCHIVE LOG ALL

TO <log_archive_dest>

Page 6: Monitoring and Managing Storage

13-7 Copyright © 2004, Oracle. All rights reserved.

Resumable Statements

A resumable statement:

• Allows 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

Page 7: Monitoring and Managing Storage

13-8 Copyright © 2004, 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;

Page 8: Monitoring and Managing Storage

13-10 Copyright © 2004, Oracle. All rights reserved.

Resuming Suspended Statements

SQL statement EMPLOYEES table

Suspended

EMPLOYEES table

Free space

Used block

Continue SQL operation

AFTER SUSPENDtrigger

Abort

Page 9: Monitoring and Managing Storage

13-12 Copyright © 2004, Oracle. All rights reserved.

Proactive Tablespace Monitoring Overview

• Server-generated alerts inform you that:– Tablespaces are running low on available space– Segments are running out of space

• Data gathering and reporting provides:– Historical tablespace disk space usage– Segment growth trend analysis

Page 10: Monitoring and Managing Storage

13-13 Copyright © 2004, Oracle. All rights reserved.

Tablespace Space Usage Monitoring

• 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.• Tablespaces that can extend automatically: Threshold

is based on the maximum file size.

MMON

85% Warning

97% Critical

Check every 10 min.

Alert

AlertCleared

Cleared

Page 11: Monitoring and Managing Storage

13-14 Copyright © 2004, Oracle. All rights reserved.

Edit Tablespace Page

Page 12: Monitoring and Managing Storage

13-15 Copyright © 2004, Oracle. All rights reserved.

Segment Advisor Overview

Page 13: Monitoring and Managing Storage

13-16 Copyright © 2004, Oracle. All rights reserved.

Shrinking Segments: Overview

HWM

HWM

Shrinkoperation

DataUnusedspace

Data

Unusedspace

Reclaimed space

Page 14: Monitoring and Managing Storage

13-17 Copyright © 2004, Oracle. All rights reserved.

Shrinking Segments: Considerations

• 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

• Indexes are maintained.

• Triggers are not fired.

Page 15: Monitoring and Managing Storage

13-18 Copyright © 2004, Oracle. All rights reserved.

Database Control and Segment Shrink

Page 16: Monitoring and Managing Storage

13-19 Copyright © 2004, Oracle. All rights reserved.

Accessing the Segment Advisor

Page 17: Monitoring and Managing Storage

13-20 Copyright © 2004, Oracle. All rights reserved.

Segment Advisor

Page 18: Monitoring and Managing Storage

13-21 Copyright © 2004, Oracle. All rights reserved.

Shrinking Segments Using SQL

ALTER TABLE employees SHRINK SPACE CASCADE;

ALTER … SHRINK SPACE [COMPACT] [CASCADE]

TABLE INDEX MATERIALIZED VIEW MATERIALIZED VIEW LOG

MODIFY PARTITION

ALTER TABLE employees ENABLE ROW MOVEMENT; 1

2

MODIFY SUBPARTITION

Page 19: Monitoring and Managing Storage

13-22 Copyright © 2004, Oracle. All rights reserved.

Segment Shrink:Execution Considerations

• Use compaction only:– To avoid unnecessary cursor invalidation– During peak hours

• DML operations and queries can be issued during compaction.

• DML operations are blocked when the HWM is adjusted.

Page 20: Monitoring and Managing Storage

13-23 Copyright © 2004, Oracle. All rights reserved.

Segment Resource Estimation

Page 21: Monitoring and Managing Storage

13-24 Copyright © 2004, Oracle. All rights reserved.

Growth Trend Report

• Used by the Segment Advisor

• Space usage statistics are collected into AWR

Page 22: Monitoring and Managing Storage

13-25 Copyright © 2004, Oracle. All rights reserved.

Monitoring Index Space

• To collect usage statistics regarding an index:

• To view statistics collected:

• Rebuild indexes with wastage greater than 20%:

• To coalesce indexes (alternative to REBUILD):

SQL> EXECUTE dbms_stats.gather_index_stats -> ('OE','CUSTOMERS_PK');

SQL> ALTER INDEX oe.customers_pk REBUILD;

SQL> SELECT name, 2 (DEL_LF_ROWS_LEN/LF_ROWS_LEN) * 100 AS wastage 3 FROM index_stats;

SQL> ALTER INDEX oe.customers_pk COALESCE;

Page 23: Monitoring and Managing Storage

13-26 Copyright © 2004, Oracle. All rights reserved.

Monitoring Index Space Usage

Actual Predicted

Page 24: Monitoring and Managing Storage

13-27 Copyright © 2004, Oracle. All rights reserved.

Deciding Whether to Rebuildor Coalesce an Index

Rebuild Coalesce

Quickly moves index to Cannot move index to another tablespace another tablespace

Higher costs: Requires more Lower costs: Does not disk space require more disk space

Creates new tree, shrinks Coalesces leaf blocks within height if applicable same branch of tree

Enables you to quickly change Quickly frees up index storage and tablespace leaf blocks for use parameters without having todrop the original index

Page 25: Monitoring and Managing Storage

13-28 Copyright © 2004, Oracle. All rights reserved.

Identifying Unused Indexes

Use index monitoring to determine whether an index is being used:

1. Enable index monitoring, and clear out any existing index use information.

2. Continue normal database operations.

3. Query the V$OBJECT_USAGE view for usage information.

4. Disable index monitoring at the end of evaluation.

SQL> ALTER INDEX emp_job_ix MONITORING USAGE;

SQL> ALTER INDEX emp_job_ix NOMONITORING USAGE;

SQL> SELECT index_name, used FROM V$OBJECT_USAGE;

Page 26: Monitoring and Managing Storage

13-29 Copyright © 2004, Oracle. All rights reserved.

Table accessby ROWID

Index-Organized Tables

Regular table access IOT access

Non-key columns

Key column

Row header

Page 27: Monitoring and Managing Storage

13-30 Copyright © 2004, Oracle. All rights reserved.

Index-Organized Tablesand Heap Tables

• Compared to heap tables, IOTs have:– Faster key-based access to table data– Do not duplicate the storage of primary key values– Require less storage – Use secondary indexes and logical rowids– Have higher availability, as table reorganization

does not invalidate secondary indexes

• IOTs have the following restrictions:– Must have a primary key that is not DEFERRABLE– Cannot be clustered– Cannot use composite partitioning – Cannot contain a column of type ROWID or LONG

Page 28: Monitoring and Managing Storage

13-32 Copyright © 2004, Oracle. All rights reserved.

Creating Index-Organized Tables

SQL> CREATE TABLE country 2 ( country_id CHAR(2) 3 CONSTRAINT country_id_nn NOT NULL, 4 country_name VARCHAR2(40), 5 currency_name VARCHAR2(25), 6 currency_symbol VARCHAR2(3), 7 map BLOB, 8 flag BLOB, 9 CONSTRAINT country_c_id_pk 10 PRIMARY KEY (country_id)) 11 ORGANIZATION INDEX 12 TABLESPACE indx 13 PCTTHRESHOLD 20 14 OVERFLOW TABLESPACE users;

Page 29: Monitoring and Managing Storage

13-33 Copyright © 2004, Oracle. All rights reserved.

Segment = SYS_IOT_OVER_nIOT_type = IOT_OVERFLOWSegment_type = TABLE

Segment = COUNTRY_C_ID_PK IOT_type = IOTSegment_type = INDEXIndex_type = IOT - TOP

IOT Row Overflow

Remaining part of the rowRows within

PCTTHRESHOLD

indx tablespace users tablespace

Page 30: Monitoring and Managing Storage

13-35 Copyright © 2004, Oracle. All rights reserved.

Querying DBA_TABLES for IOT Information

SQL> SELECT table_name, iot_name, iot_type 2 FROM DBA_TABLES;

TABLE_NAME IOT_NAME IOT_TYPE----------------- -------- ------------COUNTRY IOTSYS_IOT_OVER_2268 COUNTRY IOT_OVERFLOW

Page 31: Monitoring and Managing Storage

13-36 Copyright © 2004, Oracle. All rights reserved.

Querying DBA_INDEXESand DBA_SEGMENTS for IOT information

SQL> SELECT index_name, index_type, 2 tablespace_name, table_name 2 FROM DBA_INDEXES;INDEX_NAME INDEX_TYPE TABLESPACE TABLE_NAME--------------- ---------- ---------- ----------COUNTRY_C_ID_PK IOT - TOP INDX COUNTRY

SQL> SELECT segment_name, tablespace_name, 2 segment_type 3 FROM DBA_SEGMENTS;SEGMENT_NAME TABLESPACE_NAME SEGMENT_TYPE----------------- --------------- ------------SYS_IOT_OVER_2268 USER TABLECOUNTRY_C_ID_PK INDX INDEX

Page 32: Monitoring and Managing Storage

13-37 Copyright © 2004, Oracle. All rights reserved.

Using a Mapping Table

SQL> CREATE TABLE country 2 ( country_id CHAR(2) 3 CONSTRAINT country_id_nn NOT NULL 4 , country_name VARCHAR2(40) 5 , currency_name VARCHAR2(25) 6 , currency_symbol VARCHAR2(3) 7 , CONSTRAINT country_c_id_pk 8 PRIMARY KEY (country_id)) 9 ORGANIZATION INDEX 10 MAPPING TABLE TABLESPACE users;

Page 33: Monitoring and Managing Storage

13-38 Copyright © 2004, Oracle. All rights reserved.

Maintaining a Mapping Table

• Collect statistics on a mapping table by analyzing the IOT.

• Query the DBA_INDEXES view to determine the percentage accuracy of the mapping table.

• Rebuild the mapping table if required, using the ALTER TABLE command.

• Use the COMPRESS clause of CREATE TABLE or ALTER TABLE for the mapping table.

SQL> SELECT index_name, pct_direct_access 2 FROM DBA_INDEXES 3 WHERE pct_direct_access IS NOT NULL;

Page 34: Monitoring and Managing Storage

13-39 Copyright © 2004, Oracle. All rights reserved.

Clusters

Clustered orders and order_item tables

Cluster Key(ORD_NO) 101 ORD_DT CUST_CD 05-JAN-97 R01

PROD QTYA4102 20A5675 19 W0824 10

102 ORD_DT CUST_CD 07-JAN-97 N45

PROD QTYA2091 11G7830 20 N9587 26

Unclustered orders and order_item tables

ORD_NO ORD_DT CUST_CD------ ------ ------

101 05-JAN-97 R01102 07-JAN-97 N45

ORD_NO PROD QTY ...----- ------ ------

101 A4102 20102 A2091 11102 G7830 20

102 N9587 26101 A5675 19101 W0824 10

Page 35: Monitoring and Managing Storage

13-40 Copyright © 2004, Oracle. All rights reserved.

Cluster Types

Index clusterSorted hash

cluster

Hash function

Hash cluster

Hash function

Page 36: Monitoring and Managing Storage

13-42 Copyright © 2004, Oracle. All rights reserved.

Situations Where Clusters Are Useful

Criterion Index HashSorted

hash

Uniform key distribution X X X

Evenly distributed key values X X

Rarely updated key X X X

Often joined master-detail tables X

Predictable number of key values X X

Queries using equality predicate on key X X

Data is retrieved in the order it was inserted X

Page 37: Monitoring and Managing Storage

13-43 Copyright © 2004, Oracle. All rights reserved.

Sorted Hash Cluster: Example

CREATE CLUSTER calls_cluster( origin_number NUMBER, call_timestamp NUMBER SORT, call_duration NUMBER SORT)HASHKEYS 10000SINGLE TABLE HASH IS origin_numberSIZE 50;

CREATE TABLE calls( origin_number NUMBER, call_timestamp NUMBER , call_duration NUMBER , other_info VARCHAR2(30))CLUSTER calls_cluster(origin_number,call_timestamp,call_duration);

Cluster key

Sort key

Page 38: Monitoring and Managing Storage

13-44 Copyright © 2004, Oracle. All rights reserved.

Summary

In this lesson, you should have learned how to:

• Tune redo writing and archiving operations

• Issue statements that can be suspended when encountering space condition errors

• Reduce space-related error conditions through proactively managing tablespace space usage

• Reclaim wasted space from tables and indexes using the segment shrink functionality

• Estimate the size of new tables and indexes

• Use sorted hash clusters

• Rebuild indexes online

Page 39: Monitoring and Managing Storage

13-45 Copyright © 2004, Oracle. All rights reserved.

Practice 13 Overview:Managing Storage

This practice covers the following topics:

• Monitoring index space usage and rebuilding indexes if needed

• Using the Segment Advisor to shrink the space allocated to a table

• Using the Segment Space Estimator to determine the amount of space required to create a new table.