如何监控oracle自动增长表空间
2017-10-09 · 知道合伙人软件行家
关注
展开全部
1.跟踪数据库空间增长
SELECT SUM(MB_ALLOC)/1024 GB_DB_SIZE FROM
(SELECT SUM(ROUND(bytes_used/(1024*1024),2) + ROUND(bytes_free/(1024*1024),2)) MB_ALLOC
FROM V$temp_space_header, dba_temp_files
WHERE V$temp_space_header.file_id (+) = dba_temp_files.file_id
UNION
SELECT SUM(BYTES)/(1024*1024) MB_ALLOC FROM dba_data_files);
2.下面例子除了undo和temp表空间外,将其他表空间的的使用情况记录每周插入db_spaec_hist表,以便查询:
Create the table for database size history create table db_space_hist (
timestamp date,
total_space number(8),
used_space number(8),
free_space number(8),
pct_inuse number(5,2),
num_db_files number(5)
);
Create the procedure db_space_history CREATE OR REPLACE PROCEDURE db_space_history AS
BEGIN
INSERT INTO db_space_hist
SELECT SYSDATE, total_space,
total_space-NVL(free_space,0) used_space,
NVL(free_space,0) free_space,
((total_space - NVL(free_space,0)) / total_space)*100 pct_inuse,
num_db_files
FROM ( SELECT SUM(bytes)/1024/1024 free_space
FROM sys.DBA_FREE_SPACE WHERE tablespace_name NOT LIKE '%UNDO%') FREE,
( SELECT SUM(bytes)/1024/1024 total_space,
COUNT(*) num_db_files
FROM sys.DBA_DATA_FILES WHERE tablespace_name NOT LIKE '%UNDO%') FULL;
COMMIT;
END;
/
Create the job that runs once in a week DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
(
job => X
,what => 'SYS.DB_SPACE_HISTORY;'
,next_date => TO_DATE('22/02/2008 19:40:28','dd/mm/yyyy hh24:mi:ss')
,INTERVAL => 'TRUNC(SYSDATE+7)'
,no_parse => FALSE
);
END;
3.做周期性监控
select * from db_space_hist order by timestamp desc;
4.查询结果(每月数据库的增长情况),统计的出发条件为createion_time.
SELECT TO_CHAR(creation_time, 'RRRR Month') "Month", round(SUM(bytes)/1024/1024/1024) "Growth in GBytes"
FROM sys.v_$datafile
WHERE creation_time > SYSDATE-365
GROUP BY TO_CHAR(creation_time, 'RRRR Month');
Month Growth in GBytes
-------------- ----------------
2008 December 1331
2008 November 779
2008 October 447
2009 April 797
2009 August 344
2009 February 505
2009 January 443
2009 July 358
2009 June 650
2009 March 452
2009 May 1787
2009 October 255
2009 September 158
SELECT SUM(MB_ALLOC)/1024 GB_DB_SIZE FROM
(SELECT SUM(ROUND(bytes_used/(1024*1024),2) + ROUND(bytes_free/(1024*1024),2)) MB_ALLOC
FROM V$temp_space_header, dba_temp_files
WHERE V$temp_space_header.file_id (+) = dba_temp_files.file_id
UNION
SELECT SUM(BYTES)/(1024*1024) MB_ALLOC FROM dba_data_files);
2.下面例子除了undo和temp表空间外,将其他表空间的的使用情况记录每周插入db_spaec_hist表,以便查询:
Create the table for database size history create table db_space_hist (
timestamp date,
total_space number(8),
used_space number(8),
free_space number(8),
pct_inuse number(5,2),
num_db_files number(5)
);
Create the procedure db_space_history CREATE OR REPLACE PROCEDURE db_space_history AS
BEGIN
INSERT INTO db_space_hist
SELECT SYSDATE, total_space,
total_space-NVL(free_space,0) used_space,
NVL(free_space,0) free_space,
((total_space - NVL(free_space,0)) / total_space)*100 pct_inuse,
num_db_files
FROM ( SELECT SUM(bytes)/1024/1024 free_space
FROM sys.DBA_FREE_SPACE WHERE tablespace_name NOT LIKE '%UNDO%') FREE,
( SELECT SUM(bytes)/1024/1024 total_space,
COUNT(*) num_db_files
FROM sys.DBA_DATA_FILES WHERE tablespace_name NOT LIKE '%UNDO%') FULL;
COMMIT;
END;
/
Create the job that runs once in a week DECLARE
X NUMBER;
BEGIN
SYS.DBMS_JOB.SUBMIT
(
job => X
,what => 'SYS.DB_SPACE_HISTORY;'
,next_date => TO_DATE('22/02/2008 19:40:28','dd/mm/yyyy hh24:mi:ss')
,INTERVAL => 'TRUNC(SYSDATE+7)'
,no_parse => FALSE
);
END;
3.做周期性监控
select * from db_space_hist order by timestamp desc;
4.查询结果(每月数据库的增长情况),统计的出发条件为createion_time.
SELECT TO_CHAR(creation_time, 'RRRR Month') "Month", round(SUM(bytes)/1024/1024/1024) "Growth in GBytes"
FROM sys.v_$datafile
WHERE creation_time > SYSDATE-365
GROUP BY TO_CHAR(creation_time, 'RRRR Month');
Month Growth in GBytes
-------------- ----------------
2008 December 1331
2008 November 779
2008 October 447
2009 April 797
2009 August 344
2009 February 505
2009 January 443
2009 July 358
2009 June 650
2009 March 452
2009 May 1787
2009 October 255
2009 September 158
壹寰(深圳)科技文化有限公司
2021-03-27 广告
2021-03-27 广告
不同公司提供的方案也不一样。以上回答如果还觉得不够详细,可以来咨询下壹寰(深圳)科技文化有限公司。91数据恢复是壹寰(深圳)科技文化有限公司旗下专业数据恢复品牌,91数据恢复专注于勒索病毒数据恢复、勒索病毒数据修复、数据库修复、数据库解密恢...
点击进入详情页
本回答由壹寰(深圳)科技文化有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询