Managing Tablespaces and Data Files
Learning Objectives
| |
Database Structure: Relationships
Tablespace: Features
Tablespace: uses
Data Files: Features
· A tablespace is the largest logical storage structure in a database. The data in the tablespace is stored in the physical storage structures called data files. In this topic, you learn about the features of a data file.
· Each tablespace in an Oracle database consists of one or more data files. Data files are the physical structures that conform to the operating system on which the Oracle server is installed.
· The size of a data file can be changed by the DBA after its creation. Otherwise, the DBA can specify that the size of a data file should dynamically increase along with an increase in the number of objects in the tablespace.
· This feature enables the DBA to circumvent the MAXDATAFILES limitation, and makes it possible for the database to consist of fewer data files for each tablespace. It also prevents users and applications from getting errors due to the lack of free space in a tablespace.
· One feature of a data file is that it can belong to only one tablespace. This enables a DBA to backup the data file without affecting the availability of any other tablespace.
· Another feature is that the data file for a tablespace is created by the Oracle server. However, the amount of disk space to be occupied by the data file is specified by the DBA. The Oracle server creates the data file with the specified amount of disk space along with a small overhead.
| |
Tablespace: Types
· In this topic, you learn about the differences between the SYSTEM and Non-SYSTEM tablespaces. When you create a database, a tablespace called the SYSTEM tablespace is created by default. All other tablespaces, called Non-SYSTEM tablespaces, are created by the DBA.
· You create a Non-SYSTEM tablespace to manage the database easily and enable the users to use the database effectively.
· The Non-SYSTEM tablespace is not a mandatory requirement. The SYSTEM tablespace is required in all databases for database operation.
· The Non-SYSTEM tablespace may contain data segments, index segments, temporary segments, and rollback segments. On the other hand, the SYSTEM tablespace contains data dictionary information, definitions of stored procedures, packages, and database triggers.
· The Non-SYSTEM tablespace may contain any additional rollback segments and application indexes. A SYSTEM tablespace contains the SYSTEM rollback segment.
· You should not store user data in the SYSTEM tablespace. If the SYSTEM tablespace contains user data, you cannot take offline backups of the data without shutting down the database.
Creating a Tablespace
· In this topic, you learn about creating a tablespace. As the DBA, you are responsible for maintaining the data in the databases. One way that you can effectively manage data is by creating tablespaces for different sets of users, such as creating a marketing tablespace for the marketing personnel.
· You execute a SQL command or use Oracle Storage Manager to create a tablespace. The syntax of the SQL command used to create a tablespace is following. Alternatively, you can use Oracle Storage Manager to create a tablespace.
CREATE TABLESPACE tablespace
DATAFILE filespec [autoextend_clause]
[, filespec [autoextend_clause]
[MINIMUM EXTENT integer [K|M]]
[DEFAULT storage_clause]
[PERMANENT|TEMPORARY]
[ONLINE|OFFLINE]
storage_clause :== ([INITIAL integer [K|M]]
[NEXT integer [K|M]
[MINEXTENDS integer]
[MAXEXTENTS {integer|UNLIMITED}]
[PCTINCREACE integer])]
Ex: Create a tablespace named ACCOUNTS by using Oracle Storage Manager. The name of the data file is accts01.dbf and its size is 10 KB.
- The Oracle Storage Manager window is displayed and the Tablespaces node is selected. To begin the process of creating the ACCOUNTS tablespace, click on the Object menu now.
- To create the tablespace, click on the Create option.
- The Create Tablespace dialog box is displayed. To name the tablespace as ACCOUNTS, type ACCOUNTS and click on the Add button now.
- The Create Datafile dialog box is displayed. To create the accts01.dbf data file for the ACCOUNTS tablespace, type e:\orant\oradata\orcl\accts01.dbf and press Tab now.
- To specify the size of the data file as 10 KB, type 10 and click on the K Bytes box. To accept the values, click on the OK button.
- To complete the process of creating the ACCOUNTS tablespace, click on the Create button now.
- The Oracle Storage Manager window is displayed. You successfully created the ACCOUNTS tablespace.
- The SQL command that was generated during this creation of a tablespace is following.
CREATE TABLESPACE ACCOUNTS DATAFILE
e:\orant\oradata\orcl\accts01.dbf SIZE 10K;
- To view the ACCOUNTS tablespace that you created by using Oracle Storage Manager, click on the Tablespaces node now.
- The Tablespaces node displays the ACCOUNTS tablespace that you created.
- When creating tablespaces, the maximum number of tablespaces that you can create for each database is 64000. The maximum number of data files that can be assigned for each tablespace is 1023.
Storage Parameters
· In this topic, you learn about tablespace storage parameters. The efficiency of a tablespace depends on the amount of space used by a segment. Therefore, it is important for you to know the parameters that influence the amount of space used by a segment.
· There are five parameters that determine and control the amount of space used by a segment. These are INITIAL, NEXT, MAXEXTENTS, MINEXTENTS, and PCTINCREASE.
· The size of the first extent of any segment is set by the INITIAL parameter. The minimum size of the first extent is two blocks or 2*DB_BLOCK_SIZE. The default size is five blocks or 5*DB_BLOCK_SIZE.
· The NEXT parameter refers to the size of the second extent. The minimum size of the next extent is one block, and the default size is five blocks or 5*DB_BLOCK_SIZE.
· The value of the MINEXTENTS parameter determines the number of extents allocated when the segment is created. By default, the minimum value is one.
· PCTINCREASE is the percent by which the NEXT size increases.
· For example, NEXT is set to 200 KB, and PCTINCREASE is set to 50%. In such a situation, the second extent will be 200 KB in size, the third extent will be 300 KB, and the fourth extent will be 450 KB.
· The minimum value that the PCTINCREASE parameter can take is zero, and its default value is 50. The calculated value is rounded up to the next value, which is a multiple of 5*DB_BLOCK_SIZE.
· The MAXEXTENTS parameter determines the maximum number of extents a segment can contain. The minimum value is one. The default maximum value depends on the data block size. The maximum size can also be specified by the keyword UNLIMITED, equivalent to a value of 2,147,483,645.
· The values for these parameters should account for a typical object that will be created in the tablespace. However, these storage parameters can be overruled when creating individual segments.
| |
Creating Temporary Tablespace
· In this topic, you create a temporary tablespace. Oracle performs sort operations in memory. However, when a large amount of data is involved, Oracle needs to use some disk space temporarily to sort the data. The SYSTEM tablespace is used as the default tablespace for that purpose.
· Once the sorting is over, the space is released. When a large amount of data is involved, the efficiency of the database declines. To avoid the usage of the SYSTEM tablespace for sorting, Oracle enables you to create temporary tablespaces and assign them to database users.
· The SQL command used to create a temporary tablespace is displayed. In addition to the SQL command, you can create a temporary tablespace by using Oracle Storage Manager.
CREATE TABLESPACE tablespace
DATAFILE filespec [autoextend_clause]
[DEFAULT storage_clause]
TEMPORARY
Ex: Create a temporary tablespace named Temp by using Oracle Storage Manager. The data file should be named temp01.dbf, and its size should be 50 KB. Assign the value 500 KB to initial and next extents. The percentage increase should be zero, and the maximum number of extents should be 500.
- The Oracle Storage Manager window is displayed and the Tablespaces node is selected. To begin the process of creating the temporary tablespace named Temp, click on the Object menu now.
- To begin the process of creating the temporary tablespace, click on the Create option now.
- The Create Tablespace dialog box is displayed. To specify the name of the temporary tablespace as Temp, type Temp and click on the Add button now.
- The Create Datafile dialog box is displayed. To specify the name of the data file for the temporary tablespace as temp01.dbf, type temp01.dbf and press Tab now.
- To specify the size of the data file as 50 K, type 50 and click on the K Bytes box. To accept the values, click on the OK button.
- To specify that the new tablespace is temporary, click on the Temporary option button.
- The Create Tablespace dialog box is displayed. To specify the storage parameters, click on the Extents tab now.
- To override the default values, click on the Override Default Values check box.
- To specify the initial extent, click on the Initial Size text box.
- To specify the value of the initial extent as 500 KB, type 500 and press Tab.
- To specify the value of the next extent as 500 KB, type 500 and press Tab.
- To specify the percentage increase as zero, type 0 and click on the Value text box.
- To specify the maximum number of extents for a segment as 500, type 500 and press Tab now.
- You specified the value for the maximum number of extents. To complete the process of creating the temporary tablespace, click on the Create button now.
- You successfully created a temporary tablespace. This enables tasks such as sort operations to use this area as a temporary workspace.
- The SQL command that was generated is displayed.
· A temporary tablespace can only be used to store sort segments and cannot contain any permanent objects. The existing tablespaces can be altered so that they become temporary. However, this is possible as long as they do not contain any permanent objects, such as a table.
Locally Managed Tablespaces
· Tablespace extents can be managed using data dictionary tables or bitmaps, called locally managed tablespaces. When you create a tablespace, you must select either a data dictionary-managed tablespace or a locally managed tablespace. You cannot alter it at a later time.
· In this topic, you learn the benefits of locally managed tablespaces.
· A locally managed tablespace manages its own extents and maintains a bitmap in each data file to keep track of the free or used blocks.
· Each bit in the bitmap corresponds to a block or a group of blocks. When an extent is allocated or freed for reuse, the Oracle server changes the bitmap values to show the new status of the blocks.
· Locally managed tablespaces have some advantages over dictionary-managed tablespaces. There is reduced contention on data dictionary tables because locally managed tablespaces do not record free space in data dictionary tables.
· Locally managed tablespaces avoid recursive space management operations that can occur in dictionary-managed tablespaces. When this happens, consuming or releasing space in an extent results in another operation that consumes or releases space in a rollback segment or data dictionary table.
· Local management of extents automatically tracks adjacent free space, eliminating the need to coalesce free extents. Also, the sizes of extents that are managed locally can be automatically determined by the system. Alternatively, all extents can have the same size in a locally managed tablespace.
· To specify local tablespace management, the LOCAL command option of the EXTENT MANAGEMENT clause is used.
· In this topic, you learn to add tablespace data files. When tablespaces get filled with objects over a period of time, the space available in the data files is exhausted. To overcome this situation, you can add data files to tablespaces. This provides more disk space for allocation to database objects.
· You can add space to a tablespace by either using a SQL command or Oracle Storage Manager. The SQL command used to add a data file to a tablespace is displayed.
Ex: In addition to the SQL command, you can use a graphic interface called Oracle Storage Manager to add a data file to a tablespace. Add a data file named accts02.dbf of 100 KB located in the c:\orant\database directory to the ACCOUNTS tablespace by using Oracle Storage Manager.
- The Oracle Storage Manager window is open. To add a data file to the ACCOUNTS tablespace, it must be selected. To begin the process of selecting the ACCOUNTS tablespace, click on the Tablespaces node now.
- The contents of the Tablespaces node appear. To select the ACCOUNTS tablespace, click on the ACCOUNTS tablespace name now.
- The property sheet for the ACCOUNTS tablespace is displayed in the right pane of the Oracle Storage Manager window. To add a data file to the selected tablespace, click on the Add button now.
- The Create Datafile dialog box is displayed. To specify the name of the data file as accts2 type accts02.dbf and press Tab now.
- To specify the size of the data file as 100 KB, type 100 and click on the OK button.
- The Oracle Storage Manager window appears. The accts02.dbf data file that you created is displayed in the Datafiles group box.
| |
Extending Data Files
· Due to an increase in the number of database objects in a tablespace, the data files may run out of allocated disk space. To overcome this problem, you alter the size of a data file.
· At the time of creation, you can also specify that the data file should increase dynamically. In this topic, you learn to enable a data file to extend automatically.
· To specify the automatic file extension command option when creating a data file, you can use the CREATE DATABASE, CREATE TABLESPACE DATAFILE, or ALTER TABLESPACE ADD DATAFILE command.
· You can alter the size of an existing data file using one of two methods. You can automatically alter the size by using the AUTOEXTEND command option, or you can alter the size manually by using the ALTER DATABASE command.
· The AUTOEXTEND command option enables or disables the automatic extension of data files. The SQL command to specify the AUTOEXTEND command option for an existing data file is displayed.
· Another way of enabling the automatic extension is by using Oracle Storage Manager. Enable automatic extension of the accts01.dbf data file in the ACCOUNTS tablespace by using Oracle Storage Manager. The automatic extension should be at the rate of 2 KB.
Ex: The Oracle Storage Manager window is open. Since the accts01.dbf data file is in the ACCOUNTS tablespace, you must select the ACCOUNTS tablespace.
- To begin the process of selecting the ACCOUNTS tablespace, click on the Tablespaces node now.
- The contents of the Tablespaces node are displayed. To select the ACCOUNTS tablespace, double-click on the ACCOUNTS tablespace name now.
- The list of folders under the ACCOUNTS tablespace is displayed. The accts01.dbf data file is located in the Datafiles folder. To begin the process of selecting the ACCOUNTS data file, double-click on the Datafiles node now.
- The accts01.dbf data file appears. To select the accts01.dbf data file, click on E:\ORANT\ORADATA\ORCL\ACCTS01.DBF now.
- The property sheet for the accts01.dbf data file appears in the right pane of the Oracle Storage Manager window. To access the section where you specify the automatic extension feature of the data file, click on the Auto Extend tab now.
- The Auto Extend page appears. To specify that the data file should automatically extend, click on the Enable Auto Extend check box now.
- To select the text box for specifying the rate of increment for an automatic extension, click on the Increment text box now.
- To specify that the rate of the automatic extension should be 2 KB at a time, type 2 and press Tab now.
- You specified the value for the rate of the automatic extension. Next, you apply the changes in the data file.
- The right pane of the Oracle Storage Manager window has been scrolled. To apply the changes in the accts01.dbf data file, click on the Apply button now.
- You successfully enabled the automatic extension of the accts01.dbf data file in the ACCOUNTS tablespace by using Oracle Storage Manager.
- The SQL command that was automatically generated when you enabled the automatic extension of the accts01.dbf data file is displayed. You can also display this SQL command by using the Show SQL button in the Oracle Storage Manager.
Resizing Data Files
· As a DBA, you estimate the space requirements of a database. However, when actually using the database, you may realize that there was an error in estimating the space requirement. To overcome this problem, you resize data files. In this topic, you learn to resize a data file.
· The SQL command used to resize the data files of a tablespace is displayed.
· Resize the accts01.dbf data file in the e:\orant\database directory to 2 MB by using Oracle SQL*Plus Worksheet.
Ex: The Oracle SQL*Plus Worksheet window is open. To complete the command of resizing the data file accts01.dbf to 2 MB, type 'e:\orant\oradata\orcl\accts01.dbf' RESIZE 2M; and press F5 now.
SQL> ALTER DATABASE DATAFILE 'e:\orant\oradata\orcl\accts01.dbf' RESIZE 2M;
- The Oracle SQL*Plus Worksheet window is displayed. You successfully resized the accts01.dbf data file.
Changing Storage Parameters
· The values of the segment storage allocation parameters determine the amount of disk space used by a database. These values are determined during the creation of the segment. In this topic, you learn to modify the values of the default storage parameters.
· Over a period of time, you may need to change the storage parameters for more efficient management of the disk space. To satisfy this requirement, you alter the values of the default storage parameters for a tablespace.
· The SQL command used to alter the values of the storage parameters is displayed.
· Ex: In addition to the SQL command, you can use Oracle Storage Manager to alter the values of the storage parameters. Change the value of the storage parameters INITIAL and NEXT of the ACCOUNTS tablespace to 100 KB by using Oracle Storage Manager.
- The Oracle Storage Manager window is open, and the ACCOUNTS tablespace is selected. To access the page containing the storage information, click on the Extents tab now.
- To change the value of the INITIAL parameter to 100 KB, type 100 and press Tab.
- To change the value of the NEXT parameter, type 100 and press Tab.
- You specified the value for the next extent. This enables you to efficiently manage disk space.
- The right pane of the Oracle Storage Manager window has been scrolled. To apply the changes, click on the Apply button now.
- You successfully changed the values of the storage parameters by using Oracle Storage Manager.
- The SQL command that was generated while changing the values of the storage parameters of the tablespace is displayed. You can display the SQL statements by using the Show SQL button in Oracle Storage Manager.
Obtaining Temporary Segment Information from Oracle
· There are several data dictionary views available for obtaining information about temporary segments.
· The views in the dictionary displaying this information base their content either on temporary segments that exist in the database or on dynamic performance information about temporary segments collected while the instance is running.
· The views you should remember for viewing temporary segment information include the following:
• DBA_SEGMENTS
Gives information about the name, tablespace location, and owner of both types of temporary segments in Oracle. Note that you will only see information on temporary segments in permanent tablespaces while those segments are allocated, but you will see information about temporary segments in temporary tablespaces for the life of the instance.
• V$SORT_SEGMENT Gives information about size of the temporary tablespaces, current number of extents allocated to sort segments, and sort segment high-water mark information.
• V$SORT_USAGE Gives information about sorts that are happening currently on the database.
· You can obtain the name, segment type, and tablespace storing sort segments using the DBA_SEGMENTS view.
· Note that this segment will not exist until the first disk sort is executed after the instance starts. The following code block is an example:
SQL> select owner, segment_name, segment_type, tablespace_name
· You can get the size of sort segments allocated in temporary tablespaces by issuing queries against V$SORT_SEGMENT, which you will find useful in defining the sizes for your temporary tablespaces on an ongoing basis.
· The following query illustrates how to obtain this sort segment high-water mark information from V$SORT_SEGMENT:
from v$session a, v$sort_usage b
Dictionary Views for Temporary Tablespace Management
• DBA_TEMP_FILES This dictionary view gives you information about every datafile in your database that is associated with a temporary tablespace.
• V$TEMPFILE Similar to DBA_TEMP_FILES, this performance view gives you information about everydatafile in your database that is associated with a temporary tablespace.
| |
Tablespace Offline: Modes
· As a part of the database maintenance tasks, such as upgrading storage media, a DBA will relocate data files for a particular tablespace. To enable the relocation of data files, the DBA can take individual tablespaces offline.
· A tablespace can be taken offline in either normal, temporary, or immediate mode.
· In the normal mode, the Oracle server performs a checkpoint on all the data files before taking the tablespace offline. This is the preferred mode.
· In the temporary mode, the Oracle server performs a checkpoint on all the possible data files before taking the tablespace offline. In this mode, any offline data files may require media recovery later.
· Finally, a checkpoint is not performed by the Oracle server in the immediate mode before taking the tablespace offline. You must perform media recovery before bringing the tablespace back online.
Note that the SYSTEM tablespace and any tablespace with active rollback segments cannot be taken offline.
· The Oracle server debars any SQL statements to reference the objects contained in a tablespace that has been taken offline. Therefore, the users trying to access the objects that are offline will receive an error.
· In addition, when a tablespace is either taken offline or brought back online, the event is recorded in the data dictionary and the control file.
· Since the events are recorded in the control file, the tablespace will maintain its last recorded status. For instance, if the tablespace was offline at the time of database shutdown, it will not be checked when the database is subsequently mounted and opened.
Taking Tablespace Offline
· In this topic, you place an individual tablespace offline by using Oracle Storage Manager. As part of the database maintenance tasks, such as relocating a data file, you may need to make a tablespace unavailable while allowing normal access to the remainder of the database.
· The SQL command used to take a tablespace offline is displayed.
· In addition, you can use Oracle Storage Manager to take a tablespace offline. Take the ACCOUNTS tablespace offline by using Oracle Storage Manager.
· Ex: The Oracle Storage Manager window is open. The ACCOUNTS tablespace is selected. To begin the process of taking the tablespace offline, click on the Offline option button now.
- You performed the step to take the ACCOUNTS tablespace offline. Notice that the normal mode is selected.
- To complete the process of taking the ACCOUNTS tablespace offline, click on the Apply button now.
- The right pane of the Oracle Storage Manager window displays the status of the tablespace. You successfully took the ACCOUNTS tablespace offline.
- The SQL command that was generated is displayed.
SQL> ALTER TABLESPACE “ACCOUNTS” OFFLINE NORMAL;
| |
Moving Data Files: Non-SYSTEM
· An increase in the number of records in the database causes the data file size to increase. This may lead to a situation where the media may run out of free space. To overcome this problem, Oracle enables you to move the data files to a new location.
· Ex: Move the accts01.dbf data file of the ACCOUNTS tablespace in the e:\orant\oradata\orcl directory to d:\orant\oradata\orcl directory by using Oracle Storage Manager.
- The first step in the process of moving a data file to a new location is to take the tablespace offline. The Oracle Storage Manager window is open, and the ACCOUNTS tablespace is selected. To take the tablespace offline, click on the Offline option button now.
- To take the ACCOUNTS tablespace offline in the normal mode, click on the Apply button now.
- The next step in moving a data file is to use the operating system command to move or copy the files. The MS-DOS window is open and the source directory path is provided. To copy the data file accounts to the d:\orant\oradata\orcl directory.
C:\> copy e:\orant\oradata\orcl\accts01.dbf d:\orant\oradata\orcl\accts01.dbf
- The next step in the process of moving a data file is to change the path of the data file by using Oracle Storage Manager.
- The SQL command to move the data file is displayed. You can use either the SQL command or Oracle Storage Manager to perform the same task.
- The Oracle Storage Manager window is displayed, the ACCOUNTS tablespace is selected, and the Datafiles node has been expanded. To select the data file, click on E:\ORANT\ORADATA\ORCL\ACCTS01.DBF directory path and filename now.
- To edit the path of the accts01.dbf data file, click in the Name field.
- To change the path of the accounts data file, type d:\orant\database\accts01.dbf and click on the Apply button now.
- The next step is to bring the tablespace online. To start the process of bringing the ACCOUNTS tablespace online, click on the Online option button now.
- To bring the ACCOUNTS tablespace online, click on the Apply button.
- You successfully moved the data file accts01.dbf from the e:\orant\oradata\orcl directory to the d:\orant\oradata\orcl directory. You can now remove the original data file in the e:\orant\oradata\orcl directory.
- You use Oracle Storage Manager to move data files that belong only to the Non-SYSTEM tablespaces and that do not contain active rollback or temporary segments.
Moving Data Files: SYSTEM
· In this topic, you learn to move system data files. The SYSTEM tablespace is required for a database to operate successfully. However, in certain situations, you must move the data files of the SYSTEM tablespace to a new location.
· You can move a data file of the SYSTEM tablespace to a new location. The first step in moving a data file belonging to the SYSTEM tablespace is to shut down the database.
· The next step is to use an operating system command for moving the data file to the new location.
· Next, you mount the database.
· The next step is to execute a SQL command for moving the data file of the SYSTEM tablespace.
· Ex: The e:\orant\database directory belongs to the SYSTEM tablespace. Use the Oracle SQL*Plus Worksheet to move the SYSTEM01.DBF data file from the e:\orant\database directory to the c:\orclbackup directory.
- The Oracle SQL*Plus Worksheet window is open. The database is mounted, and the file has been copied in the c:\orclbackup directory. To complete the command of moving the data file, type RENAME FILE
'e:\orant\oradata\orcl\system01.dbf' and press Enter now.
· To complete the code, type TO 'c:\orclbackup\system01.dbf'; and press F5 now.
· The final step in moving a data file belonging to a SYSTEM tablespace is to open the database.
· You should always provide complete file names, including their directory paths, to identify the old and the new data files.
| |
Making Tablespace Read_Only Mode
· In this topic, you learn to change a tablespace to the read-only mode. To meet the organizational requirements, you may have tablespaces that contain data that is static in nature.
· To eliminate the need to perform backup and recovery of such static data, you can make the tablespaces read-only.
· Making tablespaces read-only also ensures that no write operations are performed on the data. You can store the data files on read-only media, such as CD-ROMs or WORM drives because the Oracle server never updates the files of a read-only tablespace.
Restrictions
· Several conditions must be met before you can make a tablespace read-only. First, to make a tablespace read-only, it must be online.
· If you are using Oracle(i), you can make a tablespace read-only while there are active transactions in the database.
· Once the command is issued, current write commands are completed, and the tablespace becomes read-only. Oracle(i) is the only release that can make a tablespace read-only while active transactions are in the database.
· Finally, the tablespace must not contain active rollback segments and the tablespace must not be currently involved in an online backup.
· The recommended way to meet these restrictions is to start the instance in the restricted mode. In addition, making the tablespaces read-only will cause a checkpoint on the data files.
· The SQL command used to change a tablespace to the read-only mode is displayed.
· In addition to the SQL command, Oracle provides Oracle Storage Manager, a graphic interface, for changing a tablespace to the read-only status. Make the ACCOUNTS tablespace read-only by using Oracle Storage Manager.
· The Oracle Storage Manager window is open, and the ACCOUNTS tablespace has been selected. To begin the process of making the tablespace read-only, click on the Read Only check box now.
· You started the process of making the ACCOUNTS tablespace read-only.
· To complete the process of making a tablespace read-only, click on the Apply button now.
· You successfully made the ACCOUNTS tablespace read-only.
Read-Only Tablespaces On Read-Only Media
· As a DBA, you may have an objective to minimize the time you spend on data backups. One way to reduce this time is to store static data on read-only tablespaces and then store it on read-only media.
Storing read-only data on read-only media is a three-step process
· The first step is to make the tablespace read-only.
· The next step is to copy all the data files of the tablespace to the read-only media.
· The final step in storing the read-only data on read-only media is to rename the data files to point to the new location.
| |
Dropping a Tablespace
· In this topic, you drop a tablespace by using Oracle Storage Manager. Due to a change in the user requirements, there may be tablespaces that are no longer required. The presence of these tablespaces is a waste of disk capacity. To solve this problem, you can drop such tablespaces.
· You can remove tablespaces using two methods, the SQL command and Oracle Storage Manager. The SQL command used to remove such tablespaces is displayed.
· In addition to the SQL command, Oracle provides a graphic interface, Oracle Storage Manager, to drop a tablespace. Drop the ACCOUNTS tablespace by using Oracle Storage Manager.
· The Oracle Storage Manager window is open. The ACCOUNTS tablespace has been selected. To start the process of dropping the tablespace, click on the Object menu now.
· The Object drop-down menu appears. To remove the ACCOUNTS tablespace, click on the Remove option now.
· The Oracle Storage Manager dialog box appears. To confirm the deletion of the ACCOUNTS tablespace, click on the Yes button now.
Guidelines
· You should follow a set of guidelines when you drop a tablespace. You should ensure that current transactions do not access any of the segments in the tablespace. The best way to guarantee this is taking the tablespace offline first.
· If you are using the SQL command to drop a tablespace, you must use the INCLUDING CONTENTS clause for a tablespace that still contains data.
· When the tablespace contains many objects, using the INCLUDING CONTENTS clause might generate a lot of rollback. As an alternative, use a script to drop the objects in the tablespace one by one and then drop the tablespace.
Dropping Tablespace: Effects
· To save disk capacity, you drop tablespaces that are no longer required. In this topic, you learn about the effects of dropping a tablespace.
· The data of the dropped tablespace is not available anymore. Therefore, you cannot query the data of a dropped tablespace.
· When you drop a tablespace, only the file pointers in the control file of the associated database are dropped. To reclaim the disk space used by the tablespace, you must delete the data files explicitly at the operating-system level.
· Finally, if a read-only tablespace is dropped, segments within it are also dropped. Only the data dictionary and the control files need to be updated.
| |
Multiple Tablespace: Benefits
· Organizing data in tablespaces provides multiple benefits. In this topic, you learn about the benefits of using multiple tablespaces.
· Using multiple tablespaces ensures that the user data and the data dictionary data can be kept separately. This enables flexible database operations.
· You can also store the different application data in different tablespaces. This ensures a high availability of data.
· The reduction in I/O contention is another benefit of using multiple tablespaces. The I/O contention is reduced by storing the data files of different tablespaces on separate disk drives.
· Using multiple tablespaces ensures that a permanent loss of data is avoided. This is done by separating the rollback segments from the data segments.
· Using multiple tablespaces provides a high degree of flexibility in data administration because individual tablespaces can be taken offline. This also ensures a high availability of the data.
· Using multiple tablespace also ensures backing up of individual tablespaces.
· Finally, using multiple tablespaces ensures that tablespaces can be reserved for a particular type of activity on the database, such as high-update activity, read-only activity, and temporary segment storage. This improves the efficiency of the database.
Obtaining Tablespace Information
· As a DBA, you require information about tablespaces to manage the Oracle database efficiently. In this topic, you learn the database views that access this information.
· Data dictionary views and dynamic performance views enable you to gather information on tablespaces. The data dictionary views are: DBA_TABLESPACES and DBA_DATA_FILES. The dynamic performance view is V$DATAFILE.
· The DBA_TABLESPACES view contains information about the names, default storage parameters, types, and availability of all the tablespaces.
Ex: For effectively managing the database, you obtain the location and the default storage parameters for all tablespaces. Oracle SQL*Plus Worksheet has been opened.
- To obtain the names and default storage parameters of all the tablespaces in the ORCL database, type SELECT * FROM dba_tablespaces; and press F5 now.
· The DBA_DATA_FILES view contains information about the data files that belong to a specific tablespace and their AUTOEXTEND settings.
Ex: To view the tablespaces to which the data file belongs and the setting of the AUTOEXTEND command option, type SELECT * FROM dba_data_files; and press F5 now.
· The V$DATAFILE view contains information on the name of the data file, the size, the availability, and the tablespace names to which the data files belong.
| |
Storage Structures
Database Storage Hierarchy
Segments: Types
The different types of segments are:
Note: All the data in a non-partitioned table must be stored in one tablespace.
Note: The bootstrap segment cannot be queried or updated. It does not require any maintenance by a database administrator (DBA).
| |
Extent Allocation Control
Note: If the DEFAULT STORAGE clause is not specified for the tablespace, the tablespace inherits the default specified for the Oracle server.
| |
Free Space: Coalescing
- When the System Monitor (SMON) initiates a space transaction to merge adjacent free extents.
- When the oracle server needs to allocate an extent that needs space from more than one adjacent free extent.
- When requested from the DBA.
ALTER TABLESPACE tablespace COALESCE;
Ex: Coalesce the free space in the extents of the RBS tablespace by using Oracle SQL*Plus Worksheet.
SQL> ALTER TABLESPACE rbs COALESCE;
Fragmentation Propensity: Object
Organizing tablespace based on fragmentation propensity
Tablespace Usage Fragmentation
SYSTEM Data dictionary Zero
TOOLS Applications Very Low
DATAn Data segments Low
INDEXn Index segments Low
RBSn Rollback segments High
TEMPn Temporary Segments Very High
| |
Data Blocks: Contents
Block Space Utilization Parameters
| |
• DBA_SEGMENTS This summary view contains all types of segments listed by the data dictionary views and their storage parameters.
• DBA_TABLESPACES You can use this view to see the default storage settings for the tablespaces in the database.
• DBA_TS_QUOTAS You can use this view to identify the tablespace quotas assigned for users to create objects in their default and temporary tablespaces.
• V$TABLESPACE This gives a simple listing of the tablespace number and name.
• DBA_EXTENTS You use this view to see the segment name, type, owner, name of tablespace storing the extent, ID for the extent, file ID storing the extent, starting block ID of the extent, total bytes, and blocks of the extent.
• DBA_FREE_SPACE This view identifies the location and amount of free space, by tablespace name, file ID, starting block ID, bytes, and blocks.
• DBA_FREE_SPACE_COALESCED This view identifies the location of free space in a tablespace that has been coalesced, by tablespace name, total extents, extents coalesced, percent of extents that are coalesced, as well as other information about the space in the tablespace that SMON has coalesced.
• DBA_DATA_FILES This view gives information about datafiles for every tablespace.
• V$DATAFILE This view gives information about datafiles for every tablespace.
Ex: You retrieve the information to check the current number of the extents and blocks allocated to a segment. You query the DBA_SEGMENTS view for the SEGMENT_NAME, TABLESPACE_NAME, EXTENTS, and BLOCKS columns for the segments that are owned by SCOTT by using Oracle SQL*Plus Worksheet.
SQL> SELECT segment_name, tablespace_name, extents, blocks FROM dba_segments WHERE owner = 'SCOTT';
Ex: In this exercise, you retrieve the information about the extents for the EMP segment owned by SCOTT. You query the DBA_EXTENTS view for the EXTENT_ID, FILE_ID, BLOCK_ID, and BLOCKS columns.
SQL> SELECT extent_id, file_id, block_id, blocks
FROM dba_extents WHERE owner = 'SCOTT' AND segment_name = 'EMP';
Free Space Information
Ex: You check the number of free extents and blocks in each tablespace by querying the DBA_FREE_SPACE view. The columns to be displayed are TABLESPACE_NAME, COUNT(*), and SUM(BLOCKS). You sort the information using the TABLESPACE_NAME column.
SQL> SELECT tablespace_name, COUNT(*), SUM(blocks) FROM dba_free_space GROUP BY tablespace_name;
SQL> SELECT tablespace_name, blocks FROM dba_free_space where tablespace_name='RBS';
You retrieved information on the free blocks in all the tablespaces. Notice that the tablespace RBS contains 20 free extents with the total of 6849 blocks.
| |
Summary
| |
| |
|
Manoj kumar
Sap basis admin
Sunday, 11 January 2015
Subscribe to:
Posts (Atom)