dba 常用查詢

2021-07-26 15:50:25 字數 2578 閱讀 7507

1.檢視表空間

select a.tablespace_name as "tablespace name",a.total_size as "total size", round(b.total_free_size,1) as "total free size",round((a.total_size-b.total_free_size),2) as "used size",to_char(100*b.total_free_size/a.total_size,'99.99')||'%' as "percent free" from (select tablespace_name,sum(bytes)/1024/1024 as total_size from dba_data_files group by tablespace_name) a,(select tablespace_name,sum(bytes/1024/1024) as total_free_size from dba_free_space group by tablespace_name) b where a.tablespace_name=b.tablespace_name;

2.檢查chained

1)create table test.chained_rows(

owner_name          varchar2(30),

table_name     varchar2(30),

cluster_name   varchar2(30),

partition_name varchar2(30),

subpartition_name varchar2(30),

head_rowid rowid,

analyze_timestamp date);

2)select 'analyze table '||owner||'.'||table_name||' list chained rows into test.chained_rows;' from dba_tables where owner='test';

3)analyze table test.world list chained rows into test.chained_rows;

select b.owner_name as "owner",

a.table_name as "table name",

b.row_count as "row count",

a.num_rows as "total rows"

from all_tables a,

(select b.owner_name,b.table_name,count(b.head_rowid) row_count

from chained_rows b

group by b.owner_name,b.table_name) b

where a.table_name=b.table_name;

3.檢查表空間碎片

select tablespace_name as "tablespace name",sqrt(max(blocks)/sum(blocks))*(100/sqrt((count(blocks)))) as "fsfi%" from dba_free_space group by tablespace_name order by 1;

fsfi:可用破碎表空間索引(free space fragmentation indx,fsfi)

數值最大值為100,表示完全沒有破碎的空間,數值越低代表空間碎片越嚴重,通常低於30%就需要進行重整操作

4.檢查索引

select index_name,index_type,table_name,status from dba_indexes where status='unsable';

5.檢查新增失效物件

select owner object_owner,object_name,object_type,status from dba_objects where owner not in('sys','system') and status='invalid' order by owner,object_type,object_name;

6.每月表空間增長

select a.ts# as "tablespace no",b.name as "tablespace name",to_char(a.creation_time,'rrrr month') "month",sum(a.bytes)/1024/1024/1024 "growth in gb" from sys.v_$datafile a,sys.v_$tablespace b where a.creation_time>sysdate-365 and a.ts#=b.ts# group by a.ts#,b.name,to_char(a.creation_time,'rrrr month');

7.每月資料庫增長

select to_char(creation_time,'rrrr month') "month",sum(bytes)/1024/1024/1024 "growth in gb" from sys.v_$datafile where creation_time>sysdate-365 group by to_char(creation_time,'rrrr month');

常用DBA指令碼

1 表空間統計 a 指令碼說明 這是我最常用的乙個指令碼,用它可以顯示出資料庫中所有表空間的狀態,如表空間的大小 已使用空間 使用的百分比 空閒空間數及現在表空間的最大塊是多大。b 指令碼原文 select upper f.tablespace name 表空間名 d.tot grootte mb ...

dba mysql命令 Mysql常用DBA命令

1 連線mysql伺服器 mysql h host u user p password database 不建議直接在命令列直接輸入密碼,因為密碼會以明文顯示在命令列,不安全。連線mysql伺服器可能會報以下錯誤 error 1130 hy000 host hostname is not allow...

DBA常用的Linux命令

1.按oraclesid來查詢連線資料庫的客戶端ip netstat anpt grep oraclesid awk grep o e 1.awk f sort2.按監聽埠1521來查詢連線資料庫的客戶端ip netstat anpt grep 1521 awk grep o e 1.awk f s...