Anda di halaman 1dari 17

Contact Mail-Id:oracledbatraining2009@gmail.

com
The other courses offered: Oracle Developer (SQL, PL/SQL) Basic UNIX Shell Scripting The future courses offered Red Hat Enterprise Linux 5 Advance DBA Courses RAC Oracle Streams Advance Performance Tuning (PL/SQL Performance Tuning)

Contact Mail-Id:oracledbatraining2009@gmail.com
Topics: The creation and maintenance of permanent and temporary table spaces are discussed in the following sections: Locally Managed Table spaces Big file Table spaces Temporary Table spaces Multiple Temporary Table spaces: Using Tablespace Groups

Contact Mail-Id:oracledbatraining2009@gmail.com
Using Multiple Tablespaces Using multiple tablespaces allows you more flexibility in performing database operations. When a database has multiple tablespaces, you can: Separate user data from data dictionary data to reduce I/O contention Separate data of one application from the data of another to prevent multiple applications from being affected if a tablespace must be taken offline Store different the data files of different tablespaces on different disk drives to reduce I/O contention Take individual tablespaces offline while others remain online, providing better overall availability. Optimizing tablespace use by reserving a tablespace for a particular type of database use, such as high update activity, read-only activity, or temporary segment storage. Back up individual tablespaces Note: Some operating systems set a limit on the number of files that can be open simultaneously Such limits can affect the number of tablespaces that can be simultaneously online To avoid exceeding your operating system limit, plan your tablespaces efficiently Create only enough tablespaces to fulfill your needs, and create these tablespaces with as few files as possible If you need to increase the size of a tablespace, add one or two large data files, or create data files with auto extension enabled, rather than creating many small data files Creating Tablespaces Before you can create a tablespace, you must create a database to contain it

The SYSTEM Tablespace The primary tablespace in any database is the SYSTEM tablespace It contains information basic to the functioning of the database server, such as the data dictionary and the system rollback segment The SYSTEM tablespace is the first tablespace created at database creation It is managed as any other tablespace, but requires a higher level of privilege and is restricted in some ways For example, you cannot rename or drop the SYSTEM tablespace or take it offline

Contact Mail-Id:oracledbatraining2009@gmail.com
The SYSAUX Tablespace It acts as an auxiliary tablespace to the SYSTEM tablespace It is also always created when you create a database It contains information about and the schemas used by various Oracle products and features, so that those products do not require their own tablespaces The management of the SYSAUX tablespace requires a higher level of security and you cannot rename or drop it We can monitor the occupants of the SYSAUX tablespace using the V$SYSAUX_OCCUPANTS view This view lists the following information about the occupants of the SYSAUX tablespace Name of the occupant Occupant description Schema name Move procedure Current space usage Privileges CREATE TABLESPACE CREATE TEMPORARY TABLESPACE ALTER TABLESPACE ALTER DATABASE CREATE UNDO TABLESPACE Tablespace Management: 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 extent allocation in the dictionary, are called dictionary managed tablespaces, Tablespaces that record extent allocation in the tablespace header, are called locally managed tablespaces Dictionary Managed Tablespaces (DMT): Oracle use the data dictionary (tables in the SYS schema) to track allocated and free extents for tablespaces that is in "dictionary managed" mode Free space is recorded in the SYS.FET$ table, and used space in the SYS.UET$ table Whenever space is required in one of these tablespaces, the ST (space transaction) enqueue latch must be obtained to do insert and deletes against these tables As only one process can acquire the ST enque at a given time, this often lead to contention

Contact Mail-Id:oracledbatraining2009@gmail.com
Locally Managed Tablespaces (LMT): Locally managed tablespaces track all extent information in the tablespace itself by using bitmaps Each bit corresponds to a database block or group of blocks Locally Managed SYSTEM Tablespace: From Oracle9i release 9.2 one can change the SYSTEM tablespace to locally managed If you create a database with DBCA (Database Configuration Assistant), it will have a locally managed SYSTEM tablespace by default The following restrictions apply: No dictionary-managed tablespace in the database can be READ WRITE You cannot create new dictionary managed tablespaces You cannot convert any dictionary managed tablespaces to local Note: Thus, it is best only to convert the SYSTEM tablespace to LMT after all other tablespaces are migrated to LMT It results in the following benefits: Fast, concurrent space operations. Space allocations and de allocations modify locally managed resources (bitmaps stored in header files). Enhanced performance Space allocation is simplified, because when the AUTOALLOCATE clause is specified, the database automatically selects the appropriate extent size. Eliminates the need for recursive SQL operations against the data dictionary (UET$ and FET$ tables) Reduce contention on data dictionary tables (single ST enqueue) Locally managed tablespaces eliminate the need to periodically coalesce free space (automatically tracks adjacent free space) Changes to the extent bitmaps do not generate rollback information Note the difference between AUTOALLOCATE and UNIFORM SIZE: AUTOALLOCATE Specifies that extent sizes are system managed Oracle will choose "optimal" next extent sizes starting with 64KB As the segment grows larger extent sizes will increase to 1MB, 8MB, and eventually to 64MB This is the recommended option for a low or unmanaged environment

