Showing posts with label Physical Storage. Show all posts
Showing posts with label Physical Storage. Show all posts

Row Chaining, Row Migrating, PCTFREE, PCTUSED

Row Chaining  

The row is too large to fit into an EMPTY data block that is known as chained row. Oracle stores the data for the row in a chain of data blocks (one or more) reserved for that segment. If  you have a 2k blocksize but your row size is 4k, we will use 3 blocks to store that row in pieces.  Any table with a long/long raw will have chained rows.Row chaining most often occurs with large rows, such as rows that contain a column of datatype LONG or LONG RAW. Row chaining in these cases isnot avoided. Any table whose rowsize exceeds the  blocksize will have chained rows.  Any table with more then 255 columns will have chained rows.You can see if you "have it" by looking at the system wide statistic:

select * from v$sysstat where name like 'table pop cont%';

Row Migrating

A row that was moved to another block due to an update making it too large to fit on its original block with the other rows there is known as migrated row.Oracle tries to find another Blockwith enough free space to hold the entire row.If such block is available Oracle moves the entire ROW to the NEW BLOCK.Oracle keeps the original Row piece of a Migrated row row to POINT to the NEW BLOCK containing the actual row.The ROWID of the MIGRATED rows does not change. INDEXES are not updated and they point to the ORIGINAL row LOCATION.

Migration and Chaining have negative effects on performance. INSERT and UPDATE statements that cause migration and chaining perform very poorly since due to additional PROCESSING. Queries that use an Index to select migrated or chained rows must perform additional I/O's.
 
PCTFREE Parameter

The PCTFREE parameter specifies the minimum percentage of data block to be reserved as free space. If you used PCTFREE 20 then at least 20% size of data block will be reserved as free space. For example if you use data block size 8K (DB_BLOCK_SIZE=8192) then PCTFREE 20 will reserved 1638 bytes as free space in a data block. This parameter is used to update to the existing rows already within each block.You can specify this parameter which issuing CREATE TABLE statement.
   

 

PCTUSED Parameter

This parameter specifies the minimum percentage of a block that can be used for row data plus overhead(data block header, table directory, and row directory) before new rows are 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 the percentage of that block falls below the parameter PCTUSED.

If we set PCTUSED 40 in the CREATE TABLE statement then data block used for this table's data segment is considered unavailable for the insertion of any new rows until the amount of used space in the block falls to 39% or less (Here the block's used space has previously reached PCTFREE).
Related Post:- Row Format

Row Format In DB

Oracle stores each row of a database table containing data for less than 256 columns as one or more row pieces. If an entire row can be inserted into a single data block, then Oracle stores the row as one row piece.If all of a row's data cannot be inserted into a single data block or an update to an existing row causes the row to outgrow its data block, Oracle stores the row using multiple row pieces. A data block usually contains only one row piece for each row. When Oracle must store a row in more than one row piece, it is chained across multiple blocks.

 





When a table has more than 255 columns, rows that have data after the 255th column are likely to be chained within the same block. This is called intra-block chaining. A chained row's pieces are chained together using the rowids of the pieces.Each row piece, chained or unchained, contains a row header and data for all or some of the row's columns.
The row header contains information about:
  •     Row pieces
  •     Chained row pieces only)
  •     Columns in the row piece
  •     Cluster keys

A row fully contained in one block has at least 3 bytes of row header. After the row header information, each row contains column length and data. The column length requires 1 byte for columns that store 250 bytes or less, or 3 bytes for columns that store more than 250 bytes, and precedes the column data. Space required for column data depends on the datatype. If the datatype of a column is variable length, then the space required to hold a value can grow and shrink with updates to the data.

Oracle Data Block Format

The Format of Oracle Data Block is as follows:
  1. Header 
  2. Table Directory 
  3. Row Directory 
  4. Row Data
  5.  Free Space 

 
Header  
The header contains general block information, such as the block address and the type of segment (for example, data or index).
 
Table Directory

This portion of the data block contains information about the table having rows in this block.
 
Row Directory

This portion of the data block contains information about the actual rows in the block (including addresses for each row piece in the row data area).

After the space has been allocated in the row directory of a data block's overhead, this space is not reclaimed when the row is deleted. Therefore, a block that is currently empty but had up to 50 rows at one time continues to' have 100 bytes allocated in the header for the row directory. Oracle reuses this space only when new rows are inserted in the block.
 
