Você está na página 1de 13

Oracle 10g Tablespaces

This document includes the following topics about tablespaces: 1. Introduction to tablespaces 2. SYSTEM and SYSA ! tablespaces ". T#pes of tablespaces a. $ermanent tablespaces b. Temporar# tablespaces c. ndo tablespaces %. Space management &. State of tablespaces '. sing Multiple tablespaces (. )igfile tablespaces *. +ead ,nl# tablespaces -. .reating tablespaces 1/. 0ropping tablespaces 11. 1iewing tablespace information

1. Introduction to tablespaces
The ,racle database architecture includes logical and ph#sical structures that ma2e up the database. 3 The ph#sical structure includes the control files4 redo log files4 and data files that ma2e up the database. 3 The logical structure includes tablespaces4 segments4 e5tents4 and data bloc2s. An Oracle tablespace is a logical group of datafiles in a database. A datafile can be a part of one and onl# one tablespace. 6ithin each tablespace4 the logical database structures4 such as tables and inde5es4 are segments that are further subdi7ided into e5tents and bloc2s.

2. SYSTEM and SYSAUX tablespace


8or an installation of ,racle 1/g4 a minimum of two tablespaces are created: the SYSTEM tablespace and the SYSA ! tablespace. SYSTEM Tablespace The primar# tablespace in an# database is the SYSTEM tablespace4 which contains information basic to the functioning of the database ser7er4 such as the data dictionar# and the s#stem rollbac2 segment. The SYSTEM tablespace is the first tablespace created at database creation. It is

managed as an# other tablespace4 but re9uires a higher le7el of pri7ilege and is restricted in some wa#s. 8or e5ample4 #ou cannot rename or drop the SYSTEM tablespace or ta2e it offline. SYSAUX Tablespace The SYSA ! tablespace4 which acts as an au5iliar# tablespace to the SYSTEM tablespace4 is also alwa#s created when #ou create a database. It contains information about and the schemas used b# 7arious ,racle products and features4 so that those products do not re9uire their own tablespaces. As for the SYSTEM tablespace4 management of the SYSA ! tablespace re9uires a higher le7el of securit# and #ou cannot rename or drop it.

. T!pes of tablespaces
a. "er#anent tablespaces $ermanent tablespaces are used to store user data and user created ob:ects li2e tables4 inde5es and materiali;ed 7iews. ,b:ects in permanent tablespaces are stored in datafiles. To create a new tablespace4 use the S<= statement .+EATE TA)=ES$A.E. b. Te#porar! tablespaces A temporar# tablespace contains transient data that persists onl# for the duration of the session. If a tablespace is temporar#4 the tablespace itself is permanent> onl# the segments sa7ed in the tablespace are temporar#. A temporar# tablespace can be used for sorting operations and as a wor2ing area for building inde5es. 0edicating a tablespace for these 2inds of operations helps to reduce the I?, contention between temporar# segments and permanent segments stored in another tablespace4 such as tables. 8or e5ample4 if #ou :oin two large tables4 and ,racle cannot do the sort in memor# @see S,+TAA+EAASIBE initiali;ation parameterC4 space will be allocated in a temporar# tablespace for doing the sort operation. ,ther S<= operations that might re9uire dis2 sorting are: .+EATE ID0E!4 ADA=YBE4 Select 0ISTID.T4 ,+0E+ )Y4 E+, $ )Y4 DI,D4 IDTE+SE.T4 MID S4 SortF Merge :oins4 etc. To create a new temporar# tablespace4 use the S<= statement .+EATE TEM$,+A+Y TA)=ES$A.E. You cannot e5plicitl# create ob:ects in a temporar# tablespace. 6hen the SYSTEM tablespace is locall# managed4 #ou must define at least one default temporar# tablespace when creating a database. A locall# managed SYSTEM tablespace cannot be used for default temporar# storage. If SYSTEM is dictionar# managed and if #ou do not define a default temporar# tablespace when creating the database4 then SYSTEM is still used for default temporar# storage. Gowe7er4 #ou will recei7e a warning in A=E+T.=,E sa#ing that a default temporar# tablespace is recommended and will be necessar# in future releases. @+efer Space management for locall# managed and dictionar# managedC

