Database Administration
Essentials
Unit 2:
Database Storage and Space
Management
1
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
Database Storage and Space Management
2.1. Physical and Logical Storage, Data Block
2.2. Managing Tablespaces
2.3. Managing Data Files: Operation on Data Files,
Oracle Managed Files Feature
2.4. Managing Space: Automatic Space Management Features,
Locally Managed Tablespaces,
Automatic Segment Space Management
2.5. Proactive Space Management, Segment Advisor
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
CE: 2.1.
Physical and Logical Storage,
Data Block
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
CE: 2.1.1. Physical and Logical Storage
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
4
CE: 2.1.2. Data Block
▪ A data block is the smallest unit of data storage in an Oracle
database.
▪ It is a multiple of the operating system's block size.
▪ The most common used size is 8K, but it can also be 2K, 4K, 16K,
or 32K.
▪ The DB_BLOCK_SIZE parameter sets the block size when the
database is created.
▪ Once set, the block size cannot be changed.
▪ Each block has an internal format to manage stored data and free
space.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
5
CE: 2.1.2. Data Block (Conti…)
▪ The data block can be divided into three major areas:
1. Data Block Overhead
2. Row Data
3. Free Space
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
6
CE: 2.1.2. Data Block (Conti…)
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
7
CE: 2.1.2. Data Block (Conti…)
1. Data Block Overhead:
▪ Oracle Database uses this area to maintain the content of the block,
which is not used to store actual user data.
▪ This area is called block overhead, and it useally takes up 84 to 107
bytes.
▪ The Data Block Overhead includes following parts:
▪ Block Header
▪ Table Directory
▪ Row Directory
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
8
CE: 2.1.2. Data Block (Conti…)
1. Data Block Overhead: (Conti…)
▪ The Block Header - stores basic information like disk address,
segment type, and transactions.
▪ The Table Directory - lists the tables that store rows in the block.
▪ The Row Directory – keeps track of where each row is stored within
the block.
▪ When a transaction changes a row, it’s recorded in a transaction
list inside the block. This list holds both current and past transaction
info.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
9
CE: 2.1.2. Data Block (Conti…)
2. Row Data:
▪ The row data section holds the actual table data, like rows or index
entries.
▪ Each row has:
✓ A row header, which stores info about:
- How many columns are in the row
- If parts of the row are stored in other blocks
- Cluster key info (for clustered tables)
✓ The column data, which follows the row header and stores the
actual values.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
10
CE: 2.1.2. Data Block (Conti…)
2. Row Data: (Conti…)
▪ Normally, a block stores one piece of a row, unless the row is too
big.
▪ Columns are stored in the order defined in the CREATE TABLE
statement.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
11
CE: 2.1.2. Data Block (Conti…)
2. Row Data: (Conti…)
▪ ROWID uniquely identifies a row in a table.
▪ It’s the fastest way to access a row.
▪ ROWID contains:
✓ Object number (of the table)
✓ File number (where the block is stored)
✓ Block number
✓ Row number within the block
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
12
CE: 2.1.2. Data Block (Conti…)
2. Row Data: (Conti…)
▪ For Example:
select rowid from employees where employee_id = 100;
▪ Output:
rowid
------------------
AAAPecAAFAAAABSAAA
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
13
CE: 2.1.2. Data Block (Conti…)
3. Free Space
▪ Free space in a data block is the unused area reserved for future
updates and transactions.
▪ When a table, partition, or index is created, Oracle decides:
✓ How much free space to keep in each block for future row
updates.
✓ How many transaction lists to create.
▪ Oracle uses this free space to handle transactions, so if any changes
are made during transactions, it keeps track of it.
▪ If a block is full, new transactions must wait until space becomes
available.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
14
CE: 2.2.
Managing Tablespaces
15
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
CE: 2.2 Managing Tablespaces
What is an Oracle Tablespace?
▪ Oracle divides a database into one or more logical storage units
called tablespaces.
▪ Each tablespace consists of one or more files called datafiles.
▪ A datafile physically stores the data objects of the database such as
tables and indexes on disk.
▪ In other words,
Oracle logically stores data in the tablespaces and
Oracle physically stores data in datafiles
associated with the corresponding tablespaces.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
16
CE: 2.2 Managing Tablespaces (Conti…)
Relationship between a database, tablespaces, and datafiles
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
17
CE: 2.2 Managing Tablespaces (Conti…)
▪ As datafiles physical stores database data in storage (DISKS). So
when we create a datafile of 30G in database, it will occupy 30G of
space from defined storage.
▪ Thus, the database data files are stored in tablespaces.
▪ Tablespaces are of different types. They are:
1. SYSTEM tablespace
2. SYSAUX tablespace
3. PERMANENT tablespace
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
18
CE: 2.2 Managing Tablespaces (Conti…)
1. SYSTEM tablespace:
▪ It contains the data dictionary tables of the database.
▪ All the view, procedures, functions, packages and triggers are stored
in SYSTEM tablespace
▪ It is not recommended to user SYSTEM tablespace for creating any
other table or index.
2. SYSAUX tablespace:
▪ All the database metadata, that doesn't store in SYSTEM tablespace,
will be stored here.
▪ Many database components data's are stored in this tablespace.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
19
CE: 2.2 Managing Tablespaces (Conti…)
3. PERMANENT tablespace:
▪ A tablespaces are mostly referring to PERMANENT tablespace.
▪ This tablespace are used for storing the actual schema tables or
indexes . i.e it Stores user data.
▪ It doesn't store any of the data dictionary tables.
▪ There are two types of PERMANENT tablespace:
1) SMALLFILE (DEFAULT) – It is the common size tablespace, which
can contain multiple datafiles with each datafile of size 31G.
2) BIGFILE – It can contain only one datafile, which can grow up to
128 TB.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
20
CE: 2.2 Managing Tablespaces (Conti…)
▪ Additionally, there are specialized tablespaces also:
❖ UNDO tablespace:
▪ This tablespace stores Undo data.
▪ We can’t create any table or index inside undo tablespace.
▪ Each instance in the database have one defined UNDO tablespace.
i.e for standalone database, one assigned undo tablespace, and for
multi node rac system, each instance on the node will have one
assigned undo tablespace.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
21
CE: 2.2 Managing Tablespaces (Conti…)
❖ TEMPORARY tablespace:
▪ This tablespace stores the data temporarily for sessions doing sorting
and join operations.
▪ Sort operations are also generated by SELECT * FROM ….
WHERE clause that join rows from within tables and between
tables. The segments generated during this process will be stored in
temp tablespace.
▪ Each database will have one default temporary tablespace.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
22
CE: 2.2 Managing Tablespaces (Conti…)
So,
How to create tablespaces????
▪ Tablespaces can be created using…
CREATE DATABASE or CREATE TABLESPACE statement.
▪ While creating a tablespace, one must make several choices:
✓ Whether to make the tablespace smallfile or bigfile
✓ Whether to manage extents locally or with the dictionary
✓ Whether to manage segment space automatically or manually
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
23
CE: 2.2 Managing Tablespaces (Conti…)
How to obtain tablespace information?
▪ The data dictionary views can provide tablespaces information by using…
1. DBA_TABLESPACES
2. V$TABLESPACE
3. DBA_DATA_FILES
4. DBA_TEMP_FILES
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
24
CE: 2.2 Managing Tablespaces (Conti…)
▪ The DBA_TABLESPACES view provides information such as:
1. The tablespace block size.
2. The tablespace status: online, offline, or read-only.
3. The contents of the tablespace: undo, temporary, or permanent.
4. Whether it uses dictionary-managed or locally managed extents.
5. Whether the segment space management is automatic or manual.
6. Whether it is a bigfile or smallfile tablespace.
▪ The V$TABLESPACE view also has one row per tablespace, but it
includes some information other than DBA_TABLESPACES, such as
whether the tablespace participates in database flashback operations.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
25
CE: 2.2 Managing Tablespaces (Conti…)
▪ The DBA_DATA_FILES and DBA_TEMP_FILES views contain
information on data files and temp files, respectively. This information
includes the tablespace name, filename, file size, and autoextend settings.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
26
CE: 2.3.
Managing Data Files
27
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
CE: 2.3 Managing Data Files
▪ Discussion with Practical
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
28
CE: 2.4.
Managing Space
29
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
CE: 2.4. Managing Space
▪ Oracle Database manages three main components:
1. Automatic Space Management Features
2. Locally Managed Tablespace (LMT)
3. Automatic Segment Space Management (ASSM)
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
30
CE: 2.4. Managing Space (Conti…)
1. Automatic Space Management Features:
▪ Oracle automates many tasks related to disk space allocation and space
management to reduce manual intervention, such as:
✓ Automatic extent allocation
✓ Segment shrink for reclaiming space
✓ Space usage monitoring with views like DBA_FREE_SPACE
▪ For Example:
alter system set undo_management = auto;
₋ By using this command, Oracle will now automatically
create and manage the undo tablespace and its contents.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
31
CE: 2.4. Managing Space (Conti…)
2. Locally Managed Tablespaces (LMT):
▪ Unlike data dictionary-managed tablespaces, LMTs manage extent
allocation via bitmaps.
▪ It helps…
✓ To improved performance
✓ For less disagreement on data dictionary tables
✓ For better space utilization
₋ EXTENT MANAGEMENT LOCAL
▪ For Example: tells Oracle to use LMT.
create tablespace ts_bmiit ₋ UNIFORM SIZE 1M
specifies that all extents are 1MB.
datafile ‘df_bscit.dbf' size 100M
extent management local uniform size 1M;
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
32
CE: 2.4. Managing Space (Conti…)
3. Automatic Segment Space Management (ASSM):
▪ Automates the management of free space within segments.
▪ Uses bitmaps to track free space.
▪ Replaces the need to manually define freelists and freelist groups.
▪ For Example:
create tablespace ts_bmiit
datafile ‘df_bscit.dbf' size 100M
extent management local
segment space management auto;
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
33
CE: 2.5.
Proactive Space Management,
Segment Advisor
34
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
CE: 2.5.1. Proactive Space Management
▪ Space management used to be a very time-consuming task for DBAs.
▪ Proactive space management involves anticipating (do in advance) and
preventing (avoiding) storage-related issues in a database before they
impact performance or availability.
▪ Thus, the Oracle Database provides proactive help in managing disk space
for tablespaces, by alerting you when available space is running low.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
35
CE: 2.5.2. Segment Advisor
Oracle Segment Advisor
▪ When there are lot updates, deletes inside database, it creates lot of empty
pockets of space, that are not large enough to insert new data. We call this
type of empty space as fragmented free space.
▪ Database performance can be impacted by such fragmented space.
▪ The process of combining fragmented space into one big free space is
known as de-fragmentation.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
36
CE: 2.5.2. Segment Advisor (Conti…)
▪ One of the simplest ways to do it by shrinking or compressing table, index
segments to reclaim the wasted space.
▪ But before you directly shrink table/index, you must run Oracle segment
advisor to get recommendations as to how much space can you reclaim.
▪ Oracle Segment Advisor is a diagnostic tool that analyzes database
segments (like tables and indexes) to identify space that can be reclaimed
which helps to improve space efficiency.
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY
37
Thank You
38
BHAVIK SARANG | MSC IT | UKA TARSADIA UNIVERSITY