You are on page 1of 11

Dictionary YES YES

(8i Default) NO NO
Local Auto
Plugged In Logging
(9i Default)
Create

Ext. Mgmt .Type SQL Alter


Managing Tablespaces and Datafiles Tablespace Management Drop

Mode
Status

Read only Views Contents Online


Read write

Permanent Offline
DBA_TABLESPACES

DBA_DATA_FILES Temporary
Undo
DBA_FREE_SPACE

DBA_TEMP_FILES

Logical Structure Tablespaces and Datafiles

• Dictates how the physical space of a database is Oracle stores data logically in tablespaces and
used physically in datafiles.
• Hierarchy consisting of tablespaces, segments, • Tablespaces:
extents, and blocks – Can belong to only one database at a time
– Consist of one or more datafiles
Tablespace – Are further divided into logical units of storage
Datafile • Datafiles:
Segment Database
Segment – Can belong to only one
tablespace and one database Tablespace
– Are a repository for schema
object data
Datafiles
Extent Blocks
Day - 2
Page 1
Types of Tablespaces Creating Tablespaces

• SYSTEM tablespace A tablespace is created using the command:


– Created with the database CREATE TABLESPACE
– Contains the data dictionary
CREATE TABLESPACE userdata
– Contains the SYSTEM undo segment DATAFILE '/u01/oradata/userdata01.dbf' SIZE 100M
• Non-SYSTEM tablespace AUTOEXTEND ON NEXT 5M MAXSIZE 200M;
– Separate segments
– Eases space administration
– Controls amount of space allocated to a user

Space Management in Tablespaces Locally Managed Tablespaces

• Locally managed tablespace: • Reduced contention on data dictionary tables


– Free extents managed in the tablespace
• No undo generated when space allocation or
– Bitmap is used to record free extents
deallocation occurs
– Each bit corresponds to a block or group of blocks
• No coalescing required
– Bit value indicates free or used
CREATE TABLESPACE userdata
• Dictionary-managed tablespace: DATAFILE '/u01/oradata/userdata01.dbf' SIZE 500M
– Free extents are managed by the data dictionary EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;
– Appropriate tables are updated when extents are
allocated or deallocated

Day - 2 Page 2
Dictionary-Managed Tablespaces Creating a Default Temporary Tablespace

• After database creation:


• Extents are managed in the data dictionary
ALTER DATABASE
• Each segment stored in the tablespace can have a DEFAULT TEMPORARY TABLESPACE default_temp2;
different storage clause
• Coalescing required • To find the default temporary tablespace for the
database query DATABASE_PROPERTIES
CREATE TABLESPACE userdata
DATAFILE '/u01/oradata/userdata01.dbf' SELECT * FROM DATABASE_PROPERTIES;
SIZE 500M EXTENT MANAGEMENT DICTIONARY
DEFAULT STORAGE
(initial 1M NEXT 1M PCTINCREASE 0);

Restrictions on Default Temporary Read Only Tablespaces


Tablespace

Default temporary tablespaces cannot be: • Use the following command to place a tablespace in
• Dropped until after a new default is made available read only mode
• Taken offline ALTER TABLESPACE userdata READ ONLY;

– Causes a checkpoint
– Data available only for read operations
– Objects can be dropped from tablespace

Day - 2 Page 3
Taking a Tablespace Offline Changing Storage Settings

• Not available for data access • Using ALTER TABLESPACE command to change
• Tablespaces that cannot be taken offline: storage settings:
– SYSTEM tablespace ALTER TABLESPACE userdata MINIMUM EXTENT 2M;
– Tablespaces with active undo segments
– Default temporary tablespace ALTER TABLESPACE userdata
DEFAULT STORAGE (INITIAL 2M NEXT 2M
• To take a tablespace offline: MAXEXTENTS 999);
ALTER TABLESPACE userdata OFFLINE;

• To bring a tablespace online: • Storage settings for locally managed tablespaces


cannot be altered.
ALTER TABLESPACE userdata ONLINE;

Resizing a Tablespace Enabling Automatic Extension


of Datafiles

A tablespace can be resized by:


• Changing the size of a datafile: • Can be resized automatically with the following
– Automatically using AUTOEXTEND commands:
– CREATE TABLESPACE
– Manually using ALTER TABLESPACE
– ALTER TABLESPACE … ADD DATAFILE
• Adding a datafile using ALTER TABLESPACE
• Example:

CREATE TABLESPACE user_data


DATAFILE
'/u01/oradata/userdata01.dbf' SIZE 200M
AUTOEXTEND ON NEXT 10M MAXSIZE 500M;
• Query the DBA_DATA_FILES view to determine
Day - 2 whether AUTOEXTEND is enabled.
Page 4
Manually Resizing a Datafile Adding Datafiles to a Tablespace

• Manually increase or decrease a datafile size using • Increases the space allocated to a tablespace by
ALTER DATABASE adding additional datafiles
• Resizing a datafile adds more space without adding • ADD DATAFILE clause is used to add a datafile
more datafiles • Example:
• Manual resizing of a datafile reclaims unused space
in database ALTER TABLESPACE user_data
ADD DATAFILE '/u01/oradata/userdata03.dbf'
• Example: SIZE 200M;
ALTER DATABASE
DATAFILE '/u03/oradata/userdata02.dbf'
RESIZE 200M;

Methods for Moving Datafiles Methods for Moving Datafiles

