Top Banner
Primer on Primer on Structure Structure & & Storage Analysis Storage Analysis This presentation is supposed to give a simple and brief overview for storage calculations. THREE simple methods have been discussed for TABLE size calculation. ~ Nilendu Misra [email protected]
25

Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Dec 16, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Primer on StructurePrimer on Structure & & Storage AnalysisStorage Analysis

This presentation is supposed to give a simple and brief overview for storage

calculations. THREE simple methods have been discussed for TABLE size calculation.

~ Nilendu Misra

[email protected]

Page 2: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Data Block

Data block is the smallest unit logical space allocation

Smallest unit of I/O Data block size can ONLY be specified at

creation time Always multiple of OS block size To see check DB_BLOCK_SIZE in init.ora

Page 3: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Oracle Block

Data Block = Header + “Actual” data

Header contains ‘information’about the data

A row should ideally be contained within a single

block

Header Data

Row

Free Space

Page 4: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Extent & Segment

An extent is a specific number of contiguous data blocks

Several extents make one segment(e.G table, rollback segment)

All extents for the same segment are on the same tablespace

Rollback segment has ATLEAST 2 extents

Page 5: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Free Space Management : PCTFREE Mention while creating or altering segment FREELIST - list of blocks ready for insertion % of the block kept free for updates of rows

already in that block PCTFREE = 10 (default) means the block

(say 2K) allows row insertion till it is 80% full (1.8K). The rest (0.2K) is kept free

Page 6: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Pctused

When % of the block used falls below PCTUSED insertion is again allowed on the block

PCTUSED = 40 (default), in the previous example means when the block will contain 0.8K then again insertion will start

Page 7: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Why Consider these Parameters?

Disk I/O is the around 50 times slower than reading from memory (SGA)

We should prevent multiple I/Os while reading a record (e.g., Row Chaining)

This parameters put a big role in the total space consumed by the segment

Read-in blocks take up memory in SGA Defining depends on the application (e.g.,

UPDATE intensive)

Page 8: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

CONT.

e.g., In UPDATE intensive system PCTFREE should be high to accommodate the INCREASE in length due to UPDATE

In SELECT intensive system (say DSS) PCTFREE should be low. (As no UPDATE)

A Table can be INSERTed / DELETEd upon frequently. So HIGH PCTUSED is better

Row chaining– Row is ‘spread across’ more than one block

Page 9: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Designing Parameters

Knowledge of application data. Knowledge of operations on individual Table

(particularly Large ones)

Specifically the frequency of UPDATEs, INSERTs, DELETEs has to be known

A row with LONG datatype normally ‘spreads across’ multiple data blocks

Page 10: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Row Chaining

When a row is stored over multiple blocks Because it does not get enough space on a

single block to fit in With large rows (with LONG,LONG RAW) I/O is badly hit for scanning multiple blocks

Page 11: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

EXTENT Calculation

MAXEXTENTS depend on data block size For 2K block, MAXEXTENT = 121 When one extent is filled, NEXT extent is

allocated NEXT extent size = (current extent size) * (1 +

PCTINCREASE/100) PCTINCREASE = 0 =>same sized extents (as

in rollback segment)

Page 12: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

SEGMENT Types

DATA segment INDEX segment ROLLBACK segment TEMP segment

Page 13: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Tablespace

Largest logical storage unit Has one or more datafile(s) where data is

actually stored DBA can CREATE/ALTER/DROP Associated with one or more user(s) Each user MUST have one DEFAULT &

one TEMPORARY tablespace

Page 14: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

TABLESPACE (Cont.)

Size of a tablespace = sum of the datafiles To increase ADD datafile ONLY way to remove DATAFILE ---->

DROP USER ...; Can take ONLINE/OFFLINE (except

SYSTEM) Create separate for each segment type

Page 15: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Datafile

One datafile is associated with ONE & ONLY ONE tablespace

SIZE can be ALTERED after creation CANNOT be DROPPED on the fly For big database AUTOEXTEND ON MAX no/size of datafile is restricted by OS

Page 16: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Syntax : Create TablespaceCREATE TABLESPACE test

DATAFILE ‘/data/oracle/test1.dbf’ SIZE 100M REUSE DEFAULT STORAGE (INITIAL 500K NEXT 1024K MINEXTENTS 2 MAXEXTENTS 50 PCTINCREASE 10) <TEMPORARY>;

Page 17: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Add Datafile

ALTER TABLESPACE “RBS” ADD DATAFILE ‘/data/oracle/rbs4.dbf’ SIZE 100M;

Page 18: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Resize Datafile

ALTER DATABASE DATAFILE ‘/oracle/datafile/test.dbf’

RESIZE 100m;

Page 19: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Autoextend Datafile

Alter database datafile

‘/Data/oracle/test.dbf’

Autoextend on

Next 100k

<Maxsize 10m>

<Unlimited>;

Page 20: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

To See Size of Datafile

Select file_name “name”,

Sum(bytes)/1024/1024 “size”

From sys.dba_data_files

Group by file_name;

Page 21: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Tablespace Size

Select sum(bytes)/1024/1024 “size”,

Tablespace_name

From sys.dba_data_files

Group by tablespace_name;

Page 22: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Estimate Table Size - Method 1 Row/Data size from Table Structure(DDL)

Table emp (name varchar2(30),

salary number (8,2),

join_date date);

Step 1 : each row size ->20B + 6B + 7B = 43B

Step 2 : estimated rows -> 10000

Step 3 : table size -> 43 * 10000B = 0.5 MB

Step 4 : yearly growth rate -> 43 * 2000 = 100 KB

Moral : Always be conservativeMoral : Always be conservative

Page 23: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Estimate Table Size - Method 2 From Avg Row Size of existing Data

Step 1 :Initial 40,Next 50,Extents 4,PctIncrease 50

Step 2 :Size : (90 + 50*1.5 + 50*1.5*1.5)= 287.5

Step 3 :Size with MaxExtents (121 for 2K DB Block) : It’s a G.P. Series.

S = Sum of N terms = [A(RN -1)/(R-1)]

where A = NEXT; R = (100+PctIncrease)/100;

N= (MAXEXTENTS - 1) =>

Total Size = ( S + INITIAL)

Moral : Set PctIncrease Judiciously!Moral : Set PctIncrease Judiciously!

Page 24: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

Estimate Table Size - Method 3Row/Data size from Analyzed table Info

Step 1 :ANALYZE TABLE EMP ESTIMATE[COMPUTE] STATISTICS;

Step 2 :SELECT (NUM_ROWS*AVG_ROW_LEN) FROM USER_TABLES WHERE TABLE_NAME = ‘EMP’;

Page 25: Primer on Structure& Storage Analysis Primer on Structure & Storage Analysis This presentation is supposed to give a simple and brief overview for storage.

To Check Extent Growth

Select substr(owner || ‘.’|| segment_name,1,25) “object”,

Maxextents

From sys.Dba_extents

Where maxextents -extents <= 5

Order by extents; Will give you the segment which is

approaching MAXEXTENTS