Home > Articles > Data > Oracle

A Close Look at Oracle8i Data Block Internals

Oracle expert Dan Hotka explores some internals of the Oracle RDBMS, primarily physical storage of data. This article concentrates on data blocks: how they're created, how space is really managed inside a tablespace, and some other geeky internal things of interest in the physical storage of data.

Reproduced with permission from Pinnacle Publishing. This article appeared in the Sept 1999 issue of Oracle Professional. All rights reserved.

A table segment consists of one segment header and one or more extents, and these extents are made up of one or more contiguous data blocks. The first block of each Oracle segment is the segment header. A segment is made up of at least two blocks: the segment header and the initial extent. CREATE TABLE X (C NUMBER) Storage (INITIAL 1) creates a segment with two blocks.

The block size is defined at CREATE DATABASE time and can't be changed easily. The default block size for most systems is 2KB. Oracle8 supports block sizes from 2KB to 64KB. Always choose a block size that's an even multiple of the operating system's filesystem block size. If you make the Oracle block size smaller than the operating system block size, extra data will always be read with each read operation. If the Oracle block size is not an even multiple of the operating system block size, there will be wasted space in the operating system's filesystem.

There's a distinct tradeoff between block size and performance. Larger blocks are useful for data warehouse and decision-support type systems. More data is read into memory with a single read operation and more index leaf pointers can be stored in a single read operation. If an application has lots of updates and deletes (DML), smaller blocks are useful. There will be less contention for rows because there will be fewer rows per block.

You can query the X$KVIS view to see the actual values of db_block_size.

Figure 1 illustrates the Oracle8 data block format. All Oracle blocks have similar attributes.

Figure 1

Block layout.

All blocks contain a header area consisting of a block type, a block format, relative database address (DBA), SCN, SCN sequence number, a check value, and a tail:

  • Block format refers to whether this is an Oracle7 or an Oracle8 formatted block.

  • Sequence number refers to the order of the blocks within the same SCN.

  • The check value is an optional INIT.ORA setting (DB_CHECK_SUM) that provides integrity checking at the block level.

  • The tail is used as a block consistency check to ensure that the beginning of the block and the end of the block are consistent. This number consists of the SCN + block type + SCN sequence number.

The following list shows some important block types:

Type

Description

1

Undo segment header

2

Undo segment block

5

Data segment header

7

Temporary table

11

Data file header

Several methods are used to visualize or dump the data blocks. In UNIX, use the dd command:

dd bs=2k if=/ora8/data/users01.dbf skip=200 count = 5 | od -x > pg

In the VMS world, use the DUMP command:

