Sie sind auf Seite 1von 37

Mdulo II ADMINISTRAO

Managing Tablespaces

Creating Tablespaces
Use the CREATE TABLESPACE statement to create a tablespace, which is an allocation of space in the database that can contain schema objects. A permanent tablespace contains persistent schema objects, are stored in data files. A temporary tablespace contains schema objects only for the duration of a session. An undo tablespace is a type of permanent tablespace used by Oracle Database to manage undo data. Mdulo II ADMINISTRAO
Managing Tablespaces

Creating Tablespaces
The primary tablespace in any database is the SYSTEM tablespace The SYSAUX tablespace, is also always created when you create a database To create a new tablespace, use the SQL statement CREATE TABLESPACE or CREATE TEMPORARY TABLESPACE CREATE TABLESPACE system privilege to create a tablespace CREATE UNDO TABLESPACE statement to create a special type of tablespace called an undo tablespace Mdulo II ADMINISTRAO
Managing Tablespaces

Using Multiple Tablespaces


When a database has multiple tablespaces, you can:
Separate user data from data dictionary data to reduce I/O contention. Separate data of one application from the data of another to prevent multiple applications from being affected if a tablespace must be taken offline.
Store the datafiles of different tablespaces on different disk drives to reduce I/O contention. Take individual tablespaces offline while others remain online, providing better overall availability.

Optimizing tablespace use by reserving a tablespace for a particular type of database use, such as high update activity, read-only activity, or temporary segment storage. Back up individual tablespaces.

Mdulo II ADMINISTRAO
Managing Tablespaces

Locally Managed Tablespaces


Resulting in the following benefits:
Fast, concurrent space operations. Enhanced performance Readable standby databases are allowed, because locally managed temporary tablespaces do not generate any undo or redo.

Space allocation is simplified, when using AUTOALLOCATE clause


User reliance on the data dictionary is reduced Coalescing free extents is unnecessary for locally managed tablespaces.
All tablespaces, including the SYSTEM tablespace, can be locally managed.

Mdulo II ADMINISTRAO
Managing Tablespaces

Creating a Locally Managed Tablespace


EXTENT MANAGEMENT LOCAL AUTOALLOCATE EXTENT MANAGEMENT LOCAL UNIFORM SIZE K|M|G CREATE TABLESPACE lmtbsb DATAFILE '/u02/oracle/data/lmtbsb01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL AUTOALLOCATE;

CREATE TABLESPACE lmtbsb DATAFILE '/u02/oracle/data/lmtbsb01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;
LOCAL UNIFORM, then you must ensure that each extent contains at least 5 database blocks.

Mdulo II ADMINISTRAO
Managing Tablespaces

Specifying Segment Space Management in Locally Managed Tablespaces


Are two methods that Oracle Database can use to manage segment space: automatic and manual
CREATE TABLESPACE lmtbsb DATAFILE '/u02/oracle/data/lmtbsb01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

Mdulo II ADMINISTRAO
Managing Tablespaces

Specifying Nonstandard Block Sizes for Tablespaces

CREATE TABLESPACE lmtbsb DATAFILE '/u02/oracle/data/lmtbsb01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K BLOCKSIZE 8K;

Mdulo II ADMINISTRAO
Managing Tablespaces

Controlling the Writing of Redo Records


Specify the NOLOGGING clause in the CREATE TABLESPACE statement to suppress redo when these operations are performed for objects within the tablespace. NOLOGGING mode causes problems with the availability and accuracy of the standby database. Include the FORCE LOGGING clause in the CREATE TABLESPACE statement .

Mdulo II ADMINISTRAO
Managing Tablespaces

Altering Tablespace Availability


You may want to take a tablespace offline for: To make a portion of the database unavailable while allowing normal access to the remainder of the database. To perform an offline tablespace backup (even though a tablespace can be backed up while online and in use) To make an application and its group of tables temporarily unavailable while updating or maintaining the application.

To rename or relocate tablespace datafiles


Mdulo II ADMINISTRAO
Managing Tablespaces

Taking Tablespaces Offline

You cannot take the following tablespaces offline:


SYSTEM The undo tablespace Temporary tablespaces

Mdulo II ADMINISTRAO
Managing Tablespaces

Taking Tablespaces Offline


You can specify any of the following parameters as part of the ALTER TABLESPACE...OFFLINE statement.

Clause
NORMAL

Description
A tablespace can be taken offline normally if no error conditions exist for any of the datafiles of the tablespace. NORMAL is the default. When you specify OFFLINE TEMPORARY, the database takes offline the datafiles that are not already offline. If one or more files of the tablespace are offline because of write errors, and you take the tablespace offline temporarily, the tablespace requires recovery before you can bring it back online. When you specify OFFLINE IMMEDIATE, media recovery for the tablespace is required before the tablespace can be brought online. You cannot take a tablespace offline immediately if the database is running in NOARCHIVELOG mode.

