Tải bản đầy đủ (.pdf) (40 trang)

oracle 8 database administration volume 1 instruction guide phần 7 pot

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (287.1 KB, 40 trang )

Oracle8: Database Administration 8-15


.
Creating Tablespaces
Temporary Tablespace
The database administrator has the option of creating a temporary
tablespace. A temporary tablespace can only be used for sort segments and
cannot contain any permanent objects.
Existing tablespaces can be altered so that they become temporary as long as
they do not have any permanent objects in them.
OEM
1 Use Oracle Storage Manager.
2 Select Tablespace—>Create.
3 In the General page of the property sheet, enter the name and choose the
ADD field to display the Create Datafile property sheet.
4 In the Create Datafile property sheet, specify each data file.
5 Select the TEMPORARY radio button.
6 Click Create.
Note
This is explained in more detail in the lesson “Managing Temporary
Segment.”
8-8
Copyright  Oracle Corporation, 1998. All rights reserved.
Temporary Tablespace
• Used for sort operations
• Cannot contain any permanent objects
CREATE TABLESPACE sort
DATAFILE ‘/DISK2/sort01.dbf’ SIZE 50M
MINIMUM EXTENT 1M
DEFAULT STORAGE (INITIAL 2M NEXT 2M


MAXEXTENTS 500 PCTINCREASE 0)
TEMPORARY;
8-16 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Changing the Size of Tablespaces
You can enlarge a tablespace in two ways:
• Add a data file to a tablespace
• Change the size of a data file
Adding Data Files to a Tablespace
You can add data files to a tablespace to increase the total amount of disk
space allocated for the tablespace with the ALTER TABLESPACE ADD
DATAFILE command:
ALTER TABLESPACE tablespace
ADD DATAFILE filespec [autoextend_clause]
[, filespec [autoextend_clause]]
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node.
3 Select Tablespace—>Add Datafile.
4 In the General page of the property sheet, enter the file information.
5 Click Create.
8-9
Cop
y
ri
g
ht  Oracle Corporation

,
1998. All ri
g
hts reserved.
Adding Data Files
to a Tablespace
ALTER TABLESPACE app_data
ADD DATAFILE
‘/DISK5/app03.dbf’ SIZE 200M;
Tablespace APP_DATA
app03.dbf
2M
app02.dbf
1M
app01.dbf
1M
Example
Oracle8: Database Administration 8-17


.
Changing the Size of Tablespaces
Note
If you add new data files to a tablespace, specify the full filenames,
otherwise the Oracle server creates the data files in the default directory of
the database server.
8-18 Oracle8: Database Administration


.

Lesson 8: Managing Tablespaces and Data Files
Changing the Size of Data Files
You can alter the size of a data file in one of two ways:
• Automatically using the AUTOEXTEND option
• Manually using the ALTER DATABASE command
Automatic Resizing of Data Files
The AUTOEXTEND command option enables or disables the automatic
extension of data files. When a data file is created, the following SQL
commands can be used to specify automatic file extension:
• CREATE DATABASE (see the lesson “Creating a Database”)
• CREATE TABLESPACE DATAFILE
• ALTER TABLESPACE ADD DATAFILE
Setting AUTOEXTEND While Creating a File
Use the following command to add a data file with automatic extension
enabled:
ALTER TABLESPACE tablespace
ADD DATAFILE filespec [autoextend_clause]
[, filespec [autoextend_clause]]
8-10
Copyright  Oracle Corporation, 1998. All rights reserved.
Enabling Automatic Extension
of Data Files
ALTER TABLESPACE app_data
ADD DATAFILE
‘/DISK6/app04.dbf’ SIZE 200M
AUTOEXTEND ON NEXT 10M
MAXSIZE 500M;
Tablespace APP_ DATA
app04.dbf
2M

app03.dbf
2M
app01.dbf
1M
app02.dbf
1M
Example
Oracle8: Database Administration 8-19


