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

oracle 8 database administration volume 1 instruction guide phần 9 pps

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 (160.66 KB, 40 trang )

Oracle8: Database Administration 10-27


.
Obtaining Rollback Segment Information
The OWNER column specifies the type of a rollback segment:
• SYS refers to a private rollback segment.
• PUBLIC refers to a public rollback segment.
OEM
1 Use Oracle Storage Manager.
2 Select Rollback Segments node to view a summary of all the rollback
segments in the database.
3 Expand the Rollback Segments node.
4 Select the rollback segment to view extent information and the type of
the rollback segment.
10-28 Oracle8: Database Administration


.
Lesson 10: Managing Rollback Segments
Join the V$ROLLSTAT and V$ROLLNAME views to obtain the statistics of
the rollback segments currently used by the instance:
Example
SVRMGR> SELECT n.name, s.extents, s.rssize, s.optsize,
2> s.hwmsize, s.xacts, s.status
3> FROM v$rollname n, v$rollstat s
4> WHERE n.usn = s.usn;
NAME EXTENTS RSSIZE OPTSIZE HWMSIZE XACTS STATUS

SYSTEM 43 2199552 2199552 0 ONLINE
RBS1 20 202752 204800 417792 0 ONLINE


RBS2 4 38912 38912 0 PENDING
OFFLINE
3 rows selected.
10-20
Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segment Statistics
V$ROLLNAME
USN
NAME
V$ROLLSTAT
USN
EXTENTS
RSSIZE
XACTS
OPTSIZE
HWMSIZE
AVEACTIVE
STATUS
CUREXT
CURBLK
Oracle8: Database Administration 10-29


.
Obtaining Rollback Segment Information
The columns in V$ROLLSTAT include :
Note
• The value of OPTIMAL for a rollback segment can only be obtained
from V$ROLLSTAT view.
• If a rollback segment is PENDING OFFLINE, the status shows up as

ONLINE in DBA_ROLLBACK_SEGS.
Column Description
USN Rollback (undo) segment number; join with
V$ROLLNAME.USN to get the name
EXTENTS Number of extents in the rollback segment
RSSIZE Current size of the segment in bytes
XACTS Number of transactions using this segment
OPTSIZE OPTIMAL value for the rollback segment
HWMSIZE High water mark; the maximum size in bytes to
which the segment grew since startup
AVEACTIVE Current size of active extents, averaged over time
STATUS Status of the rollback segment
(ONLINE indicates that the rollback segment is
available for use. PENDING OFFLINE indicates
that
the command to take a rollback segment
offline has been executed and there are some
active transactions using the segment. The
rollback segment will be taken offline as soon
as all transactions using the rollback segment
have been
completed.)
CUREXT Current location of the rollback segment head; the
extent and block number
CURBLK
10-30 Oracle8: Database Administration


.
Lesson 10: Managing Rollback Segments

To check the use of rollback segment by currently active transactions, join the
V$TRANSACTION and V$SESSION views:
Example
SVRMGR> SELECT s.username, t.xidusn, t.ubafil,
2> t.ubablk, t.used_ublk
3> FROM v$session s, v$transaction t
4> WHERE s.saddr = t.ses_addr;
USERNAME XIDUSN UBAFIL UBABLK USED_UBLK

SYSTEM 2 2 7 1
SCOTT 1 2 163 1
2 rows selected.
10-21
Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segment: Current Activity
V$SESSION
SADDR
USERNAME
SID
SERIAL#
V$TRANSACTION
SES_ADDR
XIDUSN
UBAFIL
UBABLK
UBASQN
UBAREC
STATUS
USED_UBLK
USED_UREC

Oracle8: Database Administration 10-31


.
Obtaining Rollback Segment Information
The relevant columns in V$TRANSACTION and their descriptions are
shown below:
Column Description
SES_ADDR Address of the session; can be joined to
V$SESSION.SADDR
XIDUSN Rollback (Undo) Segment Number used by the
transaction; used as part of the transaction ID
UBAFIL The columns UBAFIL, UBABLK, UBASQN, and
UBAREC specify the current location in the
rollback segment that the transaction is writing to
UBABLK
UBASQN
UBAREC
USED_UBLK Number of blocks of undo generated by the
transaction
START_UEXT Rollback segment extent from which the
transaction started writing
START_UBAFIL Rollback segment file number from which the
transaction started writing
START_UBABLK Rollback segment block number from which the
transaction started writing
10-32 Oracle8: Database Administration


.

