Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 3 ■ FILES 93 (data from more than one table may be stored on the same block). The row directory contains information describing the rows that are to be found on the block. This is an array of pointers to where the rows are to be found in the data portion of the block. These three pieces of the block are collectively known as the block overhead, which is space used on the block that is not available for your data, but rather is used by Oracle to manage the block itself. The remaining two pieces of the block are straightforward: there will possibly be free space on a block, and then there will generally be used space that is currently storing data. Now that you have a cursory understanding of segments, which consist of extents, which consist of blocks, let’s take a closer look at tablespaces and then at exactly how files fit into the big picture. Tablespaces As noted earlier, a tablespace is a container—it holds segments. Each and every segment belongs to exactly one tablespace. A tablespace may have many segments within it. All of the extents for a given segment will be found in the tablespace associated with that segment. Segments never cross tablespace boundaries. A tablespace itself has one or more data files associated with it. An extent for any given segment in a tablespace will be contained entirely within one data file. However, a segment may have extents from many different data files. Graphically, a tablespace might look like Figure 3-3. Figure 3-3. A tablespace containing two data files, three segments, and four extents Figure 3-3 shows a tablespace named USER_DATA. It consists of two data files, user_data01 and user_data02. It has three segments allocated it: T1, T2, and I1 (probably two tables and an index). The tablespace has four extents allocated in it, and each extent is depicted as a logically contiguous set of database blocks. Segment T1 consists of two extents, one extent in each file. Segments T2 and I1 each have one extent depicted. If we need more space in this tablespace, we could either resize the data files already allocated to the tablespace or we could add a third data file to it. Tablespaces are a logical storage container in Oracle. As developers, we will create segments in tablespaces. We will never get down to the raw “file level”—we do not specify that we want our extents to be allocated in a specific file (we can, but we do not in general). Rather, we create objects in tablespaces, and Oracle takes care of the rest. If at some point in the future, the DBA decides to move our data files around on disk to more evenly distribute I/O, that is OK with us. It will not affect our processing at all.

94 CHAPTER 3 ■ FILES Storage Hierarchy Summary In summary, the hierarchy of storage in Oracle is as follows: 1. A database is made up of one or more tablespaces. 2. A tablespace is made up of one or more data files. These files might be cooked files in a file system, raw partitions, ASM managed database files, or a file on a clustered file system. A tablespace contains segments. 3. A segment (TABLE, INDEX, and so on) is made up of one or more extents. A segment exists in a tablespace, but may have data in many data files within that tablespace. 4. An extent is a logically contiguous set of blocks on disk. An extent is in a single tablespace and, furthermore, is always in a single file within that tablespace. 5. A block is the smallest unit of allocation in the database. A block is the smallest unit of I/O used by a database. Dictionary-Managed and Locally-Managed Tablespaces Before we move on, we will look at one more topic related to tablespaces: how extents are managed in a tablespace. Prior to Oracle 8.1.5, there was only one method to manage the allocation of extents within a tablespace: a dictionary-managed tablespace. That is, the space within a tablespace was managed in data dictionary tables, in much the same way you would manage accounting data, perhaps with a DEBIT and CREDIT table. On the debit side, we have all of the extents allocated to objects. On the credit side, we have all of the free extents available for use. When an object needed another extent, it would ask the system to get one. Oracle would then go to its data dictionary tables, run some queries, find the space (or not), and then update a row in one table (or remove it all together) and insert a row into another. Oracle managed space in very much the same way you will write your applications: by modifying data and moving it around. This SQL, executed on your behalf in the background to get the additional space, is referred to as recursive SQL. Your SQL INSERT statement caused other recursive SQL to be executed to get more space. This recursive SQL can be quite expensive if it is done frequently. Such updates to the data dictionary must be serialized; they cannot be done simultaneously. They are something to be avoided. In earlier releases of Oracle, we would see this space management issue—this recursive SQL overhead—most often occurring in temporary tablespaces (this was before the introduction of “real” temporary tablespaces created via the CREATE TEMPORARY TABLESPACE command). Space would frequently be allocated (we would have to delete from one dictionary table and insert into another) and de-allocated (we would put the rows we just moved back where they were initially). These operations would tend to serialize, dramatically decreasing concurrency and increasing wait times. In version 7.3, Oracle introduced the concept of a true temporary tablespace, a new tablespace type dedicated to just storing temporary data, to help alleviate this issue. Prior to this special tablespace type, temporary data was managed in the same tablespaces as persistent data and treated in much the same way as permanent data was. A temporary tablespace was one in which you could create no permanent objects of your own. This was fundamentally the only difference; the space was still managed in the data

