Calculate OS Size with Python

df.py #! /usr/bin/python # my first python attempt. # Mark Young 14 July 2016 import sys import os import subprocess def reportUsage(label, total, free): used = total – free print “%s=%dG, used=%dG (%d%%)” % (label, free, used, used*100/total) p = subprocess.Popen([“df”, “-k”, “.”], stdout=subprocess.PIPE) print p.stdout.read() rc = p.wait() stat = os.statvfs(“.”) total = (stat.f_bsize … Read more

Table size and Growth

select * from (SELECT o.OWNER , o.OBJECT_NAME , o.SUBOBJECT_NAME , o.OBJECT_TYPE , t.NAME “Tablespace”, s.growth/(1024*1024) “Growth in MB”, (SELECT sum(bytes)/(1024*1024*1024) FROM dba_segments WHERE segment_name=o.object_name) “Total Size(GB)” FROM DBA_OBJECTS o, ( SELECT TS#,OBJ#, SUM(SPACE_USED_DELTA) growth FROM DBA_HIST_SEG_STAT GROUP BY TS#,OBJ# HAVING SUM(SPACE_USED_DELTA) > 0 ORDER BY 2 DESC ) s, v$tablespace t WHERE s.OBJ# = o.OBJECT_ID … Read more

Unused Indexes – With constraints

SELECT i.owner, a.index_name, a.table_name, c.constraint_name, a.monitoring, a.used, a.start_monitoring, ROUND (SUM (b.bytes) / 1024 / 1024 / 1024) GB, ROUND (SUM (b.bytes) / 1024 / 1024) MB, i.tablespace_name FROM all_object_usage a, dba_segments b, dba_indexes i, dba_constraints c WHERE a.index_name = b.segment_name AND a.used = ‘NO’ AND b.segment_name = i.index_name AND a.table_name = c.table_name(+) GROUP BY i.owner, … Read more

Unused Index Sizes (GB)

SELECT a.owner, a.index_name, a.table_name, a.monitoring, a.used, a.start_monitoring, SUM (b.bytes) / 1024 / 1024 / 1024 GB FROM all_object_usage a, dba_segments b WHERE a.index_name = b.segment_name AND a.used = ‘NO’ GROUP BY a.owner, a.index_name, a.table_name, a.monitoring, a.used, a.start_monitoring ORDER BY GB DESC;

Indexes Sizes

SELECT idx.index_name, SUM(bytes) FROM dba_segments seg, dba_indexes idx WHERE idx.table_owner = ‘TRANSSENDOPS_PRD’ AND idx.table_name in (select * from all_object_usage) AND idx.owner = seg.owner AND idx.index_name = seg.segment_name GROUP BY idx.index_name;

Indexes Not Used

SELECT * FROM all_views WHERE view_name LIKE ‘%USAGE%’ select a.index_name, (s.bytes/1024/1024/1024) from all_object_usage a, dba_segments s where a.index_name=s.segment_name and a.used=’NO’ group by a.index_name; SELECT SUM (ROUND (bytes / 1024 / 1024 / 1024)) AS GB FROM dba_segments WHERE segment_name IN (SELECT index_name FROM all_object_usage WHERE used = ‘NO’); SELECT * FROM gisdba.dba_object_usage; SELECT (bytes / … Read more

Average Active Sessions

How to find the average active sessions between 2 dates. SELECT rollup_timestamp, average, minimum, maximum FROM mgmt$metric_daily WHERE target_name = ‘TRCOPDOV’ AND metric_label = ‘Throughput’ AND column_label = ‘Average Active Sessions’ AND rollup_timestamp BETWEEN TO_DATE (’01/11/2015′, ‘dd/mm/yyyy’) AND TO_DATE (’01/12/2015′, ‘dd/mm/yyyy’) ORDER BY 1;