查询表空间使用情况

转载自http://www.cnblogs.com/askjacklin/archive/2012/06/04/2534571.html

--查询表空间使用情况
  SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
  D.TOT_GROOTTE_MB "表空间大小(M)",
  D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
  TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),‘990.99‘) || ‘%‘ "使用比",
  F.TOTAL_BYTES "空闲空间(M)",
  F.MAX_BYTES "最大块(M)"
  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;
  --查询表空间的free 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;

  --查询表空间的总容量
  select tablespace_name, sum(bytes) / 1024 / 1024 as MB
  from dba_data_files
  group by tablespace_name;

  --查询表空间使用率
  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.查找当前表级锁的SQL如下: 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.杀掉锁表进程: alter system kill session ‘436,35123‘;

3.RAC环境中锁查找: 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.监控当前数据库谁在运行什么SQL语句 select osuser, username, sql_text  from  v$session a, v$sqltext b where  a.sql_address =b.address order by address, piece;

5.找使用CPU多的用户session 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.查看死锁信息 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.具有最高等待的对象 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.查询当前连接会话数 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.等待最多的用户 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.等待最多的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.查看消耗资源最多的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.查看某条SQL语句的资源消耗 SELECT hash_value, buffer_gets, disk_reads, executions, parse_calls FROM V$SQLAREA WHERE hash_Value = 228801498 AND address = hextoraw(‘CBD8E4B0‘);

13.查询会话执行的实际SQL 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.显示正在等待锁的所有会话 SELECT * FROM DBA_WAITERS;

时间: 2024-10-08 16:41:23

查询表空间使用情况的相关文章

oracle增加表空间的四种方法,查询表空间使用情况

增加表空间大小的四种方法Meathod1:给表空间增加数据文件ALTER TABLESPACE app_data ADD DATAFILE'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF' SIZE 50M; Meathod2:新增数据文件,并且允许数据文件自动增长ALTER TABLESPACE app_data ADD DATAFILE'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP04.DBF'

Oracle如何查询表空间使用情况?Oracle扩展表空间的方法

一.查询表空间使用情况 select a.tablespace_name as "表空间名",        a.bytes / 1024 / 1024 as "表空间大小(M)",        (a.bytes - b.bytes) / 1024 / 1024 as "已使用空间(M)",        b.bytes / 1024 / 1024 "空闲空间(M)",        round(((a.bytes - b.

ORACLE ASM中查询表空间使用情况、数据文件路径、裸设备磁盘总大小剩余大小

在ASM中:查询所有磁盘名称.总大小.剩余大小:单位MB-----查看组的信息(总大小)select name,total_mb, free_mb from v$asm_diskgroup; ---查看磁盘成员信息分别大小select name,total_mb,free_mb from v$asm_disk; 或者: [[email protected]]asmcmdASMCMD>lsdg 查询表空间数据文件路径和总大小:单位MBSELECT tablespace_name,file_id,f

Oracle查询表空间使用情况

SELECT UPPER(F.TABLESPACE_NAME) "表空间名", D.TOT_GROOTTE_MB "表空间大小(M)", D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)", TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100, 2), '990.99') "使用比", F.TOT

[笔记] 查询表记录空间占用情况SQL脚本

USE ExpressDB CREATE TABLE #tablespaceinfo ( nameinfo VARCHAR(50) , rowsinfo BIGINT , reserved VARCHAR(20) , datainfo VARCHAR(20) , index_size VARCHAR(20) , unused VARCHAR(20) ) --创建游标 DECLARE Info_cursor CURSOR FOR SELECT '[' + [name] + ']' FROM sys

SqlServer数据库空间使用情况常用命令

--最简单的办法就是使用SSM客户端,报表查看 --查询数据文件的空间情况 dbcc showfilestats --查询日志文件的空间情况 dbcc sqlperf(logspace) --查询tempdb的空间情况 select * from sys.dm_db_file_space_usage --查询表的占用空间情况 exec sys_viewTableSpace --请慎用,对性能有影响 --dbcc showconfig() --日志诊断方法 select name,recovery

三、查看Oracle表空间使用情况

1.查询表空间的总容量 select a.TABLESPACE_NAME, sum(a.BYTES) / 1024 / 1024 as MB from sys.dba_data_files a group by a.TABLESPACE_NAME 2.查询表空间的空闲容量 select b.TABLESPACE_NAME, count(1) as extends, sum(b.BYTES) / 1024 / 1024 as MB, sum(b.BLOCKS) as blocks from sys

收集2012集群共享卷空间使用情况,并用邮件通知管理员

从Windows2012开始,ClusterStorageVolume不再是直接以盘符的方式出现了,在我的电脑中,无法直接看到,而是显示在C:\ClusterStorage\下面 如果要查看大小.使用状态,需要进到Failover Cluster Managert管理界面,进到存储设备.磁盘.然后选某一个卷,才可以查大小.空间使用情况等: 或是进到磁盘管理界面的选中磁盘.右键.属性查看 之前我有发一个收集服务器硬盘空间的工具,http://hubuxcg.blog.51cto.com/25594

df和du显示的磁盘空间使用情况不一致的原因及处理

在Linux下查看磁盘空间使用情况,最常使用的就是du和df了.然而两者还是有很大区别的,有时候其输出结果甚至非常悬殊. 1. 如何记忆这两个命令 du-Disk Usage df-Disk Free 2. df 和du 的工作原理 2.1 du的工作原理 du命令会对待统计文件逐个调用fstat这个系统调用,获取文件大小.它的数据是基于文件获取的,所以有很大的灵活性,不一定非要针对一个分区,可以跨越多个分区操作.如果针对的目录中文件很多,du速度就会很慢了. 2.2 df的工作原理 df命令使