Tablespaces and Datafiles

Embed Size (px)

Citation preview

  • 8/19/2019 Tablespaces and Datafiles

    1/28

    Tablespaces and Datafiles 

    Objectives

     These notes cover the creation and management of tablespaces and theirassociated datafiles. You will learn how to create both locally managed anddictionary managed tablespaces. 

    Tablespaces vs. Datafiles 

     An Oracle database is comprised of tablespaces.

    Tablespaces logically organize data that are physically stored indatafiles.•   A tablespace belongs to only one database, and has at least one

    datafile that is used to store data for the associated tablespace.•  The term "tablespaces" is misleading because a tablespace can

    store tables, but can also store many other database objects such asindexes, views, seuences, etc.

    •  !ecause dis drives have a finite si#e, a tablespace can span disdrives when datafiles from more than one dis drive are assigned to a

    tablespace. This enables systems to be very, very large.•  $atafiles are always assigned to only one tablespace and, therefore,

    to only one database.

     As is shown in the figure below, a tablespace can span datafiles.

  • 8/19/2019 Tablespaces and Datafiles

    2/28

  • 8/19/2019 Tablespaces and Datafiles

    3/28

    !eginning with Oracle '2g, the smallest Oracle database is twotablespaces. This applies to Oracle ''g.

    o  #$#T%M + stores the data dictionary.o

     

    #$#U& + stores data for auxiliary applications &covered in more

    detail later in these notes(. 3n reality, a typical production database has numerous tablespaces. Theseinclude #$#T%M and !O!'#$#T%M tablespaces. #$#T%M + a tablespace that is always used to store #$#T%M data thatincludes data about tables, indexes, seuences, and other objects + thismetadata comprises the data dictionary.

    •  very Oracle database has to have a #$#T%M tablespace4it is thefirst tablespace created when a database is created.

    •   Accessing it reuires a higher level of privilege.

    •  You cannot rename or drop a #$#T%M tablespace.

    •  You cannot tae a #$#T%M tablespace offline.

    •  The #$#T%M tablespace could store user data, but thisis not normally done4a good rule to follow is to never allow allow thestorage of user segments in the #$#T%M tablespace.

    •  This tablespace always has a #$#T%M Undo segment. The #$#U& tablespace stores data for auxiliary applications such asthe /og1iner, 5orspace 1anager, Oracle $ata 1ining, Oracle -treams,and many other Oracle tools.

    •  This tablespace is automatically created if you use the Database(reation ssistant software to build an Oracle database.

    •  /ie the #$#T%M tablespace, #$#U& reuires a higher level ofsecurity and it cannot be dropped or renamed.

    •  $o not allow user objects to be stored in #$#U&. This tablespaceshould only store system specific objects.

    •  This is a permanent tablespace. 

     All other tablespaces are referred to as !on'#$#T%M. A differenttablespace is used to store organi#ational data in tables accessed byapplication programs, and still a different one for undo information storage,and so on. There are several reasons for having more than onetablespace%

  • 8/19/2019 Tablespaces and Datafiles

    4/28

    •  6lexibility in database administration.

    •  -eparate data by bacup reuirements.

    •  -eparate dynamic and static data to enable database tuning.

    •  0ontrol space allocation for both applications and system users.

    •  7educe contention for input8output path access &to8frommemory8dis(.

     

    ()%T% T*+%#P(% (ommand To create a tablespace you must have the 07AT TA!/-A0privilege.

    The full ()%T% T*+%#P(% &and ()%T% T%MPO))$T*+%#P(%( command syntax is shown here.

    CREATE TABLESPACE tablespace  [DATAFILE clause]  [MINIMUM EXTENT integer[KM]]  [BL!CKSI"E integer [K]]  [L!##IN#N!L!##IN#]  [DEFAULT st$rage%clause ]  [!NLINE!FFLINE]  [PERMANENTTEMP!RAR&]  [e'tent%(anage(ent%clause]  [seg(ent%(anage(ent%clause] 

     As you can see, almost all of the clauses are optional. The clauses aredefined as follows% 

    •  T*+%#P(%% This clause specifies the tablespace name.

    •  DT,-+%% This clause names the one or more datafiles that will

    comprise the tablespace and includes the full path, example% DATAFILE)*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3) SI"E,+M  

  • 8/19/2019 Tablespaces and Datafiles

    5/28

    •  M-!-MUM %&T%!T% very used extent for the tablespace will be amultiple of this integer value. 9se either T, :, 1 or ; to specifyterabytes, gigabytes, megabytes, or ilobytes.

    •  *+O(#-/%% This specifies a nonstandard bloc si#e + this clause

    can only be used if the $!

  • 8/19/2019 Tablespaces and Datafiles

    6/28

    •  M-/%% -pecifies the maximum dis space allocated to thetablespace. 9sually set in megabytes, e.g., E221 or specified as9?/313T$.

    Tablespace #pace Management Tablespaces can be either +ocally Managed to DictionaryManaged. $ictionary managed tablespaces have been deprecated  &areno longer usedFFare obsolete( with Oracle ''gG however, you mayencounter them when woring at a site that is using Oracle '2g. 5hen you create a tablespace, if you do not specify extent management,the default is locally managed. 

    +ocally Managed The extents allocated to a locally managed tablespace are managedthrough the use of bitmaps.

    •  ach bit corresponds to a bloc or group of blocs &an extent(.

    •  The bitmap value &on or off( corresponds to whether or not an extentis allocated or free for reuse.

    •  /ocal management is the default for the #$#T%M tablespacebeginning with Oracle '2g.

    •  5hen the -Y-T1 tablespace is locally managed, the othertablespaces in the database must also be either locally managed orreadFonly.

  • 8/19/2019 Tablespaces and Datafiles

    7/28

    •  /ocal management reduces contention for the -Y-T1 tablespacebecause space allocation and deallocation operations for othertablespaces do not need to use data dictionary tables.

    •  The +O(+ option is the default so it is normally not specified.

    •  5ith the +O(+ option, you cannot specify any D%,U+T#TO)0%, M-!-MUM %&T%!T, or T%MPO))$ clauses.

    %3tent Management

    •  U!-,O)M + a specification of U!-,O)M means that the tablespaceis managed in uniform extents of the #-/% specified.o  use 9?36O71 to enable exact control over unused space and

    when you can predict the space that needs to be allocated for an

    object or objects.o

      9se , M, 0, T, etc  to specify the extent si#e in ilobytes,megabytes, gigabytes, terabytes, etc. The default is 5MG however,you can specify the extent si#e with the #-/% clause ofthe U!-,O)M clause.

    o  6or our small student databases, a good #-/% clause valueis 567.

    o  You must ensure with this setting that each extent has at least 8database bloc9s.

    •  UTO++O(T% + a specification of UTO++O(T% insteadof U!-,O)M, then the tablespace is system managed and youcannot specify extent si#es.o

     

    UTO++O(T% is the default.  this simplifies dis space allocation because the database

    automatically selects the appropriate extent si#e.  this does waste some space but simplifies management of

    tablespace.o

      Tablespaces with A9TOA//O0AT are allocated minimum extentsi#es of :; with a minimum of  8 database bloc9s per extent.

     dvantages of +ocal Management% !asically all of these advantageslead to improved system performance in terms of response time,particularly the elimination of the need to coalesce free extents. 

  • 8/19/2019 Tablespaces and Datafiles

    8/28

    •  /ocal management avoids recursive space managementoperations. This can occur in dictionary managed tablespaces ifconsuming or releasing space in an extent results in anotheroperation that consumes or releases space in an undo segment or

    data dictionary table.•  !ecause locally managed tablespaces do not record free space in

    data dictionary tables, they reduce contention on these tables.•  /ocal management of extents automatically tracs adjacent free

    space, eliminating the need to coalesce free extents.•  The si#es of extents that are managed locally can be determined

    automatically by the system.•  0hanges to the extent bitmaps do not generate undo information

    because they do not update tables in the data dictionary &except for

    special cases such as tablespace uota information(. xample 07AT TA!/-A0 command + this creates a locallymanaged -nventory tablespace with A9TOA//O0AT management ofextents. CREATE TABLESPACE in4ent$r5  DATAFILE)*u+6*stu-ent*-.$c/st-*$ra-ata*USER01+in4ent+,2-.3)SI"E 1+M 

      EXTENT MANA#EMENT L!CAL AUT!ALL!CATE7 xample 07AT TA!/-A0 command + this creates a locallymanaged -nventory tablespace with 9?36O71 management of extentswith extent si#es of ')H;. CREATE TABLESPACE in4ent$r5  DATAFILE)*u+6*stu-ent*-.$c/st-*$ra-ata*USER01+in4ent+,2-.3)

    SI"E 1+M   EXTENT MANA#EMENT L!CAL UNIF!RM SI"E ,68K7 

    Possible %rrorsYou cannot specify the following clauses when you explicitly specifyT?T 1A?A:1?T /O0A/%

    o  $6A9/T storage clause

  • 8/19/2019 Tablespaces and Datafiles

    9/28

    o  13?3191 T?To  T1O7A7Y

     #egment #pace Management in +ocally Managed Tablespaces

    9se the -:1?T -A0 1A?A:1?T clause to specify how free andused space within a segment is to be managed. Once established, youcannot alter the segment space management method for a tablespace. 

    M!U+% This setting uses free lists to manage free space withinsegments.

    o  6ree lists are lists of data blocs that have space available for

    inserting rows.o

      You must specify and tune the 0T9-$, 67/3-T-, and67/3-T :7O9- storage parameters.

    o  1A?9A/ is usually ?OT a good choice.

    UTO% This uses bitmaps to manage free space within segments.o

      This is the default.o

      A bitmap describes the status of each data bloc within asegment with regard to the data blocIs ability to haveadditional rows inserted.

    o  !itmaps allow Oracle to manage free space automatically.o

      -pecify automatic segmentFspace management only forpermanent, locally managed tablespaces.

    o  Automatic generally delivers better space utili#ation thanmanual, and it is selfFtuning.

     xample 07AT TA!/-A0 command + this creates a locallymanaged -nventory tablespace with A9TO segment space management. CREATE TABLESPACE in4ent$r5  DATAFILE)*u+6*stu-ent*-.$c/st-*$ra-ata*USER01+in4ent+,2-.3)

    SI"E 1+M   EXTENT MANA#EMENT L!CAL  SE#MENT SPACE MANA#EMENT AUT!7 

    Dictionary Managed 

  • 8/19/2019 Tablespaces and Datafiles

    10/28

    5ith this approach the data dictionary contains tables that store informationthat is used to manage extent allocation and deallocation manually.

    !OT%4 eep in mind yo2 will !OT be able to create any tablespacesof this type in yo2r 55g database. This information is provided in theevent yo2 have to wor9 with older databases. 

    The D%,U+T #TO)0% clause enables you to customi#e the allocationof extents. This provides increased flexibility, but less efficiency than locallymanaged tablespaces. 

    xample + this example creates a tablespace using all $6A9/T-TO7A: clauses. CREATE TABLESPACE in4ent$r5  DATAFILE)*u+6*stu-ent*-.$c/st-*$ra-ata*USER01+in4ent+,2-.3)SI"E 1+M   EXTENT MANA#EMENT DICTI!NAR&  DEFAULT ST!RA#E 9  INITIAL 1+K  NEXT 1+K  MINEXTENTS 6  MAXEXTENTS 1+  PCTINCREASE +:7

    •  The tablespace will be stored in a single, J21 datafile.

  • 8/19/2019 Tablespaces and Datafiles

    11/28

    •  The T?T 1A?A:1?T $30T3O?A7Y clause specifies themanagement.

    •   All segments created in the tablespace will inherit the default storageparameters unless their storage parameters are specified explicitly to

    override the default. The storage parameters specify the following%

    •  -!-T-+ + si#e in bytes of the first extent in a segment.

    •  !%&T + si#e in bytes of second and subseuent segment extents.

    •  P(T-!()%#% + percent by which each extent after the secondextent grows.

    #MO! periodically coalesces free space in a dictionaryFmanaged tablespace, but only if the P(T-!()%#% setting is

    ?OT #ero.o  9se +T%) T*+%#P(%

  • 8/19/2019 Tablespaces and Datafiles

    12/28

     1ore than one 9?$O tablespace can exist, but only one can be active at atime. 

     A later set of notes will cover 9?$O management in detail. 

    T%MPO))$ Tablespace 

     A T1O7A7Y tablespace is used to manage space for sortoperations. -ort operations generate segments, sometimes largesegments or lots of them depending on the sort reuired to satisfy thespecification in a #%+%(T statementIs >H%)% clause.

    -ort operations are also generated by #%+%(T statements that join rowsfrom within tables and between tables.

    ?ote the use of the T%MP,-+% instead of a DT,-+% specification for atemporary tablespace in the figure shown below.

    •  Tempfiles are also in a !O+O00-!0 mode.

    •  Tempfiles cannot be made read only or be renamed.

    •  Tempfiles are reuired for readFonly databases.

    •  Tempfiles are not recovered during database recovery operations.

    •  The U!-,O)M #-/% parameter needs to be a multiple ofthe #O)T1)%1#-/% to optimi#e sort performance.

    •  The UTO++O(T% clause is not allowed for temporarytablespaces.

    •  The default extent #-/% parameter is 5M.

  • 8/19/2019 Tablespaces and Datafiles

    13/28

     

    Defa2lt Temporary Tablespace 

    ach database needs to have a specified defa2lt temporarytablespace. 3f one is not specified, then any user account created withoutspecifying aT%MPO))$ T*+%#P(% cla2se is assigned a temporarytablespace in the #$#T%M tablespaceK

    This should raise a red flag as you donIt want system users to execute-/0T commands that cause sort operations to tae place within the-Y-T1 tablespace. 3f a default temporary tablespace is not specified at the time a database is

    created, a $!A can create one by altering the database. 

     ALTER DATABASE DEFAULT TEMP!RAR& TABLESPACE te(;7 

     After this, new system user accounts are automatically allocated temp astheir temporary tablespace. 3f you A/T7 $ATA!A- to assign a newdefault temporary tablespace, all system users are automaticallyreassigned to the new default tablespace for temporary operations. 

    /imitations%•   A default temporary tablespace cannot be dropped unless a

    replacement is created. This is usually only done if you were movingthe tablespace from one dis drive to another.

    •  You cannot tae a default temporary tablespace offline + this is doneonly for system maintenance or to restrict access to a tablespacetemporarily. ?one of these activities apply to default temporarytablespaces.

    •  You cannot alter a default temporary tablespace to mae it

    permanent. 

    Temporary Tablespace 0ro2psYou can have more than one temporary tablespace online andactive. Oracle supports this through the use of temporary tablespacegroups + this is a synonym for a list of temporary tablespaces.

  • 8/19/2019 Tablespaces and Datafiles

    14/28

    •   A single user can have more than one temporary tablespace in useby assigning the temporary tablespace group as the default to theuser instead of a single temporary tablespace.

    •  xample% -uppose two temporary tablespaces

    named T%MP?5 and T%MP?6 have been created. This code assignsthe tablespaces to a group namedT%MP0)P. S

  • 8/19/2019 Tablespaces and Datafiles

    15/28

     

    U#%)#B DT and -!D%&%# Tablespaces 1ost Oracle databases will have a U#%)# permanent tablespace.

    •  This tablespace is used to store objects created by individual usersof the database.

    •   At -39 we use the 9-7- tablespace as a storage location fortables, indexes, views, and other objects created by students.

    •   All students share the same 9-7- tablespace. 1any Oracle databases will have one or more DT tablespaces.

    •   A $ATA tablespace is also permanent and is used tostore application data tables such as O7$7 ?T7Y or

    3?L?TO7Y 1A?A:1?T applications.•  6or large applications, it is often a practice to create a special $ATA

    tablespace to store data for the application. 3n this case thetablespace may be named whatever name is appropriate to describethe objects stored in the tablespace accurately.

    Oracle databases having a $ATA &or more than one $ATA( tablespace willalso have an accompanying 3?$- tablespace.

    •  The purpose of separating tables from their associated indexes is to

    improve 38O efficiency.•  The $ATA and 3?$- tablespaces will typically be placed on

    different dis drives thereby providing an 38O path for each so that astables are updated, the indexes can also be updated simultaneously.

     

    *igfile Tablespaces 

     A Bigfile tablespace is best used with a server that uses a 7A3$ storagedevice with dis stripping + a single datafile is allocated and it can be up

    to 7%*&exabytes, a million terabytes( in si#e with up to ;0 blocs. ?ormal tablespaces are referred to as Smallfile tablespaces. 5hy are !igfile tablespaces importantM

  • 8/19/2019 Tablespaces and Datafiles

    16/28

    •  The maximum number of datafiles in an Oracle database is limited&usually to :; files( + thin big here4thin about a database for theinternal revenue service.

    o  A !igfile tablespace with 7 blocs can contain

    a A6 terabyte datafile.o  A !igfile tablespace with A6 blocs can contain

    a 567 terabyte datafile.o  These si#es enhance the storage capacity of an Oracle

    database.o  These si#es can also reduce the number of datafiles to be

    managed. 

    •  !igfile tablespaces can only be locally managed with automatic

    segment space management except for locally managed undotablespaces, temporary tablespaces, and the -Y-T1 tablespace.•  3f a !igfile tablespace is used for automatic undo or temporary

    segments, the segment space management must be setto M!U+.

    •  !igfile tablespaces save space in the -:A and control file becausefewer datafiles need to be traced.

    •  +T%) T*+%#P(% commands on a !igfile tablespace do notreference a datafile because only one datafile is associated with each!igfile tablespace.

     xample + this example creates a !igfile tablespace named 0raph?5 &tostore data that is graphical in nature and that consumes a lot ofspace(. ?ote use of the*-0,-+% eyword. CREATE BI#FILE TABLESPACE gra;?+, DATAFILE)*u+0*stu-ent*-.$c/st-*$ra-ata*USER01+gra;?+,2-.3) SI"E,+g7

     •  xample continued% This resi#es the !igfile tablespace to increase

    the capacity from '2 gigabytes to E2 gigabytes. S

  • 8/19/2019 Tablespaces and Datafiles

    17/28

    •  xample continued% This sets the A9TOT?$ option on toenable the tablespace to extend in si#e '2 gigabytes at a time.

     S

  • 8/19/2019 Tablespaces and Datafiles

    18/28

     

    %ncrypted Tablespaces Only permanent tablespaces can be encrypted.

    •  urpose is to protect sensitive data from unauthori#ed accessthrough the operating system file system.

    •  Tablespace encryption is transparent to applictions.

    •   All tablespace blocs are encrypted including all segment types.

    •  $ata from an encrypted tablespace is automatically encrypted whenwritten to an undo tablespace, redo logs, and temporary tablespaces.

    •  artitioned tables8indexes can have both encrypted and nonFencrypted segments in different tablespaces.

    •  The database must have the 0O1AT3!/ parameter set to ''.'.2

    or higher.•  There is no dis space overhead for encrypting a tablespace.

     ncryption reuires creation of an Oracle wallet to store the masterencryption ey. Transparent data encryption supports industryFstandard encryptionalgorithms. The default is %#567 algorithm that uses 567'bit 9eys. 

    This example creates an encrypted tablespacenamed #%(U)%1DT that uses 68:Fbit eys. CREATE TABLESPACE secure%-ata  DATAFILE)*u+6*$ra-ata*DB!RCL*DB!RCLsecure%-ata2-.3) SI"E 1+M   ENCR&&PTI!N USIN# )AES61) EXTENT MANA#EMENT L!CAL  DEFAULT ST!RA#E9ENCR&PT:7 Ta.les;ace create-2

     You cannot encrypt an existing tablespace with the +T%)T*+%#P(% statement. You would need to export the data from anunencrypted tablespace and then import it into an encrypted tablespace. 

  • 8/19/2019 Tablespaces and Datafiles

    19/28

    )ead Only Tablespaces 

     A tablespace may be made read only. One purpose for this action is toenable system maintenance that involves dropping tables and associated

    indexes stored in the tablespace. This can be accomplished while atablespace is in read only mode because the D)OP command affects onlyinformation in the $ata $ictionary which is in the -Y-T1 tablespace, andthe -Y-T1 tablespace is not read only.

    The command to mae a tablespace read only is% 

     ALTER TABLESPACE ta.les;ace%na(e READ !NL&7 This also causes an automatic checpoint of the tablespace.

     3f the tablespace being modified is locally managed, the segments that areassociated with the dropped tables and index are changed to temporarysegments so that the bitmap is not updated.

    To change a tablespace from read only to read8write, all datafiles for thetablespace must be online.

     ALTER TABLESPACE ta.les;ace%na(e READ RITE7

      Another reason for maing a tablespace read only is to support themovement of the data to read only media such as 0$F7O1. This type ofchange would probably be permanent. This approach is sometimes usedfor the storage of large uantities of static data that doesnNt change. Thisalso eliminates the need to perform system bacups of the read onlytablespaces. To move the datafiles to a read only media, first alter thetablespaces as read only, then rename the datafiles to the new location byusing the +T%) T*+%#P(% )%!M% DT,-+% option..

    Offline Tablespaces 1ost tablespaces are online all of the timeG however, a $!A can tae atablespace offline. This enables part of the database to be available + the

  • 8/19/2019 Tablespaces and Datafiles

    20/28

    tablespaces that are online + while enabling maintenance on the offlinetablespace. Typical activities include%

    •  Offline tablespace bacup + a tablespace can be baced up whileonline, but offline bacup is faster.

    • 

    7ecover an individual tablespace or datafile.•  1ove a datafile without closing the database.

     You cannot use -/ to reference offline tablespaces + this simplygenerates a system error. Additionally, the action of taing a tablespaceoffline8online is always recorded in the data dictionary and controlfile&s(. Tablespaces that are offline when you shutdown a database areoffline when the database is again opened. The commands to tae a tablespace offline and online are simple A/T7TA!/-A0 commands. These also tae the associated datafiles offline. 

     ALTER TABLESPACE a;;licati$n%-ata !FFLINE7 ALTER TABLESPACE a;;licati$n%-ata !NLINE7 The full syntax is% 

     ALTER TABLESPACE ta.les;ace!NLINE !FFLINE [N!RMALTEMP!RAR&IMMEDIATEF!R

    REC!ER] 

    !O)M+% All data blocs for all datafiles that form the tablespace arewritten from the -:A to the datafiles. A tablespace that isoffline ?O71A/ does not reuire any type of recovery when it is broughtbac online. T%MPO))$% A checpoint is performed for all datafiles in thetablespace. Any offline files may reuire media recovery.

    -MM%D-T%% A checpoint is !OT performed. 1edia recovery on thetablespace is reuired before it is brought bac online to synchroni#e thedatabase objects. ,O) )%(OC%)% 9sed to place a tablespace in offline status to enablepointFinFtime recovery.

  • 8/19/2019 Tablespaces and Datafiles

    21/28

    %rrors and )estrictions%•  3f D*>n fails to write to a datafile after several attempts, Oracle will

    automatically tae the associated tablespace offline + the $!A willthen recover the datafile.

    • 

    The -Y-T1 tablespace cannot be taen offline.•  Tablespaces with active undo segments or temporary segments.

    Tablespace #torage #ettings !ote4 $o2 will not be able to practice the commands in this sectionbeca2se Dictionary'Managed tablespaces cannot be created in Oracle55g.

      Any of the storage settings for Dictionary'Managed tablespaces can bemodified with the +T%) T*+%#P(% command. This only alters thedefault settings for future segment allocations. 

    Tablespace #izing ?ormally over time tablespaces need to have additional spaceallocated. This can be accomplished by setting the UTO%&T%!D optionto enable a tablespace to increase automatically in si#e.

    •  This can be dangerous if a PrunawayQ process or applicationgenerates data and consumes all available storage space.

  • 8/19/2019 Tablespaces and Datafiles

    22/28

    •   An advantage is that applications will not A!?$ because atablespace runs out of storage capacity.

    •  This can be accomplished when the tablespace is initially created orby using the +T%) T*+%#P(% command at a later time.

     CREATE TABLESPACE a;;licati$n%-ata  DATAFILE)*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3) SI"E6++M   AUT!EXTEND !N NEXT @8K MAXSI"E 1++M7 This uery uses the D*1DT1,-+%# view to determineif UTO%&T%!D is enabled for selected tablespaces in the -39 $!O70/database.

     SELECT ta.les;ace%na(e aut$e'tensi.leFR!M -.a%-ata%3iles7 TABLESPACE%NAME AUTGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG GGGS&STEM N!S&SAUX N!UND!TBS, &ES

    USERS N! •  1anually use the +T%) DT*#% command to resi#e a datafile.

      ALTER DATABASE  DATAFILE )*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3)  AUT!EXTEND !N MAXSI"E ++M7 This command loos similar to the above command, but this one resizes a

    datafile while the above command sets the ma3size of the datafile.

     ALTER DATABASE  DATAFILE)*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3)  RESI"E ++M7 

  • 8/19/2019 Tablespaces and Datafiles

    23/28

    •   Add a new datafile to a tablespace with the +T%)T*+%#P(% command.

     ALTER TABLESPACE a;;licati$n%-ata

      ADD DATAFILE)*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3)  SI"E 6++M7 

    Moving)elocating TablespacesDatafiles The +T%) T*+%#P(% command can be used to move datafiles byrenaming them. This cannot be used if the tablespace is the #$#T%M orcontains active undo or temporary segments.

    The +T%) DT*#% command can also be used withthe )%!M% option. This is the method that must be used to move the-Y-T1 tablespace because it cannot be taen offline. The steps are%

    '. -hut down the database.  ). 9se an operating system command to move the files.  *. 1ount the database.  E. xecute the +T%) DT*#% )%!M% ,-+% command.

  • 8/19/2019 Tablespaces and Datafiles

    24/28

      ALTER DATABASE RENAME  FILE)*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3)  T!)*u+6*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3)  SI"E 6++M7 

    J. Open the database. 

    Dropping Tablespaces Occasionally tablespaces are dropped due to database reorgani#ation. A

    tablespace that contains data cannot be dropped unless the -!(+UD-!0(O!T%!T#clause is added to the D)OP command. -ince tablespaceswill almost always contain data, this clause is almost always used.

     A $!A cannot drop the -Y-T1 tablespace or any tablespace with activesegments. ?ormally you should tae a tablespace offline to ensure noactive transactions are being processed.

     An example command set that drops the compressed

    tablespace (OMP1DT created earlier is%  ALTER TABLESPACE c$(;%-ata !FFLINE7 DR!P TABLESPACE c$(;%-ata  INCLUDIN# C!NTENTS AND DATAFILES  CASCADE C!NSTRAINTS7 The !D DT,-+%# clause causes the datafiles to also bedeleted. Otherwise, the tablespace is removed from the database as a

    logical unit, and the datafiles must be deleted with operating systemcommands.

    The (#(D% (O!#T)-!T# clause drops all referential integrityconstraints where objects in one tablespace are constrained8related toobjects in another tablespace.

  • 8/19/2019 Tablespaces and Datafiles

    25/28

     

    !on'#tandard *loc9 #izes3t may be advantageous to create a tablespace with a nonstandard blocsi#e in order to import data efficiently from another database. This also

    enables transporting tablespaces with unlie bloc si#es betweendatabases.•   A bloc si#e is nonstandard if it differs from the si#e specified by

    the D*1*+O(1#-/% initiali#ation parameter.•  The *+O(#-/% clause of the ()%T% T*+%#P(% statement is

    used to specify nonstandard bloc si#es.•  3n order for this to wor, you must have already

    set D*1((H%1#-/% and at leastone D*1n1((H%1#-/% initiali#ation parameter values to

    correspond to the nonstandard bloc si#e to be used.•  The D*1n1((H%1#-/% initiali#ation parameters that can be used

    are%o  D*161((H%1#-/%

    D*1;1((H%1#-/%

    o  D*171((H%1#-/%

    D*15:1((H%1#-/%

    D*1A61((H%1#-/%

     •

      ?ote that the D*1n1((H%1#-/% parameter corresponding to thestandard bloc si#e cannot be used + it will be invalid + instead usetheD*1((H%1#-/% parameter for the standard bloc si#e.

     xample + these parameters specify a standard bloc si#e of 7 with acache for standard bloc si#e buffers of 56M. The 6 and 5: caches willbe configured with cache buffers of 7M each. 

    DB%BL!CK%SI"EH8,6DB%CACJE%SI"EH,6M DB%6K%CACJE%SI"EH8M DB%,K%CACJE%SI"EH8M 

     xample + this creates a tablespace with a blocsi#e of 6 &assume thestandard bloc si#e for the database was H;(. 

  • 8/19/2019 Tablespaces and Datafiles

    26/28

    CREATE TABLESPACE in4ent$r5  DATAFILE )*u+,*stu-ent*-.$c/st-*$ra-ata*USER01+-ata+,2-.3)  SI"E 1+M   EXTENT MANA#EMENT L!CAL UNIF!RM SI"E ,68K  BL!CKSI"E 6K7 

    Managing Tablespaces with Oracle Managed ,iles 

     As you learned earlier, when you use an O16 approach,the D*1()%T%1,-+%1D%#T parameter in the parameter file specifiesthat datafiles are to be created and defines their

    location. The DT,-+% clause to name files is not used becausefilenames are automatically generated by the Oracle -erver, forexample,ora1tbs5163fhEE?3.dbf . You can also use the +T%) #$#T%M command to dynamically set thisparameter in the -63/ parameter file. 

     ALTER S&STEM SET  DB%CREATE%FILE%DEST H

    )*u+6*stu-ent*-.$c/st-*$ra-ata)7  Additional tablespaces are specified with the ()%T%T*+%#P(% command shown here that specifies not the datafile name,but the datafile si#e. You can also add datafiles with the +T%)T*+%#P(% command. CREATE TABLESPACE a;;licati$n%-ata DATAFILE SI"E ,++M7 

     ALTER TABLESPACE a;;licati$n%-ata ADD DATAFILE7

     -etting the D*1()%T%1O!+-!%1+O01D%#T1n parameter prevents logfiles and control files from being located with datafiles + this will reduce 38Ocontention.

    5hen O16 tablespaces are dropped, their associated datafiles are alsodeleted at the operating system level.

  • 8/19/2019 Tablespaces and Datafiles

    27/28

     

    Tablespace -nformation in the Data Dictionary The following data dictionary views can be ueried to display informationabout tablespaces.

    •  Tablespaces% $!A

  • 8/19/2019 Tablespaces and Datafiles

    28/28

    This shows output for the D*O)(+ database located onthe #O*O)6 server. 

    Ta.les;ace Sie 9MB: Free 9MB: OFree O Use- GGGGGGGGGGGGGGGGGGGGGG GGGGGGGGGG GGGGGGGGGG GGGGGGGGGGGGGGGGGGGGUND!TBS, ,Q ,2Q1 0

    QTEMP 1+ @@ 88

    ,6USERS 61 6,28Q1 8Q

    ,0S&SAUX 061 ,@,261 @0

    1QS&STEM 061 1261 6+8+

     

    ?$ O6 ?OT-