Contact Mail-Id:oracledbatraining2009@gmail.com
UNIFORM Specifies that the tablespace is managed with uniform extents of SIZE bytes (use K or M to specify the extent size in kilobytes or megabytes) The default size is 1M The uniform extent size of a locally managed tablespace cannot be overridden when a schema object, such as a table or an index, is created Specifying Segment Space Management in Locally Managed Tablespaces From Oracle 9i, one can not only have bitmap managed tablespaces, but also bitmap managed segments when setting Segment Space Management to AUTO for a tablespace In a locally managed tablespace, there are two methods that Oracle Database can use to manage segment space Automatic & Manual Manual Segment Space Management: It uses linked lists called "free lists" to manage free space in the segment Automatic Segment Space Management It uses bitmaps to manage free space in the segment It is the default for all new permanent, locally managed tablespaces Advantages: Better space utilization It eliminates the need to specify and tune the PCTUSED, FREELISTS, and FREELISTS GROUPS storage parameters for schema objects It is also self-tuning, in that it scales with increasing number of users or instances Big file Tablespaces A big file tablespace is a tablespace with a single, but very large (up to 4G blocks) data file Traditional small file tablespaces, in contrast, can contain multiple data files, but the files cannot be as large Advantages It enhances the storage capacity of an Oracle Database A big file tablespace with 8K blocks can contain a 32 terabyte data file A big file tablespace with 32K blocks can contain a 128 terabyte data file The maximum number of data files in an Oracle Database is limited (usually to 64K files) Big file tablespaces can reduce the number of data files needed for a database

Contact Mail-Id:oracledbatraining2009@gmail.com
Note: Big file tablespaces are supported only for locally managed tablespaces with automatic segment space management with three exceptions: Locally managed undo tablespaces Temporary tablespaces, and The SYSTEM tablespace Big file tablespaces are intended to be used with Automatic Storage Management (ASM) or other logical volume managers that supports striping or RAID, and dynamically extensible logical volumes Avoid creating big file tablespaces on a system that does not support striping because of negative implications for parallel query execution and RMAN backup parallelization Temporary Tablespaces A temporary tablespace contains transient data that persists only for the duration of the session Within a temporary tablespace, all sort operations for a given instance and tablespace share a single sort segment Sort segments exist for every instance that performs sort operations within a given tablespace The sort segment is created by the first statement that uses a temporary tablespace for sorting, after startup, and is released only at shutdown An extent cannot be shared by multiple transactions You can view the allocation and de allocation of space in a temporary tablespace sort segment using the V$SORT_SEGMENT view The V$TEMPSEG_USAGE view identifies the current sort users in those segments Note The AUTOALLOCATE clause is not allowed for temporary tablespaces You cannot take a temporary tablespace offline Instead, you take its temp file offline. The view V$TEMPFILE displays online status for a temp file Multiple Temporary Tablespaces: Using Tablespace Groups A tablespace group enables a user to consume temporary space from multiple tablespaces. A tablespace group has the following characteristics It contains at least one tablespace. There is no explicit limit on the maximum number of tablespaces that are contained in a group It shares the namespace of tablespaces, so its name cannot be the same as any tablespace

Contact Mail-Id:oracledbatraining2009@gmail.com
You can specify a tablespace group name wherever a tablespace name would appear when you assign a default temporary tablespace for the database or a temporary tablespace for a user You do not explicitly create a tablespace group Rather, it is created implicitly when you assign the first temporary tablespace to the group The group is deleted when the last temporary tablespace it contains is removed from it The view DBA_TABLESPACE_GROUPS lists tablespace groups and their member tablespaces Taking Tablespaces Offline We make a tablespace offline for any of the following reasons: To make a portion of the database unavailable while allowing normal access to the remainder of the database To perform an offline tablespace backup (even though a tablespace can be backed up while online and in use) To make an application and its group of tables temporarily unavailable while updating or maintaining the application To rename or relocate tablespace data files Note: When a tablespace is taken offline, the database takes all the associated files offline. You cannot take the following tablespaces offline: SYSTEM The undo tablespace Temporary tablespaces OFFLINE options NORMAL TEMPORARY IMMEDIATE NORMAL It is the default A tablespace can be taken offline normally if no error conditions exist for any of the data files of the tablespace When you specify OFFLINE NORMAL, the database takes a checkpoint for all data files of the tablespace as it takes them offline