$o% to Specif! a &efault Te#porar! Tablespace Specif# default temporar# tablespaces when #ou create a database4 using the 0E8A =T TEM$,+A+Y TA)=ES$A.E e5tension to the .+EATE 0ATA)ASE statement. If #ou drop all default temporar# tablespaces4 then the SYSTEM tablespace is used as the default temporar# tablespace. Multiple Te#porar! Tablespaces' Using Tablespace (roups Dow in ,racle 1/g4 ,racle lets us group temporar# tablespaces together to gain a bit more fle5ibilit# that allows us to create multiple temporar# tablespaces and to create tablespace groups and assign these tablespace groups to users. Temporar# tablespace group has the following characteristics: It contains at least one tablespace. There is no e5plicit limit on the ma5imum number of tablespaces that are contained in a group. It contains onl# temporar# tablespaces. It is not e5plicitl# created. It is created implicitl# when the first temporar# tablespace is assigned to it4 and is deleted when the last temporar# tablespace is remo7ed from the group. Temporar# tablespace group has the following benefits: It allows multiple default temporar# tablespaces to be specified at the database le7el. It allows the user to use multiple temporar# tablespaces in different sessions at the same time. It allows a single S<= operation to use multiple temporar# tablespaces for sorting. You create a tablespace group implicitl# when #ou include the TA)=ES$A.E E+, $ clause in the .+EATE TEM$,+A+Y TA)=ES$A.E or A=TE+ TA)=ES$A.E statement and the specified tablespace group does not currentl# e5ist. c. Undo tablespaces ndo tablespaces are special tablespaces used solel# for storing undo information. The# pro7ide a method of maintaining information that is used to roll bac24 or undo4 changes to the database. Such information consists of records of the actions of transactions4 primaril# before the# are committed. These records are collecti7el# referred to as undo. ndo records are used to: +oll bac2 transactions when a +,==)A.H statement is issued +eco7er the database $ro7ide read consistenc# Anal#;e data as of an earlier point in time b# using 8lashbac2 <uer# +eco7er from logical corruptions using 8lashbac2 features You cannot create an# other segment t#pes @for e5ample4 tables or inde5esC in undo tablespaces. A database administrator creates undo tablespaces indi7iduall#4 using the .+EATE D0, TA)=ES$A.E statement.

Auto#atic Undo Manage#ent Earlier releases of ,racle 0atabase used rollbac2 segments to store undo. ,racle- i introduced automatic undo management4 which simplifies undo space management b# eliminating the comple5ities associated with rollbac2 segment management. ,racle strongl# recommends that #ou use undo tablespace to manage undo rather than rollbac2 segments. ,racle 0atabase 1/g pro7ides two wa#s of allocating and managing undo @rollbac2C space among the 7arious transactions occurring in the database. If #ou want to control the undo space manuall#4 #ou can do so b# creating traditional rollbac2 segments. Gowe7er4 it is much more efficient and easier to let ,racle worr# about managing the undo space b# choosing Automatic ndo Management @A MC. A M ta2es the entire issue of si;ing and allocation of undo segment from the 0)AIs hands and ma2es it ,racleIs responsibilit#. 0)A has to create an ade9uate si;ed undo tablespace for storing undo information. ,racle will d#namicall# create undo @rollbac2C segments and ad:ust their number to match the instanceIs wor2load re9uirements. The database will automaticall# allocate and deallocate undo segments to match the transaction throughput in the instance.

). Space #anage#ent
Tablespaces allocate space in e5tents. Tablespaces can use two different methods to 2eep trac2 of their free and used space: =ocall# managed tablespaces: E5tent management b# the tablespace (Default) 0ictionar# managed tablespaces: E5tent management b# the data dictionar# 6hen #ou create a tablespace4 #ou choose one of these methods of space management. =ater4 #ou can change the management method with the 0)MSAS$A.EAA0MID $=?S<= pac2age. a. *ocall! #anaged tablespaces A tablespace that manages its own e5tents maintains a bitmap in each datafile to 2eep trac2 of the free or used status of bloc2s in that datafile. Each bit in the bitmap corresponds to a bloc2 or a group of bloc2s. 6hen an e5tent is allocated or freed for reuse4 ,racle changes the bitmap 7alues to show the new status of the bloc2s. Ad7antages o7er dictionar# managed tablespaces: =ocal management of e5tents automaticall# trac2s ad:acent free space4 eliminating the need to coalesce free e5tents. =ocal management of e5tents a7oids recursi7e space management operations. Such recursi7e operations can occur in dictionar# managed tablespaces if consuming or releasing space in an e5tent results in another operation that consumes or releases space in a data dictionar# table or rollbac2 segment. The si;es of e5tents that are managed locall# can be determined automaticall# b# the s#stem. Alternati7el#4 all e5tents can ha7e the same si;e in a locall# managed tablespace and o7erride ob:ect storage options.

