--查詢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;
--查詢占用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;
一些實用的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 s...
一些實用的DBA語句之二(慢慢更新)
前一篇隨筆被我寫的亂七八糟的,於是新開一塊。從庫建好了的準備工作開始寫吧。1 建立表空間 f size 50m autoextend on next 50m maxsize 1024m 上面是一次只要乙個資料檔案的,下面的是乙個以上檔案的 oracl wings tf02.dbf size 50m ...
SQL 一些常見實用的函式方法 持續學習更新中
1.group concat distinct 要連線的字段 order by 排序字段 asc desc separator 分隔符 常用語分組查詢,下圖是資料庫表資料和字段 查詢sql select group concat third name as values second name as...