Managing Tablespaces and Datafiles
8
Copyright © Oracle Corporation, 2001. All rights reserved.
Objectives
After completing this lesson, you should be able to do the following:
8-2
Copyright © Oracle Corporation, 2001. All rights reserved.
Tablespaces and Datafiles
Oracle stores data logically in tablespaces and physically in datafiles.
Database
Tablespace
Datafiles
8-3
Copyright © Oracle Corporation, 2001. All rights reserved.
Types of Tablespaces
8-4
Copyright © Oracle Corporation, 2001. All rights reserved.
Creating Tablespaces
A tablespace is created using the command:
CREATE TABLESPACE
CREATE TABLESPACE userdata
DATAFILE '/u01/oradata/userdata01.dbf' SIZE 100M
AUTOEXTEND ON NEXT 5M MAXSIZE 200M;
8-5
Copyright © Oracle Corporation, 2001. All rights reserved.
8-6
Copyright © Oracle Corporation, 2001. All rights reserved.
8-7
Copyright © Oracle Corporation, 2001. All rights reserved.
8-8
Copyright © Oracle Corporation, 2001. All rights reserved.
Space Management in Tablespaces
8-9
Copyright © Oracle Corporation, 2001. All rights reserved.
Locally Managed Tablespaces
CREATE TABLESPACE userdata
DATAFILE '/u01/oradata/userdata01.dbf' SIZE 500M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;
8-10
Copyright © Oracle Corporation, 2001. All rights reserved.
8-11
Copyright © Oracle Corporation, 2001. All rights reserved.
Dictionary-Managed Tablespaces
CREATE TABLESPACE userdata
DATAFILE '/u01/oradata/userdata01.dbf'
SIZE 500M EXTENT MANAGEMENT DICTIONARY
DEFAULT STORAGE
(initial 1M NEXT 1M PCTINCREASE 0);
8-12
Copyright © Oracle Corporation, 2001. All rights reserved.
Undo Tablespace
CREATE UNDO TABLESPACE undo1
DATAFILE '/u01/oradata/undo01.dbf' SIZE 40M;
8-13
Copyright © Oracle Corporation, 2001. All rights reserved.
Temporary Tablespaces
CREATE TEMPORARY TABLESPACE temp
TEMPFILE '/u01/oradata/temp01.dbf' SIZE 500M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 4M;
8-14
Copyright © Oracle Corporation, 2001. All rights reserved.
8-15
Copyright © Oracle Corporation, 2001. All rights reserved.
8-16
Copyright © Oracle Corporation, 2001. All rights reserved.
Default Temporary Tablespace
ALTER DATABASE
DEFAULT TEMPORARY TABLESPACE temp;
8-17
Copyright © Oracle Corporation, 2001. All rights reserved.
Creating a Default Temporary Tablespace
�
CREATE DATABASE DBA01
LOGFILE
GROUP 1 ('/$HOME/ORADATA/u01/redo01.log') SIZE 100M,
GROUP 2 ('/$HOME/ORADATA/u02/redo02.log') SIZE 100M,
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXLOGHISTORY 1
MAXDATAFILES 100
MAXINSTANCES 1
DATAFILE '/$HOME/ORADATA/u01/system01.dbf' SIZE 325M
UNDO TABLESPACE undotbs
DATAFILE '/$HOME/ORADATA/u02/undotbs01.dbf' SIZE 200
DEFAULT TEMPORARY TABLESPACE temp
TEMPFILE '/$HOME/ORADATA/u03/temp01.dbf' SIZE 4M
CHARACTER SET US7ASCII
8-18
Copyright © Oracle Corporation, 2001. All rights reserved.
Creating a Default Temporary Tablespace
ALTER DATABASE
DEFAULT TEMPORARY TABLESPACE default_temp2;
SELECT * FROM DATABASE_PROPERTIES;
8-19
Copyright © Oracle Corporation, 2001. All rights reserved.
8-20
Copyright © Oracle Corporation, 2001. All rights reserved.
Restrictions on Default Temporary Tablespace
Default temporary tablespaces cannot be:
8-21
Copyright © Oracle Corporation, 2001. All rights reserved.
Read Only Tablespaces
ALTER TABLESPACE userdata READ ONLY;
8-22
Copyright © Oracle Corporation, 2001. All rights reserved.
8-23
Copyright © Oracle Corporation, 2001. All rights reserved.
8-24
Copyright © Oracle Corporation, 2001. All rights reserved.
Taking a Tablespace Offline
ALTER TABLESPACE userdata OFFLINE;
ALTER TABLESPACE userdata ONLINE;
8-25
Copyright © Oracle Corporation, 2001. All rights reserved.
8-26
Copyright © Oracle Corporation, 2001. All rights reserved.
8-27
Copyright © Oracle Corporation, 2001. All rights reserved.
Changing Storage Settings
ALTER TABLESPACE userdata MINIMUM EXTENT 2M;
ALTER TABLESPACE userdata
DEFAULT STORAGE (INITIAL 2M NEXT 2M
MAXEXTENTS 999);
8-28
Copyright © Oracle Corporation, 2001. All rights reserved.
8-29
Copyright © Oracle Corporation, 2001. All rights reserved.
Resizing a Tablespace
A tablespace can be resized by:
8-30
Copyright © Oracle Corporation, 2001. All rights reserved.
Enabling Automatic Extension �of Datafiles
CREATE TABLESPACE user_data
DATAFILE
'/u01/oradata/userdata01.dbf' SIZE 200M
AUTOEXTEND ON NEXT 10M MAXSIZE 500M;
8-31
Copyright © Oracle Corporation, 2001. All rights reserved.
8-32
Copyright © Oracle Corporation, 2001. All rights reserved.
8-33
Copyright © Oracle Corporation, 2001. All rights reserved.
Manually Resizing a Datafile�
ALTER DATABASE
DATAFILE '/u03/oradata/userdata02.dbf'
RESIZE 200M;
8-34
Copyright © Oracle Corporation, 2001. All rights reserved.
Adding Datafiles to a Tablespace
ALTER TABLESPACE user_data
ADD DATAFILE '/u01/oradata/userdata03.dbf'
SIZE 200M;
8-35
Copyright © Oracle Corporation, 2001. All rights reserved.
8-36
Copyright © Oracle Corporation, 2001. All rights reserved.
Methods for Moving Datafiles�
ALTER TABLESPACE userdata RENAME
DATAFILE '/u01/oradata/userdata01.dbf'
TO '/u02/oradata/userdata01.dbf';
8-37
Copyright © Oracle Corporation, 2001. All rights reserved.
Methods for Moving Datafiles�
ALTER DATABASE RENAME
FILE '/u01/oradata/system01.dbf'
TO '/u03/oradata/system01.dbf';
8-38
Copyright © Oracle Corporation, 2001. All rights reserved.
8-39
Copyright © Oracle Corporation, 2001. All rights reserved.
Dropping Tablespaces
DROP TABLESPACE userdata
INCLUDING CONTENTS AND DATAFILES;
8-40
Copyright © Oracle Corporation, 2001. All rights reserved.
8-41
Copyright © Oracle Corporation, 2001. All rights reserved.
8-42
Copyright © Oracle Corporation, 2001. All rights reserved.
Managing Tablespaces Using OMF�
ALTER SYSTEM SET
db_create_file_dest = '/u01/oradata/dba01';
8-43
Copyright © Oracle Corporation, 2001. All rights reserved.
Managing Tablespaces with OMF
CREATE TABLESPACE text_data DATAFILE SIZE 20M;
ALTER TABLESPACE text_data ADD DATAFILE;
ALTER SYSTEM SET
db_create_file_dest = '/u01/oradata/dba01';
8-44
Copyright © Oracle Corporation, 2001. All rights reserved.
Obtaining Tablespace Information
Obtaining tablespace and datafile information can be obtained by querying the following:
8-45
Copyright © Oracle Corporation, 2001. All rights reserved.
Summary
In this lesson, you should have learned how to:
8-46
Copyright © Oracle Corporation, 2001. All rights reserved.
Practice 8 Overview
This practice covers the following topics:
8-47
Copyright © Oracle Corporation, 2001. All rights reserved.
8-48
Copyright © Oracle Corporation, 2001. All rights reserved.