System表空间不足的报警问题浅析
程序员文章站
2022-03-17 13:38:15
废话不多说了,具体代码如下所示:
--system表空间不足的报警
登录之后,查询,发现是sys.aud$占的地方太多。
sql> select...
废话不多说了,具体代码如下所示:
--system表空间不足的报警 登录之后,查询,发现是sys.aud$占的地方太多。 sql> select owner, segment_name, segment_type, sum(bytes)/1024/1024 space_m from dba_segments where tablespace_name = 'system' group by owner, segment_name, segment_type having sum(bytes)/1024/1024 >= 20 order by space_m desc ; 4 5 6 7 owner segment_name segment_type space_m -------- ------------------------------- ------- sys aud$ table 4480 sys idl_ub1$ table 272 sys source$ table 72 sys idl_ub2$ table 32 sys c_obj#_intcol# cluster 27 sys c_toid_version# cluster 24 6 rows selected. sql> 查看是哪个记得比较多。 col userhost format a30 select userid, userhost, count(1) from sys.aud$ where ntimestamp# >=cast(to_date('2014-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) group by userid, userhost having count(1) > 500 order by count(1) desc ; 再继续找哪天比较多。 select to_char(ntimestamp#, 'yyyy-mm-dd') audit_date, count(1) from sys.aud$ where ntimestamp# >=cast(to_date('2014-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and userid = 'xxxx' and userhost = 'xxxx' group by to_char(ntimestamp#, 'yyyy-mm-dd') order by count(1) desc ; select spare1, count(1) from sys.aud$ where ntimestamp# between cast(to_date('2014-03-10 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and cast(to_date('2014-03-11 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and userid = 'xxxx' and userhost = 'xxxx' group by spare1 ; select action#, count(1) from sys.aud$ where ntimestamp# between cast(to_date('2014-03-10 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and cast(to_date('2014-03-11 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and userid = 'xxxx' and userhost = 'xxxx' and spare1 = 'xxxx' group by action# order by count(1) desc ; 结果如下: action# count(1) ---------- ---------- 101 124043 100 124043 sql> 其实是上次打开的audit一直没有关闭。 关闭: sql> noaudit session; 清空: truncate table sys.aud$; ------------------------------------------------------------------------ 实战 ------------------------------------------------------------------------ --1,查询表空间占用情况 select dbf.tablespace_name as tablespace_name, dbf.totalspace as totalspace, dbf.totalblocks as totalblocks, dfs.freespace freespace, dfs.freeblocks freeblocks, (dfs.freespace / dbf.totalspace) * 100 as freerate from (select t.tablespace_name, sum(t.bytes) / 1024 / 1024 totalspace, sum(t.blocks) totalblocks from dba_data_files t group by t.tablespace_name) dbf, (select tt.tablespace_name, sum(tt.bytes) / 1024 / 1024 freespace, sum(tt.blocks) freeblocks from dba_free_space tt group by tt.tablespace_name) dfs where trim(dbf.tablespace_name) = trim(dfs.tablespace_name) --2,查看哪里占的比较多 system 为step1中查询 tablespace_name 内容 select owner, segment_name, segment_type, sum(bytes)/1024/1024 space_m from dba_segments where tablespace_name = 'system' group by owner, segment_name, segment_type having sum(bytes)/1024/1024 >= 20 order by space_m desc --3,查看是哪个记得比较多 count(1) 越大,说明占得比较多 select userid, userhost, count(1) from sys.aud$ where ntimestamp# >=cast(to_date('2014-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) group by userid, userhost having count(1) > 500 order by count(1) desc --4,再继续找哪天比较多 userid userhost 为上一步查询内容 select to_char(ntimestamp#, 'yyyy-mm-dd') audit_date, count(1) from sys.aud$ where ntimestamp# >=cast(to_date('2015-03-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and userid = 'userid' and userhost = 'userhost' group by to_char(ntimestamp#, 'yyyy-mm-dd') order by count(1) desc ; select spare1, count(1) from sys.aud$ where ntimestamp# between cast(to_date('2016-03-10 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and cast(to_date('2016-12-11 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and userid = 'userid' and userhost = 'userhost' group by spare1 ; --spare1 为上一步查询内容 select action#, count(1) from sys.aud$ where ntimestamp# between cast(to_date('2016-03-10 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and cast(to_date('2016-12-11 00:00:00', 'yyyy-mm-dd hh24:mi:ss') as timestamp) and userid = 'userid' and userhost = 'userhost' and spare1 = 'administrator' group by action# order by count(1) desc --5,关闭seeion noaudit session; --6,清空: truncate table sys.aud$;
总结
以上所述是小编给大家介绍的system表空间不足的报警,希望对大家有所帮助