The =,.A= clause of the .+EATE TA)=ES$A.E or .+EATE TEM$,+A+Y TA)=ES$A.E statement is specified to create locall# managed permanent or temporar# tablespaces4 respecti7el#.

b.

&ictionar! #anaged tablespaces

8or a tablespace that uses the data dictionar# to manage its e5tents4 ,racle updates the appropriate tables in the data dictionar# whene7er an e5tent is allocated or freed for reuse. ,racle also stores rollbac2 information about each update of the dictionar# tables. )ecause dictionar# tables and rollbac2 segments are part of the database4 the space that the# occup# is sub:ect to the same space management operations as all other data.

+. States of tablespaces
The tablespace can be in either ,D=IDE state or ,88=IDE state. A database administrator can bring an# tablespace other than the SYSTEM tablespace online @accessibleC or offline @not accessibleC whene7er the database is open. The SYSTEM tablespace is alwa#s online when the database is open because the data dictionar# must alwa#s be a7ailable to ,racle. A tablespace is usuall# online so that the data contained within it is a7ailable to database users. Gowe7er4 the database administrator can ta2e a tablespace offline for maintenance or bac2up and reco7er# purposes. ,ringing Tablespaces Offline The state of tablespace can be made offline for an# of the following reasons: To ma2e a portion of the database una7ailable while allowing normal access to the remainder of the database To perform an offline tablespace bac2up @e7en though a tablespace can be bac2ed up while online and in useC To ma2e an application and its group of tables temporaril# una7ailable while updating or maintaining the application To rename or relocate tablespace datafiles

6hen a tablespace is ta2en offline4 the database ta2es all the associated files offline. You cannot ta2e the following tablespaces offline: SYSTEM The undo tablespace Temporar# tablespaces

)efore ta2ing a tablespace offline4 consider altering the tablespace allocation of an# users who ha7e been assigned the tablespace as a default tablespace. 0oing so is ad7isable because those users will not be able to access ob:ects in the tablespace while it is offline. You can specif# an# of the following parameters as part of the A=TE+ TA)=ES$A.E ... ,88=IDE statement: -lause D,+MA= &escription A tablespace can be ta2en offline normall# if no error conditions e5ist for an# of the datafiles of the tablespace. Do datafile in the tablespace can be currentl# offline as the result of a write error. 6hen #ou specif# ,88=IDE D,+MA=4 the database ta2es a chec2point for all datafiles of the tablespace as it ta2es them offline. D,+MA= is the default. A tablespace can be ta2en offline temporaril#4 e7en if there are error conditions for one or more files of the tablespace. 6hen #ou specif# ,88=IDE TEM$,+A+Y4 the database ta2es offline the datafiles that are not alread# offline4 chec2pointing them as it does so. If no files are offline4 but #ou use the temporar# clause4 media reco7er# is not re9uired to bring the tablespace bac2 online. Gowe7er4 if one or more files of the tablespace are offline because of write errors4 and #ou ta2e the tablespace offline temporaril#4 the tablespace re9uires reco7er# before #ou can bring it bac2 online. A tablespace can be ta2en offline immediatel#4 without the database ta2ing a chec2point on an# of the datafiles. 6hen #ou specif# ,88=IDE IMME0IATE4 media reco7er# for the tablespace is re9uired before the tablespace can be brought online. You cannot ta2e a tablespace offline immediatel# if the database is running in D,A+.GI1E=,E mode.

TEM$,+A+Y

IMME0IATE

