harvard university oracle database administration session 5 data storage
Post on 21-Dec-2015
226 Views
Preview:
TRANSCRIPT
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
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
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
Harvard University
Extents Extents
Segment
8Kblocks
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
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
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
Harvard University
TableTable Table
Index
Table
Table
Index
Index
Index Table
Index
Tablespace
DatafileDatafile
Harvard University
Segments
There are many types of segments – Table– Table Partition– Index– Undo – Temporary– Large Object (LOB)
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
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
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
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]
Harvard University
The Storage Clause
Storage ( initial bytes,
next bytes,
minextents integer,
maxextents integer,
pctincrease integer)
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
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)
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
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
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
Harvard University
Data Block Format
The data block can be broken into the following sections
– Header– Table Directory– Row Directory– Free space – Row Data
Harvard University
Common and VariableHeader
Table Directory
Row Directory
Free Space
Row Data
Data Block Format
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
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
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.
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
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
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
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
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
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
Harvard University
Data Block Format
The data block format is the same, regardless of the type of data stored in that block
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
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
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
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
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.
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.
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.
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.
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.
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
Uniform Example
CREATE TABLESPACE USERS DATAFILE '/u04/oradata/<SID>/test.dbf' SIZE 100M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;
Harvard University
Autoallocate Example
CREATE TABLESPACE local_auto DATAFILE '/u04/11.1.0/oradata/<SID>/test.dbf' SIZE 100M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
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.
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.
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;
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
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
top related