Top Banner
Harvard University Oracle Database Administration Session 5 Data Storage
49

Harvard University Oracle Database Administration Session 5 Data Storage.

Dec 21, 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: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Oracle Database Administration

Session 5

Data Storage

Page 2: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Storage

Oracle allocates logical database space for all data in a database

The units of this allocation are data blocks, extents and segments

The lowest level of granularity that stores data are data blocks, also know as logical blocks, pages or Oracle blocks

Page 3: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Storage

The next level of storage is the extent The extent is a specific number of

contiguous data blocks The level of storage above the extent is the

segment A segment is a set of extents, allocated to a

specific data structure

Page 4: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Storage

Each table’s data is stored in it’s own data segment

Each index’s data is stored in its own index segment

If a table or index is partitioned, each partition is stored in its own segment

Page 5: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Extents Extents

Segment

8Kblocks

Data Storage

Page 6: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Storage

Oracle allocates space for each segment in units of one extent

When existing extents of a segment are full, Oracle allocates another extent to that segment

This means that the extents of a segment may or may not be contiguous on the disk

Page 7: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Storage

The segment and all it’s extents are stored in one tablespace

Inside a tablespace, a segment can include extents from more than one datafile. That means segments can span datafiles

However, each extent can contain data from only one datafile

Page 8: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Storage

All the rows for a particular index are stored in one index segment

If a table has 3 indexes, each one has it’s own index segment

The purpose of this segment is to look up the location of rows in a table, based on a specified key

Page 9: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

TableTable Table

Index

Table

Table

Index

Index

Index Table

Index

Tablespace

DatafileDatafile

Page 10: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Segments

There are many types of segments – Table– Table Partition– Index– Undo – Temporary– Large Object (LOB)

Page 11: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Segments

A table is the only method of storing data in a database

The data in a table segment is stored in no particular order

We have no control over the location of the rows in the blocks, inside the segment

All data in a table segment must be stored in one tablespace

Page 12: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Segments

Tables can be stored in many partitions, each of which are in a different tablespace

If a table is partitioned, each partition is a segment with it’s own storage parameters

To use partitions, we must have installed the Partitioning Option

Page 13: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Storage Clause

A storage clause can be specified at the segment level to control how extents are allocated to that segment

The storage parameter setting at the segment level overrides the corresponding option at the tablespace level

If parameters are not set at the segment level, they default to the tablespace level

If they are not specified at the tablespace level, the Oracle Server sets default values

Page 14: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Create Table (statement)Create table [schema.] table (column datatype [, column datatype] …)[TABLESPACE tablespace]

[pctfree integer][pctused integer][initrans integer][maxtrans integer][storage clause][logging | nologging][cache | nocache]

Page 15: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Storage Clause

Storage ( initial bytes,

next bytes,

minextents integer,

maxextents integer,

pctincrease integer)

Page 16: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Storage Clause

If these parameters are changed after the segment has been created, the new options apply only to the new extents not yet allocated

Some parameters cannot be set at the tablespace level. These need to be specified at the segment level

A minimum extent size is set at the tablespace level. This will apply to all extents that are allocated for segments in that tablespace

Page 17: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Storage Clause

Extents are allocated when the segment is – Created – Extended– Altered

Extents are deallocated when the segment is– Dropped– Altered– Truncated– Automatically resized ( manual rollback segments only)

Page 18: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Storage Clause When a tablespace is created, the associated

datafile(s) contain the following– A header block, the first block in the file– One extent consisting of the remaining part of the

file

As segments are created they allocate space from the free space

As segments release space, these extents are given back to the pool of free space

Page 19: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Storage Clause

The frequent allocation and deallocation of extents can lead to the fragmentation of space within the data files of a tablespace

Page 20: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Blocks

A data block is the smallest unit of I/O used by a database

Each Operating System has a block size. Solaris uses 512 Bytes or one half kilobyte

Oracle blocks are multiples of this block size Oracle requests data in multiples of Oracle

data blocks

Page 21: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Block Format

The data block can be broken into the following sections

– Header– Table Directory– Row Directory– Free space – Row Data

Page 22: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Common and VariableHeader

Table Directory

Row Directory

Free Space

Row Data

Data Block Format

Page 23: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

The Header

The block header contains the block address and the type of segment it belongs to.

It is also used to hold the transaction slots used when changes are made to rows in the block. Block headers grow from the top down

Page 24: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Table Directory and Row Directory

The Table Directory contains information about the table that has rows of data in this block

The Row Directory contains information about the actual rows in the block. It holds an address for each row piece in the row data area

The data block header, table directory and the row directory are referred to collectively as block overhead

Page 25: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Table Directory and Row Directory

On average, the fixed and variable portions of the 8k data block, overhead can total between 84 and 107 bytes

This portion of each data block, in every extent and segment, is taken up as overhead

The rest of the block is used to store data Rows can span data blocks, this is known as

row chaining.

Page 26: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Free Space and Row Data

Free space is used to insert new rows or update existing rows

To help us manage the use of free space in a block, we use the PCTFREE and PCTUSED parameters

The values of these parameters help to decide if a row in a block can or will be updated in that block.

It may have to be updated in another block

Page 27: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Free Space and Row Data

The PCTFREE and PCTUSED parameters are specified when creating or altering a table

The PCTFREE parameter can also be specified when creating or altering an index