TEMPORARY

IMMEDIATE

Mdulo II ADMINISTRAO
Managing Tablespaces

Bringing Tablespaces Online

ALTER TABLESPACE users ONLINE;

Mdulo II ADMINISTRAO
Managing Tablespaces

Making a Read-Only Tablespace Writable

The following statement makes the flights tablespace writable: ALTER TABLESPACE flights READ WRITE;

Mdulo II ADMINISTRAO
Managing Tablespaces

Using Read-Only Tablespaces


You can:

Drop items, such as tables or indexes, Cannot create or alter objects Can execute statements that update the file description,such as ALTER TABLE...ADD or ALTER TABLE...MODIFY, Will not be able to use the new description until the tablespace
Mdulo II ADMINISTRAO
Managing Tablespaces

Making a Tablespace Read-Only


Before you can make a tablespace read-only, the following conditions must be met: The tablespace must be online. This is necessary to ensure that there is no undo information that must be applied to the tablespace. The tablespace cannot be the active undo tablespace or SYSTEM tablespace. The tablespace must not currently be involved in an online backup, because the end of a backup updates the header file of all datafiles in the tablespace. The following statement makes the flights tablespace read-only: ALTER TABLESPACE flights READ ONLY;

Mdulo II ADMINISTRAO
Managing Tablespaces

Assigning Tablespace Quotas to Users


CREATE USER jward IDENTIFIED BY password DEFAULT TABLESPACE data_ts QUOTA 100M ON test_ts QUOTA 500K ON data_ts TEMPORARY TABLESPACE temp_ts PROFILE clerk; GRANT CREATE SESSION TO jward;

Mdulo II ADMINISTRAO
Managing Tablespaces

Temporary Tablespaces
Only for the duration of the session Temporary tablespaces are used to store the following: Intermediate sort results Temporary tables and temporary indexes Temporary LOBs Temporary B-trees By default, a single temporary tablespace named TEMP is created . You can assign a temporary tablespace to each database user with the CREATE USER or ALTER USER statement. Mdulo II ADMINISTRAO
Managing Tablespaces

Default Temporary Tablespace


ALTER DATABASE DEFAULT TEMPORARY TABLESPACE tablespace_name;
To determine the current default temporary tablespace for the database, run the following query: SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME='DEFAULT_TEMP_TABLESPACE'; PROPERTY_NAME PROPERTY_VALUE ------------------------ -----------------------------DEFAULT_TEMP_TABLESPACE TEMP

Mdulo II ADMINISTRAO
Managing Tablespaces

Creating a Locally Managed Temporary Tablespace


CREATE TEMPORARY TABLESPACE lmtemp TEMPFILE '/u02/oracle/data/lmtemp01.dbf' SIZE 20M REUSE EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M;

Mdulo II ADMINISTRAO
Managing Tablespaces

Increasing the Size of a Tablespace


ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/stuff01.dbf' RESIZE 100M; ALTER DATABASE DATAFILE '/u02/oracle/rbdb1/users03.dbf' AUTOEXTEND OFF; ALTER TABLESPACE users ADD DATAFILE '/u02/oracle/rbdb1/users03.dbf' SIZE 10M AUTOEXTEND ON NEXT 512K MAXSIZE 250M; Mdulo II ADMINISTRAO
Managing Tablespaces

Altering a Locally Managed Tablespace


You can use the ALTER TABLESPACE statement on locally managed tablespaces for some operations: Adding a datafile. For example: ALTER TABLESPACE lmtbsb 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. Mdulo II ADMINISTRAO
Managing Tablespaces

Altering a Locally Managed Temporary Tablespace


You can use ALTER TABLESPACE to add a tempfile, take a tempfile offline, or bring a tempfile online, as illustrated in the following examples: ALTER TABLESPACE lmtemp ADD TEMPFILE '/u02/oracle/data/lmtemp02.dbf' SIZE 18M REUSE; ALTER TABLESPACE lmtemp TEMPFILE OFFLINE; ALTER TABLESPACE lmtemp TEMPFILE ONLINE; Mdulo II ADMINISTRAO
Managing Tablespaces

Altering a Locally Managed Temporary Tablespace


The following statement resizes a tempfile: ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf' RESIZE 18M; The following statement drops a tempfile and deletes its operating system file: ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf' DROP INCLUDING DATAFILES; Mdulo II ADMINISTRAO
Managing Tablespaces

Shrinking a Locally Managed Temporary Tablespace


The following example shrinks the locally managed temporary tablespace lmtmp1 to a size of 20M.

ALTER TABLESPACE lmtemp1 SHRINK SPACE KEEP 20M;


Because the KEEP clause is omitted, the database attempts to shrink the tempfile to the minimum possible size. ALTER TABLESPACE lmtemp2 SHRINK TEMPFILE '/u02/oracle/data/lmtemp02.dbf'; Mdulo II ADMINISTRAO
Managing Tablespaces

