如果数据字典熟悉,可以写更多好用的SQL,集成在一起,做个监控工具
查看需要使用绑定变量的SQL
select substr(sql_text, 1, 40), count(*), sum(sharable_mem) / 1024 / 1024 "MEM" from gv$sql a group by substr(sql_text, 1, 40) having count(*) > 20 order by MEM DESC;
2.在本库也可根据v$session表来查看有哪些别的库连过来:
select * from v$session where taddr is not null;
3.查看对表进行了那些操作 (找出的是SQL语句)
SELECT * FROM GV$SQL WHERE UPPER(SQL_TEXT) LIKE '%CT_CFG_CCSUSER%' AND LAST_ACTIVE_TIME > TRUNC(SYSDATE);
4.查看表占用的空间
select s.segment_name, round((bytes / 1024 / 1024 / 1024), 1) || 'G' as 占用空间G from user_segments s where s.segment_type = 'TABLE' and (bytes / 1024 / 1024 / 1024) > 1 order by bytes desc
5.查看消耗大的SQL
select a.EXECUTIONS as 执行次数, round(a.cpu_time / 1000 / 60) || 'm' as CPU耗时, a.sql_text as SQL from v$sqlarea a where (a.BUFFER_GETS > 10000000 or a.DISK_READS > 1000000) and ((a.sql_text like 'select%') or (a.sql_text like 'SELECT%')) order by a.BUFFER_GETS + 100 * a.DISK_READS, a.EXECUTIONS, a.cpu_time DESC;
6.查询所登陆用户的数据断存储在哪个表空间,由多大,有几个区
select segment_name,tablespace_namel,bytes,blocks from user_extents;
7.查看锁
select s.INST_ID, object_name, machine, s.program, s.sid, s.serial#, p.spid, 'alter system kill session ''' || s.sid || ',' || s.serial# || ''' immediate; ' from gv$locked_object l, dba_objects o, gv$session s, gv$process p where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr;
8.查看IO吞吐量
select d.tablespace_name TABLESPACE, d.file_name FILENAME, a.PHYRDS PHYRDS, a.PHYWRTS PHYWRTS from v$filestat a, dba_data_files d where a.FILE# = d.file_id and rownum <= 10 order by a.PHYRDS DESC;
9、查看表空间物理文件的名称及大小
select tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space from dba_data_files order by tablespace_name; select tablespace_name, round(sum(bytes) / 1024 / 1024 / 1024, 0) as "物理文件(G)" from dba_data_files group by tablespace_name;
10.查询数据库CPU使用率
select * from v$osstat AS OF TIMESTAMP(sysdate-1/12); select AVG_BUSY_TIME/(AVG_BUSY_TIME+AVG_IDLE_TIME) from dual;
11.看SQL的执行次数 [EXECUTIONS_DELTA就是你两个快照内SQL的执行次数]
select * from gv$sql a where a.SQL_TEXT like '% distinct M.MEDIA_TYPE_ID%'; select * from dba_hist_sqlstat a where a.sql_id='f6f46ubynwkjt';
12.查看无效的索引
select 'alter index ' || a.index_name || ' rebuild tablespace ' || tablespace_name || ' parallel 6 nologging;', 'alter index ' || a.index_name || ' noparallel;', a.status, a.degree from dba_indexes a where a.status = 'UNUSABLE';
13 .等待事件
SELECT event, sum(decode(wait_time, 0, 1, 0)) "Curr", sum(decode(wait_time, 0, 0, 1)) "Prev", count(*) "Total" FROM v$session_wait GROUP BY event ORDER BY count(*);