Chinaunix首页 | 论坛 | 博客
  • 博客访问: 667039
  • 博文数量: 128
  • 博客积分: 265
  • 博客等级: 二等列兵
  • 技术积分: 1464
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-27 20:44
个人简介

just do it

文章分类

全部博文(128)

文章存档

2023年(1)

2020年(1)

2019年(1)

2018年(3)

2017年(6)

2016年(17)

2015年(16)

2014年(39)

2013年(34)

2012年(10)

分类: Oracle

2016-08-03 20:27:28

--查询表空间使用情况

点击(此处)折叠或打开

  1. set line 132

  2. set wrap off

  3. select t.*

  4. from (SELECT D.TABLESPACE_NAME,

  5. SPACE "SUM_SPACE(M)",

  6. BLOCKS SUM_BLOCKS,

  7. SPACE - NVL(FREE_SPACE, 0) "USED_SPACE(M)",

  8. ROUND((1 - NVL(FREE_SPACE, 0) / SPACE) * 100, 2) "USED_RATE(%)",

  9. FREE_SPACE "FREE_SPACE(M)"

  10. FROM (SELECT TABLESPACE_NAME,

  11. ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,

  12. SUM(BLOCKS) BLOCKS

  13. FROM DBA_DATA_FILES

  14. GROUP BY TABLESPACE_NAME) D,

  15. (SELECT TABLESPACE_NAME,

  16. ROUND(SUM(BYTES) / (1024 * 1024), 2) FREE_SPACE

  17. FROM DBA_FREE_SPACE

  18. GROUP BY TABLESPACE_NAME) F

  19. WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+)

  20. UNION ALL --if have tempfile

  21. SELECT D.TABLESPACE_NAME,

  22. SPACE "SUM_SPACE(M)",

  23. BLOCKS SUM_BLOCKS,

  24. USED_SPACE "USED_SPACE(M)",

  25. ROUND(NVL(USED_SPACE, 0) / SPACE * 100, 2) "USED_RATE(%)",

  26. SPACE - USED_SPACE "FREE_SPACE(M)"

  27. FROM (SELECT TABLESPACE_NAME,

  28. ROUND(SUM(BYTES) / (1024 * 1024), 2) SPACE,

  29. SUM(BLOCKS) BLOCKS

  30. FROM DBA_TEMP_FILES

  31. GROUP BY TABLESPACE_NAME) D,

  32. (SELECT TABLESPACE,

  33. ROUND(SUM(BLOCKS * 8192) / (1024 * 1024), 2) USED_SPACE

  34. FROM V$SORT_USAGE

  35. GROUP BY TABLESPACE) F

  36. WHERE D.TABLESPACE_NAME = F.TABLESPACE(+)) t
  37. order by "USED_RATE(%)" desc;


观察undo表空间的变化情况
------undospace usage-------

点击(此处)折叠或打开

  1. SELECT DISTINCT STATUS, SUM(BYTES)/1024/1024, COUNT(*) FROM DBA_UNDO_EXTENTS WHERE tablespace_name = 'UNDOTBS1' GROUP BY STATUS;



--快速查找锁并kill进程

点击(此处)折叠或打开

  1. SELECT a.sid,d.spid,e.event,C.SQL_TEXT,B.USERNAME,B.OSUSER,B.MACHINE,B.PROGRAM
  2. FROM V$SESS_IO A,V$SESSION B,V$SQL C,V$PROCESS D,v$session_wait e
  3. WHERE A.SID=B.SID AND B.SQL_HASH_VALUE=C.HASH_VALUE and B.sid=E.sid
  4. AND B.PADDR=D.ADDR and A.sid in(select sid from v$Lock where block=1);
Kill -9 spid这列即可

点击(此处)折叠或打开

  1. SELECT d.spid,a.sid,e.event,C.SQL_TEXT,B.USERNAME,B.OSUSER,B.MACHINE,B.PROGRAM
  2. FROM V$SESS_IO A,V$SESSION B,V$SQL C,V$PROCESS D,v$session_wait e
  3. WHERE A.SID=B.SID AND B.SQL_HASH_VALUE=C.HASH_VALUE and B.sid=E.sid
  4. AND B.PADDR=D.ADDR and A.sid in(select sid from v$session_wait where event not in('SQL*Net message from client','rdbms ipc message','SQL*Net message to client'));


SELECT d.spid,a.sid,e.event,C.SQL_TEXT,B.USERNAME,B.OSUSER,B.MACHINE,B.PROGRAM
FROM V$SESS_IO A,V$SESSION B,V$SQL C,V$PROCESS D,v$session_wait e
WHERE a.sid=285

--数据库服务器字符集

点击(此处)折叠或打开

  1. select * from nls_database_parameters
--查询出最大的表

点击(此处)折叠或打开

  1. select * from (select segment_name,sum(bytes)/1024/1024/1024 as s from user_segments
  2. where segment_type like 'TABLE%' group by segment_name order by s desc)

  3. select sum(S) from (select segment_name,sum(bytes)/1024/1024/1024 as s from user_segments
  4. where segment_type like 'TABLE%' group by segment_name order by s desc)
删除用户下所有表的语句:

点击(此处)折叠或打开

  1. select 'drop table '||table_name||' cascade constraints;' from user_tables;
监控索引重建的进度:

点击(此处)折叠或打开

  1. col opname format a32
  2. col target_desc format a32
  3. col perwork format a12
  4. set lines 131
  5. select sid,OPNAME,TARGET_DESC,sofar,TOTALWORK,trunc(sofar/totalwork*100,2)||'%' as perwork from v$session_longops where sofar!=totalwork;

查看每天产生归档日志的数据量:

点击(此处)折叠或打开

  1. select
  2. trunc(completion_time) as "Date"
  3. ,count(*) as "Count"
  4. ,(sum(blocks * block_size)) /1024 /1024) as "MB"
  5. from v$archived_log
  6. group by trunc(completion_time);

点击(此处)折叠或打开

  1. 对于非归档库:

  2. select to_char(first_time,'yyyy-mm-dd') day,count(*) from v$log_history group by to_char(first_time,'yyyy-mm-dd') order by day desc;

  3. 大小得出来再乘以日志大小,就可以算归档量了。



阅读(1570) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~