The following e5ample ta2es the users tablespace offline normall#: ALTER TABLESPACE users OFFLINE NORMAL; ,ringing Tablespaces Online An# tablespace in an ,racle 0atabase can be ta2en online whene7er the database is open. A tablespace is normall# online so that the data contained within it is a7ailable to database users. If a tablespace to be brought online was not ta2en offline Jcleanl#J @that is4 using the D,+MA= clause of the A=TE+ TA)=ES$A.E ,88=IDE statementC4 #ou must first perform media reco7er# on the tablespace before bringing it online. ,therwise4 the database returns an error and the tablespace remains offline.

.. Using #ultiple tablespaces


SYSTEM tablespace might be enough for a small database. ,racle recommends that #ou create at least one additional tablespace to store user data separate from data dictionar# information. 6hen a database has multiple tablespaces4 #ou can: Separate user data from data dictionar# data to reduce I?, contention.

Separate data of one application from the data of another to pre7ent multiple applications from being affected if a tablespace must be ta2en offline. Store different the datafiles of different tablespaces on different dis2 dri7es to reduce I?, contention. Ta2e indi7idual tablespaces offline while others remain online4 pro7iding better o7erall a7ailabilit#. ,ptimi;ing tablespace use b# reser7ing a tablespace for a particular t#pe of database use4 such as high update acti7it#4 readFonl# acti7it#4 or temporar# segment storage. )ac2 up indi7idual tablespaces.

Some operating s#stems set a limit on the number of files that can be open simultaneousl#. Such limits can affect the number of tablespaces that can be simultaneousl# online. To a7oid e5ceeding #our operating s#stem limit4 plan #our tablespaces efficientl#. .reate onl# enough tablespaces to fulfill #our needs4 and create these tablespaces with as few files as possible. If #ou need to increase the si;e of a tablespace4 add one or two large datafiles4 or create datafiles with auto e5tension enabled4 rather than creating man# small datafiles. .onsidering these factors4 decide how man# tablespaces #ou need for #our database design.

/. ,ig file tablespaces


,racle lets #ou create bigfile tablespaces 0,1T2. This allows ,racle 0atabase to contain tablespaces made up of single large files rather than numerous smaller ones. The s#stem default is to create a smallfile tablespace4 which is the traditional t#pe of ,racle tablespace. The SYSTEM and SYSA ! tablespace t#pes are alwa#s created using the s#stem default t#pe. )igfile tablespaces are supported onl# for locall# managed tablespaces with automatic segmentF space management. There are two e5ceptions: locall# managed undo and temporar# tablespaces can be bigfile tablespaces4 e7en though their segments are manuall# managed. An ,racle database can contain both bigfile and smallfile tablespaces. * e5ab#tes @* Million terab#tesC is the ma5imum si;e of the ,racle database when bigfile tablespaces are used with the ma5imum bloc2 si;e @"2 2C.0epending on bloc2 si;e 4 a bigfile tablespace can be as large as 12* terab#tes. To create a bigfile tablespace4 specif# the )IE8I=E 2e#word of the .+EATE TA)=ES$A.E statement @CREATE BIGFILE TABLESPACE ...). )enefits offered b# using )8Ts: You onl# need to create as man# data files as there are tablespaces. You donIt ha7e to constantl# add data files to #our tablespaces. 0ata file management in large database is simplified K #ou deal with a few tablespaces directl#4 not man# data files. Storage capacit# is significantl# increased because #ou donIt reach the ma5imum files limitation 9uic2l# when #ou use )8Ts.

8. Read Only tablespaces


The primar# purpose of readFonl# tablespaces is to eliminate the need to perform bac2up and reco7er# of large4 static portions of a database. ,racle ne7er updates the files of a readFonl# tablespace4 and therefore the files can reside on readFonl# media4 such as .0 +,Ms or 6,+M @6rite ,nceF +ead Man#C dri7es.

+eadFonl# tablespaces cannot be modified. To update a readFonl# tablespace4 first ma2e the tablespace read?write. After updating the tablespace4 #ou can then reset it to be read onl#. )ecause readFonl# tablespaces cannot be modified4 and as long as the# ha7e not been made read?write at an# point4 the# do not need repeated bac2up. Also4 if #ou need to reco7er #our database4 #ou do not need to reco7er an# readFonl# tablespaces4 because the# could not ha7e been modified. All tablespaces are initiall# created as read?write. se the +EA0 ,D=Y clause in the A=TE+ TA)=ES$A.E statement to change a tablespace to readFonl#. You must ha7e the A=TE+ TA)=ES$A.E or MADAEE TA)=ES$A.E s#stem pri7ilege. You can use the +EA0 6+ITE clause of the A=TE+ TA)=ES$A.E statement to ma2e a readFonl# tablespace readFwrite again.

