-- directory create or replace directory UTIL_DIR as '/u01' / -- table CREATE TABLE T_OS_COMMAND ( v_line varchar2(4000) ) ORGANIZATION external ( TYPE oracle_loader DEFAULT DIRECTORY UTIL_DIR ACCESS PARAMETERS ( RECORDS DELIMITED BY NEWLINE preprocessor UTIL_DIR:'os_command.sh' FIELDS TERMINATED BY "\n" LDRTRIM ) location ( 'os_command.sh') ) /
$touch /u01/os_command.sh $chmod ug+x /u01/os_command.sh
declare F1 UTL_FILE.FILE_TYPE; begin F1 := UTL_FILE.FOPEN('UTIL_DIR','os_command.sh','W', 4048); UTL_FILE.PUT_LINE (file => F1, buffer => '#!/bin/sh'); UTL_FILE.PUT_LINE (file => F1, buffer => 'export LANG=en_US.UTF-8'); UTL_FILE.PUT_LINE (file => F1, buffer => 'export PATH=$PATH:/bin'); UTL_FILE.PUT_LINE (file => F1, buffer => 'df -k | grep /'); UTL_FILE.fclose (file => F1); end; /
/dev/sda2 32414672 14870956 15870548 49% / /dev/sda1 124427 18001 100002 16% /boot tmpfs 8219820 184808 8035012 3% /dev/shm /dev/sdb2 961432104 606013444 306580660 67% /u02
V_LINE |
---|
/ dev / sda2 32414672 14871076 15870428 49% / |
/ dev / sda1 124427 18001 100002 16% / boot |
tmpfs 8219820 184808 8035012 3% / dev / shm |
/ dev / sdb2 961432104 606013444 306580660 67% / u02 |
create or replace package P_SYS_UTILITY is -- Author : ALEXEY -- Created : 23.08.2013 -- Purpose : Get system info (*nix versions) /* Get on file or folder name its device or ASM group and used/free space on it * raw devices not supported */ procedure Get_Disk_Usage ( p_file_name in varchar2, -- file name (also accept only path) o_mount_dev out nocopy varchar2, -- device or ASM group o_used_space out number, -- used space o_free_space out number); -- free space -- Collect space USAGE in BD -- Recomended evry day schedule run procedure Collect_Usage; -- Get Forecast on space usage -- Recomended base from 10 collects function Get_Forecast ( pDT in date, -- date for forecast pBASE in integer default 188, -- base days in calculate forecast pTYPE_F in varchar2 default 'SLOPE', -- type forecast: SLOPE | AVG pTABLESPACE in varchar2 default null, -- tablespace ( null = all ) pOWNER in varchar2 default null, -- user ( null = all ) pTYPE in varchar2 default null ) -- segment type ( null = all ), allow like return number; -- size in bytes on date pDT -- Get score of space usage and availability -- Can be used in external monitoring tool : Nagios, etc function Get_Space_Status ( pFOREDAYS in number default 60, -- days after that pFREE_PRCNT in number default 25 ) -- free cpace greater than return number; -- 0 - Space free enough .. 100 - not enough free space end P_SYS_UTILITY;
create table T_SPACE_USAGE ( dt$ date, owner$ varchar2(30), tablespace$ varchar2(30), type$ varchar2(18), bytes$ number, blocks$ number); create index INDX_T_SPACE_USAGE_DT on T_SPACE_USAGE (dt$); comment on table T_SPACE_USAGE is 'Store archive data of usage space in RDBMS'; comment on column T_SPACE_USAGE.DT$ is 'Date collect space usage'; comment on column T_SPACE_USAGE.OWNER$ is 'Segment owner - user in BD'; comment on column T_SPACE_USAGE.TABLESPACE$ is 'Name of tablespace in BD'; comment on column T_SPACE_USAGE.TYPE$ is 'Segment type'; comment on column T_SPACE_USAGE.BYTES$ is 'Size in bytes'; comment on column T_SPACE_USAGE.BLOCKS$ is 'Size in blocks';
Source: https://habr.com/ru/post/191870/
All Articles