Professional Documents
Culture Documents
Logical Physical
• Database allocates logical space
for all data in the database. Database
• The logical units of database
space allocation are data blocks, Schema Tablespace Data file
extents, segments, and
tablespaces.
Segment
• At a physical level, the data is
stored in data files on disk.
Extent
• The data in the data files is
stored in operating system Oracle data
OS block
blocks. block
Tablespaces and Datafiles
• A database is divided into one or more logical storage units called
tablespaces. The database's data is collectively stored in the database's
tablespaces.
• Each tablespace in a database consists of one or more files called
datafiles. These are physical structures that conform with the operating
system in which DB is running.
• A database's data is collectively stored in the datafiles that organize each
tablespace of the database.
• The simplest database would have one tablespace and one datafile. A
more complicated database might have three tablespaces, each consisting
of two datafiles (for a total of six datafiles).
Why bother with tablespaces?
• Uses tablespaces to:
• control disk space allocation for database data
• assign specific space quotas for database users
• control availability of data by taking individual tablespaces online or offline
• perform partial database backup or recovery operations
• allocate data storage across devices to improve performance
• Different functions
• System tablespace
• Temporary tablespaces
• User tablespaces
• Read-only table spaces
Segments, Extents, and Blocks
• Segments exist within a tablespace.
• Segments are made up of a collection of extents.
• Extents are a collection of data blocks.
• Data blocks are mapped to disk blocks.
Table A Table B
Rows
Segment Segment
Table
Tablespace
• Each segment
Data Blocks and Operating System Blocks
• At the physical level, database data is stored in
disk files made up of operating system blocks.
• An operating system block is the minimum unit
of data that the operating system can read or
write.
• In contrast, a Data block is a logical storage
structure whose size and structure are not
known to the operating system.
• Diagram shows that operating system blocks
may differ in size from data blocks.
• The database requests data in multiples of data
blocks, not operating system blocks.
Data Blocks and Operating System Blocks
• When the database requests a data block, the operating
system translates this operation into a requests for data in
permanent storage.
• The logical separation of data blocks from operating system
blocks has the following implications:
• Applications do not need to determine the physical
addresses of data on disk.
• Database data can be striped or mirrored on multiple
physical disks.
Data Block Format
ROWID --------------------------
AAAPec AAF AAAABS AAA
Rowid Format
• An extended rowid is displayed in a four-piece format, OOOOOOFFFBBBBBBRRR, with
the format divided into the following components:
• OOOOOO
• The data object number identifies the segment (data object AAAPec).
• A data object number is assigned to every database segment. Schema objects in
the same segment, such as a table cluster, have the same data object number.
• FFF
• The tablespace-relative data file number identifies the data file that contains the row
(file AAF).
• BBBBBB
• The data block number identifies the block that contains the row (block AAAABS).
• Block numbers are relative to their data file, not their tablespace.
• So, two rows with identical block numbers could reside in different data files of the same
tablespace.
• RRR
• The row number identifies the row in the block (row AAA)
Chained and Migrated Rows
• Database must manage rows that are too large to fit into a single block. The
following situations are possible:
• The row is too large to fit into one data block when it is first inserted.
• In row chaining, Database stores the data for the row in a chain of one or more
data blocks reserved for the segment.
• Row chaining most often occurs with large rows.
• Examples include rows that contain a column of data
type LONG or LONG RAW, a VARCHAR2(4000) column in a 2 KB block, or
a row with a huge number of columns.
•A row that originally fit into one data block is updated so that the overall row length
increases, but insufficient free space exists to hold the updated row.
Chained and Migrated Rows
• In row migration, Database moves the entire row to a new data block,
assuming the row can fit in a new block.
• The original row piece of a migrated row contains a pointer or
"forwarding address" to the new block containing the migrated
row.
• The rowid of a migrated row does not change.
• A row has more than 255 columns.
• Some Database can only store 255 columns in a row piece.
• Thus, if a row inserted into a table that has 1000 columns, then the
database creates 4 row pieces, typically chained over multiple
blocks.
• When a row is chained or migrated, the I/O needed to retrieve the data
increases.
Chained Rows
Migrated Rows
Tablespace
• Tablespaces are logical storage groups that can be used to store logical
database constructs such as tables and indexes.
• There are five types of tablespaces that are stored in the oracle database.
• SYSTEM
• SYSAUX
• TEMP
• UNDO
• USERS
Tablespace
• SYSTEM tablespace:
• The SYSTEM tablespace stores the data dictionary information means metadata (i.e. data
about data).
• The data dictionary belongs to the sys schema.
• Oracle creates system tablespace automatically when the database is created. We cannot
rename or drop the SYSTEM tablespace. We don’t create user data in the system
tablespace.
• SYSAUX tablespace:
• The SYSAUX tablespace is the helper of the system tablespace. The SYSAUX tablespace is
an supporting tablespace to the SYSTEM tablespace. It helps to reduce the load on the
SYSTEM tablespace.
• Oracle creates it automatically when the database is created. We cannot rename or drop
the SYSAUX tablespace.
Tablespace
• TEMP tablespace:
• The TEMP tablespace is used to manage space for database sort and joining operations and for storing
global temporary tables.
• Oracle uses temporary tablespaces for sorting datasets that are too big to fit into PGA.
• Other SQL operations that might require disk sorting are: CREATE INDEX, ANALYZE, SELECT DISTINCT,
ORDER BY, GROUP BY, UNION, INTERSECT, MINUS, and so on.
• Example: When a user executes a select statement containing an order by, Oracle needs
space to execute this statement and make an order for the select statement and display the
output.
• Oracle uses the temporary tablespace for this operation. There should be a question Oracle
also can use the PGA for this operation why only temp tablespace. These operations would
require huge RAM and huge space so oracle uses temp tablespace for the above operations.
• SELECT FROM STUDENTS ORDER BY ROLL_NO;
Tablespace
• UNDO tablespace:
• UNDO tablespace is used to roll back or undo, changes to the database. Roll back
transactions when a ROLLBACK statement is issued.
• Recover the database back to the original state. Provides read consistency
• Example: User runs an update statement and didn’t issue a commit yet. Oracle
keeps the old value in the undo tablespace in order to recover the data if the user
issues rollback and new values in the database buffer cache and redo log buffer.
Once the user issues a commit then the old data present in the undo tablespace is
removed and new data present in the database buffer cache and the redo log
buffer will be updated to the datafiles. The other users can be able to access the
old data which is not committed and the old data stored in the undo tablespace.
The user may commit and may not commit. This is the reason UNDO tablespace is
created. This provides read consistency.
Tablespace
• USERS tablespace:
• The USERS tablespace stores user’s objects and data. Here we can tables, insert data, and
update data.
• Every database should have a tablespace for permanent user data that is assigned to
users. Otherwise, user objects will be created in the SYSTEM tablespace, which is not
good practice.
• In the preconfigured database, USERS is designated as the default tablespace for all new
users. Once a new user is created oracle will allocate users tablespace as the default
tablespace.
• If we want a new tablespace for a particular user you need to create a separate
tablespace for the user.