監控資料庫效能的SQL

2021-04-26 15:09:35 字數 4297 閱讀 9223

監控資料庫效能的sql

檢視tablespace的空間使用情況

select

tablespace_name,

sum(bytes)

/1024

/1024

from

dba_free_space

group

bytablespace_name

1. 監控事例的等待

select

event,

sum(decode(wait_time,0,

0,1)) "prev",

sum(decode(wait_time,0,

1,0)) "curr",

count(*

) "tot"

from

v$session_wait

group

byevent

orderby4

; 2. 回滾段的爭用情況

select

name, waits, gets, waits

/gets "ratio"

from

v$rollstat a, v$rollname b

where

a.usn

=b.usn;

3. 監控表空間的 i

/o 比例

select

df.tablespace_name name,df.

file_name

"file

",f.phyrds pyr,

f.phyblkrd pbr,f.phywrts pyw, f.phyblkwrt pbw

from

v$filestat f, dba_data_files df

where

f.file# =

df.file_id

order

bydf.tablespace_name;

4. 監控檔案系統的 i

/o 比例

select

substr(a.

file#,1

,2) "#", substr(a.name,1,

30) "name",

a.status, a.bytes, b.phyrds, b.phywrts

from

v$datafile a, v$filestat b

where

a.file# =

b.file

#; 5

.在某個使用者下找所有的索引

select

user_indexes.table_name, user_indexes.index_name,uniqueness, column_name

from

user_ind_columns, user_indexes

where

user_ind_columns.index_name

=user_indexes.index_name

anduser_ind_columns.table_name

=user_indexes.table_name

order

byuser_indexes.table_type, user_indexes.table_name,

user_indexes.index_name, column_position;

6. 監控 sga 的命中率

select

a.value

+b.value "logical_reads", c.value "phys_reads",

round

(100

*((a.value

+b.value)

-c.value)

/(a.value

+b.value)) "buffer hit ratio"

from

v$sysstat a, v$sysstat b, v$sysstat c

where

a.statistic# =38

andb.statistic# =39

andc.statistic# =40

; 7. 監控 sga 中字典緩衝區的命中率

select

parameter, gets,getmisses , getmisses

/(gets

+getmisses)

*100

"miss ratio", (1

-(sum(getmisses)/(

sum(gets)

+sum

(getmisses))))

*100

"hit ratio"

from

v$rowcache

where

gets

+getmisses

<>

0group

byparameter, gets, getmisses;

8. 監控 sga 中共享快取區的命中率,應該小於1

%select

sum(pins) "total pins",

sum(reloads) "total reloads",

sum(reloads)

/sum

(pins)

*100

libcache

from

v$librarycache;

select

sum(pinhits

-reloads)

/sum

(pins) "hit radio",

sum(reloads)

/sum

(pins) "reload

percent

" from

v$librarycache;

9. 顯示所有資料庫物件的類別和大小

select

count

(name) num_instances ,type ,

sum(source_size) source_size ,

sum(parsed_size) parsed_size ,

sum(code_size) code_size ,

sum(error_size) error_size,

sum(source_size)

+sum

(parsed_size)

+sum

(code_size)

+sum

(error_size) size_required

from

dba_object_size

group

bytype

orderby2

; 10

. 監控 sga 中重做日誌快取區的命中率,應該小於1

%select

name, gets, misses, immediate_gets, immediate_misses,

decode(gets,0,

0,misses

/gets

*100

) ratio1,

decode(immediate_gets

+immediate_misses,0,

0, immediate_misses

/(immediate_gets

+immediate_misses)

*100

) ratio2

from

v$latch

where

name in(

'redo allocation',

'redo copy

');

11. 監控記憶體和硬碟的排序比率,最好使它小於 .

10,增加 sort_area_size

select

name, value

from

v$sysstat

where

name in(

'sorts (memory)',

'sorts (disk)

');

12. 監控當前資料庫誰在執行什麼sql語句

select

osuser, username, sql_text

from

v$session a, v$sqltext b

where

a.sql_address

=b.address

order

byaddress, piece;

MySQL 資料庫 效能監控

show status flush status 檢視當前連線數 show status like thread thread cached 被快取的執行緒的個數 thread running 處於啟用狀態的執行緒的個數 thread connected 當前連線的執行緒的個數 thread cre...

MySQL 資料庫 效能監控

show status flush status 檢視當前連線數 show status like thread thread cached 被快取的執行緒的個數 thread running 處於啟用狀態的執行緒的個數 thread connected 當前連線的執行緒的個數 thread cre...

資料庫SQL效能查詢

作為乙個開發 測試人員,或多或少都得和資料庫打交道,而對資料庫的操作歸根到底都是sql語句,所有操作到最後都是運算元據,那麼對sql效能的掌控又成了我們工作中一件非常重要的工作。下面簡單介紹下一些檢視oracle效能的一些實用方法 1 查詢每台機器的連線數 select t.machine,coun...