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 分钟前
性能飙升!KingbaseES V9R2C13 Windows安装与优化特性深度实测
数据库
梦里不知身是客111 分钟前
Doris 中主键模型的读时合并模式
数据库·sql·linq
GanGuaGua7 分钟前
MySQL:复合查询
数据库·mysql·oracle
gugugu.7 分钟前
MySQL事务深度解析:从ACID到MVCC的实现原理
数据库·mysql·oracle
狮子也疯狂11 分钟前
【天翼AI-星辰智能体平台】| 基于Excel表实现智能问数助手智能体开发实战
人工智能·oracle·excel
DechinPhy12 分钟前
使用Python免费合并PDF文件
开发语言·数据库·python·mysql·pdf
杨了个杨898234 分钟前
PostgreSQL 完全备份与还原
数据库·postgresql
爱吃KFC的大肥羊35 分钟前
Redis持久化详解(一):RDB快照机制深度解析
数据库·redis·缓存
黎明破晓.38 分钟前
Redis
数据库·redis·缓存
Dovis(誓平步青云)44 分钟前
《MySQL从入门:基础安装与数据库核心概念全解析》
数据库·mysql