码迷,mamicode.com
首页 > 数据库 > 详细

Oracle 一些实用的DBA语句

时间:2014-11-17 19:22:06      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:des   blog   io   os   使用   sp   for   文件   数据   

--查询LOB的大小和所在表空间
SELECT A.TABLE_NAME,
       A.COLUMN_NAME,
       B.SEGMENT_NAME,
       B.SEGMENT_TYPE,
       B.TABLESPACE_NAME,
       round((B.BYTES / 1024 / 1024 / 1024),2)
  FROM USER_LOBS A, USER_SEGMENTS B
WHERE A.SEGMENT_NAME = B.SEGMENT_NAME
ORDER BY B.BYTES DESC;

--查询查询一个表空间上所有表的大小
select us.segment_name, us.segment_type,us.tablespace_name,
  us.tablespace_name,
  round((us.BYTES/1024/1024/1024),2)
  from user_segments us
 where us.tablespace_name = ‘‘;


--查询特定一些表的大小,可以更换查询关键字
select segment_name,
       alt.OWNER
       tablespace_name,
       segment_type,
       round((BYTES /1024/1024/1024), 2) as "大小(GB)"
  from user_segments, all_tables alt
 where segment_type = ‘TABLE‘
   and segment_name like ‘%%‘
   and alt.TABLE_NAME = segment_name
   order by tablespace_name, BYTES desc;


--查询当前表空间的使用情况
SELECT a.tablespace_name "表空间名",
       total/1024/1024 表空间大小,
       trunc((free/1024/1024),2) 表空间剩余大小,
       trunc(((total - free)/1024/1024),2) 表空间使用大小,
       ROUND((total - free) / total, 4) * 100 "使用率%"
  FROM (SELECT tablespace_name, SUM(bytes) free
          FROM DBA_FREE_SPACE
         GROUP BY tablespace_name) a,
       (SELECT tablespace_name, SUM(bytes) total
          FROM DBA_DATA_FILES
         GROUP BY tablespace_name) b
 WHERE a.tablespace_name = b.tablespace_name;


?/*查询锁表情况*/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

  

?/*1 统计数据表的num_row  2 统计索引列的distinct_keys  3 计算distinct_keys/num_rows的值,  该值越接近1,则列的选择度越高,  索引的效率就越高*/ analyze table schema.tablename compute statistics for all indexes for all columns; --收集最新的信息 select ut.num_rows, ui.distinct_keys, round((ui.distinct_keys/ut.num_rows), 2) from user_indexes ui, user_tables ut where ui.table_name = upper(‘tablename‘) and ui.index_name = upper(‘indexname‘) and ut.table_name = ui.table_name; /*比较笨的办法,纯手工统计,计算*/select count(*) from schema.tablename; --统计出了表的总行数select distinct(ind_row) from schema.tablename; --统计索引所在列的distinct值--之后就是纯手工计算了

?/*查询等待事件*/SELECT event,       sum(decode(wait_time, 0, 1, 0)) "当前等待",       sum(decode(wait_time, 0, 0, 1)) "当前未在等待",       count(*) "Total"  FROM v$session_wait GROUP BY event ORDER BY count(*) desc;  select a.EVENT, count(*)  from v$session_wait a group by a.EVENT, a.WAIT_CLASS# order by count(*) desc;<br><br>

--查询占用UNDO的用户相关情况
SELECT S.USERNAME, U.NAME, S.SID, S.SERIAL#
FROM V$TRANSACTION T, V$ROLLSTAT R, V$ROLLNAME U, V$SESSION S
WHERE S.TADDR = T.ADDR
AND T.XIDUSN = R.USN
AND R.USN = U.USN
ORDER BY S.USERNAME;

 

  --锁定、解锁账户语句
   alter user username account lock;
   alter user username account unlock;
   --修改用户密码,如果遇到ORA-28001错误也可如此解决
   alter user username identified by password;
   --手工扩大一个数据文件
   alter database datafile ‘/data/data_file1.dbf‘ resize 10G;
?

 

Oracle 一些实用的DBA语句

标签:des   blog   io   os   使用   sp   for   文件   数据   

原文地址:http://www.cnblogs.com/jameslif/p/4104104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!