Contact Mail-Id:oracledbatraining2009@gmail.com
TEMPORARY A tablespace can be taken offline temporarily, even if there are error conditions for one or more files of the tablespace When you specify OFFLINE TEMPORARY, the database takes offline the data files that are not already offline, check pointing them as it does so IMMEDIATE A tablespace can be taken offline immediately, without the database taking a checkpoint on any of the data files We cannot take a tablespace offline immediately if the database is running in NOARCHIVELOG mode Renaming Tablespaces Using the RENAME TO clause of the ALTER TABLESPACE You can rename a permanent or temporary tablespace When you rename a tablespace the database updates all references to the tablespace name in the data dictionary, control file, and (online) data file headers The database does not change the tablespace ID The following affect the operation of this statement: The COMPATIBLE parameter must be set to 10.0 or higher If the tablespace being renamed is the SYSTEM tablespace or the SYSAUX tablespace, then it will not be renamed and an error is raised If any data file in the tablespace is offline, or if the tablespace is offline, then the tablespace is not renamed and an error is raised If the tablespace is read only, then data file headers are not updated. This should not be regarded as corruption; instead, it causes a message to be written to the alert log indicating that data file headers have not been renamed. The data dictionary and control file are updated If the tablespace is the default temporary tablespace, then the corresponding entry in the database properties table is updated and the DATABASE_PROPERTIES view shows the new name If the tablespace is an undo tablespace and if the following conditions are met, then the tablespace name is changed to the new tablespace name in the server parameter file (SPFILE). The server parameter file was used to start up the database. The tablespace name is specified as the UNDO_TABLESPACE for any instance. If a traditional initialization parameter file (PFILE) is being used then a message is written to the alert log stating that the initialization parameter file must be manually changed

Contact Mail-Id:oracledbatraining2009@gmail.com
Tablespace Options CREATE DROP RENAME ALTER (ADD/DROP/RENAME/RESIZE/REUSE/ONLINE/OFFLINE/RELOCATE a data file) ALTER (READ ONLY/READ WRITE/OFFLINE/ONLINE a tablespace status) COALESCE Moving objects from one tablespace to another tablespace Migration of tablespace Dictionary to Local & Vice-Versa Compressing a tablespace (11g New Feature) Tablespace types Undo tablespace Temporary tablespace Temporary tablespace group Creating a Tablespace Syntax: CREATE TABLESPACE <tablespace_name> DATAFILE 'LOCATION' SIZE nK|M|G|T; tablespace_name Name of the tablespace Location Path to store the data file Size We specify the size of the data file in terms of Kilo bytes or Mega bytes or Giga bytes or Tera bytes

Contact Mail-Id:oracledbatraining2009@gmail.com
Demo Notes: An Oracle data file may automatically expand when it runs out of space, if the DBA created the data file with the AUTOEXTEND parameter The DBA can also limit the amount of expansion for a given data file by using the MAXSIZE parameter In any case, the size of the data file is ultimately limited by the disk volume on which it resides TIP The DBA often has to decide whether to allocate one data file that can auto extend indefinitely or to allocate many smaller data files with a limit to how much each can extend Although the performance of each solution is likely very similar, it is probably a better idea to stick with more data files that are each less than 2GB in size It is a lot easier to move around relatively smaller files, and some file systems may limit the size of an individual file to 2GB anyway Also, if you need to temporarily move all the data files for a tablespace to another server, it is often easier to find several volumes, each with enough space to hold one of the data files, rather than one volume with enough space to hold a single data file that is 25GB

Practice Questions: Q1) create a tablespace with a single data file CREATE TABLESPACE ts1 DATAFILE '/u01/zone/prod/data/d1.dbf' SIZE 2M; Syntax: CREATE TABLESPACE <tablespace_name> DATAFILE 'LOCATION' SIZE nK|M|G|T Autoextend on Next size nK|M|G|T maxsize nK|M|G|T; Q2) create a tablespace with a single data file with autoextend on CREATE TABLESPACE ts2 DATAFILE '/u01/zone/prod/data/d2.dbf' SIZE 2M AUTOEXTEND ON; Q3) Create a tablespace with a single data file with auto extend on , along with next size & maximum size CREATE TABLESPACE ts3 DATAFILE '/u01/zone/prod/data/d3.dbf' SIZE 2M AUTOEXTEND ON NEXT 2M MAXSIZE 10M; Q4) create a tablespace with a single data file with autoextend with maxsize unlimited