3. -reating tablespaces
)efore #ou can create a tablespace #ou must create a database to contain it. The first tablespace in an# database is alwa#s the SYSTEM tablespace4 and the first datafiles of an# database are automaticall# allocated in the SYSTEM tablespace during database creation. To create a new tablespace4 use the S<= statement .+EATE TA)=ES$A.E or .+EATE TEM$,+A+Y TA)=ES$A.E. You must ha7e the .+EATE TA)=ES$A.E s#stem pri7ilege to create a tablespace. =ater4 #ou can use the A=TE+ TA)=ES$A.E or A=TE+ 0ATA)ASE statements to alter the tablespace. You must ha7e the A=TE+ TA)=ES$A.E or A=TE+ 0ATA)ASE s#stem pri7ilege. -reating ,asic Tablespaces' E4a#ple .reate a tablespace named tbsA/1 with one datafile: .+EATE TA)=ES$A.E tbsA/1 0ATA8I=E L?u/1?oradata?userdata/1.dbfI SIBE %/M ,D=IDE> Enabling Auto e4tend for a Tablespace' E4a#ple .reate a tablespace named tbsA/2 with one datafile. 6hen more space is re9uired4 &// 2ilob#te e5tents will be added up to a ma5imum si;e of 1// megab#tes: .+EATE TA)=ES$A.E tbsA/2 0ATA8I=E L?u/1?oradata?userdata/2.dbf L SIBE &//H +E SE A T,E!TED0 ,D DE!T &//H MA!SIBE 1//M> -reating te#porar! tablespaces and tablespaces groups E4a#ple' .reate a temporar# tablespace named temp/1 with one tempfile: .+EATE TEM$,+A+Y TA)=ES$A.E temp/1 TEM$8I=E L?u/1?oradata?tempdata/1.tmpI SIBE 1//M> E4a#ple' Set temp/1 to default temporar# tablespace A=TE+ 0ATA)ASE 0E8A =T TEM$,+A+Y TA)=ES$A.E temp/1> E4a#ple' .reate temporar# tablespace temp/2 and implicitl# add it to a temporar# tablespace group.

.+EATE TEM$,+A+Y TA)=ES$A.E temp/2 TEM$8I=E L?u/1?oradata?tempdata/2.tmpI SIBE 1//M> TA)=ES$A.E E+, $ tempgroupAa> E4a#ple' +emo7e a tablespace from tablespace group A=TE+ TA)=ES$A.E temp/2 TA)=ES$A.E E+, $ MM > -reating an Undo Tablespace E4a#ple The following e5ample creates a 1/ M) undo tablespace undots1: .+EATE D0, TA)=ES$A.E undots1 0ATA8I=E LundotbsA1a.fL SIBE 1/M A T,E!TED0 ,D> -reating a *ocall! Managed Tablespace E4a#ple The following statement assumes that the database bloc2 si;e is 2H. .+EATE TA)=ES$A.E tbsA/% 0ATA8I=E L?u/1?oradata?userdata/1.dbfL SIBE 1/M E!TEDT MADAEEMEDT =,.A= DI8,+M SIBE 12*H> This statement creates a locall# managed tablespace in which e7er# e5tent is 12*H and each bit in the bit map describes '% bloc2s. -reating a &ictionar! Managed Tablespace E4a#ple ' .+EATE TA)=ES$A.E userdata 0ATA8I=E L?u/1?oradata?userdata/1.dbfL SIBE &//M E!TEDT MADAEEMEDT 0I.TI,DA+Y 0E8A =T ST,+AEE @initial 1M DE!T 1MC> E4a#ple' To ta2e a tablespace offline: A=TE+ TA)=ES$A.E userdata ,88=IDE> E4a#ple' To bring a tablespace online: A=TE+ TA)=ES$A.E userdata ,D=IDE> -reating a ,igfile Tablespace' E4a#ple The following e5ample creates a bigfile tablespace bigtbsA/1 with a datafile bigtbsAf1.dat of 1/ M): .+EATE )IE8I=E TA)=ES$A.E bigtbsA/1 0ATA8I=E L?u/1?oradata?bigtbs/1.dbfI SIBE 2/M A T,E!TED0 ,D> 5ead onl! tablespace' E4a#ple' The following statement ma2es the tbsA/1 tablespace readFonl#: A=TE+ TA)=ES$A.E tbsA/1 +EA0 ,D=Y> E4a#ple' The following statement ma2es the tbsA/1 tablespace writable: A=TE+ TA)=ES$A.E tbsA/1 +EA0 6+ITE>