.
Changing the Size of Data Files
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node.
3 Select Tablespace—>Add Datafile.
4 In the General page of the property sheet, enter the file information.
5 In the Autoextend page of the property sheet, enter the information.
6 Click Create.
Specifying AUTOEXTEND for an Existing Data File
Use the SQL command ALTER DATABASE to enable or disable automatic
file extension for existing data files:
ALTER DATABASE [database]
DATAFILE 'filename'[, 'filename']
autoextend_clause
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node.
3 Select the data file.
4 In the Autoextend page of the property sheet, turn off the Enable Auto

Extend button.
5 Click Apply.
8-20 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Manually Resizing Data Files
Instead of adding space to the database by adding data files, the database
administrator can change the size of a data file. The database administrator
can correct errors in estimates of space requirements and reclaim unused
space in the database. Use the following ALTER DATABASE command to
manually increase or decrease the size of a data file:
ALTER DATABASE [database]
DATAFILE 'filename'[, 'filename']
RESIZE integer[K|M]
where:
integer is the absolute size of the resulting data file.
Instructor Note
Mention that decreasing a data file is only possible if there is no object
stored above the specified limit.
8-11
Copyright  Oracle Corporation, 1998. All rights reserved.

1M
ALTER DATABASE DATAFILE
‘/DISK5/app02.dbf’ RESIZE 200M;
Tablespace APP_DATA
app02.dbf
1M

Changing the Size
of Data Files Manually
app01.dbf
1M
Example
Oracle8: Database Administration 8-21


.
Changing the Storage Settings
Changing the Storage Settings
Use the following ALTER TABLESPACE command to alter the default
storage definition of a tablespace:
ALTER TABLESPACE tablespace
{MINIMUM EXTENT integer[K|M]
|DEFAULT storage_clause
}
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node.
3 Select the data file.
4 In the Extents page of the property sheet, enter storage information.
5 Click Apply.
8-12
Copyright  Oracle Corporation, 1998. All rights reserved.
Changing the Storage Settings
Example
ALTER TABLESPACE app_data
MINIMUM EXTENT 2M;
ALTER TABLESPACE app_data

DEFAULT STORAGE
(INITIAL 2M NEXT 2M
MAXEXTENTS 999);
8-22 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Taking Tablespaces Offline or Online
Users can access a tablespace only if it is online. The database administrator
might take a tablespace offline to make:
• A portion of the database unavailable, while allowing normal access to
the remainder of the database
• Tables or an application unavailable while relocating data files (see next
section)
The Offline Status of a Tablespace
The Oracle server does not permit any SQL statements to reference objects
contained in that tablespace.
The Oracle server performs a checkpoint on all data files in the tablespace
before a tablespace is taken offline.
Users trying to access tables or trying to access objects in a tablespace that is
offline, either directly or for checking referential integrity, receive an error.
8-13
Copyright  Oracle Corporation, 1998. All rights reserved.
OFFLINE Status
• The tablespace that is offline is not
available for data access.
• The SYSTEM tablespace and any
tablespace with active rollback
segments cannot be taken offline.

ALTER TABLESPACE app_data OFFLINE;
Example
Oracle8: Database Administration 8-23


.
Taking Tablespaces Offline or Online
When a tablespace goes offline or comes back online, the event is recorded
in the data dictionary and in the control file. If a tablespace is offline when
you shut down a database, the tablespace remains offline and will not be
checked when the database is subsequently mounted and reopened.
Taking Tablespaces Offline
Whenever the database is open, a database administrator can take any
tablespace, except the SYSTEM tablespace or any tablespace with active
rollback segments or temporary segments, offline. When a tablespace is
taken offline, the Oracle server takes all the associated data files offline.
ALTER TABLESPACE tablespace
{ONLINE
|OFFLINE [
NORMAL|TEMPORARY|IMMEDIATE]
}
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node.
3 Select the tablespace.
4 In the General page of the property sheet, select the Offline radio button.
5 Click Apply
Note
There are three different modes in which a tablespace can be taken offline:
• Normal