• ALTER TABLESPACE
• ALTER DATABASE
– Tablespace must be offline
– Database must be mounted
– Target datafiles must exist
– Target datafile must exist
ALTER TABLESPACE userdata RENAME
DATAFILE '/u01/oradata/userdata01.dbf' ALTER DATABASE RENAME
TO '/u02/oradata/userdata01.dbf'; FILE '/u01/oradata/system01.dbf'
• Steps to rename a datafile: TO '/u03/oradata/system01.dbf';
– Take the tablespace offline.
– Use an OS command to move or copy the files.
– Execute the ALTER TABLESPACE RENAME DATAFILE
command.
– Bring the tablespace online.
– Use an OS command to delete the file if necessary.
Page 5
Day - 2
Dropping Tablespaces Obtaining Tablespace Information

• Cannot drop a tablespace if it: Obtaining tablespace and datafile information can be
– Is the SYSTEM tablespace obtained by querying the following:
• INCLUDING CONTENTS drops the segments • Tablespaces:
• INCLUDING CONTENTS AND DATAFILES deletes – DBA_TABLESPACES
datafiles – V$TABLESPACE
• Datafile information:
– DBA_DATA_FILES
– V$DATAFILE

DROP TABLESPACE userdata


• Temp file information:
INCLUDING CONTENTS AND DATAFILES; – DBA_TEMP_FILES
– V$TEMPFILE

Storage and Relationship Structure

Database
PROD
TABLESPACES
SYSTEM USER_DATA RBS TEMP
DATAFILES
Storage Structure and Relationships DISK2/
DISK1/SYS1.dbf USER1.dbf
DISK3/ DISK1/ DISK1/
USER2.dbf ROLL1.dbf TEMP.dbf
SEGMENTS S_DEP T S_E MP S _DE P T S _EM P RBS1 RBS2 RBS1 RBS2
Temp
(c ont 'd) FI RST _N (c ont 'd) (c ont 'd)
D.D. D.D. AME
In dex
Table Index RB RB RB RB
RB Data Data Data S eg S eg S eg S eg Temp
Data Index S eg
I ndex
Seg Seg Seg S eg Seg
Seg Seg

EXTENTS
1 2 1 2 1 2 1 1 2 2 1 FREE 1 1 2 2 1

Oracle DATA BLOCKS

Day - 2 Page 6
Types of Segments Types of Segments

Index-organized Index
table partition
Table Table
partition

Undo Temporary
Cluster Index segment segment

Types of Segments Storage Clause Precedence

Oracle default

Tablespace

Segment
Bootstrap
segment

Day - 2 Page 7
Extent Allocation and Deallocation Used and Free Extents

Data file
• An extent is a chunk of space used by a segment
within a tablespace.
• An extent is allocated when the segment is:
– Created
• An extent is deallocated when the segment is:
– Dropped
– Truncated

File header Used extent Free extent

Database Block Multiple Block Size Support

• A database can be created with a standard block


• Consists of one or more operating system blocks size and up to four nonstandard block sizes.
• Set at tablespace creation • Block sizes can have any power-of-two value
• DB_BLOCK_SIZE is the default block size between 2 KB and 32 KB.

Day - 2 Page 8
Standard Block Size Nonstandard Block Size

• Set at database creation using the DB_BLOCK_SIZE • Configure additional caches with the following
parameter; cannot be changed without re-creating dynamic parameters:
the database – DB_2K_CACHE_SIZE for 2 KB blocks
– DB_4K_CACHE_SIZE for 4 KB blocks
• DB_CACHE_SIZE specifies the size of the DEFAULT – DB_8K_CACHE_SIZE for 8 KB blocks
buffer cache for standard block size: – DB_16K_CACHE_SIZE for 16 KB blocks
– DB_32K_CACHE_SIZE for 32 KB blocks

Creating Nonstandard Block Size Database Block Contents


Tablespaces

CREATE TABLESPACE tbs_1


DATAFILE 'tbs_1.dbf' Header
SIZE 10M BLOCKSIZE 4K;

Free space

Data

Day - 2 Page 9
Block Space Data Block Management
Utilization Parameters

Two methods are available for managing data blocks:


INITRANS • Automatic Segment-Space Management
• Manual Management
MAXTRANS

PCTFREE

PCTUSED

Automatic Segment-Space Automatic Segment-Space


Management Management

• It is a method of managing free space inside • Bitmap segments contain a bitmap that describes
database segments. the status of each block in the segment with respect
• Tracking in-segment free and used space is done to its available space.
using bitmaps as opposed to using free lists. • The map is contained in a separate set of blocks
• This method provides: referred to as bitmapped blocks (BMBs).
– Ease of management • When inserting a new row, the server searches the
– Better space utilization map for a block with sufficient space.
– Better performance for concurrent INSERT operations • As the amount of space available in a block
changes, its new state is reflected in the bitmap.

Day - 2 Page 10
Configuring Automatic Segment-Space Manual Data Block Management
Management

• Automatic segment-space management can be • Allows you to configure data blocks manually using
enabled at the tablespace level only, for locally parameters such as:
managed tablespaces. – PCTFREE
CREATE TABLESPACE data02 – PCTUSED
DATAFILE ‘/u01/oradata/data02.dbf’ SIZE 5M – FREELIST
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 64K • Only method available in previous Oracle versions
SEGMENT SPACE MANAGEMENT AUTO;

• After a tablespace is created, the specifications


apply to all segments created in the tablespace.

Obtaining Storage Information

Information about storage can be obtained by


querying the following views:
• DBA_EXTENTS
• DBA_SEGMENTS
• DBA_TABLESPACES
• DBA_DATA_FILES

Day - 2 Page 11

You might also like