Lesson 10: Managing Rollback Segments
Troubleshooting Rollback Segment Problems
10-22
Copyright  Oracle Corporation, 1998. All rights reserved.
Rollback Segment Problems
• Insufficient space for transactions
• Read-consistency error
• Blocking transaction
• Error in taking tablespace offline
Oracle8: Database Administration 10-33


.
Troubleshooting Rollback Segment Problems
Possible Causes
A transaction cannot use multiple rollback segments and may fail because
there is insufficient space in the rollback segment (ORA-01562). This could
be caused by one of the following:
• There is insufficient space in the tablespace (ORA-01560)
• The number of extents in the rollback segment has reached
MAXEXTENTS and additional extents cannot be allocated
(ORA-01628)
Solution
If the tablespace does not have free space, increase the space available to the
tablespace by:
• Extending the data files in the tablespace
• Allowing the data files to AUTOEXTEND
• Adding files to the tablespace
If a rollback segment cannot allocate more extents because the limit imposed
by MAXEXTENTS has been reached:

• Increase MAXEXTENTS for the rollback segment
• Drop and recreate the rollback segment with larger extent sizes to avoid
recurrence of the problem
10-23
Copyright  Oracle Corporation, 1998. All rights reserved.
Insufficient Space for Transactions
• No space in tablespace
– Extend data files
– Allow automatic extension of data
files
– Add data files
• MAXEXTENTS reached for segment
– Increase MAXEXTENTS
– Recreate segments with larger extent
sizes
10-34 Oracle8: Database Administration


.
Lesson 10: Managing Rollback Segments
Possible Causes
As shown in the section on Read-Consistency, the Oracle server guarantees
that a statement will only process data committed at a given time. Any
changes that are not committed when the statement begins or are made after
the statement begins execution, will not be seen by the statement. If the
Oracle server cannot construct a read-consistent image of data, the user will
receive an ORA-01555 SNAPSHOT TOO OLD error. This error can occur
when the transaction that made the change has already committed and:
• The transaction slot in the rollback header has been reused
• The before-image in the rollback segment has been overwritten by

another transaction
10-24
Copyright  Oracle Corporation, 1998. All rights reserved.
Read-Consistency Error
Image at statement
commencement
New image
Table
SELECT *
FROM table
Reused
block
Oracle8: Database Administration 10-35


.
Troubleshooting Rollback Segment Problems
Solution
Read-consistency errors can be minimized by ensuring that rollback
segments are created with:
• Higher MINEXTENTS
• Larger extent sizes
• Higher OPTIMAL value
Note that these errors cannot be avoided by increasing MAXEXTENTS.
Instructor Note
There are other possible causes of the ORA-01555 error, which also occurs
when a read-consistent image cannot be constructed because the transaction
slot in the data block is reused.
10-36 Oracle8: Database Administration



.
Lesson 10: Managing Rollback Segments
Possible Causes
When an extent in a rollback segment is filled up, the Oracle server attempts
to reuse the next extent in the ring. Even if this new extent contains one
active entry—that is, an entry that was written by a transaction that is still
active—it cannot be used. In these cases, a rollback segment allocates an
additional extent. The transaction cannot skip an extent in the ring and
continue writing to a subsequent extent. A transaction that has made only a
few changes, but has been idle for a long time could cause rollback segments
to grow even though there are many free extents. In such situations there is a
lot of space wasted and a database administrator may need to intervene to
avoid excessive rollback segment growth.
10-25
Copyright  Oracle Corporation, 1998. All rights reserved.
Blocking Session
Extent 3
Existing extent
New extent
41
32
1
2
3
4
5
Blocking
session
Oracle8: Database Administration 10-37



.
Troubleshooting Rollback Segment Problems
Detecting Blocking Sessions
Query V$ROLLSTAT, V$SESSION, and V$TRANSACTION views to find
any blocking transactions.
Example
SVRMGR> SELECT s.sid, s.serial#, t.start_time, t.xidusn,
s.username
2> FROM v$session s, v$transaction t, v$rollstat r
3> WHERE s.saddr = t.ses_addr
4> AND t.xidusn = r.usn
5> AND ((r.curext = t.start_uext-1) OR
6> ((r.curext = r.extents-1) AND t.start_uext=0));
SID SERIAL# START_TIME XIDUSN USERNAME

9 27 10/30/97 21:10:41 2 SYSTEM
1 row selected.
Check if the transaction can be ended or whether the transaction needs to be
killed, and take the necessary action.
10-38 Oracle8: Database Administration


.
Lesson 10: Managing Rollback Segments
Problem Diagnosis and Resolution
If a tablespace contains one or more active rollback segments, it cannot be
taken offline, and the session attempting to execute the statement will
receive an ORA-01546 error. In this situation, perform the following steps:

