Question: I want to be able to see temporary
segments created and destroyed within my TEMP tablespace, and I
would also like to tie-in TEMP segments with the session that has
created the TEMP tables. Are these scripts to map the segments
in the TEMP tablespace?
Answer: Oracle uses the
TEMP tablespace for a variety of tasks, primarily for sorting rows,
and holding the intermediate row sets between n-way tables joins,
but also for temporary table row storage.
Both subquery factoring (WITH clause) and global temporary tables
will write the intermediate results to the TEMP tablespace.
Oracle stores GTT rows in the users temporary tablespace of the
user, but you can change this to a "real" tablespace by using the
tablespace clause of the create global temporary table
syntax.
You can check for held
TEMP segments with this query:
select
srt.tablespace,
srt.segfile#,
srt.segblk#,
srt.blocks,
a.sid,
a.serial#,
a.username,
a.osuser,
a.status
from
see code depot for full scripts
v$session a,
v$sort_usage srt
where
a.saddr = srt.session_addr
order by
srt.tablespace, srt.segfile#, srt.segblk#,
srt.blocks;
The
Oracle script collection has a script that will display all TEMP
segments in the TEMP tablespace,
but Oracle does not have any way to join v$session information into
the actual objects created within the TEMP tablespace.
For sorting in the TEMP tablespace, the
v$sort_usage view can be queried to see what session is storing
temporary segments in the TEMP tablespace:
select
(select
username
from
v$session
where
saddr = session_addr) uname,
v.*
from
v$sort_usage v;
The v$sort_usage will show more than
just disk sorts. The sort segment in v$sort_usage can be
temporary tables, open cursors or some temporary LOBs.
select
a.name,
b.value
from
v$statname a,
v$sesstat b,
v$session
s,
v$sort_usage su
where
a.statistic#=b.statistic#
and
b.sid=s.sid
and
s.saddr=su.session_addr;
|
|
|
|
Guarantee your Success!
Oracle is the
world's most complex, robust and flexible database, considered
impossible to master without a mentor.
That's why all BC
Oracle trainers are working professionals, experts in Oracle who
share their tips and secrets. |
|
| |
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright ? 1996 - 2012
All rights reserved.
Oracle ?
is the registered trademark of Oracle Corporation.
|
|