• Temporary
• Immediate
Oracle recommends that if no errors occur on any data files, take a
tablespace offline in normal mode. The normal option is covered in this
lesson.
The different error situations and the offline status of tablespaces and data
files are covered in more detail in the course Oracle8: Backup and Recovery
Workshop.
8-24 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Moving Data Files
Depending on the type of tablespace, the database administrator can move
data files using one of the following three methods:
Using the ALTER TABLESPACE Command
The following ALTER TABLESPACE command is applied only to data files
in a non-SYSTEM tablespace, that does not contain active rollback or
temporary segments:
ALTER TABESPACE tablespace
RENAME DATAFILE 'filename'[, 'filename']
TO 'filename'[, 'filename']
Use the following process to rename a data file:
1 Take the tablespace offline.
2 Use an operating system command to move or copy the files.
3 Execute the ALTER TABLESPACE RENAME DATAFILE command.
4 Bring the tablespace online.
5 Use an operating system command to delete the file if necessary.
Note

The source filenames should match the names stored in the control file.
8-14
Copyright  Oracle Corporation, 1998. All rights reserved.
Moving Data Files:
ALTER TABLESPACE
• The tablespace APP_DATA must be
offline.
• The target data files must exist.
ALTER TABLESPACE app_data RENAME
DATAFILE ‘/DISK4/app01.dbf’ TO
‘/DISK5/app01.dbf’;
Example
Oracle8: Database Administration 8-25


.
Moving Data Files
Using the ALTER DATABASE Command
The ALTER DATABASE command (see the lesson “Maintaining Redo Log
Files”) can be used to move any type of data file:
ALTER DATABASE [database]
RENAME FILE 'filename'[, 'filename']
TO 'filename'[, 'filename']
Use the following process to rename files in tablespaces that cannot be taken
offline:
1 Shut down the database.
2 Use an operating system command to move the files.
3 Mount the database.
4 Execute the ALTER DATABASE RENAME FILE command.
5 Open the database.

8-15
Copyright  Oracle Corporation, 1998. All rights reserved.
Moving Data Files:
ALTER DATABASE
• The database must be mounted.
• The target data file must exist.
ALTER DATABASE RENAME FILE
‘/DISK1/system01.dbf’ TO
‘/DISK2/system01.dbf’;
Example
8-26 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node and select the data file.
3 In the General page of the property sheet, update the file information.
4 Click Apply.
Note
• These commands check that the file exists in the new location; they do
not create or move files.
• Always provide complete filenames (including their paths) to identify
the old and new data files.
Instructor Note
Stress that Oracle recommends the ALTER TABLESPACE command for the
non-SYSTEM tablespace and any tablespaces that do not contain active
rollback segments to move data files, because this guarantees high
availability.

Oracle8: Database Administration 8-27


.
Read-Only Tablespaces
Read-Only Tablespaces
Making tablespaces read-only prevents further write operations on the data
files. The purpose of read-only tablespaces is to ensure that no changes are
made and to eliminate the need to perform backup and recovery of large,
static portions of a database. The Oracle server never updates the files of a
read-only tablespace, and therefore the files can reside on read-only media,
such as CD ROMs or WORM drives.
Use the SQL command ALTER TABLESPACE to change a tablespace to
read-only or read-write:
ALTER TABLESPACE tablespace
READ{ONLY|WRITE}
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node.
3 Select the tablespace.
4 Select Tablespace—>Make Read Only.
5 Click OK.
8-16
Copyright  Oracle Corporation, 1998. All rights reserved.
The READ-ONLY
Tablespace Status
ALTER TABLESPACE app_data READ
ONLY;
The tablespace APP_DATA is only available
for read operations.

Example
8-28 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Note
Because you can only bring a tablespace online in the database in which it
was created, read-only tablespaces are not meant to satisfy archiving or data
publishing requirements.
Oracle8: Database Administration 8-29


