Oracle8: Database Administration 9-15 ......Types of Segments Coalescing on Demand The view DBA_FREE_SPACE_COALESCED can be used to find out if any tablespace has extents that can be coa
Trang 1Oracle8: Database Administration 9-15
Types of Segments
Coalescing on Demand
The view DBA_FREE_SPACE_COALESCED can be used to find out if any
tablespace has extents that can be coalesced Use the following query to get
1 Use Oracle Tablespace Manager
2 Expand Tablespaces node
3 Select the tablespace
4 Select Tools—>Coalesce Free Extents
Trang 2Using Block Space Utilization Parameters
9-11 Copyright Oracle Corporation, 1998 All rights reserved.
Database Block: Review
• Minimum unit of I/O
• Consists of one or more O/S blocks
• Set by DB_BLOCK_SIZE
• Set at database creation
Trang 3Oracle8: Database Administration 9-17
Using Block Space Utilization Parameters
Oracle data blocks contain:
• Block header: Header contains the data block address, table directory,
row directory, and transaction slots that are used when transactions make
changes to rows in the block Block headers grow from the top down
• Data space: Row data is inserted into the block bottom up
• Free space: The free space in a block is in the middle allowing both the
header and the row data space to grow if necessary The free space in a
block is contiguous initially However, deletions and updates may
fragment the free space in the block The free space in the block is
coalesced by the Oracle server when necessary
9-12 Copyright Oracle Corporation, 1998 All rights reserved.
Database Block Contents
Header Free space
Data
Trang 4Block space utilization parameters can be used to control the use of space in
data and index segments
Parameters Controlling Concurrency
INITRANS and MAXTRANS specify the initial and the maximum number
of transaction slots, which are created in an index or a data block The
transaction slots are used to store information about transactions that are
making changes to the block at a point in time A transaction only uses one
transaction slot even if it is changing more than one row or index entry
INITRANS, which defaults to 1 for a data segment, and 2 for an index
segment, guarantees minimum level of concurrency For example, if set to 3,
INITRANS ensures that at least three transactions can concurrently make
changes to the block If necessary, additional transaction slots can be
allocated from the free space in the block, to permit more concurrent
transactions to modify rows in the block
9-13 Copyright Oracle Corporation, 1998 All rights reserved.
Block Space Utilization Parameters
INITRANS MAXTRANS PCTFREE PCTUSED
Trang 5Oracle8: Database Administration 9-19
Using Block Space Utilization ParametersMAXTRANS, which has a default value of 255, sets the limit for the
number of concurrent transactions that can make changes to a data or an
index block When set, this value restricts use of space for transaction slots
and therefore guarantees that there is sufficient space in the block for use by
row or index data
Parameters Controlling the Use of Data Space
PCTFREE for a data segment specifies the percentage of space in each data
block reserved for growth resulting from updates to rows in the block The
default for PCTFREE is 10 percent
PCTUSED for a data segment represents the minimum percentage of used
space that Oracle Server tries to maintain for each data block of the table A
block is put back on the free list when its used space falls below PCTUSED
The free list of a segment is a list of blocks that are candidates for
accommodating future inserts A segment, by default, is created with one
free list Segments can be created with a higher number of free lists by
setting the FREELISTS parameter of the storage clause The default for
PCTUSED is 40 percent
Both PCTFREE and PCTUSED are calculated as percentages of available
data space, that is, the block space that remains after deducting the header
space from the total block size
Block space utilization parameters can only be specified for segments and
cannot be set at the tablespace level
Trang 6The following steps explain how space within a block is used for a data
segment, such as a table with PCTFREE=20 and PCTUSED=40:
1 Rows are inserted into the block until the utilization reaches 80% or
(100-PCTFREE) The block is no longer available for inserts when rows
occupy 80% of available data space in the block
2 The remaining 20% can be used when the size of the row increases, for
example, the case in which a column that was originally NULL is
updated to be assigned a value Thus block utilization may be in excess
of 80% as a result of updates
3 If rows are deleted in the block or if rows reduce in size as a result of
updates, block utilization may fall below 80% However, a block is not
used for inserts until the utilization falls below PCTUSED, which in this
example, is 40%
4 When the utilization falls below PCTUSED, the block is available for
9-14 Copyright Oracle Corporation, 1998 All rights reserved.
Block Space Usage
Trang 7Oracle8: Database Administration 9-21
Obtaining Information About Storage Structures
Obtaining Information About Storage Structures
The relationships between tablespaces, data files, segments, and extents
(both used and free) can be viewed by querying the data dictionary
When a tablespace with one or more files is created, a row is added to
DBA_TABLESPACES For each file in the database, a row is added to
DBA_DATA_FILES At this stage, the space in each data file, excluding the
file header, shows up as one free extent in DBA_FREE_SPACE
When a segment is created, a row is visible in DBA_SEGMENTS The
space allocated to the extents in this segment can be viewed from
DBA_EXTENTS, while DBA_FREE_SPACE is adjusted to show lower free
space in the files where the extents have been created for the segment
All the space in a file (excluding the header block) must be accounted for
either in DBA_FREE_SPACE or in DBA_EXTENTS
9-15 Copyright Oracle Corporation, 1998 All rights reserved.
Data Dictionary Views
Tablespaces DBA_TABLESPACES
Segments DBA_SEGMENTS
Data files DBA_DATA_FILES
Free extents DBA_FREE_SPACE Used extents
DBA_EXTENTS
Trang 8Query the DBA_SEGMENTS view to check the current number of extents
and blocks allocated to a segment
SVRMGR> SELECT segment_name,tablespace_name,extents,blocks 2> FROM dba_segments
9-16 Copyright Oracle Corporation, 1998 All rights reserved.
Querying Segment Information
DBA_SEGMENTS
– OWNER SEGMENT_NAME – SEGMENT_TYPE – TABLESPACE_NAME
– EXTENTS – BLOCKS
– INITIAL_EXTENT – NEXT_EXTENT – MIN_EXTENTS – MAX_EXTENTS – PCT_INCREASE
Trang 9Oracle8: Database Administration 9-23
Obtaining Information About Storage Structures
Use the DBA_EXTENTS view to check the extents for a given segment
9-17 Copyright Oracle Corporation, 1998 All rights reserved.
Getting Used Extent Information
DBA_EXTENTS
– OWNER – SEGMENT_NAME – EXTENT_ID
– TABLESPACE_NAME – RELATIVE_FNO – FILE_ID
– BLOCK_ID – BLOCKS
Trang 10Use the DBA_FREE_SPACE view to check the extents for a given segment.
SVRMGR> SELECT tablespace_name, count(*),
DBA_FREE_SPACE
– TABLESPACE_NAME – RELATIVE_FNO – FILE_ID
– BLOCK_ID – BLOCKS
Trang 11Oracle8: Database Administration 9-25
Planning the Location of Segments
Planning the Location of Segments
Different types of segments have varying propensities for fragmentation It
is recommended that they are placed in different tablespaces in order to
minimize the waste of space
Types of Objects and Fragmentation
The recommended structure for the tablespaces, their uses, and their
fragmentation propensities are shown in the table The following are the
different types of objects listed in an increasing order of fragmentation
propensity:
• Data dictionary objects, with the exception of the audit table, are never
dropped or truncated, and therefore are not likely to fragment the
tablespace
• Space used for repositories of applications such as Oracle Enterprise
Manager and Designer/2000 are only deallocated while reorganizing
these structures Since these tables are seldomly reorganized, these
objects have very low propensity for fragmentation
• Data and index segements used for user-written applications might need
to be reorganized more frequently than repositories So, they have a
higher propensity for fragmentation than application repositories
9-19 Copyright Oracle Corporation, 1998 All rights reserved.
Organizing Tablespaces Based
Very low Low Low High Very high*
Usage Data dictionary Applications Data segments Index segments Rollback segments Temporary segments
* Relevant only if tablespace PERMANENT
Trang 12• Since rollback segments can deallocate extents automatically, they are
likely to cause fragmentation in a system with high update activity
• Temporary segments in permanent tablespaces can release space quite
frequently, and therefore they must be located in separate tablespaces
Temporary segments are discussed in a later lesson
Influence of Segment Life Span
Segments may have different life spans in a database For example, in a
project-based environment, such as a software house, all data relating to an
application may need to be purged when the development of the system is
complete Using a separate set of tablespaces for locating these segments
may help during clean up At the end of the project the whole tablespace can
be backed up and dropped to provide space for other applications using the
database
Trang 13Oracle8: Database Administration 9-27
Summary
Summary
Quick Reference
Initialization parameters DB_BLOCK_SIZE
Dynamic performance views None
Data dictionary views DBA_TABLESPACES
DBA_DATA_FILES DBA_SEGMENTS DBA_EXTENTS DBA_FREE_SPACE DBA_FREE_SPACE_COALESCED Commands ALTER TABLESPACE COALESCE
9-20 Copyright Oracle Corporation, 1998 All rights reserved.
Summary
for different types of segments
Trang 1510
Managing Rollback
Segments
Trang 17Oracle8: Database Administration 10-3
• Creating rollback segments using
appropriate storage settings
• Maintaining rollback segments
• Obtaining rollback segment information
from the data dictionary
• Troubleshooting rollback segment
problems
Trang 18A rollback segment is used to save the old value when a process is making
changes to the data in a database It stores block information such as file and
block ID, and also data, as it existed before being modified
The header of a rollback segment contains a transaction table where
information about current transactions using the segment is stored
A transaction can use only one rollback segment to store all of its rollback
(undo) records
Many concurrent transactions can write to one rollback segment
10-3 Copyright Oracle Corporation, 1998 All rights reserved.
Rollback Segment
Update transaction
Old image
New image Rollback
segment
Table
Trang 19Oracle8: Database Administration 10-5
Rollback Segments
Rollback Segments
Transaction Rollback
When a transaction makes changes to a row in a table, the old image is saved
in the rollback segment If the transaction is rolled back, the value in the
rollback segment is written back to the row, restoring the original value
Transaction Recovery
If the instance fails when transactions are in progress, Oracle server needs to
rollback the uncommitted changes when the database is opened again This
rollback is known as transaction recovery and is only possible if changes
made to the rollback segment are also protected by the redo log files
Read Consistency
When transactions are in progress, other users in the database should not see
any uncommitted changes made by these transactions In addition, a
statement should not see any changes that were committed after the
statement commences execution The old values in the rollback segments are
also used to provide the readers a consistent image for a given statement
10-4 Copyright Oracle Corporation, 1998 All rights reserved.
Rollback Segments: Purpose
Transaction rollback
Transaction
recovery
Rollback segment
Read consistency
Trang 20SYSTEM Rollback Segment
The SYSTEM rollback segment is created in the SYSTEM tablespace when
a database is created This rollback segment can only be used for changes
made to objects in the SYSTEM tablespace
Non-SYSTEM Rollback Segments
A database that has multiple tablespaces needs at least one non-SYSTEM
rollback segment A non-SYSTEM rollback segment, which is created by
the database administrator, can be used for changes made to objects in any
non-SYSTEM tablespace There are two types of non-SYSTEM rollback
segments
Private
Private rollback segments are segments that are only acquired by an instance
if they are either named in the parameter file or if they are explicitly brought
online by issuing a command manually
10-5 Copyright Oracle Corporation, 1998 All rights reserved.
Types of Rollback Segments
• SYSTEM
• Non-SYSTEM
Trang 21Oracle8: Database Administration 10-7
Rollback Segments
Public
Public rollback segments form a part of a pool of rollback segments
available in a database Public rollback segments can be used with the
Oracle Parallel Server
Note
The use of public rollback segments is discussed in the manual Oracle8
Parallel Server Concepts and Administration.
Instructor Note
Although deferred rollback segments are used by the Oracle server, no
maintenance is required on the part of the DBA They are created when a
user rolls back a transaction that made changes to data in a tablespace that is
currently offline They are automatically dropped when they are no longer
needed
Trang 22Using Rollback Segments with Transactions
Allocation of Rollback Segment
When a transaction begins, a rollback segment needs to be assigned to this
transaction A transaction may request a specific rollback segment using the
following command:
SET TRANSACTION USE ROLLBACK SEGMENT rollback_segment
If no such request is made, the Oracle server chooses the rollback segment
with the fewest transactions, and assigns it to the transaction
Using Extents
Transactions use extents of a rollback segment in an ordered circular
fashion, moving from one to the next after the current extent is full A
transaction writes a record to the current location in the rollback segment
and advances the current pointer by the size of the record
10-6 Copyright Oracle Corporation, 1998 All rights reserved.
Transactions and Rollback
A A A
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
A A A A A A A A A A A
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
A A A A A A A A A A A AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
A A A A A A A A A A A
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA AAAA
A A A A A A A A A A A
Transaction 2