Beruflich Dokumente
Kultur Dokumente
Creating Tablespaces
• Before you can create a tablespace, you must create a database to contain it. The primary
tablespace in any database is the SYSTEM tablespace, which contains information basic to
the functioning of the database server, such as the data dictionary and the system rollback
segment. The SYSTEM tablespace is the first tablespace created at database creation. It is
managed as any other tablespace, but requires a higher level of privilege and is restricted
in some ways. For example, you cannot rename or drop the SYSTEM tablespace or take
it offline
• The steps for creating tablespaces vary by operating system, but the first step is always to
use your operating system to create a directory structure in which your datafiles will be
allocated. On most operating systems, you specify the size and fully specified filenames
of datafiles when you create a new tablespace or alter an existing tablespace by adding
datafiles. Whether you are creating a new tablespace or modifying an existing one, the
database automatically allocates and formats the datafiles as specified.
• To create a new tablespace, use the SQL statement CREATE TABLESPACE or CREATE
TEMPORARY TABLESPACE. You must have the CREATE TABLESPACE system privilege to
create a tablespace. Later, you can use the ALTER TABLESPACE or ALTER DATABASE
statements to alter the tablespace. You must have the ALTER TABLESPACE or ALTER
DATABASE system privilege, correspondingly
• You can also use the CREATE UNDO TABLESPACE statement to create a special
type of tablespace called an undo tablespace, which is specifically designed
to contain undo records. These are records generated by the database that
are used to roll back, or undo, changes to the database for recovery, read
consistency, or as requested by a ROLLBACK statement.
The following statement creates a locally managed tablespace named scc and specifies
AUTOALLOCATE:
CREATE TABLESPACE scc DATAFILE '/u02/oracle/data/lmtbsb01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCAL AUTOALLOCATE;
The following example creates a tablespace with uniform 128K extents. (In a database with 2K
blocks, each extent would be equivalent to 64 database blocks). Each 128K extent is represented
by a bit in the extent bitmap for this file.
CREATE TABLESPACE ceet DATAFILE '/u02/oracle/data/lmtbsb01.dbf' SIZE 50M
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;
Altering a Locally Managed Tablespace
You can use the ALTER TABLESPACE statement on locally managed tablespaces for some
operations, including the following:
• Adding a datafile. For example:
• ALTER TABLESPACE scc
• ADD DATAFILE '/u02/oracle/data/lmtbsb02.dbf' SIZE 1M;
•
• Altering tablespace availability (ONLINE/OFFLINE).
• Making a tablespace read-only or read/write..
• Renaming a datafile, or enabling or disabling the autoextension of the size of a datafile
in the tablespace
Creating a Locally Managed Temporary Tablespace
• Because space management is much simpler and more efficient in locally managed
tablespaces, they are ideally suited for temporary tablespaces. Locally managed
temporary tablespaces use tempfiles, which do not modify data outside of the
temporary tablespace or generate any redo for temporary tablespace data. Because of
this, they enable you to perform on-disk sorting operations in a read-only or standby
database.
CREATE TEMPORARY TABLESPACE scc2 TEMPFILE '/u02/oracle/data/lmtemp01.dbf'
SIZE 20M REUSE EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M;
• The default storage parameters for any segments created in this tablespace are specified.
The parameters specified in the preceding example determine segment storage allocation in the
tablespace. These parameters affect both how long it takes to access data stored in the database
and how efficiently space in the database is used. They are referred to as storage parameters, and
are described in the following table:
Storage
Parameter Description
INITIAL Defines the size in bytes of the first extent in the segment
NEXT Defines the size in bytes of the second and subsequent extents
PCTINCREASE Specifies the percent by which each extent, after the second (NEXT) extent,
grows
MINEXTENTS Specifies the number of extents allocated when a segment is first created
in the tablespace
MAXEXTENTS Specifies the maximum number of extents that a segment can have. Can
Dropping Tablespaces
You can drop a tablespace and its contents (the segments contained in the tablespace) from the
database if the tablespace and its contents are no longer required. You must have the DROP
TABLESPACE system privilege to drop a tablespace.
DROP TABLESPACE yemen INCLUDING CONTENTS;
DROP TABLESPACE yemen INCLUDING CONTENTS AND DATAFILES;