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
Oracle匯出空表資料庫
經常我們在匯出資料庫進行備份的時候,會發現有些空表沒有匯出,如何匯出包含空表的完整資料庫呢?那麼請按照下面的方法進行即可。1.使用plsql工具,連線oracle資料庫 2.開啟乙個sql視窗,用以下這句查詢空表並生成執行命令 1select alter table table name alloc...
Oracle資料庫空值操作
空值操作 null表示空的意思。一 情況 1 表中的任何字段預設情況下都可以為null值。2 not null表示非空,是一種約束 設定為非空約束的字段,必須有有效值,不能為空。3 插入資料時 reg insert into emp ename,empno values 2001,張三 此記錄中,沒...
nagios監控oralce資料庫的表空間大小
一 安裝nrpe 本處使用直接解壓的方式來安裝的nrpe 二 配置nrpe服務 1.修改libexec資料夾中的check oracle 在其中新增如下項 1 2 oracle home oradata oracle product 11.2.0 path path oradata oracle p...