Script For Tablespace Utilization Alert With UTL MAIL Package - Smart Way of Technology
Script For Tablespace Utilization Alert With UTL MAIL Package - Smart Way of Technology
REPORT THIS AD
UTL_MAIL is the oracle internal utility for sending mail through the database.
2. Need to create UTL_MAIL package if not exists in oracle Environment with following script:
SQL> @$ORACLE_HOME/rdbms/admin/utlmail.sql;
SQL> @$ORACLE_HOME/rdbms/admin/prvtmail.sql;
3. If you want to execute from specific user you need to give execute permission on it.
Script:
create or replace procedure Proc_emailalert_tablespace_70
as
var_name VARCHAR2(35);
var_hostname VARCHAR2(25);
var_mode VARCHAR2(10);
var_result NUMBER;
var VARCHAR2(5000);
var_Date varchar2(15);
CURSOR cn IS
SELECT a.tablespace_name,
a.bytes_alloc/(1024*1024*1024) "TOTAL_ALLOC_GB",
a.physical_bytes/(1024*1024*1024) "TOTAL_PHYS_ALLOC_GB",
nvl(b.tot_used,0)/(1024*1024*1024) "USED_GB",
(a.bytes_alloc-b.tot_used)/(1024*1024*1024) "FREE_GB",
(nvl(b.tot_used,0)/a.bytes_alloc)*100 "PERC_USED"
FROM
(SELECT tablespace_name,
sum(bytes) physical_bytes,
sum(decode(autoextensible,'NO',bytes,'YES',maxbytes)) bytes_alloc
FROM dba_data_files
GROUP BY tablespace_name ) a,
(SELECT
tablespace_name,
sum(bytes) tot_used
FROM dba_segments
GROUP BY tablespace_name ) b
BEGIN
var_result := 0;
var := '';
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<th>Tablespace Name</th>
<th>Alloc Space(GB)</th>
<th>Physical Alloc(GB)</th>
<th>Used(GB)</th>
<th>Free(GB)</th>
<th>Percent Used</th>
</tr>';
-- Loop for calculating multiple tablspace output having more than 70%
for data_cur in cn
loop
var_result := 1;
<td>'||data_cur.tablespace_name||'</td>
<td>'||to_char(DATA_CUR.TOTAL_ALLOC_GB,9999999.99)||'</td>
<td>'||to_char(data_cur.TOTAL_PHYS_ALLOC_GB,9999999.99)||'</td>
<td>'||to_char(data_cur.USED_GB,9999999.99)||'</td>
<td>'||to_char(data_cur.FREE_GB,9999999.99)||'</td>
<td>'||to_char(data_cur.perc_used,999.99)||'</td>
</tr>';
end loop;
var := var||'
</tbody>
</table>
<br></br>
';
---dbms_output.put_line(var);
-- Sending Mail Utility in HTML format.
end if;
end;
Output
This entry was posted in Oracle and tagged Script, send alert of tablespace, Send mail for tablespace alert, UTL_MAIL
on February 16, 2015 [https://smarttechways.com/2015/02/16/configured-tablespace-utilization-mail-alert-from-
utl_mail-package/] by SandeepSingh DBA.
This site uses Akismet to reduce spam. Learn how your comment data is processed.