Contact Mail-Id:oracledbatraining2009@gmail.com
CREATE TABLESPACE ts4 DATAFILE '/u01/zone/prod/data/d4.dbf' SIZE 2M AUTOEXTEND ON NEXT 2M MAXSIZE UNLIMITED; Syntax: CREATE TABLESPACE <tablespace_name> DATAFILE 'LOCATION' SIZE nK|M|G|T EXTENT MANAGEMENT LOCAL|DICTIONARY; Q5) create a tablespace with a single datafile with extent management local CREATE TABLESPACE ts5 DATAFILE '/u01/zone/prod/data/d5.dbf' SIZE 2M EXTENT MANAGEMENT local; Q6) create a tablespace with a single datafile with extent management dictionary CREATE TABLESPACE ts6 DATAFILE '/u01/zone/prod/data/d6.dbf' SIZE 2M EXTENT MANAGMENT DICTIONARY; Q7) create a tablespace with a single datafile with extent management dictionary CREATE TABLESPACE ts7 DATAFILE '/u01/zone/prod/data/d7.dbf' SIZE 2M EXTENT MANAGMENT dictionary DEFAULT STORAGE (INITIAL 50K NEXT 50K MINEXTENTS 2 MAXEXTENTS 50 PCTINCREASE 0); Syntax: CREATE TABLESPACE <tablespace_name> DATAFILE 'LOCATION' SIZE nK|M|G|T SEGMENT SPACE MANUAL| AUTO|UNIFORM SIZE| UNIFORM;

Q8) create a tablespace with a single datafile with segment space management manual CREATE TABLESPACE ts8 DATAFILE '/u01/zone/prod/data/d8.dbf' SIZE 2M SEGMENT SPACE MANAGEMENT MANUAL; Q9) create a tablespace with a single datafile with segment space management auto CREATE TABLESPACE ts9 DATAFILE '/u01/zone/prod/data/d9.dbf' SIZE 2M SEGMENT SPACE MANAGEMENT AUTO; Q10) create a tablespace with a single datafile with segment space management manual with uniform size

Contact Mail-Id:oracledbatraining2009@gmail.com
CREATE TABLESPACE ts10 DATAFILE '/u01/zone/prod/data/d10.dbf' SIZE 2M SEGMENT SPACE MANAGEMENT MANUAL UNIFORM SIZE; Q11) create a tablespace with a single datafile with segment space management manual with uniform Note: Space 1MB will be allocated CREATE TABLESPACE ts11 DATA FILE '/u01/zone/prod/data/d11.dbf' SIZE 2M SEGMENT SPACE MANAGEMENT MANUAL UNIFORM; Q12) create a tablespace with two datafiles CREATE TABLEPSACE ts12 DATAFILE '/u01/zone/prod/data/d12.dbf' SIZE 2M '/u01/zone/prod/data/d12a.dbf' SIZE 2M; ALTERING A TABLESPACE Q13) Add a single data file to the existing tablespace ALTER TABLESPACE ts12 ADD DATAFILE '/u01/zone/prod/data/d12b.dbf' SIZE 2M; Q14) Adding multiple data files to the existing tablespace ALTER TABLESPACE ts12 ADD DATAFILE '/u01/zone/prod/data/d12c.dbf' SIZE 2M '/u01/zone/prod/data/d12d.dbf' SIZE 2M; SYNTAX: ALTER TABLESPACE DROP DATAFILE ID|LOCATION; Note: We can drop only single data file at a time Q15) Dropping a Single data file by specifying location ALTER TABLESPACE DROP DATAFILE '/u01/zone/prod/data/d12d.dbf'; DATAFILE STATUS Q16) Change the data file status to OFFLINE ALTER DATAFILE '/u01/zone/prod/ts9/d12c.dbf' OFFLINE;