5ena#ing tablespaces' sing the +EDAME T, clause of the A=TE+ TA)=ES$A.E4 #ou can rename a permanent or temporar# tablespace. 8or e5ample4 the following statement renames the users tablespace: A=TE+ TA)=ES$A.E users +EDAME T, usersts>

10. &ropping tablespaces


You can drop a tablespace and its contents @the segments contained in the tablespaceC from the database if the tablespace and its contents are no longer re9uired. You must ha7e the 0+,$ TA)=ES$A.E s#stem pri7ilege to drop a tablespace. To drop a tablespace4 use the 0+,$ TA)=ES$A.E statement. The following statement drops the users tablespace4 including the segments in the tablespace: DROP TABLESPACE users INCLUDING CONTENTS; If the tablespace is empt# @does not contain an# tables4 7iews4 or other structuresC4 #ou do not need to specif# the ID.= 0IDE .,DTEDTS clause. se the .AS.A0E .,DST+AIDTS clause to drop all referential integrit# constraints from tables outside the tablespace that refer to primar# and uni9ue 2e#s of tables inside the tablespace.To delete the datafiles associated with a tablespace at the same time that the tablespace is dropped4 use the ID.= 0IDE .,DTEDTS AD0 0ATA8I=ES clause. The following statement drops the users tablespace and its associated datafiles: DROP TABLESPACE users INCLUDING CONTENTS AND DATAFILES;

11. 6ie%ing tablespace infor#ation


The following data dictionar# and d#namic performance 7iews pro7ide useful information about the tablespaces of a database. 6ie% 1NTA)=ES$A.E 0)AATA)=ES$A.ES4 SE+ TA)=ES$A.ES 0)AATA)=ES$A.EAE+, $S 0)AASEEMEDTS4 SE+ASEEMEDTS 0)AAE!TEDTS4 SE+AE!TEDTS 0)AA8+EEAS$A.E4 SE+A8+EEAS$A.E 1N0ATA8I=E &escription Dame and number of all tablespaces from the controlfile.

0escriptions of all @or user accessibleC tablespaces. 0ispla#s the tablespace groups and the tablespaces that belong to them. Information about segments within all @or user accessibleC tablespaces Information about data e5tents within all @or user accessibleC tablespaces Information about free e5tents within all @or user accessibleC tablespaces Information about all datafiles4 including tablespace number of owning tablespace.

1NTEM$8I=E

Information about all tempfiles4 including tablespace number of owning tablespace. Shows files @datafilesC belonging to tablespaces. Shows files @tempfilesC belonging to temporar# tablespaces. Information for all e5tents in all locall# managed temporar# tablespaces. 8or locall# managed temporar# tablespaces: the state temporar# space cached and used for b# each instance. Shows space used?free for each tempfile. 0efault and temporar# tablespaces for all users. =ists tablespace 9uotas for all users Information about e7er# sort segment in a gi7en instance. The 7iew is onl# updated when the tablespace is of the TEM$,+A+Y t#pe. 0escribes temporar# @sortC segment usage b# user for temporar# or permanent tablespaces.

0)AA0ATAA8I=ES 0)AATEM$A8I=ES 1NTEM$AE!TEDTAMA$

of

1NTEM$AE!TEDTA$,,= 1NTEM$AS$A.EAGEA0E+ 0)AA SE+S 0)AATSA< ,TAS 1NS,+TASEEMEDT 1NTEM$SEEA SAEE

5E1E5E7-ES
Oracle Documents Oracle Technology Network Website

Você também pode gostar