The PCTFREE parameter sets the minimum percentage of a data block, to be reserved as free space, for possible updates to existing rows

Page 28: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

PCTFREE

If we set the parameter in the CREATE TABLE statement, as follows

– PCTFREE 20

This states that 20% of each data block in this table’s data segment, will be kept free for possible updates, of existing rows, in the future

The default value is 10

Page 29: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

PCTFREE

This means that new rows can be added to the block and the associated overhead can grow.

Up to the point where the total gets to 80% of the total block size

Page 30: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

PCTUSED

The PCTUSED parameter sets the minimum percentage of a block that can be used for row data plus overhead, before new rows will be added to the block

After the block has been filled to the limit set by PCTFREE, Oracle considers the block to be unavailable for the insertion of new rows

Page 31: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

PCTUSED

New rows will not be added until the percentage free of that block falls below the parameter PCTUSED

Until that time the free space is used only for updates of existing rows

The parameter is set in the CREATE TABLE statement

– PCTUSED 40

Page 32: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Data Block Format

The data block format is the same, regardless of the type of data stored in that block

Page 33: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Block Use Concurrency

The parameters used to control concurrency usage of the block are INITRANS and MAXTRANS

These set the initial and maximum number of transaction slots

Transaction slots are used to hold information about transactions that are making changes to the block at that point in time

Page 34: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Block Use Concurrency

A transaction only uses one transaction slot, even if it is changing multiple rows in the block

INITRANS defaults to 1 in a data segment and to 2 in an index segment. So, if we set INITRANS=3, it ensures that at least 3 transactions can concurrently make changes to the block

Page 35: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Block Use Concurrency

MAXTRANS, defaults to 255 and sets the limit for the number of concurrent transactions that can make changes to the data or index block

When set, this value restricts the space used for transaction slots

A transaction slot can take up to 20 bytes

Page 36: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces

The CREATE TABLESPACE command has the "extent_management_clause", that specifies how the extents of the tablespace will be managed. This clause uses one of the following parameters:

- DICTIONARY: Specifies that the tablespace is managed using dictionary tables. This is the default for 8i.

- LOCAL: Specifies that the tablespace is locally managed. Locally managed tablespaces have some part of the tablespace set aside for a bitmap. This is the default for 9i and 10g

Page 37: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces AUTOALLOCATE specifies that the tablespace is

system managed. Users cannot specify an extent size.

UNIFORM specifies that the tablespace is managed with uniform extents of SIZE bytes. The default SIZE is 1 megabyte.

If you do not specify either AUTOALLOCATE or

UNIFORM with the LOCAL parameter, then AUTOALLOCATE is the default.

Page 38: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces A tablespace that manages its own extents

maintains a bitmap in each datafile, to keep track of the free or used status of blocks in that datafile.

Each bit in the bitmap corresponds to a block or a group of blocks.

When an extent is allocated or freed for reuse, Oracle changes the bitmap values to reflect the new status of the blocks.

Page 39: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces

Local management of extents automatically tracks adjacent free space, eliminating the need to coalesce free extents.

The sizes of extents are determined automatically by the system.

All extents can have the same size in a locally-managed tablespace, if UNIFORM is used.

Page 40: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces

For system-managed extents, you can specify the size of the initial extent and Oracle determines the optimal size of additional extents, with a minimum extent size of 64 KB. This is the default for permanent tablespaces.

Page 41: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces

For uniform extents, you can specify an extent size or use the default size, which is 1 MB.

Temporary tablespaces that manage their extents locally, can only use this type of allocation.

Page 42: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Locally Managed Tablespaces

The storage parameters NEXT, PCTINCREASE, MINEXTENTS, MAXEXTENTS, and DEFAULT STORAGE are not valid for extents that are managed locally.

Page 43: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Uniform Example

CREATE TABLESPACE USERS DATAFILE '/u04/oradata/<SID>/test.dbf' SIZE 100M

EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;

Page 44: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Autoallocate Example

CREATE TABLESPACE local_auto DATAFILE '/u04/11.1.0/oradata/<SID>/test.dbf' SIZE 100M

EXTENT MANAGEMENT LOCAL AUTOALLOCATE;

Page 45: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Benefits Locally managed tablespaces track all extent

information in the tablespace itself, using bitmaps

This results in Improved concurrency and speed of space operations, as space allocations and deallocations predominantly modify locally managed resources (bitmaps stored in file header) rather than requiring centrally managed resources such as enqueues.

Page 46: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Benefits Improved performance, because recursive

operations that are sometimes required during dictionary-managed space allocation are eliminated.

Simplified space allocation--when the AUTOALLOCATE clause is specified, appropriate extent sizes are automatically selected.

Page 47: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Automatic Segment Space Management (ASSM)

CREATE TABLESPACE USERS DATAFILE '/u04/oradata/<SID>/test.dbf' SIZE 1M

EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K

SEGMENT SPACE MANAGEMENT AUTO;

Page 48: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

ASSM The tablespace must be permanent and

locally managed. If used, the segment ignores PCTUSED and

FREELIST

This means that there is no advantage to having segments of various sizes. Keeping the sizes uniform is simpler to maintain

Page 49: Harvard University Oracle Database Administration Session 5 Data Storage.

Harvard University

Assignment 2

Name your database the same as your Unix Login

Your Unix Login is the first character of your first name and the next 7 of your last name

Source the Change file that is in your account