1 Query DBA_ROLLBACK_SEGS to find which rollback segments are in
the tablespace.
2 Take all rollback segments in the tablespace offline.
3 Check V$TRANSACTION to find which transactions are currently
using these rollback segments.
4 Use V$SESSION to obtain the user name and session information.
5 Terminate the sessions if necessary.
6 Take the tablespace offline.
10-26
Copyright  Oracle Corporation, 1998. All rights reserved.
Error in Taking a
Tablespace Offline
Cannot take tablespace containing active
RBS offline
• Check rollback segments in the
tablespace
• Find active transactions using these
rollback segments
• Find session ID and serial number
• Terminate the session, if necessary
Oracle8: Database Administration 10-39


.
Summary
Summary
10-27
Copyright  Oracle Corporation, 1998. All rights reserved.
Summary
• Creating adequate rollback segments

• Troubleshooting rollback segment
problems
10-40 Oracle8: Database Administration


.
Lesson 10: Managing Rollback Segments
Quick Reference
Context Reference
Initialization parameters ROLLBACK_SEGMENTS
TRANSACTIONS
TRANSACTIONS_PER_ROLLBACK_SEGMENTS
MAX_ROLLBACK_SEGMENTS
Dynamic performance views V$ROLLNAME
V$ROLLSTAT
V$TRANSACTION
V$SESSION
Data dictionary views DBA_ROLLBACK_SEGS
Commands CREATE ROLLBACK SEGMENT
ALTER ROLLBACK SEGMENT ONLINE
ALTER ROLLBACK SEGMENT STORAGE
ALTER ROLLBACK SEGMENT SHRINK
ALTER ROLLBACK SEGMENT OFFLINE
DROP ROLLBACK SEGMENT
SET TRANSACTION USE ROLLBACK SEGMENT

11
Managing Temporary
Segments
11-2 Oracle8: Database Administration



.
Lesson 11: Managing Temporary Segments
Instructor Note
Topic Timing
Lecture 20 minutes
Practice 20 minutes
Total 40 minutes
Oracle8: Database Administration 11-3


.
Objectives
Objectives
11-2
Copyright  Oracle Corporation, 1998. All rights reserved.
Objectives
• Distinguishing the different types of
temporary segments
• Allocating space for temporary
segments within a database
• Obtaining temporary segment
information for a database or instance
11-4 Oracle8: Database Administration


.
Lesson 11: Managing Temporary Segments
Overview

Temporary Segment Usage
Temporary segments are used when statements such as the following are
executed and the Oracle server cannot perform the sorting needed in
memory:
• SELECT. . . ORDER BY
• CREATE INDEX
• SELECT DISTINCT
• SELECT. . . GROUP BY
• SELECT. . . UNION
The amount of memory used by a process for sorting is determined by the
SORT_AREA_SIZE initialization parameter. If the sort volume exceeds this
size, several sort runs are needed, and intermediate results are stored on disk.
Temporary segments are created and used by the Oracle server in the
tablespace that has been assigned to the user for sorting.
11-3
Copyright  Oracle Corporation, 1998. All rights reserved.
Temporary Segment
Data file
Memory
SORT_AREA_SIZE
Oracle8: Database Administration 11-5


.
Overview
Note
• Since SORT_AREA_SIZE affects memory used by each session,
increasing it might increase the memory requirement significantly.
• Assigning tablespaces for sorts is discussed in the lesson “Managing
Users.”

• A discussion on specifying SORT_AREA_SIZE is made in the course
Oracle8: Performance Tuning.
Instructor Note
When using MTS, memory is allocated for sorts in the SGA.
11-6 Oracle8: Database Administration


.
Lesson 11: Managing Temporary Segments
Types of Temporary Segments
Temporary segments may be created either in a PERMANENT tablespace or
in a TEMPORARY tablespace. A user may be assigned one of these types of
tablespaces for sorting.
Temporary Tablespace
A TEMPORARY tablespace is used exclusively for temporary segments and
cannot have any other type of segment. They can be created as
TEMPORARY by using the following command:
CREATE TABLESPACE tablespace_name TEMPORARY
DATAFILE filespec [autoextend_clause]
[ , filespec [autoextend_clause]]
A PERMANENT tablespace can be changed into a TEMPORARY
tablespace by using:
ALTER TABLESPACE tablespace_name TEMPORARY
A tablespace cannot contain any permanent objects for this command to be
successful. A temporary tablespace can be converted into a PERMANENT
tablespace by using the following command:
ALTER TABLESPACE tablespace_name PERMANENT
11-4
Copyright  Oracle Corporation, 1998. All rights reserved.
Types of Temporary Segments