.
Read-Only Tablespaces
Before the DBA can make a tablespace read-only, several conditions must
be met. The recommended way to meet these restrictions is to start the
instance in restricted mode.
To make a read-only tablespace writable, all of the data files in the
tablespace must be online.
Making tablespaces read only will cause a checkpoint on the data files of the
tablespace.
Creating Read-Only Tablespaces on Read-Only Media
• Make a tablespace read-only.
• Copy its files to read-only media.
• Rename the data files to point to the new location.
Instructor Note
Mention that you can drop database objects in a read-only tablespace.
8-17
Copyright  Oracle Corporation, 1998. All rights reserved.

Making Tablespace Read-Only
• The tablespace must be online.
• No active transactions are allowed.
• The tablespace must not contain active
rollback segments.
• The tablespace must not currently be
involved in an online backup.
8-30 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Dropping Tablespaces
You can remove a tablespace from the database when the tablespace and its
contents are no longer required with the following DROP TABLESPACE
SQL command:
DROP TABLESPACE tablespace
[INCLUDING CONTENTS [CASCADE CONSTRAINTS]]
where: tablespace specifies the name of the tablespace to be
dropped
INCLUDING CONTENTS
drops all the segments in the tablespace
CASCADE CONSTRAINTS
drops referential integrity constraints from
tables outside the tablespace that refer to
primary and unique keysinthetablesinthe
dropped tablespace
8-18
Copyright  Oracle Corporation, 1998. All rights reserved.
Dropping Tablespaces

DROP TABLESPACE app_data
INCLUDING CONTENTS;
The following statement removes the
APP_DATA tablespace and all its
contents.
Example
Oracle8: Database Administration 8-31


.
Dropping Tablespaces
Guidelines
• A tablespace that still contains data cannot be dropped without the
INCLUDING CONTENTS option.
• Once a tablespace has been dropped, its data is no longer in the database.
• When a tablespace is dropped, only the file pointers in the control file of
the associated database are dropped. The database files still exist and
must be deleted explicitly at the operating system level.
• Even if a tablespace is switched to read-only it can still be dropped,
along with segments within it. This is possible because the DROP
command only updates the data dictionary (which has to be read-write),
but not the physical files that make up the tablespace.
• It is recommended that you take the tablespace offline before dropping it
to ensure that no transactions access any of the segments in the
tablespace.
OEM
1 Use Oracle Storage Manager.
2 Expand the Tablespace node and select the tablespace.
3 Select Tablespace—>Remove.
4 Click OK.

Instructor Note
You may mention that using the INCLUDING CONTENTS option may
generate a lot of rollback when the tablespace contains many objects. As an
alternative, use a script to drop the objects in the tablespace and drop the
tablespace.
8-32 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Data Dictionary Information
To list the names and default storage parameters of all tablespaces in a database use
the following query on the DBA_TABLESPACES view:
SVRMGR> SELECT tablespace_name, initial_extent, next_extent,
2 > max_extents, pct_increase, min_extlen
3 > FROM dba_tablespaces;
TABLESPACE_NAME

INITIAL_EX

NEXT_EXT

MIN_EXTENT

MAX_EXTENT

PCT_I

MIN_EXTLEN


SYSTEM 10240 10240 1 121 50 0
RBS 10240 10240 1 121 50 0
TEMP 262144 262144 1 999 50 131072
DATA01 204800 204800 1 999 50 51200
4 rows selected.
8-19
Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Tablespace Information
DBA_TABLESPACES
• TABLESPACE_NAME
• NEXT_EXTENT
• MAX_EXTENTS
• PCT_INCREASE
• MIN_EXTLEN
• STATUS
• CONTENTS
Oracle8: Database Administration 8-33


.
Data Dictionary Information
Use the following query to obtain information about the type of tablespace,
such as temporary or permanent, and the availability of the data files:
SVRMGR> SELECT tablespace_name, contents,status
2> FROM dba_tablespaces;
TABLESPACE_NAME CONTENTS STATUS

SYSTEM PERMANENT ONLINE
RBS PERMANENT ONLINE
TEMP TEMPORARY ONLINE