Row Data

This portion of the data block contains table or index data. Rows can span blocks.
Related Post:- Row Format
 
Free Space

- Free space is allocated for insertion of new rows and for updates to rows that require additional space.
- In data blocks allocated for the data segment of a table or cluster, or for the index segment of an index, free space can also hold transaction entries.
- A transaction entry is required in a block for each INSERT, UPDATE, DELETE, and SELECT...FOR UPDATE statement accessing one or more rows in the block. 
- The space required for transaction entries in most operating systems require approximately 23 bytes.

Oracle Data Block Overview

  • Oracle manages the storage space in the datafiles of a database in units called data blocks.  
  • Data block is the smallest unit of data used by a database.  
  • At the physical, operating system level, all data is stored in bytes. Each operating system has a block size. Oracle requests data in multiples of Oracle data blocks, not operating system blocks.  
  • The standard block size is specified by the initialization parameter DB_BLOCK_SIZE. 
  • You can specify of up to five nonstandard block sizes. 
  • The data block sizes should be a multiple of the operating system's block size within the maximum limit to avoid unnecessary I/O. 
  • Oracle data blocks are the smallest units of storage that Oracle can use or allocate.
Related Topic: Data Block Format

Logical Storage Structure


Oracle Database allocates logical space for all data in the database. The logical units of database space allocation are data blocks, extents, segments, and tablespaces. At a physical level, the data is stored in data files on disk. The data in the data files is stored in operating system blocks.
The logical parts of the Oracle database are those structures within Oracle that determine where in the physical structures your table and index data reside. Since at the core of every operating system are mechanisms to access the physical data block defined on disk, Oracle must also have a logical structure that will relate down to that data block as your tables are created within the data files and as they grow over time. This is done by three logical structures that are kept for every object created in Oracle. These three structures are data blocks, extents, and segments.


Related Video:- Oracle DBA - Logical Database Structure

Physical Storage Structure


The physical structure of an Oracle database is determined by the operating system files that provide the actual physical storage for database information.One characteristic of an RDBMS is the independence of logical data structures such as tables, views, and indexes from physical storage structures. Because physical and logical structures are separate, you can manage physical storage of data without affecting access to logical structures. For example, renaming a database file does not rename the tables stored in it. An Oracle database is a set of files that store Oracle data in persistent disk storage.The physical structure of an Oracle database includes only three types of files: control files, data files, and redo log files


Data files

A data file is a physical file on disk that was created by Oracle Database and contains data structures such as tables and indexes. A temp file is a data file that belongs to a temporary tablespace. The data is written to these files in an Oracle proprietary format that cannot be read by other programs.

Control files

A control file is a root file that tracks the physical components of the database.

Online redo log files

The online redo log is a set of files containing records of changes made to data.

Database Storage Structure

An Oracle database is made up of physical and logical structures. Physical structures are those that can be seen and operated on from the operating system, such as the physical files that store data on a disk. Logical structures are created and recognized by Oracle Database and are not known to the operating system. The primary logical structure in a database, a tablespace, contains physical files. The applications developer or user may be aware of the logical structure, but is not usually aware of this physical structure. The DBA must understand the relationship between the physical and logical structures of a database.

Oracle Database


Oracle introduced the first commercial Relational Database Management System (RDBMS) almost 30 years ago. Oracle database consists of operating system files, also known as database files, that provide the actual physical storage for database information. The database files are used to ensure that the data is kept consistent and can be recovered in the event of a failure of the instance.

The general purpose of a database is to store and retrieve related information. An Oracle database has a logical and a physical structure. The physical structure of the database is the set of operating system files in the database. An Oracle database consists of three file types.

  • Data files containing the actual data in the database
  • Redo logs containing a record of changes made to the database to enable recovery of     the data in case of failures
  • Control files containing information necessary to maintain and verify database integrity Other Key File Structures

     The Oracle server also uses other files that are not part of the database:  
  • The parameter file defines the characteristics of an Oracle instance. For example, it contains parameters that size some of the memory structures in the SGA.
  • The password file authenticates users privileged to start up and shut down an Oracle instance.
  • Archived redo log files are offline copies of the redo log files that may be necessary to recover from media failures.



Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More