Contact Mail-Id:oracledbatraining2009@gmail.com
Q17)Change the data file status to ONLINE ALTER DATAFILE '/u01/zone/prod/ts9/d12c.dbf' ONLINE; Q18) Resize a data file ALTER TABLESPACE ts12 DATAFILE '/u01/zone/prod/ts9/d12c.dbf' RESIZE 5M; TABLESPACE STATUS Q19) Change the tablespace status to READ ONLY ALTER TABLESPACE ts12 READ ONLY; Q20) Change the tablespace status to READ WRITE ALTER TABLESPACE ts12 READ WRITE; Q21) Change the tablespace status to OFFLINE ALTER TABLESPACE ts12 OFFLINE; Q22) Change the tablespace status to ONLINE ALTER TABLESPACE ts12 ONLINE; Q23) Rename a tablespace ALTER TABLESPACE ts12 rename to ts12new;

TABLESPACE COALESCING Syntax: ALTER TABLESPACE<tablespace_name> COALESCE; Q24) Coalesce a tablespace ALTER TABLESPACE ts12 COALESCE Dropping tablespace Q25) Dropping a tablespace logically only

Contact Mail-Id:oracledbatraining2009@gmail.com
DROP TABLESPACE ts12; Q26) Drop a tablespace logically along with segments DROP TABLESPACE ts11 INCLUDING CONTENTS; Q27) Drop a tablespace logically along with segments & physical along with data files DROP TABLESPACE ts10 INCLUDING CONTENTS AND DATAFILES; Q28) Drop a tablespace logically along with segments & physical along with data files & cascading (along with dependent objects) DROP TABLESPACE ts9 INCLUDING CONTENTS AND DATAFILES CASCADE; Moving objects from one Tablespace to another Tablespace Syntax: ALTER TABLE <table_name> MOVE TO TABLESPACE <tablespace_name>; Q29) Moving the tables from ts1 to ts8 ALTER TABLE emp MOVE TO TABLESPACE ts8; Q30) Rename a data file Step1: Make the tablespace OFFLINE Step2: Physically rename the datafile at the Operating System Level Step3: Logically rename the datafile in the database control file Step4: Make the tablespace ONLINE ALTER TABLESPACE ts6 OFFLINE; mv d8.dbf d8a.dbf ALTER TABLESPACE ts8 RENAME FILE '/u01/zone/prod/data/d8.dbf' TO '/u01/zone/prod/data/d8a.dbf'; Q31) Relocate a data file Step1: Make the tablespace OFFLINE Step2: Physically move the datafile to the destination at the Operating System Level Step3: Logically update the database controlfile Step4: Make the tablespace ONLINE ALTER TABLESPACE ts6 OFFLINE; mv d8a.dbf ../

Contact Mail-Id:oracledbatraining2009@gmail.com
ALTER TABLESPACE ts6 RENAME FILE '/u01/zone/prod/data/d8a.dbf' TO '/u01/zone/prod/d8a.dbf'; Q32) Reuse the data file Step1: Drop the tablespace along with the contents Step2: Logically update the database controlfile DROP TABLESPACE ts8 INCLUDING CONTENTS; ALTER TABLESPACE ts8 ADD DATAFILE '/u01/zone/prod/d8.dbf' REUSE; Q33) Create the undo tablespace CREATE TABLESPACE UNDOTBS1 DATAFILE '/u01/zone/prod/data/undo1.dbf' SIZE 200m; Q34) Assign the UNDOTBS1 as the default undo tablespace ALTER TABLESPACE DEFAULT UNDO TABLESPACE undotbs1; Q35) Create a Temporary tablespace CREATE TEMPORARY TABLESPACE temp1 TEMPFILE '/u01/zone/prod/data/temp1.dbf' SIZE 5m; Q36) Create a Temporary tablespace with a group CREATE TEMPORARY TABLESPACE temp2 TEMPFILE '/u01/zone/prod/data/temp2.dbf' SIZE 5m TABLESPACE GROUP TG; Q37) Make a Tablespace group as the default temporary tablespace ALTER DATABASE DEFAULT TEMPORARY TABLESPACE temp2; Q38) Assign temp1 tablespace to tablespace group TG ALTER TABLESPACE temp1 TO TABLESPACE GROUP TG; Q39) Remove temp1 tablespace from a tablespace group TG ALTER TABLESPACE TEMP1 TABLESPACE GROUP '';

Contact Mail-Id:oracledbatraining2009@gmail.com
Big file Tablespace Syntax: CREATE BIGFILE TABLESPACE <tablespace_name> DATAFILE 'LOCATION' SIZE nK|M|G|T SEGMENT SPACE MANUAL| AUTO|UNIFORM SIZE| UNIFORM; Q40) Create a Big file Tablespace CREATE BIGFILE TABLESPACE ts11 DATAFILE /u01/zone/prod/ts11.dbf SIZE 1G;

Anda mungkin juga menyukai