web viewall data stored on behalf of stored pl/sql program units (procedures, functions, packages...

21
Contents: Introduction Type Of Tablespaces System Tablespace Sysaux Tablespace Undo Tablespace Temporary Tablespace Bigfile Tablespace Creating Tablespaces Altering Tablespaces Dropping Tablespaces Introduction: An Oracle database consists of one or more logical storage units called tablespaces. The tablespace is collectively stores the data of the database. Each tablespace in an Oracle database consists of one or more files called datafiles, which are physical structures that conform to the operating system in which Oracle is running. A database’s data is collectively stored in the datafiles that constitute each tablespace of the database. A tablespace may contains one or more datafiles in each. The files in a tablespace usually share a common characteristic. For example, a database for a wholesale distributor might consist of tablespaces entitled ACCOUNTING, ORDERS, SHIPPING, SERVICE, and SYSTEM.Each tablespace might contain only one data file, or thousands of files, or anything in between. Tablespaces can be created, deleted, and merged, just as can the folders on the hard drive of a computer. Type of Tablespaces: The tablespaces are categorized into different types as follows. System Tablespace: Some database programs, such as Oracle, automatically create a tablespace called SYSTEM that contains general information about the structure and

Upload: hoangnguyet

Post on 30-Jan-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

Contents: Introduction

Type Of Tablespaces

System Tablespace

Sysaux Tablespace

Undo Tablespace

Temporary Tablespace

Bigfile Tablespace

Creating Tablespaces

Altering Tablespaces

Dropping Tablespaces

 

Introduction:An Oracle database consists of one or more logical storage units called tablespaces. The tablespace is collectively stores the data of the database. Each tablespace in an Oracle database consists of one or more files called datafiles, which are physical structures that conform to the operating system in which Oracle is running. A database’s data is collectively stored in the datafiles that constitute each tablespace of the database. A tablespace may contains one or more datafiles in each. The files in a tablespace usually share a common characteristic. For example, a database for a wholesale distributor might consist of tablespaces entitled ACCOUNTING, ORDERS, SHIPPING, SERVICE, and SYSTEM.Each tablespace might contain only one data file, or thousands of files, or anything in between. Tablespaces can be created, deleted, and merged, just as can the folders on the hard drive of a computer.

Type of Tablespaces:The tablespaces are categorized into different types as follows.

System Tablespace:Some database programs, such as Oracle, automatically create a tablespace called SYSTEM that contains general information about the structure and contents of the database. The SYSTEM tablespace always contains the data dictionary tables for the entire database. The Data Dictionary contains the all the metadata information of the database. Before any application can access the data in the database, the Data Dictionary is consulted to manage the transaction. Basically, the Data Dictionary is the master guide to everything in the database. The primary purpose of the system tablespace is to hold the Data Dictionary. The Data Dictionary is composed of all tables owned by the SYS user.

Page 2: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

A small database might need only the SYSTEM tablespace. however, it is recommended that you create at least one additional tablespace to store user data separate from data dictionary information. This allows you more flexibility in various database administration operations and can reduce contention among dictionary objects and schema objects for the same datafiles.

All data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you create many of these PL/SQL objects, the database administrator needs to plan for the space in the SYSTEM tablespace that these objects use.

The SYSTEM tablespace must always be kept online when the database in open state.

 Sysaux Tablespace:The SYSAUX tablespace is a new tablespace that is required from Oracle Database 10g. The SYSAUX tablespace is an auxiliary tablespace to the SYSTEM tablespace. Many database components use the SYSAUX tablespace as their default location to store data. Therefore, the SYSAUX tablespace is always created during database creation or database upgrade. The SYSAUX tablespace provides a centralized location for database metadata that does not reside in the SYSTEM tablespace. It reduces the number of tablespaces created by default, both in the seed database and in user-defined databases. The SYSAUX Tablespace should have a minimum size of 250M. SYSAUX Tablespace needs to be permanent with extent management local and Automatic Segment Space Management.

Previously, many Oracle features required their own separate tablespaces for their opearations. This increases the management responsibility of the DBA. The SYSAUX tablespace consolidates these tablespaces into one location, which becomes the default tablespace for these Oracle features.

The SYSAUX Tablespace cannot be made read only. Hence, proper care should be taken while creating the SYSAUX tablespace as the tablespace attributes are not modifiable once these are set. During normal database operation, the Oracle database server does not allow the SYSAUX tablespace to be dropped or renamed. Transportable tablespaces for SYSAUX is not supported.

The sysaux tablespace is used for AWR Snapshots Information. It helps you to plan AWR space usage if the default interval or retention period is changed by estimating size for AWR snapshots. This information is also useful when expanding the number of Oracle RAC nodes. V$SYSAUX_OCCUPANTS view can be used to monitor the occupants of the SYSAUX tablespace. This view lists the Name of the occupant ,Occupant description,Schema name,Move procedure and Current space usage of the SYSAUX tablespace.

 View information is maintained by the occupants by using below command,

Page 3: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

SQL>select occupant_desc, space_usage_kbytes from v$sysaux_occupants where space_usage_kbytes > 0 order by space_usage_kbytes desc;

The below figure shows the result.

 

Undo Tablespace:Undo tablespaces are special tablespaces used solely for storing undo information. You cannot create any other segment types in undo tablespaces. Each database contains one or more undo tablespaces. In automatic undo management mode, each Oracle instance is assigned only one undo tablespace. Undo data is managed within an undo tablespace using undo segments that are automatically created and maintained by Oracle.

The transaction undo information was stored in Rollback Segments until a commit or rollback statement was issued, at which point it was purged. In Oracle 9i this method of manual undo management is still available. In addition to a new automatic undo management method which frees DBAs from routine undo management tasks and tuning. It allows DBA’s to specify how long undo information should be retained after commit, preventing “snapshot too old” errors on long running queries in addition to supporting Oracle flashback query.

The Undo tablespace is used for several features in the database. Undo information is used for Read Consistency. Some Oracle features are build based upon using Undo information, meaning undo is more utilized. Because ‘old’ data is stored for a certain time i.e undo_retention, one can access this information to have look at data back in time by using FLASHBACK features.

Page 4: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

A database administrator creates undo tablespaces individually, using the CREATE UNDO TABLESPACE statement. It can also be created while creation of the database. A set of datafiles are assigned to each newly created undo tablespace. Like regular tablespaces, attributes of undo tablespaces can be modified with the ALTER TABLESPACE statement and dropped with the DROP TABLESPACE statement. You can create a bigfile undo tablespace.

You can add more space to an undo tablespace by adding more datafiles to the undo tablespace with the ALTER TABLESPACE statement. You can have more than one undo tablespace and switch between them. Use the Database Resource Manager to establish user quotas for undo tablespace. You can specify the retention period for undo to store the data up to the retention period in the undo by undo_retention parameter. Automatic undo management requires a locally managed undo tablespace to store undo segments in.

 Undo tablespace can be created during database creation or using the CREATE UNDO TABLESPACE statement.

1. As part of database creation

CREATE DATABASE bsprod CONTROLFILE REUSE

– – – – – – – – – – – – – – – –

UNDO TABLESPACE undo_tbs DATAFILE ‘/u01/bsprod/oradata/undo_tbs01.dbf’ SIZE 100M REUSE AUTOEXTEND ON;

 

 

Page 5: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

2. Using the create undo tablespace statement

SQL> CREATE UNDO TABLESPACE undo_tbs DATAFILE ‘/u01/bsprod/oradata/undo_tbs01.dbf’ SIZE 100M REUSE AUTOEXTEND ON;

 

 You can assign an undo tablespace to an instance in two ways:

1. Before starting Oracle instance .

You can specify the undo tablespace parameters in parameter file as,

undo_management=AUTO

undo_tablespace= undotbs1

2. While the instance is running.

Use ALTER SYSTEM SET UNDO_TABLESPACE to replace the active undo tablespace with another undo tablespace.

SQL> alter system set undo_manaement= AUTO;

SQL> alter system set undo_tablespace=undotbs1;

You can view the undo tablespace name from v$tablesapce or dba_tablesapces and undo datafiles from the views v$datafile or dba_data_files;

SQL>select name from v$datafile;

Page 6: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

SQL>select tablespace_name from dba_tablespaces;

 

Managing Undo Tablespace:

Maintenance of undo tablespace is similar to that of regular tablespaces, although some options are not neccessary as Oracle takes over the burden of most management tasks.

If an undo tablespace runs out of space, or you want to prevent it from doing so, you can add one or more files to it. To add a datafile to the undo tablespace the command is,

SQL> ALTER TABLESPACE undotbs1 ADD DATAFILE  ‘/u01/bsprod/oradata/undotbs02.dbf’ AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED;

 

 To Resize an undo datafile.

SQL>ALTER DATABASE DATAFILE  ‘/ u01/bsprod/oradata/undotbs02.dbf’ RESIZE 150M;

 

To Perform backup operations when the database in open mode the commands are,

SQL>ALTER TABLESPACE undotbs1 BEGIN BACKUP;

SQL>ALTER TABLESPACE undotbs1 END BACKUP;

 

To Drop an undo tablespace.

SQL> DROP TABLESPACE undo_tbs1;

In the above example the tablespace will only be dropped if it is not currently being used or contains undo information for a current transaction. It will however drop tablespace where the undo information has not yet expired, thus affecting long running queries and flashback query.

Oracle Database 10g lets you guarantee undo retention. When you enable this option, the database never overwrites unexpired undo data i.e. undo data whose age is less than the undo retention period. This option is disabled by default, which means that the database can overwrite the unexpired undo data in order to avoid failure of DML operations if there is not enough free space left in the undo tablespace. You do not guarantee that unexpired undo is preserved if you specify the RETENTION NOGUARANTEE clause. In order to guarantee the success of queries even at the price of compromising the success of DML operations, you can enable retention guarantee. This option must be used with caution, because it can cause DML operations to fail if the undo tablespace is not big enough. However, with proper settings, long-running queries can complete without risk of receiving the ORA-01555 “snapshot too old” error message, and you can guarantee a time window in which the execution of Flashback features will succeed.

   Enabling and disabling undo retention guarantee

Page 7: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

SQL> ALTER TABLESPACE undotbs1 RETENTION GUARANTEE;

SQL> ALTER TABLESPACE undotbs1 RETENTION NOGUARANTEE;

You can use the DBA_TABLESPACES view to determine the RETENTION setting for the undo tablespace. A column named RETENTION will contain a value on GUARANTEE, NOGUARANTEE.

You can switch from using one undo tablespace to another. Because the UNDO_TABLESPACE initialization parameter is a dynamic parameter, the ALTER SYSTEM SET statement can be used to assign a new undo tablespace.

SQL> ALTER SYSTEM SET UNDO_TABLESPACE = undotbs02;

 

The following dynamic performance views are useful for obtaining space information about the undo tablespace:

View                                                                                              Description

V$UNDOSTAT                           Contains statistics for monitoring and tuning undo space. Use thisview to help estimate the amount of undo space                                                                             required for thecurrent workload. Oracle uses this view information to tune undousage in the system.

V$ROLLSTAT                            For automatic undo management mode, information reflects behavior of the undo segments in the undo tablespace.

V$TRANSACTION                    Contains undo segment information.

DBA_UNDO_EXTENTS            Shows the status and size of each extent in the undo tablespace.

WRH$_UNDOSTAT                 Contains statistical snapshots of V$UNDOSTAT information.

WRH$_ROLLSTAT                   Contains statistical snapshots of V$ROLLSTAT information.

Temporary Tablespace:A temporary tablespace contains transient data that persists only for the duration of the session. These are used to manage space for database sort and joining operations and for storing global temporary tables and can improve the efficiency of space management operations during sorts..

For joining two large tables or sorting a bigger result set, Oracle cannot do in memory by using SORT_AREA_SIZE in Programmable Global Area. Space will be allocated in a temporary tablespace for doing these types of operations that improves the concurrency of multiple sort operations. Other SQL operations that might requires the temporary segments are: create index, analyze, select distinct, order by, group by, union, intersect, minus, sort-merge joins, etc.

Note that a temporary tablespace cannot contain permanent objects and therefore doesn’t need to be backed up. A temporary tablespace contains schema objects only for the duration of a session. Unlike normal datafiles, tempfiles are not fully allocated. When you create a tempfiles, Oracle only writes to the header and last block of the file. This is why it is much quicker to create a tempfiles than to create a normal datafile. Tempfiles are not recorded in the database’s control file. This implies that just recreate them whenever you restore the database, or after deleting them by accident.

Restrictions:

Page 8: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

(1). You cannot specify nonstandard block sizes for a temporary tablespace or if you intend to assign this tablespace as the temporary tablespace for any users.

(2). You cannot specify FORCE LOGGING for an undo or temporary tablespace.

(3). You cannot specify AUTOALLOCATE for a temporary tablespace.

The temporary tablespace can be created by following command,

SQL> create temporary tablespace <tablespace name> tempfile < tempfile path> size 100m;

SQL> create temporary tablespace tempx tempfile ‘/u01/bsprod/oradata/tempx01.dbf’ size 100m autoextend on;

SQL>create temporary tablespace tempx tempfile ‘/u01/bsprod/oradata/temp01.dbf’ size 500m, ‘/u01/bsprod/oradata/temp02.dbf’ size 200m autoextend off extent management local uniform size 1m;

 

Use the following statement to add a tempfile to a temporary tablespace:

SQL> alter tablespace tempx add tempfile ‘/u01/bsprod/oradata/tempx02.dbf’ size 100m autoextend on next 50m maxsize unlimited;

 

Unlike datafiles, tempfiles are not listed in V$DATAFILE and DBA_DATA_FILES. Use V$TEMPFILE and DBA_TEMP_FILES instead. You can view the temporary tablespaces and tempfiles from the following views,

SQL> SELECT tablespace_name, file_name, bytes FROM dba_temp_files WHERE tablespace_name = ‘TEMP’;

SQL> select file#, name, sum(bytes/1024/1024) “SIZE IN MB’s” from v$tempfile;

 

To determine the current default temporary tablespace for the database, run the following query:

SQL> select property_name, property_value from database_properties where property_name=’DEFAULT_TEMP_TABLESPACE’;

 

You can change the default temporary tablespace for the database with the following command:

SQL>alter database default temporary tablespace <tablespace_name>;

SQL> alter database default temporary tablespace tempx;

 

DBA_FREE_SPACE does not record free space for temporary tablespaces. Use DBA_TEMP_FREE_SPACE or V$TEMP_SPACE_HEADER instead.

Page 9: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

SQL> select tablespace_name, bytes_used, bytes_free from v$temp_space_header;

SQL> select * from dba_temp_free_space;

 

The DBA should assign a temporary tablespace to each user in the database to prevent them from allocating sort space in the SYSTEM tablespace. This can be done with one of the following commands,

SQL> alter user <user name> temporary tablespace <temp tbs name>;

SQL> alter user accountant temporary tablespace tempx;

 

To change a user account to use a non-default temp tablespace

SQL> ALTER USER <user name> SET TEMPORARY TABLESPACE <temp tbs name>;

SQL> alter user accountant set temporary tablespace tempx;

 

We can check free temp space in new view DBA_TEMP_FREE_SPACE.

SQL> select * from DBA_TEMP_FREE_SPACE;

 

To Resizing tempfile use the below commands,

SQL> alter database tempfile temp-name resize integer K|M|G|T|P|E;

SQL> alter database tempfile ‘/u01/bsprod/oradata/tempx01.dbf’ resize 1000M;

 

To Resizing temporary tablespace

SQL> alter tablespace tempx resize 1000M;

You can perform an online shrink of a temporary tablespace using the ALTER TABLESPACE command. Shrinking frees as much space as possible while maintaining the other attributes of the tablespace or temp files. The optional KEEP clause defines a minimum size for the tablespace or temp file.

SQL> alter tablespace temp-tbs shrink space;

SQL> alter tablespace temp-tbs shrink space keep n{K|M|G|T|P|E};

Example: SQL> alter tablespace tempx shrink space keep 40m;

SQL> alter tablespace temp-tbs shrink tempfile ‘tempfile-name’ ;

SQL> alter tablespace temp-tbs shrink tempfile ‘tempfile-name’ keep n{K|M|G|T|P|E};

Page 10: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

Example: SQL> alter tablespace tempx shrink tempfile ‘/u01/bsprod/oradata /temp01.dbf’ keep 30m;

 

You cannot remove datafile from a tablespace that has single datafile unless you drop the entire tablespace. However, one can remove a tempfile from a database. Look at this example:

SQL> alter database tempfile ‘tempfile_name’ drop including datafiles;

 

 You cannot remove datafiles from a tablespace that has single datafile until you drop the entire tablespace. However, one can remove a tempfile from a database. Look at this example:

SQL> alter database tempfile ‘tempfile_name’ drop including datafiles;

SQL> alter database datafile ‘tempfile_name’ drop;

 

Dropping temporary tablespaces can be done by using below commands,

SQL> drop tablespace temp_tbs;

SQL> drop tablespace tempx including contents and datafiles;

 

The following restrictions apply to default temporary tablespaces:

1.DEFAULT TEMPORARY TABLESPACE must be of type TEMPORARY.

2.DEFAULT TEMPORARY TABLESPACE cannot be taken offline.

3.DEFAULT TEMPORARY TABLESPACE cannot be dropped until you specify another one.

Some views for temporary tablespace managemnet:

DBA_TEMP_FILES

DBA_TABLESPACES

DBA_TEMP_FREE_SPACE

V$TEMPFILE

V$TEMP_SPACE_HEADER

V$TEMPORARY_LOBS

V$TEMPSTAT

V$TEMPSEG_USAGE

 

Bigfile Tablespace:

Page 11: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

Oracle 10g (and continuing into 11g) introduced a new locally managed tablespace type for extreme-size databases called Bigfile tablespace. This allows Oracle Database to contain tablespaces made up of single large files rather than numerous smaller ones. This lets Oracle Database utilize the ability of 64-bit systems to create and manage ultralarge files. The consequence of this is that Oracle Database can now scale up to 8 exabytes in size. When implemented with Oracle Managed Files or Automatic Storage Management (ASM), bigfile tablespaces can greatly simplify the management of your storage system. Additionally, because you should have fewer datafiles, performance of database management operations such as checkpoints should improve, but be aware that recovery operation times are likely to increase in the event of datafile corruption.

With Oracle managed files, bigfile tablespaces make datafiles completely transparent for users. In other words, you can perform operations on tablespaces, rather than the underlying datafile. Bigfile tablespaces also simplify datafile management with Oracle managed files and Automatic Storage Management by eliminating the need for adding new datafiles and dealing with multiple files.

The system default is to create a smallfile tablespace, which is the traditional type of Oracle tablespace. The SYSTEM and SYSAUX tablespace types are always created using the system default type. Bigfile tablespaces are supported only for locally managed tablespaces with automatic segment space management. There are two exceptions the the locally managed undo and temporary tablespaces can be bigfile tablespaces, even though their segments are manually managed.

An Oracle database can contain both bigfile and smallfile tablespaces. Tablespaces of different types are indistinguishable in terms of execution of SQL statements that do not explicitly refer to datafiles.

Bigfile tablespace has the following benefits: The bigfile tablespace simplifies large database tablespace management by reducing the

number of datafiles needed. The bigfile tablespace simplifies datafile management with Oracle managed files and

Automated Storage Management (ASM) by eliminating the need for adding new datafiles and dealing with multiple files.

The bigfile tablespace allows you to create a bigfile tablespace of up to eight exabytes (eight million terabytes) in size, and significantly increase the storage capacity of an Oracle database.

The bigfile tablespace follows the concept that a tablespace and a datafile are logically equivalent.

 The maximum bigfile (data file) size is calculated by:

Maximum datafile size = db_block_size * maximum number of blocks

 

 The bigfile tablespace can be created by using the below command,

SQL> Create bigfile tablespace bigtbs_1 datafile ‘/u01/bsprod/oradata/bigtbs01.dbf’ size 1G autoextend on;

 

Moving data between smallfile and bigfile tablespaces.

SQL>ALTER TABLE employee MOVE TABLESPACE bigtbs_1;

 

Page 12: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

Create a bigfile tablespace and change its size.

SQL>CREATE BIGFILE TABLESPACE bigtbs_1 DATAFILE ‘/u01/bsprod/oradata/bigtbs01.dbf’ SIZE 1024 M;

SQL>ALTER TABLESPACE big_tbs RESIZE 10G;

 

You can set a bigfile tablespace as a default tablespace for the database by using following command,

SQL> Alter database default tablesapce bigtbs_1 ;

 

A new column is added to both dba_tablespaces and v$tablesapce views to indicate whether a particular tablespace is bigfile or smallfile:

SQL> select name, bigfile from v$tablespace;

SQL> select tablespace_name, bigfile from dba_tablespaces;

 

Creating Tablespaces: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.

The commands to create a different tablespaces are,

SQL> Create tablespace userdata datafile ‘/u01/bsprod/oradata/userdata01.dbf’ size 100m;

SQL>Create temporary tablesapce temptbs tempfile  ‘/u01/bsprod/oradata/temptbs01.dbf’ size 100m;

SQL> Create undo tablespace undotbs datafile  ‘/u01/bsprod/oradata/undotbs01.dbf’ size 100m;

 

Creating a tablespace with more than on datafile,

SQL> Create tablespace abcadata datafile ‘/u01/bsprod/oradata/abcdata01.dbf’ size 100m, ‘/u01/bsprod/oradata/abcdata02.dbf’ size 150m;

 

Creating a Locally Managed Tablespace

Page 13: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

Create a locally managed tablespace by specifying LOCAL in the EXTENT MANAGEMENT clause of the CREATE TABLESPACE statement. This is the default for new permanent tablespaces, but you must specify the EXTENT MANAGEMENT LOCAL clause if you want to specify either the AUTOALLOCATE clause or the UNIFORM clause. You can have the database manage extents for you automatically with the AUTOALLOCATE clause (the default), or you can specify that the tablespace is managed with uniform extents of a specific size (UNIFORM).

SQL> Create tablespace userdata datafile ‘/u01/bsprod/oradata/userdata01.dbf’ size 100m extent management local autoallocate ;

SQL> Create tablespace userdata datafile ‘/u01/bsprod/oradata/userdata01.dbf ‘ SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K;

If you specified the MINIMUM EXTENT clause, the database evaluates whether the values of MINIMUM EXTENT, INITIAL, and NEXT are equal and the value of PCTINCREASE is 0. If so, the database creates a locally managed uniform tablespace with extent size = INITIAL. If the MINIMUM EXTENT, INITIAL, and NEXT parameters are not equal, or if PCTINCREASE is not 0, the database ignores any extent storage parameters you may specify and creates a locally managed, autoallocated tablespace.

If you did not specify MINIMUM EXTENT clause, the database evaluates only whether the storage values of INITIAL and NEXT are equal and PCTINCREASE is 0. If so, the tablespace is locally managed and uniform. Otherwise, the tablespace is locally managed and autoallocated.

SQL> Create tablespace userdata datafile ‘/u01/bsprod/oradata/userdata01.dbf’ size 100m extent management local INITIAL 10m NEXT 50m PCTINCREASE 50;

 

Creating tablespace with Segment space management:

When you create a locally managed tablespace using the CREATE TABLESPACE statement, the SEGMENT SPACE MANAGEMENT clause allows you to specify how free and used space within a segment is to be managed. Your choices are:

MANUAL:  Specifying MANUAL tells Oracle that you want to use free lists for managing free space within segments. Free lists are lists of data blocks that have space available for inserting rows. This form of managing space within segments is called manual segment-space management because of the need to specify and tune the PCTUSED, FREELISTS, and FREELISTS GROUPS storage parameters for schema objects created in the tablespace. MANUAL is the default.

AUTO : This keyword tells Oracle that you want to use bitmaps to manage the free space within segments. A bitmap, in this case, is a map that describes the status of each data block within a segment with respect to the amount of space in the block available for inserting rows. As more or less space becomes available in a data block, its new state is reflected in the bitmap. Bitmaps allow Oracle to manage free space more automatically, and thus, this form of space management is called automatic segment-space management.

SQL> CREATE TABLESPACE userdata  DATAFILE ‘/u01/bsprod/oradata/userdata01.dbf’ SIZE 50M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;

 

Altering  Tablespaces:Use the ALTER TABLESPACE statement to alter an existing tablespace or one or more of its datafiles or tempfiles. If you have ALTER TABLESPACE system privilege, then you can perform any

Page 14: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

ALTER TABLESPACE operation. If you have MANAGE TABLESPACE system privilege, then you can alter the tablespaces.

To Take the tablespace online or offline:

SQL> Alter tablespace userdata online;

SQL> Alter tablespace userdata offline;

OFFLINE NORMAL: Specify NORMAL to flush all blocks in all datafiles in the tablespace out of the system global area (SGA). You need not perform media recovery on this tablespace before bringing it back online. This is the default.

OFFLINE TEMPORARY: If you specify TEMPORARY, then Oracle Database performs a checkpoint for all online datafiles in the tablespace but does not ensure that all files can be written. Files that are offline when you issue this statement may require media recovery before you bring the tablespace back online.

OFFLINE IMMEDIATE: If you specify IMMEDIATE, then Oracle Database 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.

SQL> Alter tablespace userdata OFFLINE NORMAL ;

SQL> Alter tablespace userdata OFFLINE TEMPORARY;

SQL> Alter tablespace userdata OFFLINE IMMEDIATE;

 

To Begin or end backup a tablespace:

SQL> Alter tablespace userdata begin backup;

SQL> Alter tablespace userdata end backup;

 

To Make the tablespace read only or read write:

SQL> Alter tablespace userdata read only;

SQL> Alter tablespace userdata read write;

 

To add a datafile to tablespace:

SQL> Alter tablespace userdata add datafile ‘/u01/bsprod/oradata/userdata02.dbf’ size 100m;

SQL> Alter tablespace tempx add tempfile ‘/u01/bsprod/oradata/tempx02.dbf’ size 100m;

SQL>ALTER TABLESPACE userdata ADD DATAFILE ‘/u01/bsprod/oradata/userdata02.dbf’ SIZE 100K AUTOEXTEND ON NEXT 10K MAXSIZE 100K;

 

Page 15: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

To drop a datafile from the tablespace:

SQL> Alter tablespace userdata drop datafile ‘/u01/bsprod/oradata/userdata02.dbf’;

SQL> Alter tablespace userdata drop datafile 5;

SQL> Alter tablespace tempx drop tempfile ‘/u01/bsprod/oradata/tempx02.dbf’;

 

To rename the datafile:

SQL> Alter tablespace userdata rename datafile ‘/u01/bsprod/oradata/userdata02.dbf’ to ‘ /prod/bsprod/oradata/users01.dbf’ ;

 

To enable or disable force logging mode:

SQL> Alter tablespace userdata force logging;

SQL> Alter tablespace userdata no logging;

 

To Enabling and disabling undo retention guarantee

SQL> ALTER TABLESPACE undotbs RETENTION GUARANTEE;

SQL> ALTER TABLESPACE undotbs RETENTION NOGUARANTEE;

 

To Enable and disable flash back for the tablespaces:

SQL> Alter tablespace userdata FLASHBACK ON;

SQL> Alter tablespace userdata FLASHBACK OFF;

 

To enable and disable AUTOEXTEND to tablespace:

SQL> Alter tablespace userdata AUTOEXTEND ON;

SQL> Alter tablespace userdata AUTOEXTEND OFF;

 

To convert a tablespace from temporary to permanent:

Specify PERMANENT to indicate that the tablespace is to be converted from a temporary to a permanent tablespace. A permanent tablespace is one in which permanent database objects can be stored. This is the default when a tablespace is created. Specify TEMPORARY to indicate that the tablespace is to be converted from a permanent to a temporary tablespace. A temporary tablespace

Page 16: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

is one in which no permanent database objects can be stored. Objects in a temporary tablespace persist only for the duration of the session.

SQL> Alter tablespace userdata TEMPORARY;

SQL> Alter tablespace tempx PERMANENT;

 

To add a temporary tablespace to temporary group use the following alter command,

SQL> Alter tablespace temp_tbs group temptb_group;

 

To rename the tablespace:

SQL> Alter tablespace <tablesapce name> rename to <new name>;

SQL> Alter tablespace userdata rename to users;

 

For each datafile in the tablespace, this clause combines all contiguous free extents into larger contiguous extents.

SQL> Alter tablespace userdata COALESCE ;

 

Dropping Tablespaces:You can drop a tablespace and its contents 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.

To drop tablespaces including contents,

SQL> Drop tablespace userdata INCLUDING CONTENTS ;

If the tablespace is empty (does not contain any tables, views, or other structures), you do not need to specify the INCLUDING CONTENTS clause. Use the CASCADE CONSTRAINTS clause to drop all referential integrity constraints from tables outside the tablespace that refer to primary and unique keys of tables inside the tablespace.

SQL> Drop tablespace userdata;

 

To drop tablespaces with out dropping datafiles,

SQL> drop tablespace userdata INCLUDING CONTENTS KEEP DATAFILES;

 

To drop tablespaces with dropping datafiles,

Page 17: Web viewAll data stored on behalf of stored PL/SQL program units (procedures, functions, packages and triggers) resides in the SYSTEM tablespace. If you

SQL> drop tablespace userdata INCLUDING CONTENTS and DATAFILES;

A message is written to the alert log for each datafile that is deleted. If an operating system error prevents the deletion of a file, the DROP TABLESPACE statement still succeeds, but a message describing the error is written to the alert log.