94<br />

CHAPTER 3 ■ FILES<br />

Storage Hierarchy Summary<br />

In summary, the hierarchy of storage in <strong>Oracle</strong> is as follows:<br />

1. A database is made up of one or more tablespaces.<br />

2. A tablespace is made up of one or more data files. These files might be cooked files in<br />

a file system, raw partitions, ASM managed database files, or a file on a clustered file<br />

system. A tablespace contains segments.<br />

3. A segment (TABLE, INDEX, <strong>and</strong> so on) is made up of one or more extents. A segment<br />

exists in a tablespace, but may have data in many data files within that tablespace.<br />

4. An extent is a logically contiguous set of blocks on disk. An extent is in a single tablespace<br />

<strong>and</strong>, furthermore, is always in a single file within that tablespace.<br />

5. A block is the smallest unit of allocation in the database. A block is the smallest unit of<br />

I/O used by a database.<br />

Dictionary-Managed <strong>and</strong> Locally-Managed Tablespaces<br />

Before we move on, we will look at one more topic related to tablespaces: how extents are<br />

managed in a tablespace. Prior to <strong>Oracle</strong> 8.1.5, there was only one method to manage the allocation<br />

of extents within a tablespace: a dictionary-managed tablespace. That is, the space<br />

within a tablespace was managed in data dictionary tables, in much the same way you would<br />

manage accounting data, perhaps with a DEBIT <strong>and</strong> CREDIT table. On the debit side, we have all<br />

of the extents allocated to objects. On the credit side, we have all of the free extents available<br />

for use. When an object needed another extent, it would ask the system to get one. <strong>Oracle</strong><br />

would then go to its data dictionary tables, run some queries, find the space (or not), <strong>and</strong> then<br />

update a row in one table (or remove it all together) <strong>and</strong> insert a row into another. <strong>Oracle</strong><br />

managed space in very much the same way you will write your applications: by modifying<br />

data <strong>and</strong> moving it around.<br />

This SQL, executed on your behalf in the background to get the additional space, is<br />

referred to as recursive SQL. Your SQL INSERT statement caused other recursive SQL to be executed<br />

to get more space. This recursive SQL can be quite expensive if it is done frequently.<br />

Such updates to the data dictionary must be serialized; they cannot be done simultaneously.<br />

They are something to be avoided.<br />

In earlier releases of <strong>Oracle</strong>, we would see this space management issue—this recursive<br />

SQL overhead—most often occurring in temporary tablespaces (this was before the introduction<br />

of “real” temporary tablespaces created via the CREATE TEMPORARY TABLESPACE comm<strong>and</strong>).<br />

Space would frequently be allocated (we would have to delete from one dictionary table <strong>and</strong><br />

insert into another) <strong>and</strong> de-allocated (we would put the rows we just moved back where they<br />

were initially). These operations would tend to serialize, dramatically decreasing concurrency<br />

<strong>and</strong> increasing wait times. In version 7.3, <strong>Oracle</strong> introduced the concept of a true temporary<br />

tablespace, a new tablespace type dedicated to just storing temporary data, to help alleviate<br />

this issue. Prior to this special tablespace type, temporary data was managed in the same<br />

tablespaces as persistent data <strong>and</strong> treated in much the same way as permanent data was.<br />

A temporary tablespace was one in which you could create no permanent objects of your<br />

own. This was fundamentally the only difference; the space was still managed in the data

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!