首页 > 代码库 > Oracle 一些实用的DBA语句
Oracle 一些实用的DBA语句
--查询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 BWHERE A.SEGMENT_NAME = B.SEGMENT_NAMEORDER 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 SWHERE S.TADDR = T.ADDRAND T.XIDUSN = R.USNAND R.USN = U.USNORDER 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语句
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。