Overview of Tablespaces and Datafiles
Let us first understand the logical structure of the database before we look at the tablespace.
- Tablespace
- Datafiles
- Segments
- Extents
- Data blocks
Tablespaces:
Oracle Database consists of one or
more logical storage units called tablespace
Its collectively store all the
database data.
Each tablespace consists one or more
files called datafiles.
Data is collectively stored in the
datafiles that constitute each tablespace of the database
Image Source: Oracle Doumentations
Types of tablespaces
There are 2-types of tablespaces there
System tablespace
Non-System tablespace
System tablespace
System tablespace created along with
database
It’s must require in all database
Should not contain user data’s
Non-System tablespace
Enable more flexibility in database
administration
Control the amount of space to user
objects
Separate data by backup requirement
Creating tablespace
Create tablespace <Tablespace_Name>
Datafile <Datafie_Location>
Autoextend on next 100M Maxsize 1G;
We can create tablespace with below
parameters based on requirements
CREATE TABSESPACE tablespace
Minimum Extent integer [k/M]
Logging|Nologging
Online|Offline
Permanent|Temporary
Read Only Tablespaces
Alter tablespace
<Tablespace_Name> Read Only;
How to take tablespace in offline mode:
Whenever the database is open mode we
can take any tablespace to move offline mode except the system,stsaux,undo and
tmp tablespace
Command
Alter tablespace <tablespace
name> Offline;
Alter tablespace <tablespace
name> Online;
Alter tablespace tablespace_name
[Online | Offline [Normal | Temporary
| Immediate| For Recover]]
Normal: Flush all blocks in all datafiles in the
tablespace out of the SGA
This is default option
Temporary: Performs a checkpoint for all
online datafiles in the tablespace even if some files could not be written.
For Recover: Takes tablespace offline for Pont -in-time recovery
A datafile can only be a part of one tablespace.
How to Move the Datafiles:
Table space must be offline mode
User OS command to move/Copy the files
Execute the below command in sql
Alter tablespace <Tablespace_name> Rename
Datafile ‘U01/oradata/<Datafile_name.dbf>’
To ‘U02/ oradata/<Datafile_name.dbf>’;
Being tablespace online mode
How to drop the tablespace:
We can drop the table space from the
DB when tablespace and its contents are no longer required
DEROP TABLESPACE <TALESPACE_NAME> INCLUDING CONTENTS AND
DATAFILES;
TABLESPACE: Specifies name of the tablespace to
be dropped
INCLUSING CONTENTS: Drop all the segments in the
tablespace
AND DATAFILES: Delete the associated OS files
CASCADE CONSTRAINTS: Drop referential integrity
Constraints table outside the tablespace that refer to primary and unique keys
in the tables in the dropped tablespace.
Segments
Segments is the space allocated for a specific logical storage structure within a tablespace
Tablespace may consists of one or more segments
Each segments made up of one or more extents.
Extents:
Space is allocated to a segment by extents
One or more extents make up a segments
The DBA Can manually add extents to segments
Extents is a group of connected blocks.
Reference:
Comments
Post a Comment