Beruflich Dokumente
Kultur Dokumente
A small database might need only the SYSTEM tablespace; however, Oracle
recommends that you create additional tablespaces to store user data, user
indexes, undo segments, and temporary segments separate from data dictionary
This gives you more flexibility in various database administration operations and
reduces contention among dictionary objects and schema objects for the same
data files.
The Oracle database architecture includes logical and physical structures that
make up the database.
• The physical structure includes the control files, online redo log files, and data
files that make up the database.
• The logical structure includes tablespaces, segments, extents, and data blocks.
• An Oracle database can be logically grouped into smaller logical areas of space
known as tablespaces.
• Each tablespace consists of one or more operating system files, which are
called data files.
Except for the SYSTEM tablespace or a tablespace with an active undo segment,
tablespaces can be taken offline, leaving the database running.
Data Files
• Each tablespace in an Oracle database consists of one or more files called data
files. These are physical structures that conform with the operating system on
which the Oracle server is running.
• An Oracle server creates a data file for a tablespace by allocating the specified
amount of disk space plus a small amount of overhead.
• The database administrator can change the size of a data file after its creation
or can specify that a data file should dynamically grow as objects in the
tablespace grow.
Segments:
• A segment is the space allocated for a specific logical storage structure within a
tablespace.
Data Blocks
The Oracle server manages the storage space in the data files in units called
Oracle blocks or data blocks.
• Oracle data blocks are the smallest units of storage that the Oracle server can
allocate,read, or write.
• One data block corresponds to one or more operating system blocks allocated
from anexisting data file.
• The standard data block size for an Oracle database is specified by the
DB_BLOCK_SIZE initialization parameter when the database is created.
• The data block size should be a multiple of the operating system block size to
avoid unnecessary I/O.
System Tablespace:
Non-SYSTEM tablespaces:
– Separate segments
– Ease space administration
– Control amount of space allocated to a user
where:
tablespace - the name of the tablespace to be created
DATAFILE - the data file or data files that make up the tablespace
DEFAULT specifies the default storage parameters for all objects created
in the tablespace creation
where:
filename is the name of a data file in the tablespace
SIZE specifies the size of the file. Use K or M to specify the size in kilobytes or
megabytes.
Create a new tabelspace
CREATE TABLESPACE userdata
DATAFILE 'D:\Oracle\oradata\home\userdata01.dbf' SIZE 100M
AUTOEXTEND ON NEXT 5M MAXSIZE 200M;
Will get a message like tablespace created
To view all the tablespaces
select * from dba_tablespaces
A tablespace that manages its own extents maintains a bitmap in each datafile to
keep track of the free or used status of blocks in that data file.
Each bit in the bitmap corresponds to a block or a group of blocks.
When an extent is allocated or freed for reuse, the Oracle server changes the
bitmap values to show the new status of the blocks.
Dictionary-Managed Tablespaces
For a tablespace that uses the data dictionary to manage its extents, the Oracle
server updates the appropriate tables in the data dictionary whenever an extent
is allocated or deallocated.
Coalescing required
Syntax:
extent_management_clause :==
[ EXTENT MANAGEMENT
[ DICTIONARY | LOCAL
[ AUTOALLOCATE | UNIFORM [SIZE integer[K|M]] ] ] ]
where:
• For a permanent tablespace other than SYSTEM, you can specify EXTENT
MANAGEMENT LOCAL in the CREATE TABLESPACE command.
Undo Tablespace:
• Can only use the DATAFILE and EXTENT MANAGEMENT clauses of the CREATE
TABLESPACE command
Ex:
CREATE UNDO TABLESPACE undo1
DATAFILE '/u01/oradata/undo101.dbf' SIZE 40M;
Temporary Tablespace:
• Used for sort operations
• Eliminates the use of the SYSTEM tablespace for storing temporary data
• When created with the CREATE DATABASE command, the default temporary
tablespace is locally managed
Creating a default temporary tablespace during database creation prevents the
SYSTEM tablespace from being used for temporary space.
By Me; I ran the same query in my local database. I get the below error stating
that TEMP is already the default temporary database.
where:
NORMAL flushes all blocks in all data files in the tablespace out of the SGA.
This is the default. You need not perform media recovery on this tablespace
before bringing it back online.
TEMPORARY performs a checkpoint for all online data files in the tablespace
only. Any offline files may require media recovery.
IMMEDIATE does not ensure that tablespace files are available and does not
perform a checkpoint. You must perform media recovery on the tablespace
before bringing it back online.
Read-only Tablespaces:
You can drop items, such as tables and indexes, from a read-only tablespace,
because these commands affect only the data dictionary. This is possible
because the DROP command updates only the data dictionary, but not the
physical files that make up the tablespace.
Dropping Tablespaces:
where:
tablespace specifies the name of the tablespace to be dropped
Use the ALTER DATABASE command to manually increase or decrease the size of
a data file:
ALTER DATABASE
DATAFILE '/u03/oradata/userdata02.dbf'
RESIZE 200M;
Examples:
Changing the Size of Data Files Manually
ALTER DATABASE
DATAFILE 'D:\Oracle\oradata\home\userdata01.dbf'
RESIZE 300M;
Adding Data Files to a Tablespace
ALTER TABLESPACE userdata
ADD DATAFILE 'D:\Oracle\oradata\home\userdata02.dbf'
SIZE 200M;
The source filenames must match the names stored in the control file.
Because the SYSTEM tablespace cannot be taken offline, you must use this
method to move data files in the SYSTEM tablespace
Use the following process to rename files in tablespaces that cannot be taken
offline:
1. Shut down the database.
2. Use an operating system command to move the files.
3. Mount the database.
4. Execute the ALTER DATABASE RENAME FILE command.
5. Open the database.
• Tablespace information:
– DBA_TABLESPACES
– V$TABLESPACE
– DBA_DATA_FILES
– V$DATAFILE
• Temp file information:
– DBA_TEMP_FILES
– V$TEMPFILE