From 8eb106f8a480826dc1861c5251c3d9b915108dc1 Mon Sep 17 00:00:00 2001 From: Franz Rustler Date: Fri, 19 Sep 2014 15:22:32 +0200 Subject: [PATCH] Tablespace scripte --- Mortan/SpaceUsage.sql | 223 ++++++++++++++++++++++++++++++++++++++++++ Mortan/TFSDBSPA.SQL | 48 +++++++++ Tanel/html2.sql | 4 +- Tanel/html2.sql.bak | 30 ++++++ glogin.sql | 2 - 5 files changed, 303 insertions(+), 4 deletions(-) create mode 100644 Mortan/SpaceUsage.sql create mode 100644 Mortan/TFSDBSPA.SQL create mode 100644 Tanel/html2.sql.bak diff --git a/Mortan/SpaceUsage.sql b/Mortan/SpaceUsage.sql new file mode 100644 index 0000000..13926ae --- /dev/null +++ b/Mortan/SpaceUsage.sql @@ -0,0 +1,223 @@ +set linesize 132; +set pagesize 1000; +set long 50; +set echo on; + +break on "TBL SPACE" on "TOTAL BYTES"; + +/* *************************************************** */ +/* block-size */ +/* *************************************************** */ +column db_block_size new_value BLOCK_SIZE +select to_char(value, '9999') db_block_size + from v$parameter + where name = 'db_block_size'; + + +/* *************************************************** */ +/* date & user_id */ +/* *************************************************** */ +column today new_value dba_date +select to_char(sysdate, 'mm/dd/yy hh:miam') today + from dual; + +break on instance +column instance new_value instance_name +select substr(name,1,4) instance + from v$database; + +clear breaks +set termout on + +set pagesize 60 linesize 132 verify off +set space 2 +ttitle left 'Date: ' format a18 dba_date - + center 'Space Report - ' format a4 instance_name - + right 'Page: ' format 999 sql.pno skip 2 + +set echo off; + +set echo on; + + +/* *************************************************** */ +/* tablespace usage via the dba_data_files */ +/* *************************************************** */ +set echo off; + +select substr(D.tablespace_name, 1, 12) "TBL SPACE", + substr(to_char(sum(D.bytes), '999,999,999,999'), 1, 16) "TOTAL BYTES", + substr(to_char(sum(D.bytes)/1024/1024, '999,999.9'), 1, 10) "TOT MBYTES", + substr(to_char(sum(D.bytes)/(Z.VALUE), '99,999,999'), 1, 11) "BLOCKS" +from sys.dba_data_files D, + v$parameter Z +where Z.name = 'db_block_size' +group by D.tablespace_name, Z.value; + +set echo on; + + +/* *************************************************** */ +/* show tablespace usage */ +/* *************************************************** */ +set echo off; + +select distinct substr(tablespace_name, 1, 12) "TBL SPACE", + substr(to_char(sum(blocks), '999,999,999'), 1, 12) "TOT BLKS", + substr(to_char(sum(bytes), '999,999,999,999'), 1, 16) "TOT BYTES" +from sys.dba_free_space +group by + tablespace_name; + +set echo on; + + +/* *************************************************** */ +/* show tablespace usage */ +/* *************************************************** */ +set echo off; + +break on "TBL SPACE"; + +select substr(tablespace_name,1,12) "TBL SPACE", + substr(to_char(file_id, '99'), 1, 4) "ID", + substr(to_char(count(*), '9,999'), 1, 6) "PCS", + substr(to_char(max(blocks), '9,999,999'), 1, 10) "MAX BLKS", + substr(to_char(min(blocks), '9,999,999'), 1, 10) "MIN BLKS", + substr(to_char(avg(blocks), '9,999,999.9'), 1, 12) "AVG BLKS", + substr(to_char(sum(blocks), '9,999,999'), 1,10) "SUM BLKS", + substr(to_char(sum(bytes), '99,999,999,999'), 1, 15) "SUM BYTES" +from + sys.dba_free_space +group by + tablespace_name,file_id +order by 1, 4; + +set echo on; + + +/* *************************************************** */ +/* show tablespace usage */ +/* *************************************************** */ +set echo off; + +select + distinct substr(tablespace_name,1,12) "TBL SPACE", + substr(to_char(sum(blocks), '999,999,999'), 1, 12) "SUM BLKS", + substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 16) "SUM MBYTES" +from + sys.dba_free_space +group by + tablespace_name; + +set echo on; +/* *************************************************** */ +/* show tablespace segments - order by segment */ +/* *************************************************** */ +set echo off; + +break on "SEGMENT" on "TYPE"; + +select substr(segment_name, 1, 20) "SEGMENT", + substr(segment_type,1,7) "TYPE", + substr(tablespace_name,1,8) "TBL SPACE", + substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 11) + "SUM Mb", + /* substr(to_char(sum(blocks), '999,999'), 1, 8) "SUM BLKS", */ + substr(to_char(extents, '999'), 1, 4) "EXTENTS", + substr(to_char((initial_extent/(1024*1024)), '99,999.999'), 1, 10) + "INI (Mb)", + substr(to_char((next_extent/(1024*1024)), '999.999'), 1, 8) "NXT (Mb)" +from user_segments +group by segment_name, + segment_type, + tablespace_name, + bytes, + blocks, + extents, + initial_extent, + next_extent +order by 1, 2; + +set echo on; + + +/* *************************************************** */ +/* show tablespace segments - order by tablespace */ +/* *************************************************** */ +set echo off; + +break on "TBL SPACE" on "SEGMENT" on "TYPE"; + +select substr(tablespace_name,1,12) "TBL SPACE", + substr(segment_name, 1, 20) "SEGMENT", + /* substr(segment_type,1,7) "TYPE", */ + substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 12) + "SUM Mb", + /* substr(to_char(sum(blocks), '9,999,999'), 1, 10) "SUM BLKS", */ + substr(to_char(extents, '999'), 1, 4) "EXTS", + substr(to_char(initial_extent/(1024*1024), '999.999'), 1, 8) + "INI Mb", + substr(to_char(next_extent/(1024*1024), '999.999'), 1, 8) + "NXT Mb" +from user_segments +group by segment_name, + segment_type, + tablespace_name, + bytes, + blocks, + extents, + initial_extent, + next_extent +order by 1, 2; + +set echo on; + + +/* *************************************************** */ +/* show tablespace segments - order by bytes */ +/* *************************************************** */ +set echo off; + +break on "SUM BYTES" on "SEGMENT" on "TYPE"; + +select substr(to_char(sum(bytes)/(1024*1024), '999,999.999'), 1, 11) + "SUM Mb", + substr(segment_name, 1, 20) "SEGMENT", + substr(tablespace_name,1,12) "TBL SPACE", + /*substr(to_char(sum(blocks), '9,999,999'), 1, 10) "SUM BLKS",*/ + substr(to_char(extents, '999'), 1, 4) "EXTS", + substr(to_char(initial_extent/(1024*1024), '9,999.999'), 1, 10) + "INI Mb", + substr(to_char(next_extent/(1024*1024), '999.999'), 1, 8) + "NXT Mb" +from user_segments +group by segment_name, + segment_type, + tablespace_name, + bytes, + blocks, + extents, + initial_extent, + next_extent +order by 1, 2; + +set echo on; + + +/* *************************************************** */ +/* show size of database */ +/* *************************************************** */ +set echo off; + +select substr(to_char(sum(bytes)/1024/1024, '999,999,999.99'), 1, 15) "TOT MBYTES", + substr(to_char(sum(bytes)/1024/1024/1024, '999,999.99'), 1, 11) "TOT GBYTES" +from sys.dba_data_files; + +undefine BLOCK_SIZE; +set echo off; + +set long 80; + + + - - - - - - - - - - - - - - - - Code ends here - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Mortan/TFSDBSPA.SQL b/Mortan/TFSDBSPA.SQL new file mode 100644 index 0000000..68453f8 --- /dev/null +++ b/Mortan/TFSDBSPA.SQL @@ -0,0 +1,48 @@ +SET ECHO off +REM NAME: TFSDBSPA.SQL +REM USAGE:"@path/tfsdbspa" +REM ------------------------------------------------------------------------ +REM REQUIREMENTS: +REM SELECT on SYS.TS$, SYS.USER$, SYS.SEG$ +REM ------------------------------------------------------------------------ +REM AUTHOR: +REM G. Godart-Brown +REM Copyright 1991, Oracle Corporation +REM ------------------------------------------------------------------------ +REM PURPOSE: +REM Report how much space each user is consuming in the database. +REM ------------------------------------------------------------------------ +REM DISCLAIMER: +REM This script is provided for educational purposes only. It is NOT +REM supported by Oracle World Wide Technical Support. +REM The script has been tested and appears to work as intended. +REM You should always run new scripts on a test instance initially. +REM ------------------------------------------------------------------------ +REM Main text of script follows: + +SET ECHO OFF +set newpage 0 +ttitle center 'Database Usage by user and Tablespace'- +right 'Page:' format 999 sql.pno skip skip +break on owner skip 2 +col K format 999,999,999 heading 'Size K' +col ow format a24 heading 'Owner' +col ta format a30 heading 'Tablespace' +spool tfsdbspa.lst +set feedback off +set feedback 6 + SELECT us.name ow, + ts.name ta, + round(SUM (seg.blocks * ts.blocksize) /1073741824, 2) GB + FROM sys.ts$ ts, sys.user$ us, sys.seg$ seg + WHERE seg.user# = us.user# AND ts.ts# = seg.ts# + AND us.name not in ('SYS','SYSTEM','PERFSTAT','DBSNMP','XDB') + GROUP BY ROLLUP(us.name, ts.name); +/ +prompt End of Report +spool off +ttitle off +clear breaks +clear columns +clear computes +set verify on \ No newline at end of file diff --git a/Tanel/html2.sql b/Tanel/html2.sql index 227a3bd..2d5dd36 100644 --- a/Tanel/html2.sql +++ b/Tanel/html2.sql @@ -19,12 +19,12 @@ BODY "" - TABLE "border='1' align='center' summary='Script output'" - SPOOL ON ENTMAP ON PREFORMAT OFF -spool %SQLPATH%\tmp\output_&_connect_identifier..html +spool d:\tmp\output_&_connect_identifier..html l / spool off set markup html off spool off -host start %SQLPATH%\tmp\output_&_connect_identifier..html +host start d:\tmp\output_&_connect_identifier..html set termout on diff --git a/Tanel/html2.sql.bak b/Tanel/html2.sql.bak new file mode 100644 index 0000000..227a3bd --- /dev/null +++ b/Tanel/html2.sql.bak @@ -0,0 +1,30 @@ +set termout off + +set markup HTML ON HEAD " - + - +SQL*Plus Report" - +BODY "" - +TABLE "border='1' align='center' summary='Script output'" - +SPOOL ON ENTMAP ON PREFORMAT OFF + +spool %SQLPATH%\tmp\output_&_connect_identifier..html + +l +/ + +spool off +set markup html off spool off +host start %SQLPATH%\tmp\output_&_connect_identifier..html +set termout on diff --git a/glogin.sql b/glogin.sql index ad71484..ba1a9fa 100644 --- a/glogin.sql +++ b/glogin.sql @@ -48,7 +48,6 @@ COLUMN other_plus_exp FORMAT a44 COLUMN result_plus_xquery HEADING 'Result Sequence' set termout off -@D:\work\scripte\oracle\Oracle_scripte\Tanel\i.sql col dbname new_value prompt_dbname select substr(global_name,1,instr(global_name,'.')-1) dbname @@ -57,7 +56,6 @@ set sqlprompt "_USER'@'&&prompt_dbname> " -- set title of CMD col mysid new_value mysid -select sid || ':' || serial# as mysid from v$session where sid = SYS_CONTEXT('userenv','sid'); alter session set NLS_DATE_FORMAT = 'DD.MM.YYYY HH24:MI:SS'; set serveroutput on