Renaming Tablespaces

The following statement renames the users tablespace:

ALTER TABLESPACE users RENAME TO usersts;

Mdulo II ADMINISTRAO
Managing Tablespaces

Dropping Tablespaces
You cannot drop a tablespace that contains any active segments.
DROP TABLESPACE users INCLUDING CONTENTS;

DROP TABLESPACE users INCLUDING CONTENTS AND DATAFILES;

Mdulo II ADMINISTRAO
Managing Tablespaces

CREATE PERMANENT TABLESPACE


CREATE [<BIGFILE | SMALLFILE>] TABLESPACE <tablespace_name> DATAFILE '<path_and_file_name>' SIZE <integer><K | M | G | T | P | E> [REUSE] AUTOEXTEND <OFF | ON> BLOCKSIZE <bytes> [<LOGGING | NOLOGGING | FILESYSTEM_LIKE_LOGGING>] [FORCE LOGGING] [ENCRYPTION USING '<encryption_algorithm>' IDENTIFIED BY <password> [NO] SALT] [<ONLINE | OFFLINE>] EXTENT MANAGEMENT LOCAL <AUTOALLOCATE | UNIFORM SIZE <extent_size>> [SEGMENT SPACE MANAGEMENT <AUTO | MANUAL>] [FLASHBACK <ON | OFF>];

Mdulo II ADMINISTRAO
Managing Tablespaces

CREATE PERMANENT TABLESPACE


CREATE TABLESPACE uwdata DATAFILE 'c:\oracle\oradata\orabase\uwdata01.dbf' SIZE 150M, 'c:\oracle\oradata\orabase\uwdata02.dbf' SIZE 100M AUTOEXTEND OFF BLOCKSIZE 8192 FORCE LOGGING EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K FLASHBACK ON; Mdulo II ADMINISTRAO
Managing Tablespaces

ALTER PERMANENT TABLESPACE


ADD DATAFILE
ALTER TABLESPACE ADD DATAFILE <file_name>, <integer><K | M | G | T> [REUSE] <autoextend> <ON | OFF> NEXT <integer><K | M | G | T> MAXSIZE <integer><K | M | G | T | UNLIMITED>

Mdulo II ADMINISTRAO
Managing Tablespaces

ALTER PERMANENT TABLESPACE


ALTER TABLESPACE <tablespace_name> OFFLINE; ALTER TABLESPACE <tablespace_name> ONLINE; ALTER TABLESPACE <tablespace_name> READ ONLY; ALTER TABLESPACE <tablespace_name> READ WRITE; Mdulo II ADMINISTRAO
Managing Tablespaces

DATABASE TABLESPACE DEFAULT

ALTER DATABASE SET DEFAULT <tablespace_type> TABLESPACE;

Mdulo II ADMINISTRAO
Managing Tablespaces

CREATE TEMPORARY TABLESPACE


CREATE TEMPORARY TABLESPACE <tablespace_name> TEMPFILE '<path_and_file_name>' SIZE <integer><K | M | G | T> AUTOEXTEND <ON | OFF> TABLESPACE GROUP <group_name> EXTENT MANAGEMENT LOCAL UNIFORM SIZE <extent_size>;

Mdulo II ADMINISTRAO
Managing Tablespaces

ALTER TEMPORARY TABLESPACE


ALTER TABLESPACE <tablespace_name> ADD TEMPFILE '<path_and_file_name>' SIZE <n>M;

ALTER DATABASE TEMPFILE '<file_name>' RESIZE <mega_bytes_integer>M;


ALTER DATABASE TEMPFILE '<file_name>' DROP; ALTER DATABASE TEMPFILE '<path_and_file_name>' OFFLINE; ALTER DATABASE TEMPFILE '<path_and_file_name>' ONLINE;

Mdulo II ADMINISTRAO
Managing Tablespaces

CREATE UNDO TABLESPACE


CREATE UNDO TABLESPACE <tablespace_name> DATAFILE '<path_and_file_name>' SIZE <integer><K | M | G | T> AUTOEXTEND <ON | OFF> RETENTION <GUARANTEE | NOGUARANTEE>;

Mdulo II ADMINISTRAO
Managing Tablespaces

ALTER UNDO TABLESPACE


ALTER TABLESPACE <tablespace_name> RETENTION <GUARANTEE | NOGUARANTEE>; RETENTION GUARANTEE specifies that Oracle Database should preserve unexpired undo data in all undo segments of tablespace even if doing so forces the failure of ongoing operations that need undo space in those segments. RETENTION NOGUARANTEE returns the undo behavior to normal. Mdulo II ADMINISTRAO
Managing Tablespaces

Dvidas ???
Mdulo II ADMINISTRAO
Managing Tablespaces

Das könnte Ihnen auch gefallen