DATA01 PERMANENT ONLINE
4 rows selected.
8-34 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
The following query returns information about the tablespace to which the
data files belong and the setting of the AUTOEXTEND option:
SVRMGR> SELECT file_name, tablespace_name, bytes,
2> autoextensible, maxbytes, increment_by
3> FROM dba_data_files;
FILE_NAME TABLESPACE_NAME BYTES AUT MAXBYTES INCREMENT_

/DISK1/system01.dbf SYSTEM 31457280 NO 0 0
/DISK2/rbs01.dbf RBS 5242880 NO 0 0
/DISK3/temp01.dbf TEMP 5242880 NO 0 0
/DISK4/data01.dbf DATA01 5242880 NO 0 0
/DISK5/data02.dbf DATA01 512000 YES 15728640 512
5 rows selected.
8-20
Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Data File Information
DBA_DATA_FILES
• FILE_NAME
• TABLESPACE_NAME
• BYTES
• AUTOEXTENSIBLE
• MAXBYTES
• INCREMENT_BY

Oracle8: Database Administration 8-35


.
Data Dictionary Information
The following query of the dynamic performance view V$DATAFILE lists
the name of the data file and sizes, the tablespace name to which the data
files belong, and the availability—the OFFLINE, ONLINE, READ WRITE,
or READ ONLY status—of the data files:
SVRMGR> SELECT file#, d.name, status, enabled,
2> bytes, create_bytes, t.name
3> FROM v$datafile d, v$tablespace t
4> where t.ts#=d.ts#;
FILE# RFILE #D.NAME STATUS ENABLED BYTES CREATE_ BYT T.NAME

1 1 /DISK1/system01.dbf SYSTEM READ WRITE 31457280 31457280 SYSTEM
2 2 /DISK2/rbs01.dbf ONLINE READ WRITE 5242880 5242880 RBS
3 3 /DISK3/temp01.dbf ONLINE READ WRITE 5242880 5242880 TEMP
4 4 /DISK4/data01.dbf ONLINE READ WRITE 5242880 5242880 DATA01
5 5 /DISK5/data02.dbf ONLINE READ WRITE 512000 512000 DATA01
5 rows selected.
8-21
Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Data File and Tablespace
Information from the Control File
V$DATAFILE
- TS#
- NAME
- FILE#
- RFILE#

- STATUS
- ENABLED
- BYTES
- CREATE_BYTES
V$TABLESPACE
- TS#
- NAME
8-36 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Note
The column FILE# contains the absolute data file number and the column
RFILE# the tablespace relative data file number.
Oracle8: Database Administration 8-37


.
Considerations in Creating Tablespaces
Considerations in Creating Tablespaces
Use Multiple Tablespaces
Using multiple tablespaces affords you more flexibility in performing
database operations.
• Separate user data from data dictionary data.
• Separate application data from each other.
• Store the data files of different tablespaces on separate disk drives to
reduce I/O contention.
• Separate the rollback segment from data segments, to prevent a single
disk failure from causing permanent loss of data.

• Take individual tablespaces offline while others remain online.
• Reserve tablespaces for a particular type of database use, such as
high-update activity, read-only activity, or temporary segment storage.
• Back up individual tablespaces.
Specify Storage Parameters for the Tablespace
• Specify default storage parameters for objects that will be created in a
tablespace.
• Set the default storage parameters for a tablespace to account for the size
of a typical object that will be created in the tablespace.
8-22
Copyright  Oracle Corporation, 1998. All rights reserved.
Guidelines
• Use multiple tablespaces.
• Specify storage parameters for
tablespaces.
• Assign tablespace quotas to users.
8-38 Oracle8: Database Administration


.
Lesson 8: Managing Tablespaces and Data Files
Assign Tablespace Quotas to Users
Assign tablespace quotas, as necessary, to database users.
Note
This is covered in more detail in the lesson “Managing Users.”
Oracle8: Database Administration 8-39


.
Considerations in Creating Tablespaces

Summary
8-23
Copyright  Oracle Corporation, 1998. All rights reserved.
Summary
• Understanding the logical database
structure
• Administering tablespaces

×