Oracle-查询表空间使用率很慢

近期发现,因数据库监控指标采集比较频繁,甚至触发等待。

解决方案如下:

1、调整采集周期。现行的10S采集频率太高。

2、优化表空间查询语句。

3、考虑回收站原因:

3.1:查询回收站大小:

SYS@evansdb2> SELECT count(*) FROM dba_recyclebin;

COUNT(*)


127

SYS@evansdb2> SELECT value FROM v$parameter WHERE name = 'recyclebin';

VALUE


OFF

3.3:清空全库回收站

SYS@evansdb2> purge DBA_RECYCLEBIN;

DBA Recyclebin purged.

3.4 再次查询回收站大小:

SYS@evansdb2> SELECT count(*) FROM dba_recyclebin;

COUNT(*)


0

3.5 再次查询回收站大小:

SYS@evansdb2> SELECT count(*) FROM dba_recyclebin;

COUNT(*)


0

3.6 收集统计信息:

SYS@evansdb2> exec dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'RECYCLEBIN$', estimate_percent => 100, method_opt=> 'for all indexed columns',degree=>8);

PL/SQL procedure successfully completed.

3.7 重新查询表空间使用率

SYS@evansdb2> set linesize 200 pagesize 999 long 20000

set timi on ti on

col name format a30

col contents format a9

col extent_management format a8

col size_mb format a12

col Used_MB format a12

col free_mb format a12

col "Used%" format a8

col dt format a20

SELECT d.tablespace_name Name,

d.status,

d.contents,

d.extent_management,

d.segment_space_management,

a.file_cnt,

TO_CHAR(NVL(a.bytes/1048576, 0), '999G999G999') SIZE_MB,

TO_CHAR(DECODE(d.contents,'UNDO',NVL(u.bytes, 0)/1048576,NVL(a.bytes - NVL(f.bytes, 0), 0)/1048576),'999G999G999') Used_MB,

TO_CHAR(DECODE(d.contents,'UNDO',NVL(a.bytes - NVL(u.bytes, 0), 0)/1048576,NVL(f.bytes, 0)/1048576), '999G999G999') FREE_MB,

TO_CHAR(DECODE(d.contents,'UNDO',NVL(u.bytes/a.bytes * 100, 0),NVL((a.bytes - NVL(f.bytes, 0))/a.bytes * 100, 0)),'990D00') "Used%",

TO_CHAR(sysdate, 'yyyy-mm-dd hh24:mi:ss') dt

FROM sys.dba_tablespaces d,

(SELECT tablespace_name, SUM(bytes) bytes, COUNT(file_id) file_cnt

from dba_data_files

GROUP BY tablespace_name) a,

(select tablespace_name, sum(bytes) bytes

from dba_free_space

group by tablespace_name) f,

(SELECT tablespace_name, SUM(bytes) bytes

FROM (SELECT tablespace_name, sum(bytes) bytes, status

from dba_undo_extents

WHERE status = 'ACTIVE'

group by tablespace_name, status

UNION ALL

SELECT tablespace_name, sum(bytes) bytes, status

from dba_undo_extents

WHERE status = 'UNEXPIRED'

group by tablespace_name, status)

group by tablespace_name) u

WHERE d.tablespace_name = a.tablespace_name(+)

AND d.tablespace_name = f.tablespace_name(+)

AND d.tablespace_name = u.tablespace_name(+)

AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY')

UNION ALL

SELECT d.tablespace_name,

d.status,

d.contents,

d.extent_management,

d.segment_space_management,

a.file_cnt,

TO_CHAR(NVL(a.bytes/1048576, 0), '999G999G999') SIZE_MB,

TO_CHAR(NVL(t.bytes, 0)/1048576, '999G999G999') Used_MB,

TO_CHAR((NVL(a.bytes, 0)/1048576 - NVL(t.bytes, 0)/1048576),'999G999G999') FREE_MB,

TO_CHAR(NVL(t.bytes/a.bytes * 100, 0), '990D00') "Used%",

TO_CHAR(sysdate, 'yyyy-mm-dd hh24:mi:ss') dt

FROM sys.dba_tablespaces d,

(select tablespace_name, sum(bytes) bytes, count(file_id) file_cnt

from dba_temp_files

group by tablespace_name) a,

(select ss.tablespace_name,

sum((ss.used_blocks * ts.blocksize)) bytes

from gvsort_segment ss, sys.ts ts

where ss.tablespace_name = ts.name

group by ss.tablespace_name) t

WHERE d.tablespace_name = a.tablespace_name(+)

AND d.tablespace_name = t.tablespace_name(+)

AND d.extent_management = 'LOCAL'

AND d.contents = 'TEMPORARY'

ORDER BY "Used%";

相关推荐
三天不学习1 分钟前
【Select 语法全解密】.NET开源ORM框架 SqlSugar 系列
数据库·.net·orm·微软技术·sqlsugar
CC呢14 分钟前
基于单片机的智能婴儿床监护系统多功能婴儿床摇篮系统
数据库·mongodb
林的快手1 小时前
209.长度最小的子数组
java·数据结构·数据库·python·算法·leetcode
HEU_firejef2 小时前
Redis——缓存预热+缓存雪崩+缓存击穿+缓存穿透
数据库·redis·缓存
KELLENSHAW2 小时前
MySQL45讲 第三十七讲 什么时候会使用内部临时表?——阅读总结
数据库·mysql
SelectDB3 小时前
飞轮科技荣获中国电信星海大数据最佳合作伙伴奖!
大数据·数据库·数据分析
core5123 小时前
flink cdc各种数据库 jar下载地址
mysql·oracle·flink·jar·oceanbase·cdc
小刘鸭!3 小时前
Hbase的特点、特性
大数据·数据库·hbase
凡人的AI工具箱4 小时前
每天40分玩转Django:Django表单集
开发语言·数据库·后端·python·缓存·django
奔跑草-4 小时前
【数据库】SQL应该如何针对数据倾斜问题进行优化
数据库·后端·sql·ubuntu