Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Oracle query the use of tablespaces

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how Oracle queries the use of tablespaces". In the operation process of actual cases, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

--Query table space usage

SELECT UPPER(F.TABLESPACE_NAME) Tablespace name,

D.TOT_GROOTTE_MB "Tablespace size",

D.TOT_GROOTTE_MB - F.TOTAL_BYTES "Used Space",

TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') ||'%' "usage ratio",

F.TOTAL_BYTES "free space",

F.MAX_BYTES "Maximum block"

FROM (SELECT TABLESPACE_NAME,

ROUND(SUM(BYTES) / (1024 * 1024), 2) TOTAL_BYTES,

ROUND(MAX(BYTES) / (1024 * 1024), 2) MAX_BYTES

FROM SYS.DBA_FREE_SPACE

GROUP BY TABLESPACE_NAME) F,

(SELECT DD.TABLESPACE_NAME,

ROUND(SUM(DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB

FROM SYS.DBA_DATA_FILES DD

GROUP BY DD.TABLESPACE_NAME) D

WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME

ORDER BY 1;

--Query free space of table space

select tablespace_name,

count(*) as extends,

round(sum(bytes) / 1024 / 1024, 2) as MB,

sum(blocks) as blocks

from dba_free_space

group by tablespace_name;

--Query the total capacity of the table space

select tablespace_name, sum(bytes) / 1024 / 1024 as MB

from dba_data_files

group by tablespace_name;

--Query Tablespace Usage

select total.tablespace_name,

round(total.MB, 2) as Total_MB

round(total.MB - free.MB, 2) as Used_MB,

round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct

from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB

from dba_free_space

group by tablespace_name) free,

(select tablespace_name, sum(bytes) / 1024 / 1024 as MB

from dba_data_files

group by tablespace_name) total

where free.tablespace_name = total.tablespace_name;

1. The SQL to find the current table-level lock is as follows:

select sess.sid,

sess.serial#,

lo.oracle_username,

lo.os_user_name,

ao.object_name,

lo.locked_mode

from v$locked_object lo,

dba_objects ao,

v$session sess

where ao.object_id = lo.object_id and lo.session_id = sess.sid;

2. Kill lock table process:

alter system kill session '436,35123';

3. Lock lookup in RAC environment:

SELECT inst_id,DECODE(request,0,'Holder: ','Waiter: ')||sid sess,

id1, id2, lmode, request, type,block,ctime

FROM GV$LOCK

WHERE (id1, id2, type) IN

(SELECT id1, id2, type FROM GV$LOCK WHERE request>0)

ORDER BY id1, request;

4. Monitor current database who is running what SQL statements

select osuser, username, sql_text

from v$session a, v$sqltext b

where a.sql_address =b.address order by address, piece;

5. Find user sessions that use more CPU

select a.sid,spid,status,substr(a.program,1,40) prog, a.terminal,osuser,value/60/100 value

from v$session a,v$process b,v$sesstat c

where c.statistic#=12 and

c.sid=a.sid and

a.paddr=b.addr

order by value desc;

6. View deadlock information

SELECT (SELECT username

FROM v$session

WHERE SID = a.SID) blocker, a.SID, 'is blocking',

(SELECT username

FROM v$session

WHERE SID = b.SID) blockee, b.SID

FROM v$lock a, v$lock b

WHERE a.BLOCK = 1 AND b.request > 0 AND a.id1 = b.id1 AND a.id2 = b.id2;

7. Object with highest wait

SELECT o.OWNER,o.object_name, o.object_type, a.event,

SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, dba_objects o

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

AND a.current_obj# = o.object_id

GROUP BY o.OWNER,o.object_name, o.object_type, a.event

ORDER BY total_wait_time DESC;

SELECT a.session_id, s.osuser, s.machine, s.program, o.owner, o.object_name,

o.object_type, a.event,

SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, dba_objects o, v$session s

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

AND a.current_obj# = o.object_id

AND a.session_id = s.SID

GROUP BY o.owner,

o.object_name,

o.object_type,

a.event,

a.session_id,

s.program,

s.machine,

s.osuser

ORDER BY total_wait_time DESC;

8. Query the number of currently connected sessions

select s.value,s.sid,a.username

from

v$sesstat S,v$statname N,v$session A

where

n.statistic#=s.statistic# and

name='session pga memory'

and s.sid=a.sid

order by s.value;

9. Users waiting the most

SELECT s.SID, s.username, SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, v$session s

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

GROUP BY s.SID, s.username

ORDER BY total_wait_time DESC;

10. The Most Waited SQL

SELECT a.program, a.session_id, a.user_id, d.username, s.sql_text,

SUM (a.wait_time + a.time_waited) total_wait_time

FROM v$active_session_history a, v$sqlarea s, dba_users d

WHERE a.sample_time BETWEEN SYSDATE - 30 / 2880 AND SYSDATE

AND a.sql_id = s.sql_id

AND a.user_id = d.user_id

GROUP BY a.program, a.session_id, a.user_id, s.sql_text, d.username;

11. View the most resource-consuming SQL

SELECT hash_value, executions, buffer_gets, disk_reads, parse_calls

FROM V$SQLAREA

WHERE buffer_gets > 10000000 OR disk_reads > 1000000

ORDER BY buffer_gets + 100 * disk_reads DESC;

12. View the resource consumption of an SQL statement

SELECT hash_value, buffer_gets, disk_reads, executions, parse_calls

FROM V$SQLAREA

WHERE hash_Value = 228801498 AND address = hextoraw('CBD8E4B0');

13. Query the actual SQL executed by the session

SELECT a.SID, a.username, s.sql_text

FROM v$session a, v$sqltext s

WHERE a.sql_address = s.address

AND a.sql_hash_value = s.hash_value

AND a.status = 'ACTIVE'

ORDER BY a.username, a.SID, s.piece;

14. Show all sessions waiting for lock

SELECT * FROM DBA_WAITERS;

"Oracle how to query the use of table space" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 273

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report