DUMP /BLOCKS = (START:<os block #>, END:,os block #>) 
/OUT = blockdmp.out users01.dbf

The NT world uses HEDIT. A formatted dump can be attained through Oracle via SVRMGR:

alter system dump datafile 7 block 201

Since this discussion is on physical storage, this article discusses the blocks related to physical storage, such as segment headers and data blocks. A segment header is always the first block of an object (see Figure 2). The segment header has six major areas: extent control header, map header, extent map, and three types of free lists (free lists are described in the next section).

  • The extent control header contains the number of extents allocated to this segment, the number of blocks allocated to the segment, DBA of the last block of the extent map (0 if no UNLIMITED EXTENTS is used), number of extent map blocks, high water mark (HWM) extent size, HWM extent number, and HWM block number within the extent. The high water mark (HWM) is the pointer to the DBA of the last block to receive inserts. Blocks below this mark are maintained on free lists. Blocks in extents above this mark have been allocated to the segment but haven't been used yet. Blocks above the HWM are available for SQL*Loader direct-load operations, parallel DML, and for inserts after the free list has been exhausted and the HWM has been moved.

  • The map header simply contains DBA information of the next block containing extent map information.

  • The extent map contains the beginning data block DBA and the number of blocks associated with the extent. The size of the extent map is directly related to the block size being utilized.

    Oracle7.3 introduced a concept known as unlimited extents. Instead of having the block size constrained by a limited number of extents (such as 121 for a 2KB block), Oracle allows for objects to grow and dynamically extend indefinitely. This is accomplished by chaining additional blocks to store additional extent-map information.

Figure 2

Space utilization in a segment.

There are three types of free lists that store information about available space within a segment:

  • Master free lists (MFL) contain newly allocated blocks up to the HWM and blocks freed by a committed transaction.

  • Process free lists (PFL) are user definable (storage parameter FREELISTS N) and are used to reduce contention on the master free list. This list spreads the requests over several blocks.

  • The transaction free list (TFL) holds blocks freed by a particular transaction to see whether that same transaction can use the space later. After the commit, this space is then put on the MFL. The MFL contains a flag that says whether the free list is used or not (1 or 0). The segment header also contains the DBA of the first block on the free list chain and the DBA of the last block on the free list chain. The blocks on the free list chain (FLC) contain a flag indicating that this block is linked to the free list chain and the DBA of the next block on the chain. This information is stored in the cache layer of the data block header.

Blocks below the HWM that meets the PCTFREE parameters are managed on the MFL (master free list).

Figure 3 shows how Oracle looks for free space to store a newly inserted row. Oracle searches the uncommitted TFL first. If it finds space, it uses that space; otherwise, it searches the PFL. If it finds space, it uses that space. Oracle then searches the MFL for free space. If it finds free space, it moves the space to the PFL and uses it. Oracle then searches the committed TFLs; if it finds space there, it moves the space to the MFL and begins the whole search process again. If this entire process is unsuccessful, Oracle checks whether the HWM can be advanced. If so, it adds this new space to the MFL and searches again. Otherwise, Oracle adds another extent to the object, advances the HWM, and searches the MFL yet again for space. If max-extents is hit, the max extents exceeded error is returned; otherwise, the no more space in tablespace error is returned.

Figure 3

Finding free space.

An extent is a contiguous set of blocks as defined by the storage parameter. If the extent size is indicated in bytes, Oracle rounds up the extent size to the nearest multiple of five blocks or to the nearest multiple of the MINIMUM EXTENT storage parameter value (if defined). Oracle searches the dictionary cache first, looking for an exact extent size match. If not found, it searches the fet$ for an exact or larger extent size match. If no exact match is found, Oracle repeats the two searches, looking for a larger area. If found, Oracle uses the required extent size from the larger area; if no matches are found, it coalesces the tablespace and repeats this whole process again. If no space is found, Oracle rounds down the extent size and tries the whole process again. If on the third loop of this process no space is found, Oracle either extends the tablespace (if this tablespace option is set) or returns an error. Figure 4 shows this process.

Figure 4

Dynamic extent allocation.

Adjacent unused extents are coalesced to create larger extents that may satisfy space searches more quickly. Free space can be coalesced via three methods: on demand (as needed during a search, as explained above), manually alter tablespace ... coalesce, or by SMON. SMON performs this action for the tablespaces during a space transaction and only if PCTINCREASE is greater than 0 at the tablespace level.

Data blocks also contain a cache layer, a transaction layer, and a data layer (see Figure 5). This discussion is limited to data blocks, but suffice to say that the contents of the data layer depend on the type of flag as to what kind of Oracle block this is.

Figure 5

Data block layout.

The data block contains a header, a table directory, a row directory, row data, and hopefully some free space. The block header contains the same static block information as all other blocks, discussed previously in this article.

The cache layer contains information about the number of interested transaction list (ITL) slots, a flag for data or index block, and free list information such as free list flag and next block on the free list (that is, the free list chain). The ITL is used to mark the row locked until the transaction completes. The ITL contains the transaction identifier. The ITL defaults to 1 and is maintained by storage parameters INITRANS and MAXTRANS. The number of ITLs controls how many concurrent DML operations can happen to a particular block.

The transaction layer contains the actual ITL number (or numbers as determined by INITRANS and MAXTRANS), the undo address information, a status flag, the number of rows being affected by this transaction, and free space credits. Free space credits holds any space that was freed by an update or delete until the commit actually occurs.

NOTE

ITLs do take space that would otherwise be available for rows.

The table directory tracks the tables that have rows in this data block; that is, tables involved in a cluster.

Transaction free lists (TFLs) are stored in the block as a separate structure and are not controlled by any external parameters. There are a minimum of 16 per segment, created implicitly by Oracle. Each TFL is associated with only one transaction. If the limit of TFLs is reached, the transaction waits for a TFL to free. This activity can be monitored with V$WAIT and V$TRANSACTIONS.

The row directory contains information about the rows stored in the data block.

Figure 6 illustrates the row data format. Notice that the available space in a block is between the row data and the block header information. As rows are inserted or updated, the row data part grows from the end of the block toward the front. The block header grows down from the top based on the number of ITLs, rows added, and so on. This free space is managed by a combination of PCTUSED and PCTFREE storage clause parameters. PCTUSED determines when a block is no longer available for inserted rows. PCTFREE determines when a block is again available to have inserted rows.

TIP

The combination of PCTFREE and PCTUSED should be 75.

NOTE

PCTFREE always defaults to at least 10%, even if set lower than 10%.

Figure 6

Row layout.

Row data is added from the bottom of the free space in a block toward the top. The static part of the row format contains a row flag, a lock byte (ITL entry locking this row), number of columns in this row, and a cluster key indicator. Then there's a column length (1 byte if length is < 254, otherwise 3 bytes) and the actual column data. Trailing null value fields are not stored. When reading a dump, the next row would be indicated by the presence of another row flag.

The following table shows some values for row flags:

Value

Description

H

Head of row piece

K

Cluster key

D

Deleted row

F

First data piece

L

Last data piece

P

First column continued from previous location

Row chaining (see Figure 7) occurs when a row is either inserted or updated and is physically longer than the available block size. Row migration (see Figure 8) occurs when an updated row no longer fits into the existing block. In my experience, Oracle migrates and/or chains rows based on a variety of conditions.

Figure 7

Chained row layout.

Figure 8

Migrated row layout.

The truncate command is the quickest way to delete all the rows from a table. This method of clearing out a table has no recovery. It's fast because it simply sets HWM, MFL, and TFLs to null. If the REUSE option isn't specified (default behavior), all the extents except for MINEXTENTS are then released to the tablespace. Full table scans scan through all the blocks until reaching the HWM. If objects are loaded with many rows, most of the rows are deleted; the table should be reorganized to move the HWM where it belongs, rather than at the end of many empty or almost-empty blocks.

Direct-path loading is a very fast way of loading data into an Oracle database. It completely circumvents the SGA, read-consistent features, and so on. Direct-path loading happens above the HWM. This method of loading data begins by putting a shared lock on the object being loaded. A temporary segment is then created, based on the extent size of the object being loaded. The tablespace must have enough room to accommodate an extent size of the initial and next extent of the original table. This temporary segment is populated with the rows, the extents are added to the original table, and the HWM is moved to the end of these new extents.

SQL*Loader and some parallel operations utilize direct-path loading.

Temporary segments are needed when Oracle is unable to sort in memory. Create index or select statements that have an order by, distinct, group by, or union clause cause a sort operation. The INIT.ORA parameter, sort_area_size, defines the amount of memory dedicated for sort operations. When this area is exhausted, Oracle utilizes temporary segments to do the sort operation. There are two types of temporary storage: permanent tablespace (the tablespace as we know it) and temporary tablespaces. These are easily created by adding the TEMPORARY clause in the CREATE TABLESPACE command. Tablespaces can be exchanged with the ALTER TABLESPACE command. The basic difference in the two is that SMON cleans up unused temporary segments in a permanent tablespace where the segments are left alone after a sort operation in a temporary tablespace. Also, only temporary segments can exist in a temporary tablespace. This allows the space requirements of sort operations to grow and be maintained throughout the life of the instance.

Monitor this sort area via V$SORT_SEGMENT and V$SORT_USAGE.

NOTE

Use a consistent value for initial and next extent size with PCTINCREASE = 0. Make the extent size a multiple of sort_area_size. Add one db_block size to allow for the segment header in the initial extent.

About the Author

Dan Hotka is a director of database field operations for Quest Software. He has more than 22 years in the computer industry and more than 17 years of experience with Oracle products. He is an acknowledged Oracle expert, with Oracle experience dating back to the Oracle V4.0 days. He has just completed Oracle8i from Scratch (Que, 2000, ISBN 0789723697) and coauthored the popular books Oracle Unleashed (SAMS, 1996, 067230872X), Oracle8 Server Unleashed (SAMS, 1998, ISBN 0672312077), Oracle Development Unleashed, Third Edition (SAMS, 2000, ISBN 0672315750), and Special Edition Using Oracle8/8i (Que, 2000, ISBN 0789719754). Dan is frequently published in Oracle Professional, the monthly trade journal by Pinnacle Publications, and regularly speaks at Oracle conferences and usergroups around the world. Dan can be reached at dhotka@earthlink.net or dhotka@quest.com.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020