Temporary
tablespace
Permanent
tablespace
Memory
Oracle8: Database Administration 11-7


.
Types of Temporary Segments
The Oracle server may create a temporary segment in a PERMANENT
tablespace if the following conditions are satisfied:
• The user executes a statement needing sort space on disk.
• The user running the statement has been assigned a PERMANENT
tablespace for sorting.
If a PERMANENT tablespace is used for sorting, an instance may have
more than one temporary segment in the tablespace.
A temporary segment is dropped by SMON on completion of a statement
and space is released for use by other objects. If PERMANENT tablespaces
are used for sorting, the free space in the tablespace may be highly
fragmented. So it is recommended that this tablespace be used exclusively
for sorts.
11-5
Copyright  Oracle Corporation, 1998. All rights reserved.
Temporary Segments
in a Permanent Tablespace
• Created when needed on a per
transaction basis
• Reclaimed by SMON when the
statement completes execution

11-8 Oracle8: Database Administration


.
Lesson 11: Managing Temporary Segments
If TEMPORARY tablespaces are used for temporary segments, an instance
only creates one sort segment in this tablespace. Several transactions
requiring disk sorts can use the same segment. An extent cannot be shared
by multiple transactions.
Use of Sort Segments
A sort segment is created by the first statement that uses a TEMPORARY
tablespace for sorting, after startup. A sort segment created in a
TEMPORARY tablespace is released only at shutdown. This decreases the
frequent allocation and deallocation of extents by operations needing sorts
and helps improve performance. There is no limit to the number of extents
for a sort segment created in a TEMPORARY tablespace.
Sort Extent Pool
The Oracle server maintains sort segment details in the SGA in an area
called the Sort Extent Pool, and any statement that needs to allocate space
for sorting in the tablespace checks this common pool for free extents.
11-6
Copyright  Oracle Corporation, 1998. All rights reserved.
Temporary Segments
in a Temporary Tablespace
• Known as sort segments
• Only one segment per tablespace per
instance
• Created when the first disk sort occurs
in the instance after startup
• Reused by several transactions based

on information in the Sort Extent Pool
• Released on instance shutdown
Oracle8: Database Administration 11-9


.
Allocating Space for Temporary Segments
Allocating Space for Temporary Segments
Create and use TEMPORARY tablespaces for sorting to improve
concurrency and to decrease frequent allocation and deallocation of space.
The sizes of the extents used by a temporary segment are governed by the
DEFAULT STORAGE clause specified for the tablespace.
Specifying Default Storage
Use the following guidelines to specify DEFAULT STORAGE:
• Set INITIAL=NEXT. Since a process always writes data equal to
SORT_AREA_SIZE to a temporary segment, a good value for the extent
size is (n*s + b)
where: n is a positive integer
s is the value of SORT_AREA_SIZE initialization parameter
b is the value of DB_BLOCK_SIZE initialization parameter
Using this value optimizes temporary segment usage by allowing for
sufficient space for a header block and multiple sort run data to be stored
in each extent.
11-7
Copyright  Oracle Corporation, 1998. All rights reserved.
Guidelines
for Temporary Segments
• Set up different TEMPORARY tablespaces
based on sorting needs
• Specify DEFAULT STORAGE for these

tablespaces as shown:
– INITIAL= NEXT = (multiple of
SORT_AREA_SIZE) + DB_BLOCK_SIZE
– PCTINCREASE = 0
11-10 Oracle8: Database Administration


.
Lesson 11: Managing Temporary Segments
• Specify a PCTINCREASE of zero to ensure that all extents are of the
same size.
• The MAXEXTENTS parameter only affects a temporary segment if the
tablespace is a PERMANENT tablespace.
Note
Create tablespaces with different default storage clauses and assign them to
users based on their sorting needs.
Oracle8: Database Administration 11-11


.
Obtaining Temporary Segment Information
Obtaining Temporary Segment Information
The following views can be used to obtain information about temporary
segments and their usage:
• DBA_SEGMENTS
Query this view to get information on both types of temporary segments.
• V$SORT_SEGMENT
This view gives the status of the sort extent pool used by the instance.
• V$SORT_USAGE
This view only shows currently active sorts for the instance.

11-8
Copyright  Oracle Corporation, 1998. All rights reserved.
Obtaining Information for a
Database Instance
DBA_SEGMENTS
V$SORT_SEGMENT
V$SORT_USAGE

×