Tablespace scripte

This commit is contained in:
Franz Rustler 2014-09-19 15:22:32 +02:00
parent 3ead6c4b20
commit 8eb106f8a4
5 changed files with 303 additions and 4 deletions

223
Mortan/SpaceUsage.sql Normal file
View File

@ -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 - - - - - - - - - - - - - - - -

48
Mortan/TFSDBSPA.SQL Normal file
View File

@ -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

View File

@ -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

30
Tanel/html2.sql.bak Normal file
View File

@ -0,0 +1,30 @@
set termout off
set markup HTML ON HEAD " -
<style type='text/css'> -
body {font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} -
p { font:10pt Arial,Helvetica,sans-serif; color:black; background:White;} -
table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black; background:#f7f7e7; -
padding:0px 0px 0px 0px; margin:0px 0px 0px 0px; white-space:nowrap;} -
th { font:bold 10pt Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; -
padding:0px 0px 0px 0px;} -
h1 { font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; -
border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px 0px;} -
h2 { font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White; -
margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif; color:#663300; -
background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;} -
</style> -
<title>SQL*Plus Report</title>" -
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

View File

@ -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