DBA 常用的10個SQL
1: SGA
select (case when pool is null then 'Buffer cache'
else pool end) "SGA area",round(sum(sga.megs),1) megs
from (
select pool,name,sum(bytes)/(1000*1024) megs
from V$SGASTAT
group by pool,name
) sga
where pool is not null
group by pool
else pool end) "SGA area",round(sum(sga.megs),1) megs
from (
select pool,name,sum(bytes)/(1000*1024) megs
from V$SGASTAT
group by pool,name
) sga
where pool is not null
group by pool
union
select name "SGA area",round(sum(bytes)/(1000*1024),1) megs
from V$SGASTAT
where pool is null
group by name
from V$SGASTAT
where pool is null
group by name
B: Shared pool
SELECT name,bytes / (1024 * 1024) megs
FROM v$sgastat
WHERE pool = 'shared pool'
AND name IN ('sql area',
'dictionary cache',
'library cache',
'free memory',
'miscellaneous'
)
ORDER BY megs desc
FROM v$sgastat
WHERE pool = 'shared pool'
AND name IN ('sql area',
'dictionary cache',
'library cache',
'free memory',
'miscellaneous'
)
ORDER BY megs desc
2: Instance
SELECT
instance_number,instance_name,host_name,version,startup_time,
status,parallel,thread#,archiver,log_switch_wait,
logins,shutdown_pending,database_status,instance_role
FROM v$instance
instance_number,instance_name,host_name,version,startup_time,
status,parallel,thread#,archiver,log_switch_wait,
logins,shutdown_pending,database_status,instance_role
FROM v$instance
3: database
SELECT
name,created,log_mode,checkpoint_change#,
archive_change#,controlfile_type,controlfile_created,controlfile_sequence#,controlfile_change#,
controlfile_time,open_resetlogs,version_time,open_mode
FROM v$DATABASE
name,created,log_mode,checkpoint_change#,
archive_change#,controlfile_type,controlfile_created,controlfile_sequence#,controlfile_change#,
controlfile_time,open_resetlogs,version_time,open_mode
FROM v$DATABASE
4: Options
select parameter "Parameter",value "Value" from v$option
[@more@]
5: Parameters select name "Options",value "Setting",isdefault "Default",description "Description",
isses_modifiable "Session modified"
from v$parameter
isses_modifiable "Session modified"
from v$parameter
6:Toad Session SQL
/* Formatted by PL/Formatter v2.2.0.4 on 2005/03/15 15:18 */
SELECT machine "Machine",
process "Process",
osuser "OS user",
username "User name",
schemaname "Schema name",
status "Status",
lockwait "Lockwait",
sid "SID",
serial# "Serial",
module "Module",
action "Action"
FROM v$session
WHERE schemaname <> 'SYS'
ORDER BY machine desc
SELECT machine "Machine",
process "Process",
osuser "OS user",
username "User name",
schemaname "Schema name",
status "Status",
lockwait "Lockwait",
sid "SID",
serial# "Serial",
module "Module",
action "Action"
FROM v$session
WHERE schemaname <> 'SYS'
ORDER BY machine desc
7: Top Sessions
SELECT s.username, s.sid, s.serial#, upper(decode(s.command, 1, 'Create Table',
2, 'Insert', 3, 'Select', 4, 'Create Cluster', 5, 'Alter Cluster', 6,
'Update', 7, 'Delete', 8, 'Drop Cluster', 9, 'Create Index', 10,
'Drop INdex', 11, 'ALter Index', 12, 'Drop Table', 13, 'Create Sequence',
14, 'ALter Sequence', 15, 'ALter Table', 16, 'Drop Sequence', 17,
'Grant', 18, 'Revoke', 19, 'Create Synonym', 20, 'Drop Synonym', 21,
'Create View', 22, 'Drop View', 23, 'Validate Index', 24,
'Create Procedure', 25, 'Alter Procedure', 26, 'Lock Table', 27,
'No Operation', 28, 'Rename', 29, 'Comment', 30, 'Audit', 31, 'NoAudit',
32, 'Create Database Link', 33, 'Drop Database Link', 34,
'Create Database', 35, 'Alter Database', 36, 'Create Rollback Segment',
37, 'Alter Rollback Segment', 38, 'Drop Rollback Segment', 39,
'Create Tablespace', 40, 'ALter Tablespace', 41, 'Drop TAblespace', 42,
'ALter Sessions', 43, 'ALter User', 44, 'Commit', 45, 'Rollback', 46,
'Savepoint', 47, 'PL/SQL Execute', 48, 'Set Transaction', 49,
'ALter System switch Log', 50, 'Explain Plan', 51, 'Create User', 52,
'Create Role', 53, 'Drop User', 54, 'Drop Role', 55, 'Set Role', 56,
'Create Schema', 57, 'Create Control File', 58, 'ALter Tracing', 59,
'Create Trigger', 60, 'Alter Trigger', 61, 'Drop Trigger', 62,
'Analyze Table', 63, 'Analyze Index', 64, 'Analyze Cluster', 65,
'Create Profile', 66, 'Drop Profile', 67, 'Alter Profile', 68,
'Drop Procedure', 69, 'Drop Procedure', 70, 'Alter Resource Cost', 71,
'Create Snapshot Log', 72, 'ALter Snapshot LOg', 73, 'Drop Snapshot Log',
74, 'Create Snapshot', 75, 'Alter Snapshot', 76, 'Drop Snapshot', 79,
'ALter Role', 85, 'Truncate Table', 86, 'Truncate Cluster', 88,
'Alter View', 91, 'Create Function', 92, 'ALter Function', 93,
'Drop FUnction', 94, 'Create Package', 95, 'ALter Package', 96,
'Drop Package', 97, 'Create Package Body', 98, 'ALter Package Body', 99,
'Drop Package Body')) command, t.value cpu_time,
i.physical_reads phy_reads, i.block_gets blk_gets, s.status, s.lockwait,
q.sql_text, s.sql_hash_value
FROM v$session s, v$sesstat t, v$statname n, v$sess_io i, v$sqlarea q
WHERE s.username IS NOT NULL
AND (t.value > 100
OR i.physical_reads > 100
OR i.block_gets > 100)
AND s.sid = t.sid
AND t.statistic# = n.statistic#
AND n.name = 'CPU used by this session'
AND s.sid = i.sid
AND s.sql_address = q.address
AND s.sql_hash_value = q.hash_value
ORDER BY t.value DESC
2, 'Insert', 3, 'Select', 4, 'Create Cluster', 5, 'Alter Cluster', 6,
'Update', 7, 'Delete', 8, 'Drop Cluster', 9, 'Create Index', 10,
'Drop INdex', 11, 'ALter Index', 12, 'Drop Table', 13, 'Create Sequence',
14, 'ALter Sequence', 15, 'ALter Table', 16, 'Drop Sequence', 17,
'Grant', 18, 'Revoke', 19, 'Create Synonym', 20, 'Drop Synonym', 21,
'Create View', 22, 'Drop View', 23, 'Validate Index', 24,
'Create Procedure', 25, 'Alter Procedure', 26, 'Lock Table', 27,
'No Operation', 28, 'Rename', 29, 'Comment', 30, 'Audit', 31, 'NoAudit',
32, 'Create Database Link', 33, 'Drop Database Link', 34,
'Create Database', 35, 'Alter Database', 36, 'Create Rollback Segment',
37, 'Alter Rollback Segment', 38, 'Drop Rollback Segment', 39,
'Create Tablespace', 40, 'ALter Tablespace', 41, 'Drop TAblespace', 42,
'ALter Sessions', 43, 'ALter User', 44, 'Commit', 45, 'Rollback', 46,
'Savepoint', 47, 'PL/SQL Execute', 48, 'Set Transaction', 49,
'ALter System switch Log', 50, 'Explain Plan', 51, 'Create User', 52,
'Create Role', 53, 'Drop User', 54, 'Drop Role', 55, 'Set Role', 56,
'Create Schema', 57, 'Create Control File', 58, 'ALter Tracing', 59,
'Create Trigger', 60, 'Alter Trigger', 61, 'Drop Trigger', 62,
'Analyze Table', 63, 'Analyze Index', 64, 'Analyze Cluster', 65,
'Create Profile', 66, 'Drop Profile', 67, 'Alter Profile', 68,
'Drop Procedure', 69, 'Drop Procedure', 70, 'Alter Resource Cost', 71,
'Create Snapshot Log', 72, 'ALter Snapshot LOg', 73, 'Drop Snapshot Log',
74, 'Create Snapshot', 75, 'Alter Snapshot', 76, 'Drop Snapshot', 79,
'ALter Role', 85, 'Truncate Table', 86, 'Truncate Cluster', 88,
'Alter View', 91, 'Create Function', 92, 'ALter Function', 93,
'Drop FUnction', 94, 'Create Package', 95, 'ALter Package', 96,
'Drop Package', 97, 'Create Package Body', 98, 'ALter Package Body', 99,
'Drop Package Body')) command, t.value cpu_time,
i.physical_reads phy_reads, i.block_gets blk_gets, s.status, s.lockwait,
q.sql_text, s.sql_hash_value
FROM v$session s, v$sesstat t, v$statname n, v$sess_io i, v$sqlarea q
WHERE s.username IS NOT NULL
AND (t.value > 100
OR i.physical_reads > 100
OR i.block_gets > 100)
AND s.sid = t.sid
AND t.statistic# = n.statistic#
AND n.name = 'CPU used by this session'
AND s.sid = i.sid
AND s.sql_address = q.address
AND s.sql_hash_value = q.hash_value
ORDER BY t.value DESC
8: RBS Active:
select n.usn,n.name,s.tablespace_name,l.status,s.initial_extent,s.next_extent,
l.extents,s.BYTES,l.RSSIZE,l.xacts "Active Trans"
from V$ROLLNAME N ,V$ROLLSTAT L,dba_segments S
where n.usn=l.usn
and s.segment_name=n.name
and s.SEGMENT_TYPE='ROLLBACK'
l.extents,s.BYTES,l.RSSIZE,l.xacts "Active Trans"
from V$ROLLNAME N ,V$ROLLSTAT L,dba_segments S
where n.usn=l.usn
and s.segment_name=n.name
and s.SEGMENT_TYPE='ROLLBACK'
9: Space Used
SELECT s.tablespace_name "Tablespace",
-- "Megs Alloc","Megs Free","Megs Used","Pct Free","Pct Used",
df.total "Megs Alloc", fs.bytes "Megs Free",df.total-fs.bytes "Megs Used",
(fs.bytes/df.total)*100 "Pct Free %" ,(100-(fs.bytes/df.total)*100) "Pct Used",
s.initial_extent/(1024*1024) "Init Ext",nvl(s.next_extent/(1024*1024),0) "Next Ext",s.min_extents/(1024*1024) "Min Ext",s.max_extents/(1024*1024) "Max Ext",
s.status "Status",s.contents "Contents",s.allocation_type "Allocation_type"
from DBA_TABLESPACES S,
( select tablespace_name,sum(bytes/(1024*1024)) bytes
from DBA_FREE_SPACE
group by tablespace_name ) FS,
( select tablespace_name,SUM(BYTES/(1024*1024)) total
from DBA_DATA_FILES
group by tablespace_name) DF
where s.tablespace_name=Fs.tablespace_name
and s.tablespace_name=df.tablespace_name
-- "Megs Alloc","Megs Free","Megs Used","Pct Free","Pct Used",
df.total "Megs Alloc", fs.bytes "Megs Free",df.total-fs.bytes "Megs Used",
(fs.bytes/df.total)*100 "Pct Free %" ,(100-(fs.bytes/df.total)*100) "Pct Used",
s.initial_extent/(1024*1024) "Init Ext",nvl(s.next_extent/(1024*1024),0) "Next Ext",s.min_extents/(1024*1024) "Min Ext",s.max_extents/(1024*1024) "Max Ext",
s.status "Status",s.contents "Contents",s.allocation_type "Allocation_type"
from DBA_TABLESPACES S,
( select tablespace_name,sum(bytes/(1024*1024)) bytes
from DBA_FREE_SPACE
group by tablespace_name ) FS,
( select tablespace_name,SUM(BYTES/(1024*1024)) total
from DBA_DATA_FILES
group by tablespace_name) DF
where s.tablespace_name=Fs.tablespace_name
and s.tablespace_name=df.tablespace_name
10: Datafile I/O (Cannot Get totalIO and total block IO)
select df.tablespace_name "Tablespace",df.file_name "Filename",ft.phyrds "Reads",
ft.PHYBLKRD "Block Read",
ft.phywrts "Write",ft.PHYBLKWRT "Block write"
from dba_data_files df,V$FILESTAT ft
where df.file_id=ft.file#
ft.phywrts "Write",ft.PHYBLKWRT "Block write"
from dba_data_files df,V$FILESTAT ft
where df.file_id=ft.file#
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/34596/viewspace-800451/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DBA常用SQLSQL
- GreenPlum DBA常用SQLSQL
- dba 常用維護sqlSQL
- DBA常用SQL語句SQL
- Oracle DBA常用sql分享OracleSQL
- sqlserver dba常用的sql語句SQLServer
- DBA常用SQL語句[sql server] 2SQLServer
- dba常用sql-1(轉)SQL
- dba常用sql-2(轉)SQL
- dba常用sql-3(轉)SQL
- DBA常用SQL語句系列SQL
- dolphindb dba一些常用的維護sqlSQL
- DBA常用的一些SQL和檢視SQL
- postgresql dba常用sql查詢語句SQL
- DBA常用的一些SQL和檢視(轉)SQL
- 2010年:給SQL Server DBA的三個建議SQLServer
- DBA常用資料庫管理SQL (摘錄整理)資料庫SQL
- ORACLE DBA常用SQL指令碼工具->管理篇(zt)OracleSQL指令碼
- ORACLE DBA必須記住的常用SQL命令和檢視OracleSQL
- 5個讓DBA愛上你的SQL技巧SQL
- ORACLE DBA常用SQL指令碼工具->管理篇(1) (轉)OracleSQL指令碼
- 8個DBA最常用的監控Oracle資料庫的常用shell指令碼Oracle資料庫指令碼
- 8個DBA最常用的監控Oracle資料庫的常用shell指令碼--Oracle資料庫指令碼
- DBA常用的linux命令Linux
- 8個DBA最常用的監控Oracle資料庫的常用shell指令碼--轉Oracle資料庫指令碼
- dba常用指令碼指令碼
- Oracle資料庫DBA日常Sql列表及常用檢視(轉)Oracle資料庫SQL
- mongodb dba常用的nosql語句MongoDBSQL
- 【UNIX】DBA常用的linux命令Linux
- SQL優化常用方法10SQL優化
- Oracle dba 常用檢視Oracle
- Oracle DBA常用查詢Oracle
- 常用的sqlSQL
- MongoDB DBA常用的NoSQL語句(全)MongoDBSQL
- mysql dba常用的查詢語句MySql
- sql server dba大牛的祕籍SQLServer
- flutter10個常用的元件Flutter元件
- 史上最全:PostgreSQL DBA常用SQL查詢語句(建議收藏學習)SQL