Harvard University
Oracle Database Administration
Session 6
Object Storage
Harvard University
Note
The mid-term will be held week 8, March 18st , just before spring break
It will be open book. An understanding of the concepts is most important.
Harvard University
Note
On-line TA session run by Joel Thursday Nights 7:30PM - 9:30PM Using Elluminate
Hands-on TA session run by Rohit After class Wednesday night, RM 102,
53 Church St
Harvard University
Data Storage
The units for data storage allocation are extents
A table is a segment An index is a segment Segments are sets of extents An extent is a specific number of contiguous
data blocks
Harvard University
Data Storage
The data for a table is stored in a data segment
The data for an index is stored in an index segment
Harvard University
Data Storage
The extents of a segment may or may not be contiguous on the disk
A segment and all of its extents are stored in one tablespace
Harvard University
Blocks
The data block is broken into the following sections– Header contains the block address and type of segment– Table Directory contains information about the table– Row Directory contains the address for each row or row
piece– Free space is used to insert new rows or update existing
rows– Row Data is the area that currently has data
Harvard University
Blocks
Harvard University
PCTFREE
PCTFREE – States that a percentage of each data block in a
table’s data segment, will be kept free for possible updates, of existing rows, in the future
Harvard University
PCTUSED
PCTUSED – The parameter that 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 a data block is filled to the limit determined by PCTFREE, Oracle considers the block unavailable for the insertion of new rows until it falls below PCTUSED block falls
below the parameter PCTUSED.
Harvard University
The Table
A regular table is the method used to store user data
We have very little control in how data is stored in a regular table
Rows may be stored in any order, depending on the activity on the table
Harvard University
Ordinary Tables
Ordinary (heap-organized) table General purpose table The data is stored as an unordered collection
(heap)
Harvard University
The Row
Row data is stored in database blocks as variable length records
The Columns of a row are stored in the order in which they are defined
Each row in a table can have a different number of columns
Harvard University
The Row Each row has a row header It contains the number of columns in the row,
the chaining information and the row lock status
Each row has row data For each column, Oracle stores the column
length and then the value
Harvard University
The Row
Each row in a table having less than 256 columns are stored as one or more row pieces
If there are more than 255 columns then the row uses intra-block chaining
Harvard University
The Row One byte is needed to store the column length
if the length cannot exceed 250 bytes
Three bytes are needed if the the length is longer
The column value is stored immediately after the column length bytes
Harvard University
The Row
Adjacent rows do not need any space between them
Each row in the block has a slot in the row directory
The directory slot points to the beginning of the row
Harvard University
Data Types There are a number of scalar data types
– Character data– Numeric data– Date data type
Character data can be stored in either fixed-length or variable length strings
Fixed length such as CHAR is stored with padded blanks
Harvard University
Data Types
Variable-length use only the number of bytes needed to store the actual column value
These can vary in size up to 4,000 bytes
VARCHAR2 is an example of variable length
Harvard University
Data Types
Numbers are always stored as variable length data
It can store up to 38 significant digits
Harvard University
Data Types
Numeric data needs– One byte for the exponent -- Exponents are a
shorthand way to show how many times a number, called the base, is multiplied times itself. A number with an exponent is said to be "raised to the power" of that exponent.
– One byte for every two significant digits in the mantissa – after the decimal point
– One byte for negative numbers if the number of significant digits is less than 38 bytes
Harvard University
Data Types
Dates are stored in fixed-length fields of seven bytes
An Oracle DATE always includes time
The Raw data type enables the storage of small binary data
The number of bytes needed to store the column is variable, up to 2,000 bytes
Harvard University
Null Values A null is the absence of a value in a column of a row.
Nulls indicate missing, unknown, or inapplicable data.
A null should not be used to imply any other value, such as zero.
A column allows nulls unless a NOT NULL, in which case no row can be inserted without a value for that column.
Nulls are stored in the database if they fall between columns with data values. In these cases they require 1 byte to store the length of the column (zero).
Harvard University
Null Values In tables with many columns, the columns more
likely to contain nulls should be defined last to conserve disk space.
Comparisons between nulls and other values are by definition neither true nor false, but unknown.
Harvard University
ROWID
The ROWID is a pseudo-column that can be queried along with other columns in a table
It has the following characteristics– It is unique identifier for each row in the database– It is not stored as a column value– It does not give the actual physical address of the
row, but can be used to locate the row
Harvard University
ROWID
– It is the fastest means of accessing a row in a table
– ROWID needs 10 bytes of storage and is displayed using 18 characters
Harvard University
ROWID The ROWID are made up of the following components
– The data object number is assigned to each data object, such as a table or index, when it is created. It is unique within the database
– The relative file number is unique to each file within a tablespace
– The block number represents the position of the block containing the row within the file
– The row number identifies the position of the row directory slot in the block header
Harvard University
ROWID ROWID is displayed using a base-64
encoding scheme– Data object number 6 positions– Relative file number 3 positions– Block number 6 positions– Row number 3 positions
Harvard University
ROWID
Select ROWID from <table name> Example
– AAADC4AACAAAAMAAAA– AAADC4 is the data object number– AAC is the relative file number– AAAAMA is the block number– AAA is the row number
Harvard University
The Storage Clause
Storage ( initial bytes,
next bytes,
minextents integer,
maxextents integer,
pctincrease integer)
Harvard University
Create TableCreate table [schema.] table (column datatype [, column datatype] …)[TABLESPACE tablespace]
[pctfree integer][pctused integer][initrans integer][maxtrans integer][Segment storage clause][logging | nologging][cache | nocache]
Harvard University
Create Table
create table [schema].table_name
(first_name varchar2(15), ---15 characters
middle_initial char(2), ---2 characters
last_name varchar2(20)), ---20 characters
Harvard University
Create Table
Schema is the table owner Table_name is the name of the table Column is the name of the column Datatype is the data type of the column
Tablespace is the tablespace where the table will be created
Harvard University
Create Table
Logging specifies that the creation of the table will be logged in the redo log file
Nologging specifies that the creation of the table and certain types of data loads will not be logged in the redo log file
Harvard University
Create Table
Cache specifies that the blocks retrieved for this table are in the most recently used end of the LRU list, in the buffer cache
Nocache specifies that the blocks retrieved for this table are in the least recently used end of the LRU list, in the buffer cache
Harvard University
Create Table
Create tables in a separate tablespace, one that does not have indexes, rollback segments or temporary segments
Use a few standard extent sizes that are multiples of 5 * db_block_size, to minimize fragmentation
example 5 * 8k = 40k * 100 = 4M
5 * 16k = 80k * 100 = 8M
Harvard University
Create Table
It is easier to use the autoallocate clause, when creating the locally managed tablespace
Use the cache clause for small reference tables that are accessed frequently
Harvard University
Alter Table To change an existing table we use the
ALTER TABLE commandAlter table [schema.] table{[storage-clause][pctfree integer][Pctused integer][Initrans integer][maxtrans integer]
Harvard University
Alter Table The changes in the storage take effect on any
new extents that are allocated The value of INITIAL extent cannot be
modified The value of the NEXT extent is rounded to a
multiple of the block size greater to or equal to the value specified
Harvard University
Alter Table
Changes to the block parameters PCTFREE and INITRANS will effect only new blocks
Changes to PCTUSED and MAXTRANS will effect all blocks
Block Parameters are changed to improve space utilization and reduce migration
Harvard University
Row Chaining
Row chaining occurs when a row is too large to fit into a single block
The row is too large to fit into one data block upon first insertion it is first inserted
It is then divided into row pieces Each row piece is stored in different blocks The necessary pointers to retrieve the whole
row are provided
Harvard University
Migration
When a row that originally fit into one data block, is updated, so that the overall row length increases, and the block’s free space is already completely filled.
Oracle migrates the data for the entire row to a new data block, assuming the entire row can fit in a new block.
The rowid of a migrated row does not change.
Harvard University
Migration
When a row is chained or migrated, I/O performance associated with this row decreases
Oracle now must scan more than one data block to retrieve the information for the row.
Row Chaining can be minimized by choosing a larger block size or splitting the table into multiple tables, with fewer columns
Harvard University
Views
A view is not allocated any storage space A view does not contain data A view is defined by a query that extracts or
derives data from the tables that the view references.
These tables are called base tables.
Harvard University
Materialized Views
Materialized views are schema objects that can be used to summarize, compute, replicate, and distribute data.
Data is stored as if they were tables
Harvard University
Locally Managed Tablespaces
The CREATE TABLESPACE command has an "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.
Harvard University
Locally Managed Tablespaces
The storage parameters NEXT, PCTINCREASE, MINEXTENTS, MAXEXTENTS, and DEFAULT STORAGE are not valid for extents that are managed locally.
Harvard University
Automatic Segment Space Management (ASSM)
CREATE TABLESPACE USERS DATAFILE '/u04/app/oracle/product/9.0.1/oradata/<SID>/test.dbf' SIZE 1M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K
SEGMENT SPACE MANAGEMENT AUTO;
Harvard University
Automatic Segment Space Management (ASSM
The tablespace must be permanent and locally managed.
If used, the segment ignores PCTUSED and FREELIST
Harvard University
Reading
Oracle11g Concepts Guide– Part 2 Oracle Database Architecture
Chap 2 and 3 Chap 5 thru 8 Chap 12
Harvard University
Reading
Oracle11 Administration Guide– Part 1 Basic Database Administration
Chap 1 thru 6
– Part 2 Oracle Database Structure and Storage Chap 9 thru 14