Upload
emory-preston
View
213
Download
0
Embed Size (px)
Citation preview
9-9-22
ObjectivesObjectives
• Listing the different segment types and their uses
• Controlling the use of extents by segments
• Stating the use of block space utilization parameters by objects
• Obtaining information about storage structures from the data dictionary
• Locating the segments by considering fragmentation and life-spans
• Listing the different segment types and their uses
• Controlling the use of extents by segments
• Stating the use of block space utilization parameters by objects
• Obtaining information about storage structures from the data dictionary
• Locating the segments by considering fragmentation and life-spans
9-9-33
Database
Logical Physical
Tablespace Data file
O/S blockOracle block
Segment
Extent
Database Storage HierarchyDatabase Storage Hierarchy
9-9-44
Types of SegmentsTypes of Segments
TableTable
ClusterCluster
Table Table partitionpartition
IndexIndex
9-9-55
Types of SegmentsTypes of SegmentsSegments occupy spaceSegments occupy space
•TableTable
•Table PartitionTable Partition
table with high concurrent usagetable with high concurrent usage
need partitioning optionneed partitioning option
•ClusterCluster
based on key col valuesbased on key col values
one or more tables in a clusterone or more tables in a cluster
•IndexIndex
9-9-66
Types of SegmentsTypes of Segments
Index-organizedIndex-organizedtabletable Index Index
partitionpartition
RollbackRollbacksegmentsegment TemporaryTemporary
segmentsegment
9-9-77
Types of SegmentsTypes of Segments
•Index-organized tableIndex-organized tableindex+data stored togetherindex+data stored together
•Index PartitionIndex Partitionindex can be partitionedindex can be partitioned
•Rollback segmentRollback segmentbefore image of a data valuebefore image of a data value
•Temporary segmentTemporary segment
when sorts need more spacewhen sorts need more space
9-9-88
Types of SegmentsTypes of Segments
LOB index LOB index LOBLOB
segmentsegment
BootstrapBootstrapsegmentsegment
Nested tableNested table
9-9-99
Storage Clause PrecedenceStorage Clause Precedence
Oracle default (5 blocks)
Tablespace
Segment
Controls how extents are allocated to segmentsControls how extents are allocated to segments
Storage Storage parameter at parameter at segment level segment level overrides the overrides the one at TS level, one at TS level, etc.etc.
9-9-1010
Extent Allocation and DeallocationExtent Allocation and Deallocation
• Allocated when the segment is+ Created + Extended+ Altered
• Deallocated when the segment is– Dropped– Altered– Truncated– Automatically resized (rollback segments
only)
• Allocated when the segment is+ Created + Extended+ Altered
• Deallocated when the segment is– Dropped– Altered– Truncated– Automatically resized (rollback segments
only)
9-9-1111
Used and Free ExtentsUsed and Free Extents*When tablespace is created, the data files *When tablespace is created, the data files contain the following elements:contain the following elements:-A header block: the first blockA header block: the first block-One free extent consisting of the One free extent consisting of the remaining part of the fileremaining part of the file*As segments are created, or extended, *As segments are created, or extended, they are allocated space from the pool of they are allocated space from the pool of free extents; as segments are released, free extents; as segments are released, truncated, released extents are added to truncated, released extents are added to the poolthe pool*Frequent allocation/deallocation leads to *Frequent allocation/deallocation leads to fragmentationfragmentation
9-9-1212
Used and Free ExtentsUsed and Free Extents
Data fileData file
Free extentFree extentUsed extentUsed extentFile headerFile header
SMON compacts free space; this is SMON compacts free space; this is called coalescingcalled coalescing
9-9-1313
Coalescing Free SpaceCoalescing Free Space
Free extentFree extentUsed extentUsed extentFile headerFile header
BeforeBefore
ALTER TABLESPACE data01 COALESCE;ALTER TABLESPACE data01 COALESCE;
AfterAfter
9-9-1414
Database Block: ReviewDatabase Block: Review
• Minimum unit of I/O
• Consists of one or more O/S blocks
• Set by DB_BLOCK_SIZE
• Set at database creation and cannot be altered
• Minimum unit of I/O
• Consists of one or more O/S blocks
• Set by DB_BLOCK_SIZE
• Set at database creation and cannot be altered
9-9-1515
Database Block ContentsDatabase Block Contents
Header Header (contains (contains row ptrs, trans info,row ptrs, trans info,Can grow as more rows areCan grow as more rows areadded)added)
Free spaceFree space(can get fragmented as(can get fragmented asRows are inserted andRows are inserted andDeleted; needs coalescing)Deleted; needs coalescing)
DataData
9-9-1616
Table Row ContentsTable Row Contents
Row headerRow header
(locked or not, deleted or not, trans., etc.)(locked or not, deleted or not, trans., etc.)
Col 1 size, col1 dataCol 1 size, col1 data
Col k sizeCol k size
(null)(null)
Col l sizeCol l size
(null)(null)
Define cols that can take null values lastDefine cols that can take null values last
9-9-1717
Block Space Utilization Parameters(managing free space to account for updates to rows)
Block Space Utilization Parameters(managing free space to account for updates to rows)
INITRANSINITRANSMAXTRANS MAXTRANS (initial and max num of(initial and max num oftransactions that can concurrently make transactions that can concurrently make changes to the block at a point in time)changes to the block at a point in time)
PCTFREE PCTFREE (can insert rows until(can insert rows untilfree space falls below this; default is 10)free space falls below this; default is 10)
PCTUSED (PCTUSED (if free space falls if free space falls below this, block goes on freebelow this, block goes on freeList; default is 40)List; default is 40)
Blocks are on “free” listBlocks are on “free” list
9-9-1818
Block Space UsageBlock Space Usage
InsertsInserts
InsertsInserts
InsertsInserts
InsertsInserts
1 2
3 4
PCTFREE=20PCTFREE=20 PCTUSED=40PCTUSED=40
80%80%
80%80%
40%40%
9-9-1919
ExampleExample
Create table Employee
(EID number not null,
ENAME varchar2(50)
Using INDEX Tablespace INDX
Pctfree 10 Pctused 40 INITRANS 5
STORAGE (INITIAL … PCTINCREASE)
)
PCTFREE 10 PCTUSED 60 INITRANS 5
STORAGE (INITIAL….)
TABLESPACE DATA01;
-- COLUMN placement can also be specified
Create table Employee
(EID number not null,
ENAME varchar2(50)
Using INDEX Tablespace INDX
Pctfree 10 Pctused 40 INITRANS 5
STORAGE (INITIAL … PCTINCREASE)
)
PCTFREE 10 PCTUSED 60 INITRANS 5
STORAGE (INITIAL….)
TABLESPACE DATA01;
-- COLUMN placement can also be specified
9-9-2020
Segment Space Management in LMT Segment Space Management in LMT
From Oracle 9i, one can not only have bitmap managed tablespaces, but also bitmap managed segments when setting Segment Space Management to AUTO for a tablespace. Look at this example:
SQL> CREATE TABLESPACE ts4 DATAFILE '/oradata/ts4_01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
From Oracle 9i, one can not only have bitmap managed tablespaces, but also bitmap managed segments when setting Segment Space Management to AUTO for a tablespace. Look at this example:
SQL> CREATE TABLESPACE ts4 DATAFILE '/oradata/ts4_01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
9-9-2121
Segment Space Management in LMT Segment Space Management in LMT
Segment Space Management eliminates the need to specify and tune the PCTUSED, FREELISTS, and FREELISTS GROUPS storage parameters for schema objects. The Automatic Segment Space Management feature improves the performance of concurrent DML operations significantly since different parts of the bitmap can be used simultaneously eliminating serialization for free space lookups against the FREELSITS. This is of particular importance when using RAC.
Segment Space Management eliminates the need to specify and tune the PCTUSED, FREELISTS, and FREELISTS GROUPS storage parameters for schema objects. The Automatic Segment Space Management feature improves the performance of concurrent DML operations significantly since different parts of the bitmap can be used simultaneously eliminating serialization for free space lookups against the FREELSITS. This is of particular importance when using RAC.
9-9-2222
Data Dictionary ViewsData Dictionary Views
TablespacesDBA_TABLESPACES
SegmentsDBA_SEGMENTS
Data filesDBA_DATA_FILES
Free extentsDBA_FREE_SPACE
Used extentsDBA_EXTENTS
9-9-2323
Querying Segment InformationQuerying Segment Information
DBA_SEGMENTS
– General information– OWNER
SEGMENT_NAME
– SEGMENT_TYPE
– TABLESPACE_NAME
DBA_SEGMENTS
– General information– OWNER
SEGMENT_NAME
– SEGMENT_TYPE
– TABLESPACE_NAME
– Size– EXTENTS
– BLOCKS
– Storage settings– INITIAL_EXTENT
– NEXT_EXTENT
– MIN_EXTENTS
– MAX_EXTENTS
– PCT_INCREASE
9-9-2424
ExampleExample
Select segment_name, tablespace_name,
extents, blocks
From dba_segments
Where owner = ‘SCOTT’;
Select segment_name, tablespace_name,
extents, blocks
From dba_segments
Where owner = ‘SCOTT’;
9-9-2525
Getting Used Extent InformationGetting Used Extent Information
DBA_EXTENTS
– Identification– OWNER
– SEGMENT_NAME
– EXTENT_ID
– Location and size– TABLESPACE_NAME
– RELATIVE_FNO
– FILE_ID
– BLOCK_ID
– BLOCKS
DBA_EXTENTS
– Identification– OWNER
– SEGMENT_NAME
– EXTENT_ID
– Location and size– TABLESPACE_NAME
– RELATIVE_FNO
– FILE_ID
– BLOCK_ID
– BLOCKS
9-9-2626
ExampleExample
Select extent_id, file_id, block_id, blocks
From dba_extents
Where owner = ‘SCOTT’ AND
segment_name = ‘EMP’;
Select extent_id, file_id, block_id, blocks
From dba_extents
Where owner = ‘SCOTT’ AND
segment_name = ‘EMP’;
9-9-2727
Checking Free Extent Information
Checking Free Extent Information
DBA_FREE_SPACE
– Location and size– TABLESPACE_NAME
– RELATIVE_FNO
– FILE_ID
– BLOCK_ID
– BLOCKS
DBA_FREE_SPACE
– Location and size– TABLESPACE_NAME
– RELATIVE_FNO
– FILE_ID
– BLOCK_ID
– BLOCKS
9-9-2828
ExampleExample
Select tablespace_name, count(*),
max(blocks), sum(blocks)
From dba_free_space
Group by tablespace_name;
Select tablespace_name, count(*),
max(blocks), sum(blocks)
From dba_free_space
Group by tablespace_name;
9-9-2929
Organizing Tablespaces Based on Fragmentation Propensity
Organizing Tablespaces Based on Fragmentation Propensity
Tablespace
SYSTEM
TOOLS
DATAn
INDEXn
RBSn
TEMPn
Fragmentation
Zero
Very low
Low
Low
High
Very high*
Usage
Data dictionary
Applications
Data segments
Index segments
Rollback segments
Temporary segments* Relevant only if tablespace PERMANENT* Relevant only if tablespace PERMANENT