Tablespace mgmt in 10g.pdf

Embed Size (px)

Citation preview

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    1/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    LOGICAL STORAGE STRUCTURES

    The logical units of database space allocation are data blocks, extents, segments,

    tablespaces. At a physical level the data is stored in data files (disk).

    Tablespaces Segments Extents Blocks

    Physically Oracle stores everything in file, called data files. Physical storage is

    how Oracle stores the data physically in the system. Whereas logical storage

    talks about how an end user actually accesses that data. The logical structures

    are created and recognized by Oracle and are not known to the OS.

    Tablespaces are divided into logical units of storage called SEGMENTS.

    Segments are further divided into EXTENTS.

    Extents are a collection of contiguous BLOCKS.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    2/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    ****

    INTRODUCTION TO TABLESPACES

    LOGICALstorage units called as tablespaces. It is a logical storage container for

    segments. Segments are database objects, such as tables & indexes that

    consume storage space.

    A tablespace is a logical group of one or more data files in a database. It is logical

    because a tablespace is not visible in the oracle file system. Oracle database can

    contain multiple tablespaces, It can be ONLINE (accessible) or OFFLINE (not

    accessible)whenever the database is open. The SYSTEM and TEMPORARY

    tablespaces can NOT be taken offline. Oracle database must have system &

    sysaux tablespaces.

    Oracle stores data logically in TABLESPACES & physically in DATAFILES

    (oslevel) associated with the corresponding tablespace. Tablespaces can be

    either SMALLFILE TABLESPACES or BIGFILE TABLESPACES.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    3/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    Three different types of Tablespaces

    PERMANENT TEMPORARY UNDO

    When a database is created, following tablespaces are created by DBCA.

    SYSTEM SYSAUX TEMP UNDOTBS1 USERS

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    4/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    EXTENT MANAGEMENT OF TABLESPACES

    DICTIONARY MANAGED Vs. LOCALLY MANAGED

    Prior to oracle database 8i, EXTENT management was always controlled by

    data dictionary tables. Oracle 8i introduced a new method of extent

    management called LOCALLY MANAGED TABLESPACES (LMT).

    When oracle allocates space to a segment (like a table or index), a group of

    contiguous free blocks, called an extent, is added to the segment. Metadata

    regarding extent allocation and unallocated extents are either stored in the data

    dictionary, or in the tablespace itself.

    Tablespaces that record extentallocation in the data dictionary, are called

    DICTIONARY MANAGED. Tablespaces that record extentallocation in the

    tablespace (datafile) header, are called LOCALLY MANAGED. DMT is an

    obsolete Technology. AlwaysLMT is superior to DMT in every respect.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    5/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    DBA need to create tablespaces with EXTENT management defined as

    either DICTIONARY or LOCAL. Tablespaces can use any one method to

    keep track of free and used space. (dictionary or locally) managed.

    SPACE MANAGEMENT

    Oracle maintains extents for a tablespace.

    Two different methods for oracle to keeping of free and used extents.

    They are dictionary managed tablespace & locally managed tablespace.

    DICTIONARY MANAGED TABLESPACES

    Oracle use the data dictionary (tables in SYS schema) to track allocated and

    free extents for tablespaces that is in " DICTIONARY MANAGED" mode.

    Oracle updates the following tables in the data dictionary whenever an

    extent is allocated, or freed for reuse.

    Free space is recorded in the SYS.FET$ table.

    Used space in the SYS.UET$ table.

    CREATING DICTIONARY MANAGED TABLESPACE

    SQL> create tablespace test datafile '/u01/test01.dbf' size 10m

    Extent management DICTIONARY;

    SQL> select tablespace_name, extent_management from

    dba_tablespaces where tablespace_name=TEST;

    TABLESPACE_NAME EXTENT_MANAGEMENT

    TEST DICTIONARY

    http://oracletipstricks.blogspot.in/2007/09/locally-vs-dictionary-managed.htmlhttp://oracletipstricks.blogspot.in/2007/09/locally-vs-dictionary-managed.htmlhttp://oracletipstricks.blogspot.in/2007/09/locally-vs-dictionary-managed.html
  • 8/10/2019 Tablespace mgmt in 10g.pdf

    6/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    ORA - 12913

    Lets check SYS.FET$ view to tablespace TEST (dictionary managed ).

    SQL> select * from SYS.FET$ where ts#='6'; (test tablespace).

    TS# FILE# BLOCK# LENGTH

    6 4 2 1279

    SQL> create table tab1(no number , name varchar(10));

    Table created.

    SQL> begin

    2 for i in 1..10000 loop

    3 insert into tab1 values (i, 'sam');

    4 end loop;

    6 end;

    7 /

    PL/SQL procedure successfully completed.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    7/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    Lets check SYS.UET$ view to tablespace TEST (dictionary managed).

    SQL> select SEGBLOCK#, EXT#, FILE#, BLOCK#, LENGTH, SEGBLOCK#

    from SYS.UET$ where ts#='8';

    SEGBLOCK# EXT# FILE# BLOCK# LENGTH SEGBLOCK#

    2 0 4 2 5 2

    2 1 4 7 5 2

    2 2 4 12 10 2

    STORAGE PARAMETERS

    The storage parameters are NOT valid if extents that are managed locally.

    NEXT, INITIAL, PCTINCREASE ,

    MINEXTENTS, MAXEXTENTS, DEFAULT STORAGE

    Initial Extent Default initial extent size

    Next Extent Default incremental extent size

    Min Extents Default minimum number of extents

    Max Extents Default maximum number of extents

    PCT Increase Default percent increase for extent size

    SQL>select initial_extent, min_extents, max_extents, next_extent ,

    pct_increase from dba_tablespaces where tablespace_name=TEST;

    INITIAL_EXTENT MIN_EXTENTS MAX_EXTENTS NEXT_EXTENT PCT_INCREASE

    40960 1 505 40960 50

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    8/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    ADVANTAGES OF LOCALLY MANAGED TABLESPACES

    Do NOT record free space in data dictionary, it reduces contention on these

    tables. LMT of extents automatically tracks adjacent free space.

    Oracle is managing extents by maintaining a bitmap in each datafile to keep track

    of the free or used status of blocks in datafile. Each bit in the bitmap corresponds

    to a block or a group of blocks. When the extents are allocated or freed for reuse,

    Oracle simply changes the bitmap values to show the new status of the blocks.

    Eliminates the need for recursive SQL operations against the data dictionary

    (UET$&FET$tables). Reduce contention on data dictionary tables. Locally

    managed tablespaces eliminate the need to periodically coalesce free space

    (automatically tracks adjacent free space)

    POINTS TO REMEMBER

    A dictionary tablespace can be changed into a locally managed but a

    locally manged tablespace cannot be changed into a dictionary one.

    If the SYSTEMtablespace is locally managed only create locally managed

    tablespaces , trying to create a dictionary one will fail.

    DBA CAN USE TABLESPACES TO DO THE FOLLOWING ACTIONS

    Create new table spaces & data files to table spaces.

    Make a table space read only or read/write.

    Make a table space temporary or permanent.

    Rename , Relocate table spaces & drop table spaces.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    9/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    MIGRATING DMT TO LMT ( USERS TABLESPACE )

    SQL> select tablespace_name , extent_management from dba_tablespaces ;

    TABLESPACE_NAME EXTENT_MAN

    SYSTEM DICTIONARY

    SYSAUX LOCAL

    TEMP LOCAL

    USERS DICTIONARY

    SQL> execute dbms_space_admin.tablespace_migrate_to_local(XXXX);

    SQL> exec dbms_space_admin.tablespace_migrate_to_local(TEST);

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    10/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    CONVERTING LMT TO DMT

    SQL>execute dbms_space_admin.tablespace_migrate_from_local(XXXX);

    SQL>exec dbms_space_admin.tablespace_migrate_to_local(TEST);

    PL/SQL procedure successfully completed.

    If we create a database with DBCA , it will have a locally managed SYSTEM

    tablespace by default. we cannot create new dictionary managed tablespaces.

    Sizes of extents that are managed locally can be determined automatically by

    the system. Alternatively, all extents might be the same size in a LMT. If we

    want to create extents with the same sizes, you need to specify UNIFORM.

    Changes to the extent bitmaps do NOT generate rollback information because

    they do NOT update tables in the data dictionary (except for special cases such

    as tablespace quota information). Reduced fragmentation.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    11/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    As I said , see the keyword "autoallocate" why extents are allocated with

    different sizes as autoallocatespecifies extentsizes are system generated. Most

    likely our tablespace will be autoalloctate LMT.

    Who wants to create extents with the same sizes, need to specify UNIFORM.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    12/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    Lets start with two users . Each user is assigned different , different

    tablespace. User ROSE is assigned to test tablespace(uniform). User SONA

    is assigned to samp tablespace (autoallocate).

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    13/44

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    14/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    When creating tablespace samp , I did NOT mention UNIFORMso extents

    sizes are NOT same. We can see bytes column from following screen shot.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    15/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    TO FIND TABLESPACE PARAMS

    I am attaching screen shot for both tablespaces ( test&

    samp).

    SQL> SELECT tablespace_name

    , contents

    , extent_management

    , allocation_type

    , segment_space_management

    FROM dba_tablespaces ;

    SQL> select tablespace_name, contents, status, block_size, initial_extent,

    extent_namagement, allocation_type, segment_space_management,

    bigfile from dba_tablespaces ;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    16/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    LMT can use either autoallocate or uniform is all about allocation of new

    extents when space pressure increases in the tablespace

    UNIFORMLY SIZED EXTENTS - UNIFORM

    AUTO SIZED EXTENTS -AUTOALLOCATE

    AUTO ALLOCATE

    Means that the extent sizes are managed by Oracle. It will choose the optimal

    next size for the extents starting with 64 KB. As the segments grow and more

    extents are needed, Oracle starts allocating larger and larger sizes then it moves

    to 1Mb , 8MB ultimately to 64Mb extents. We can make initial extent size of

    greater than 64KB , it will allocate extents atleast the amount of the space.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    17/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    UNIFORM

    Create the extents the same size by specifying the size when create the

    tablespace. i.e. UNIFORM specifies that the tablespace is managed with

    uniform extents of SIZEbytes (use Kor Mto specify the extent size).

    When the SYSTEMtablespace is dictionarymanaged other tablespaces can bemanaged either LOCALLY (LM) or DICTIONARY (DM). Extent management on

    the SYSAUX & UNDO tablespaces is always LOCAL.

    When using auto allocateSpace allocation is simplified, because

    when AUTOALLOCATE is specified, i.e. database automatically selects the

    appropriate extent size. Space allocations and deallocations modify locally

    managed resources (bitmaps stored in header files).

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    18/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    MANAGING TABLESPACE

    CREATE TABLESPACE

    SYNTAX - CREATING A NEW TABLESPACE

    SQL> create tablespace datafile filepath size m ;

    SQL> create tablespace TEST datafile 'test01.ora' size 10m;

    SQL> create tablespace TEST datafile /u01/oradata/test02.orasize 15m;

    Tablespace created.

    If path is not specified, by default it is located at dbsdirectory

    ALTER TABLESPACE

    SYNTAX - ADDING A NEW DATAFILE

    SQL> alter tablespace add datafile filepath size m;

    SQL> alter tablespace TEST add datafile 'test03.dbf' size 10m;

    SQ> alter tablespace TEST add datafile

    '/u01/app/oracle/oradata/samp/test04.dbf' size 10m;

    Tablespace altered.

    SYNTAX - RESIZING THE EXSISTING DATAFILE

    SQL> alter database datafile filepath resize m;

    SQL> alter database datafile 'test01.dbf' resize 20m;

    Datbase altered

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    19/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    DROP TABLESPACE

    SYNTAX - DROP THE TABLESPACE

    SQL> drop tablespace ;

    SQL> drop tablespace INCLUDING CONTENTS;

    SQL> drop tablespace INCLUDING CONTENTS AND DATAFILES;

    SQL> drop tablespace test;

    SQL> drop tablespace test including contents;

    SQL> drop tablespace test including contents and datafiles;

    Tablespace dropped.

    RENAME TABLESPACE

    SYNTAX RENAMING A EXISTING TABLESPACE

    SQL>alter tablespace rename to ;

    SQL> alter tablespace TEST rename to TESTS;

    Tablespace altered.

    RENAMING DATAFILE

    SQL> shutdown normal;

    linux> mv 'OLDFILE.DBF ' 'NEWFILE.DBF'

    SQL> startup mount;

    SQL> alter database RENAME file 'old file path' to 'newfile path'

    Database altered

    SQL> alter database open;

    Database opened.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    20/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    II) SYNTAX

    SQL>alter database RENAME FILE old filepath to 'newfilepath;

    SQL>alter database rename file /u01/app/test.dbfto /u01/test.dbf;

    Database altered.

    CREATING DICTIONARY MANAGED TABLESPACE

    SYNTAX

    SQL>create tablespace datafile 'file path ' size m

    extent management DICTIONARY;

    SQL> create tablespace samp datafile '/u01/oradata/samp/samp01. dbf '

    size 10m extent management dictionary ;

    Tablespace created.

    In 10g , If not specified Extent management dictionary automatically

    tablespace will be created as LOCALLY MANAGED .

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    21/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    SYSTEM tablespace should be DICTIONARY MANAGED otherwise cannot

    create dictionary managed tablespaces.

    As far as I remember, dbcacreates databases with locally managed databases,

    when creating database manually In release 10.x, the default was dictionary

    managed. Locally managed tablespaces are much more efficient than dictionary

    managed ones.

    LOCALLY MANAGED TABLESPACE

    SYNTAX CREATE LOCALLY MANAGED TABLESPCE

    SQL> create tablespace datafile filepathf' size m

    extent management LOCAL;

    SQL>create tablespace samp datafile

    '/u01/app/oracle/oradata/samp/samp01 .dbf' size 20m

    extent management local;

    Tablespace created.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    22/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    SYNTAX - LOCALLY MANAGED TABLESPACE USING AUTO

    SQL> create tablespace datafile 'file path' size m

    extent management LOCAL AUTO ALLOCATE;

    SQL> create tablespace samp datafile '/u01/oradata/samp/samp02.dbf

    size 10m extent management local autoallocate;

    SYNTAX - LOCALLY MANAGED TABLESPACE USING UNIFORM

    SQL> create tablespace datafile 'file path' size m

    extent management LOCAL UNIFORM SIZE 120K;

    SQL> create tablespace samp datafile '/u01/oradata/samp03.dbf'

    size 20m extent management local uniform size 120k ;

    TABLESPACE SPECIFYING SEGMENT SPACE ( ASSM )

    SQL>create tablespace datafile 'file path'size m

    extent management LOCAL segment space management AUTO;

    SQL> create tablespace test datafile '/u01/oradata/samp/test01.dbf' size

    15m extent management local -- ENABLE LMT

    segment space management auto ; -- ENABLE ASSM

    *******

    ASSM takes total control of the parameters FREELISTS, FREELIST GROUPS, &

    PCTUSED. Oracle will track and manage the used and free space in data blocks

    using bitmaps for all objects defined in the tablespace.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    23/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    *************

    LMT WITH AUTO EXTEND

    EXAMPLE -I

    SQL> create tablespace datafile filepath size m

    AUTOEXTEND ON:

    SQL> create tablespace test datafile '/u01/oradata/samp/test02.ora' size

    10m autoextend on;

    EXAMPLE II

    SQL> create tablespace datafile filepath size m

    AUTOEXTEND ON MAXSIZE m;

    SQL> create tablespace test datafile '/u01/oradata/samp/test03.ora' size

    10m autoextend on maxsize 100m;

    EXAMPLE III

    SQL> create tablespace datafile filepath size m

    AUTOEXTEND ON NEXT m MAXSIZE m;

    SQL> create tablespace test datafile '/u01/oradata/samp/test04.ora'

    size 10m autoextend on next 2m maxsize 100m;

    EXAMPLE IV

    SQL> create tablespace datafile filepath size m

    AUTOEXTEND ON MAXSIZE UNLIMITED.

    SQL> create tablespace test datafile '/u01/oradata/samp/test04.ora' size

    10m autoextend on maxsize 100m;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    24/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    EXAMPLE - V

    SQL> create tablespace add datafile filepath size

    mAUTOEXTEND ON MAXSIZE UNLIMITED

    SQL> create tablespace test datafile '/u01/oradata/samp/test05.ora'

    size 10m autoextend on maxsize unlimited;

    EXAMPLE - VI

    SQL> alter database datafile filepath AUTOEXTEND ON

    MAXSIZE UNLIMITED ;

    SQL> alter database test datafile '/u01/oradata/samp/test05.ora'

    autoextend on maxsize unlimited;

    EXAMPLE - VII

    SQL>alter database datafile 'pathfile' AUTOEXTEND OFF;

    SQL>alter database datafile '/u01/oradata/samp/test04.dbf'

    autoextend off;

    TO CHECK AUTO EXTENSIBLE STATUS

    SQL> select file_name, autoextensible from dba_data_files

    where tablespace_name like '%TES%';

    ASSIGNING A DEFAULT TABLESPACE FOR WHOLE DATABASE

    SQL>alter database default tablespace ;

    SQL>alter database default tablespace sample;*****************

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    25/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    CHECKING DEFAULT TABLESPACES IN DATABASE

    ASSIGNING TABLESPACE TO A SPECIFIC USER

    SQL> alter user default tablespace ;

    SQL> alter user san default tablespace users;

    TO FIND DEFAULT TABLESPACES FOR SPECIFIC USERS

    SQL> select username , default_tablespace from dba_users

    where username='SAM' or username='SAN';

    USERNAME DEFAULT_TABLESPACE

    SAN USERS

    SAM SAMP

    ALTERING TABLESPACE AVAILABILITY

    SQL>alter tablespace read only;

    SQL>alter tablespace sample read only

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    26/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    SQL>alter tablespace read write;

    SQL>alter tablespace sample read write

    SQL>alter tablespace offline;

    SQL>alter tablespace sample offline;

    SQL>alter tablespace online;

    SQL>alter tablespace sample online;

    CHECKING TABLESPACE STATUS

    SOME RESTRICTIONS IMPOSED ON TABLESPACES.

    TABLESPACE OFFLINE RENAME DROP

    SYSTEM NO NO NO

    SYSAUX YES NO NO

    TEMPORARY NO YES NO

    UNDO NO YES YES

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    27/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    CHECKING DATAFILES BYTES , BLOCKS IN DATABASE

    CHECKING DATAFILES UNDER ANYONE TABLESPACE

    CHECKING DATAFILE FILE_ID , BYTES , FILE_NAME UNDER TABLESPACE

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    28/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    RESIZING DATAFILE USING FILE_ID

    SQL> alter database datafile resize m;

    SQL>alter database datafile 4 resize 25m;

    GET PROPERTIES OF AN EXISTING TABLESPACE

    SQL> select DBMS_METADATA.GET_DDL('TABLESPACE', ' tsname') from dual;

    SQL> select DBMS_METADATA.GET_DDL('TABLESPACE', ' USERS') from dual;

    ASSIGNING QUOTAS TO A USER IN DEFAULT TABLESPACE

    SQL> alter user default tablespace

    quota m on ;

    SQL> alter user sam default tablespace sample quota 2m on sample;

    SET DEFAULT TABLESPACE TYPE

    SQL>alter database set default tablespace;

    SQL>alter database set default SMALLFILE tablespace;

    SQL>alter database set default BIGFILE tablespace;

    DISPLAY DEFAULT TABLESPACE TYPE

    SQL> select property_value from database_properties

    where property_name = 'DEFAULT_TBS_TYPE';

    PROPERTY_VALUE

    It will show what already set smallfile or bigfile.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    29/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    FIND DEFAULT_PERMANENT_TABLESPACE

    SQL>select property_value from database_properties

    where property_name='DEFAULT_PERMANENT_TABLESPACE';

    CAN WE DROP PERMANENT TABLESPACE

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    30/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    PERMANENT TABLESPACE

    Permanaent tablespaces can be either small tablespacesorbig tablespaces.

    Small tablespace can be made up of a number of data files. Big tablespace will

    only be made up of one data file and this can get extremely large. We cannot

    add datafile to a bigfile tablespace.

    A bigfile tablespace with 8K blocks can contain a 32 terabyte datafile. A bigfile

    tablespace with 32K blocks can contain a 128 terabyte datafile. The maximum

    number of datafiles in an Oracle Database is limited (usually to 64K files). We

    can specify SIZE in kilobytes (K), megabytes (M), gigabytes (G), or terabytes (T).

    Bigfile tablespaces are supported only for locally managed tablespaces with

    automatic segment space management.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    31/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    TEMPORARY TABLESPACES

    CREATING LOCALLY MANAGED TEMPORARY TABLESPACE

    SQL>create temporary tablespace TEMPFILE file path size

    m EXTENT MANAGENT LOCAL;

    SQL>create temporary tablespace temptbs tempfile

    '/u01/app/oracle/oradata/orc/temp01.ora' size 20m

    Extent management local;

    ADDING TEMPFILE TO TEMPORARY TABLESPACE

    SQL>alter tablespace add tempfile file path size m;

    SQL>alter tablespace temptbs add tempfile

    '/u01/app/oracle/oradata/orcl/temp02.ora' size 8m;

    RESIZING A TEMPORARY FILE

    SQL>alter database TEMPFILE file path resize m;

    SQL>alter database tempfile

    '/u01/app/oracle/oradata/orcl/temp02.ora' resize 15m;

    HOW TO ASSIGN DEFAULT TEMPORARY TABLESPACE

    SQL> alter database DEFAULT temporary tablespace

    SQL> alter database default temporary tablespace temp;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    32/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    TEMPFILES AND ASSOCIATED TEMPORARY TABLESPACE

    CHECKING LOCAL MANAGED TEMPFILES AND STATUS

    MAKING TEMPORARY TABLESPACE TO OFFLINE

    SQL>alter tablespace TEMPFILE OFFLINE;

    SQL>alter tablespace TEMPTBS TEMPFILE OFFLINE ;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    33/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    ORA-12905

    The DEFAULT TEMPORARY TABLESPACE cannot be taken off-line

    The DEFAULT TEMPORARY TABLESPACE cannot be dropped until create

    another one. We cannot change a default temporary tablespace into a

    permanent tablespace. Oracle10gintroduced new feature which we will create

    the temp file automatically when we restart the database.

    If we make Temporary tablespace goes offline, associated all temp files will be

    offline status. Even if tablespace is offline , can add temp file under this

    tablespace by default ONLINE status. Even a tablespace is offline, can set

    temporary tablespace as Default temporary tablespace.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    34/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    ALTERING TEMPORARY TABLESPACE TO ONLINE

    SQL>alter tablespace TEMPFILE ONLINE;

    SQL>alter tablespace tmpbs tempfile online;

    CREATING TEMPORARY TABLESPACE AND GROUP

    SQL> create temporary tablespace tempfile

    filepath' size m tablespace GROUP ;

    SQL> create temporary tablespace temtbs tempfile

    '/u01/app/oracle/oradata/orcl/temp01.ora' size 2m

    tablespace GROUP T1;

    ORA-10918:

    TABLESPACE GROUP name cannot be the same as tablespace name.

    CREATING GROUP FOR EXISTING TEMPORARY TABLESPACE

    SQL> alter tablespace tablespace GROUP ;

    SQL> alter tablespace temp tablespace group t2;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    35/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    Here tmpts1 is created by oracle. If NO group exists oracle will create it.

    TEMPORARY TABLESPACE WITH ASSOCIATED GROUP

    SQL>select * from DBA_TABLESPACE_GROUPS;

    DROPPING TEMPORARY TABLESPACE

    SQL> drop tablespace including contents and datafiles;

    SQL>drop tablespace tmpts including contents and datafiles;

    REMOVE A TABLESPACE FROM A GROUP

    SQL> alter tablespace tablespace group '';

    SQL> alter tablespace tmpts tablespace group '';

    QUERY TO FIND DEFAULT TEMPORARY TABLESPACE

    SQL> select property_value from database_properties where

    property_name = 'DEFAULT_TEMPORARY_TABLESPACE';

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    36/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    SQL>select property_value from database_properties where

    property_name = 'DEFAULT_TEMPORARY_TABLESPACE';

    PROPERTY_VALUE

    TEMP

    V$SORT_SEGMENT

    It contains information about every sort segment in TEMP TABLESPACE. This

    view is only updated when the tablespace is of the temporarytype. We can

    check total_extents , extent_size, total_blocks, free_extents, free_blocks from

    v$sort_segment view.

    SQL> select * from V$SORT_SEGMENT;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    37/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    DISPLAY FREE TEMP SPACE

    V$TEMP_SPACE_HEADER

    SQL> select sum(bytes_used), sum(bytes_free)

    from v$temp_space_header group by tablespace_name;

    MAKE USER USE TEMP GROUP

    SQL> alter user temporary tablespace ;

    SQL> alter user sam temporary tablespace t3;

    The DBA should assign a temporary tablespace to each user in the database to

    prevent them from allocating sort space in the SYSTEM tablespace.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    38/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    UNDO TABLESPACES

    Undo tablespaces are used to store original data after it has been changed.

    We can create more than one undo tablespace, but one of them can be

    active at any one time. Oracle provides a fully automated mechanism, referred

    to as automatic undo management, for managing undo information and space.

    AUM (AUTOMATIC UNDO MANAGEMENT)

    CREATING UNDO TABLESPACE

    SQL> create UNDO tablespace datafile filepath' size m;

    RESIZING UNDO TABLESPACE

    SQL> alter database datafile pathfile resize m;

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    39/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    ADDING DATAFILE TO UNDO TABLESPACE

    SQL> alter tablespace add filepath size m;

    TO FIND CURRENTLY USED UNDO TABLESPACE

    ORA-30013

    SQL> drop tablespace UNDOTBS1 including contents and datafiles;

    ERROR at line 1:

    ORA-30013: undo tablespace 'UNDOTBS1'is currently in use

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    40/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    TO FIND ALL UNDO TABLESPACES

    SQL> select tablespace_name , status from DBA_TABLESPACES

    Where tablespace_name like '%UNDO%';

    Only one undo tablespace can be active at a time. Here UNDOTBS1. We cannot

    drop an undo tablespace if it is being used by any instance or if it contains any undo

    data needed to roll back uncommitted transactions.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    41/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    SWITCHING UNDO TABLESPACE

    SQL>alter system set undo_tablespace=undo_tsname;

    SQL> alter system set undo_tablespace='UNDOTBS';

    UNASSIGN CURRENT UNDO TABLESPACE

    SQL>alter system set undo_tablespace=' ';

    SQL>alter system set undo_tablespace=' '

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    42/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    DROP UNDO TABLESPACE

    SQL> drop tablespace including contens and datfiles;

    FIND ALLOCATED/FREE SIZE OF THE UNDO DATAFILE

    Now I have removed UNDOTBS1&UNDOTEST, my default undo tablespace

    is UNDOTBS. Letsperform small test with UNDOTBS.

  • 8/10/2019 Tablespace mgmt in 10g.pdf

    43/44

    MANAGING TABLESPACES IN ORACLE 10g

    Exploring the Oracle DBA Technology by Gunasekaran ,Thiyagu

    POINTS TO NOTE

    Space for undo segments is dynamically allocated, consumed, freed, and

    reusedall under the control of Oracle Database, rather than by DBAS so

    Oracle takes care undo tablespace.

    undo_extent_stat.sql

    DATABASE_PROPERTIES

    The current settings for the default tablespaces can be viewed using the

    DATABASE_PROPERTIES view.

    SEGMENT_NAME ( ROLL BACK SEGMENT NAME )

    https://www.scribd.com/doc/249018916/Undo-Extent-Stat?secret_password=Cocf0nkL3L3Uc3irlLoPhttps://www.scribd.com/doc/249018916/Undo-Extent-Stat?secret_password=Cocf0nkL3L3Uc3irlLoP
  • 8/10/2019 Tablespace mgmt in 10g.pdf

    44/44

    MANAGING TABLESPACES IN ORACLE 10g

    TO GET TABLESPACE METADATA

    SQL> set serveroutput on ;

    SQL> declare c clob;

    begin

    for t in( select tablespace_name from dba_tablespaces)

    loop

    select dbms_metadata.get_ddl('TABLESPACE', t.tablespace_name) into c

    from dual;

    dbms_output.put_line(c);

    dbms_output.put(';');

    end loop;

    end;

    /

    SOME IMPORTANT PARAMS ABOUT TABLESPACES

    COLUMNS VALUES

    CONTENTS PERMANENT , TEMPORARY , UNDO

    STATUS ONLINE , OFFLINE , READ ONLY

    EXTENT_MANAGEMENT DICTIONARY , LOCAL

    ALLOCATION_TYPE SYSTEM ( autoallocate), UNIFORM (manual )

    SEGMENT_SPACE_MANAGEMENT MANUAL , AUTO