Search This Blog

Total Pageviews

Tuesday, 22 November 2011

Oracle 11gr2 compression


procedure example works only in 11gR2

you will get this message  in  11gR2
Please use DBMS_COMPRESSION package for estimating compression ratio


go to rdbms dir

oracle@apt-amd-02:/opt/app/oracle/product/11.2/rdbms/admin> ls -ltr dbmscomp.sql
-rw-r--r-- 1 oracle oinstall 5180 2009-07-02 13:48 dbmscomp.sql
oracle@apt-amd-02:/opt/app/oracle/product/11.2/rdbms/admin> ls -ltr prvtcomp.plb
-rw-r--r-- 1 oracle oinstall 1226 2009-08-14 22:33 prvtcomp.plb
oracle@apt-amd-02:/opt/app/oracle/product/11.2/rdbms/admin> !sql
sqlplus  / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Tue Nov 22 14:48:28 2011

Copyright (c) 1982, 2009, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> @dbmscomp.sql

Package created.


Synonym created.


Grant succeeded.

No errors.
SQL> @prvtcomp.plb

Library created.


Package body created.

No errors.


SQL> set serveroutput on
SQL>

DECLARE
 blkcnt_cmp pls_integer;
 blkcnt_uncmp pls_integer;
 row_cmp pls_integer;
 row_uncmp pls_integer;
 cmp_ratio pls_integer;
 comptype_str varchar2(100);
 BEGIN
 DBMS_COMPRESSION.GET_COMPRESSION_RATIO ('USERS', 'SCOTT', 'EMP', '',
 DBMS_COMPRESSION.COMP_FOR_OLTP,
 blkcnt_cmp, blkcnt_uncmp, row_cmp, row_uncmp, cmp_ratio, comptype_str);
 DBMS_OUTPUT.PUT_LINE('Block count compressed = ' || blkcnt_cmp);
 DBMS_OUTPUT.PUT_LINE('Block count uncompressed = ' || blkcnt_uncmp);
 DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' || row_cmp);
 DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' || row_uncmp);
 DBMS_OUTPUT.PUT_LINE('Compression type = ' || comptype_str);
 DBMS_OUTPUT.PUT_LINE('Compression ratio = '||blkcnt_uncmp/blkcnt_cmp||' to 1');
 DBMS_OUTPUT.PUT_LINE('Compression ratio org= '||cmp_ratio);
 END;
 /

Block count compressed = 1
Block count uncompressed = 1
Row count per block compressed = 14
Row count per block uncompressed = 14
Compression type = "Compress For OLTP"
Compression ratio = 1 to 1
Compression ratio org= 1

PL/SQL procedure successfully completed.


===


DECLARE
 blkcnt_cmp pls_integer;
 blkcnt_uncmp pls_integer;
 row_cmp pls_integer;
 row_uncmp pls_integer;
 cmp_ratio pls_integer;
 comptype_str varchar2(100);
 BEGIN
 DBMS_COMPRESSION.GET_COMPRESSION_RATIO ('USERS', 'SCOTT', 'ANUJ_BIG_TABLE', '',
 DBMS_COMPRESSION.COMP_FOR_OLTP,
 blkcnt_cmp, blkcnt_uncmp, row_cmp, row_uncmp, cmp_ratio, comptype_str);
 DBMS_OUTPUT.PUT_LINE('Block count compressed = ' || blkcnt_cmp);
 DBMS_OUTPUT.PUT_LINE('Block count uncompressed = ' || blkcnt_uncmp);
 DBMS_OUTPUT.PUT_LINE('Row count per block compressed = ' || row_cmp);
 DBMS_OUTPUT.PUT_LINE('Row count per block uncompressed = ' || row_uncmp);
 DBMS_OUTPUT.PUT_LINE('Compression type = ' || comptype_str);
 DBMS_OUTPUT.PUT_LINE('Compression ratio = '||blkcnt_uncmp/blkcnt_cmp||' to 1');
 DBMS_OUTPUT.PUT_LINE('Compression ratio org= '||cmp_ratio);
 END;
 /



Block count compressed = 12
Block count uncompressed = 194
Row count per block compressed = 550
Row count per block uncompressed = 34
Compression type = "Compress For OLTP"
Compression ratio = 16.16666666666666666666666666666666666667 to 1
Compression ratio org= 16

PL/SQL procedure successfully completed.



col SEGMENT_NAME format a20
select segment_name, bytes, a.blocks, compression, compress_for from dba_segments a, dba_tables b
where a.segment_name = b.table_name
and a.segment_name='ANUJ_BIG_TABLE';


SEGMENT_NAME              BYTES     BLOCKS COMPRESS COMPRESS_FOR
-------------------- ---------- ---------- -------- ------------
ANUJ_BIG_TABLE         26673152       3256 DISABLED





declare
 lv_cmp_ratio number;
 lv_comptype_str varchar2(300);
 lv_BLKCNT_CMP number;
 lv_BLKCNT_UNCMP number;
 lv_ROW_CMP number;
 lv_ROW_UNCMP number;
 begin
dbms_compression.GET_COMPRESSION_RATIO(
 SCRATCHTBSNAME=>'USERS', ---- TableSpace
 OWNNAME=>'SCOTT', ---- User Name
 TABNAME=>'ANUJ_BIG_TABLE',   --- Table Name
 PARTNAME =>null,
 COMPTYPE =>2, ---2 means OLTP
 BLKCNT_CMP=>lv_BLKCNT_CMP,
 BLKCNT_UNCMP=>lv_BLKCNT_UNCMP,
 ROW_CMP =>lv_ROW_CMP,
 ROW_UNCMP =>lv_ROW_UNCMP,
 CMP_RATIO=>lv_cmp_ratio,
 COMPTYPE_STR=>lv_COMPTYPE_STR);
 dbms_output.put_line('====================================================');
 dbms_output.put_line('1. Compression Ratio :'||lv_cmp_ratio);
 dbms_output.put_line('2. Block Count :'||lv_blkcnt_cmp);
 dbms_output.put_line('3. Compression Type :'||lv_comptype_str);
 dbms_output.put_line('4. Blk Count Compressed :'||lv_BLKCNT_CMP);
 dbms_output.put_line('5. Blk Count Un-compressed:'||lv_BLKCNT_UNCMP);
 dbms_output.put_line('6. Row Count Compressed :'||lv_row_cmp);
 dbms_output.put_line('4. Row Count Un-Compressed:'||lv_row_uncmp);
 dbms_output.put_line('====================================================');
 end;
 /



   
====================================================
1. Compression Ratio :17.25
2. Block Count :12
3. Compression Type :"Compress For OLTP"
4. Blk Count Compressed :12
5. Blk Count Un-compressed:207
6. Row Count Compressed :584
4. Row Count Un-Compressed:33
====================================================

PL/SQL procedure successfully completed.


 


 


 

Oracle Export ( Data pump ) Shell script

 


Oracle Export ( Data pump  ) Shell script


 


cat oraexpdb.sh


 


# !/bin/bash
TODAY=`date`
ORACLE_SID=db ; export ORACLE_SID
ORACLE_BASE=/opt/oracle ; export ORACLE_BASE
ORACLE_HOME=/opt/oracle/product/10.2 ; export ORACLE_HOME
PATH=${ORACLE_HOME}/bin:$PATH ; export PATH
EXPFILE=$ORACLE_SID.datapump.`date +%m%d%Y`.dmp; export EXPFILE
ERRFILE=$ORACLE_SID.datapump.`date +%m%d%Y`.err; export ERRFILE
LOGFILE=$ORACLE_SID.datapump.`date +%m%d%Y`.log ; export LOGFILE
SUCC=/opt/oracle/backup/DataPump/Backup/SUCC.txt ; export SUCC

# echo $EXPFILE

ps -ef | grep -i smon|grep -v grep|wc -l> oracle.exp

if [ `cat oracle.exp|grep -v grep|grep -i "1"|wc -l` -eq 1 ]; then

[ -f $ERRFILE ]; rm $ERRFILE

expdp "'/ as sysdba'"  directory=datapump DUMPFILE=$EXPFILE SCHEMAS=PROD1,UAT2,ESEARCH  logfile=$LOGFILE EXCLUDE=STATISTICS  parallel=4

fi


echo "-------------- Deleting old File ----------------------"


find /opt/oracle/backup/DataPump/Backup -name "*.err"  -ctime +2 -exec rm {} \;
find /opt/oracle/backup/DataPump/Backup  -name "*.dmp*"  -ctime +2 -exec rm {} \;


 # find /opt/oracle/backup/DataPump/Backup  -name "$ORACLE_SID.export.*"  -mtime  +2 -exec rm {} \;


echo "Done........ "
exit 0




Monday, 21 November 2011

For Oracle license info

                              Oracle license Info


Oracle product Info 


 


 


col DESCRIPTION format a30 
col name format a20
SELECT
DBID ,NAME ,VERSION ,DETECTED_USAGES ,TOTAL_SAMPLES ,CURRENTLY_USED ,FIRST_USAGE_DATE ,LAST_USAGE_DATE ,
-- LAST_SAMPLE_DATE ,LAST_SAMPLE_PERIOD ,
--SAMPLE_INTERVAL ,
DESCRIPTION
from DBA_FEATURE_USAGE_STATISTICS
where detected_usages > 0 and
( name like '%ADDM%'
or name like '%Automatic Database Diagnostic Monitor%'
or name like '%Automatic Workload Repository%'
or name like '%AWR%'
or name like '%Baseline%'
or name like '%Compression%'
or name like '%Data Guard%'
or name like '%Data Mining%'
or name like '%Database Replay%'
or name like '%EM%'
or name like '%Encrypt%'
or name like '%Exadata%'
or name like '%Flashback Data Archive%'
or name like '%Label Security%'
or name like '%OLAP%'
or name like '%Pack%'
or name like '%Partitioning%'
or name like '%Real Application Clusters%'
or name like '%SecureFile%'
or name like '%Spatial%'
or name like '%SQL Monitoring%'
or name like '%SQL Performance%'
or name like '%SQL Profile%'
or name like '%SQL Tuning%'
or name like '%SQL Access Advisor%'
or name like '%Vault%')
and CURRENTLY_USED='TRUE' ---------------------<<<<<<<<<<<<<<<<<<<<<<<
order by name;


 


 


      DBID NAME                 VERSION           DETECTED_USAGES TOTAL_SAMPLES CURRE FIRST_USA LAST_USAG DESCRIPTION
---------- -------------------- ----------------- --------------- ------------- ----- --------- --------- ------------------------------
1267852645 Automatic Maintenanc 11.2.0.1.0 40 40 TRUE 10-JAN-11 16-NOV-11 Automatic initiation of SQL Tu
e - SQL Tuning Advis ning Advisor
or

1267852645 Automatic SQL Tuning 11.2.0.1.0 39 40 TRUE 18-JAN-11 16-NOV-11 Automatic SQL Tuning Advisor h
Advisor as been used.

1267852645 Backup BASIC Compres 11.2.0.1.0 9 40 TRUE 28-JUL-11 16-NOV-11 BASIC compressed backups are b
sion eing used.

1267852645 Partitioning (system 11.2.0.1.0 40 40 TRUE 10-JAN-11 16-NOV-11 Oracle Partitioning option is
) being used - there is at least
one partitioned object create
d.

1267852645 Partitioning (user) 11.2.0.1.0 8 40 TRUE 29-SEP-11 16-NOV-11 Oracle Partitioning option is
being used - there is at least
one user partitioned object c
reated.

1267852645 SQL Profile 11.2.0.1.0 5 40 TRUE 20-OCT-11 16-NOV-11 SQL profiles have been used.
1267852645 SQL Tuning Set (syst 11.2.0.1.0 21 40 TRUE 30-JUN-11 16-NOV-11 A SQL Tuning Set has been crea
em) ted in the database in the SYS
schema.

1267852645 SecureFiles (system) 11.2.0.1.0 40 40 TRUE 10-JAN-11 16-NOV-11 SecureFiles is being used by s
ystem users

1267852645 Transparent Data Enc 11.2.0.1.0 8 40 TRUE 29-SEP-11 16-NOV-11 Transparent Database Encryptio
ryption n is being used. There is atle
ast one column or tablespace t
hat is encrypted.


9 rows selected.

Sunday, 20 November 2011

Oracle role info for schema

schema role info
user role info

col pr head "Profile" for a8
col rn head "Resource" for a25
col rt head "Type" for a10
col li head "Value" for a10
break on pr skip

prompt
prompt Profile Details
prompt ===============

select p.profile pr,p.resource_name rn,p.resource_type rt,p.limit li from dba_users u,dba_profiles p
where u.profile=p.profile
and u.username='&&user';

col gr head "Grantor" for a8
col tn head "Object" for a20
col ow head "Owner" for a8
col pr head "Privilege" for a10

prompt
prompt Object Privileges
prompt =================

select t.grantor gr,t.table_name tn,t.owner ow,t.privilege pr from dba_tab_privs t
where t.grantee='&&user';

col cn head "Column" for a20

prompt
prompt Column Privileges
prompt =================
select c.grantor gr,c.column_name cn,c.table_name tn,c.owner ow,c.privilege pr from dba_col_privs c
where c.grantee='&&user';

col ad head "Adm" for a3
col pr head "Privilege" for a30

prompt
prompt System Privileges
prompt =================
select s.privilege pr,s.admin_option ad from dba_sys_privs s
where s.grantee='&&user';

col gr head "Granted Role" for a30
col dr head "Def" for a3
col ad head "Adm" for a3
prompt
prompt Role Privileges
prompt ===============
select r.granted_role gr,r.default_role dr,r.admin_option ad from dba_role_privs r
where r.grantee='&&user';





Profile Details
===============
Enter value for user: SCOTT
old 3: and u.username='&&user'
new 3: and u.username='SCOTT'

Profile Resource Type Value
-------- ------------------------- ---------- ----------
DEFAULT COMPOSITE_LIMIT KERNEL UNLIMITED
SESSIONS_PER_USER KERNEL UNLIMITED
CPU_PER_SESSION KERNEL UNLIMITED
CPU_PER_CALL KERNEL UNLIMITED
LOGICAL_READS_PER_SESSION KERNEL UNLIMITED
LOGICAL_READS_PER_CALL KERNEL UNLIMITED
IDLE_TIME KERNEL UNLIMITED
CONNECT_TIME KERNEL UNLIMITED
PRIVATE_SGA KERNEL UNLIMITED
FAILED_LOGIN_ATTEMPTS PASSWORD 10
PASSWORD_LIFE_TIME PASSWORD 180
PASSWORD_REUSE_TIME PASSWORD UNLIMITED
PASSWORD_REUSE_MAX PASSWORD UNLIMITED
PASSWORD_VERIFY_FUNCTION PASSWORD NULL
PASSWORD_LOCK_TIME PASSWORD 1
PASSWORD_GRACE_TIME PASSWORD 7

16 rows selected.


Object Privileges
=================
old 2: where t.grantee='&&user'
new 2: where t.grantee='SCOTT'

Grantor Object Owner Privilege
-------- -------------------- -------- ----------
SYS DBMS_REDEFINITION SYS EXECUTE


Column Privileges
=================
old 2: where c.grantee='&&user'
new 2: where c.grantee='SCOTT'

no rows selected


System Privileges
=================
old 2: where s.grantee='&&user'
new 2: where s.grantee='SCOTT'

Privilege Adm
------------------------------ ---
UNLIMITED TABLESPACE NO


Role Privileges
===============
old 2: where r.grantee='&&user'
new 2: where r.grantee='SCOTT'

Granted Role Def Adm
------------------------------ --- ---
RESOURCE YES NO
DBA YES NO
CONNECT YES NO

Friday, 18 November 2011

Oracle AWR Report for a Single SQL Statement

Generating an AWR Report for a Single SQL Statement
AWR for single sql
Oracle AWR report for single sql



SQL> select DBID from v$database ;

DBID
----------
1267852645

select SNAP_ID,BEGIN_INTERVAL_TIME from dba_hist_snapshot ;


@$ORACLE_HOME/rdbms/admin/awrsqrpt.sql

65j29t2qc8cqt


sys> @$ORACLE_HOME/rdbms/admin/awrsqrpt.sql


Current Instance
~~~~~~~~~~~~~~~~

DB Id DB Name Inst Num Instance
----------- ------------ -------- ------------
204677159 xxxDB 1 xxxdb


Specify the Report Type
~~~~~~~~~~~~~~~~~~~~~~~
Would you like an HTML report, or a plain text report?
Enter 'html' for an HTML report, or 'text' for plain text
Defaults to 'html'
Enter value for report_type: text

Type Specified: text


Instances in this Workload Repository schema
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DB Id Inst Num DB Name Instance Host
------------ -------- ------------ ------------ ------------
* 204677159 1 xxxDB aptdb apt-xxxx-01
.xxxxxxxx

Using 204677159 for database Id
Using 1 for instance number


Specify the number of days of snapshots to choose from
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Entering the number of days (n) will result in the most recent
(n) days of snapshots being listed. Pressing <return> without
specifying a number lists all completed snapshots.


Enter value for num_days: 2

Listing the last 2 days of Completed Snapshots

Snap
Instance DB Name Snap Id Snap Started Level
------------ ------------ --------- ------------------ -----
xxxdb xxxDB 3937 17 Nov 2011 00:00 1
3938 17 Nov 2011 01:00 1
3939 17 Nov 2011 02:00 1
3940 17 Nov 2011 03:00 1
3941 17 Nov 2011 04:00 1
3942 17 Nov 2011 05:00 1
3943 17 Nov 2011 06:00 1
3944 17 Nov 2011 07:00 1
3945 17 Nov 2011 08:00 1
3946 17 Nov 2011 09:00 1
3947 17 Nov 2011 10:00 1
3948 17 Nov 2011 11:00 1
3949 17 Nov 2011 12:00 1
3950 17 Nov 2011 13:00 1
3951 17 Nov 2011 14:00 1
3952 17 Nov 2011 15:00 1
3953 17 Nov 2011 16:00 1
3954 17 Nov 2011 17:00 1
3955 17 Nov 2011 18:00 1
3956 17 Nov 2011 19:00 1
3957 17 Nov 2011 20:00 1
3958 17 Nov 2011 21:00 1
3959 17 Nov 2011 22:00 1
3960 17 Nov 2011 23:00 1
3961 18 Nov 2011 00:00 1
3962 18 Nov 2011 01:00 1
3963 18 Nov 2011 02:00 1
3964 18 Nov 2011 03:00 1
3965 18 Nov 2011 04:00 1
3966 18 Nov 2011 05:00 1
3967 18 Nov 2011 06:00 1
3968 18 Nov 2011 07:00 1
3969 18 Nov 2011 08:00 1
3970 18 Nov 2011 09:00 1
3971 18 Nov 2011 10:00 1
3972 18 Nov 2011 11:00 1
3973 18 Nov 2011 12:00 1
3974 18 Nov 2011 13:00 1



Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Enter value for begin_snap: 3937
Begin Snapshot Id specified: 3937

Enter value for end_snap: 3974
End Snapshot Id specified: 3974




Specify the SQL Id
~~~~~~~~~~~~~~~~~~
Enter value for sql_id: 65j29t2qc8cqt --- <<<<<<<<<<<<<<<<<<<< you have to put sql id here

Tuesday, 15 November 2011

Oracle Tablespace High water mark

Tablespace High water mark
Tablespace HWM



col tablespace_name format a15
col file_size format 99999
col file_name format a50
col hwm format 99999
col can_save format 99999

SELECT tablespace_name, file_name, file_size, hwm, file_size-hwm can_save
FROM (SELECT /*+ RULE */ ddf.tablespace_name, ddf.file_name file_name,
ddf.bytes/1048576 file_size,(ebf.maximum + de.blocks-1)*dbs.db_block_size/1048576 hwm
FROM dba_data_files ddf,(SELECT file_id, MAX(block_id) maximum FROM dba_extents GROUP BY file_id) ebf,dba_extents de,
(SELECT value db_block_size FROM v$parameter WHERE name='db_block_size') dbs
WHERE ddf.file_id = ebf.file_id
AND de.file_id = ebf.file_id
AND de.block_id = ebf.maximum
ORDER BY 1,2);



TABLESPACE_NAME FILE_NAME                                          FILE_SIZE    HWM CAN_SAVE
--------------- -------------------------------------------------- --------- ------ --------
ANUJTEST /opt/app/oracle/oradata/orcl/anujtest.dbf 10 8 2
EXAMPLE /opt/app/oracle/oradata/orcl/example01.dbf 100 81 19
PERFSTAT /opt/app/oracle/oradata/orcl/anuj_perfstat.dbf 1000 115 885
RMAN /opt/app/oracle/oradata/orcl/rman.dbf 50 7 43
SYSAUX /opt/app/oracle/oradata/orcl/sysaux01.dbf 830 777 53
SYSTEM /opt/app/oracle/oradata/orcl/system01.dbf 840 823 17
TSAPEXU /opt/app/oracle/oradata/orcl/tsapexu01.dbf 110 97 13
UNDOTBR /opt/app/oracle/oradata/orcl/undotbR.dbf 500 46 454
USERS /opt/app/oracle/oradata/orcl/users01.dbf 609 576 33

9 rows selected.

Oracle object on System and sysaux tablespace more then 10Mb size

Oracle Table IDL_UB1$




col SEGMENT_NAME format a30
col owner format a20
select owner,segment_name,segment_type,bytes/(1024*1024) size_m,TABLESPACE_NAME from dba_segments
where tablespace_name = 'SYSTEM'
and bytes/(1024*1024) > 10 --- Mb
union all
select owner,segment_name,segment_type,bytes/(1024*1024) size_m,TABLESPACE_NAME from dba_segments




 set linesize 300
 col SEGMENT_NAME format a30
 col owner format a20
 select owner,segment_name,segment_type,bytes/(1024*1024) size_m,TABLESPACE_NAME from dba_segments
   where tablespace_name = 'SYSTEM'
   and bytes/(1024*1024) > 10 --- Mb
    union all
    select owner,segment_name,segment_type,bytes/(1024*1024) size_m,TABLESPACE_NAME from dba_segments
    where tablespace_name = 'SYSAUX'
   and bytes/(1024*1024) > 10 -- Mb
    order by size_m desc;










set lines 500 pages 10000
col TSname format a25 			heading 'TSpace|Name|||'
col TSstatus format a9  		heading 'TSpace|Status|||'
col TSSizeMb format 99999999 		heading 'TSpace|Size|Mb||'
col TSUsedMb format 99999999 		heading 'TSpace|Used|Space|Mb|'
col TSFreeMb format 99999999 		heading 'TSpace|Free|Space|Mb|'
col TSUsedPrct format 99999999 		heading 'TSpace|Used|Space|%|'
col TSFreePrct format 99999999 		heading 'TSpace|Free|Space|%|'
col TSSegUsedMb format 99999999 	heading 'TSpace|Segmt|Space|Mb|'
col TSExtUsedMb format 99999999 	heading 'TSpace|Extent|Space|Mb|'
col AutoExtFile format a6 		heading 'Auto|Extend|File|?|'
col TSMaxSizeMb format a6 		heading 'TSpace|MaxSize|Mb||'
col TSMaxUsedPrct format a6 		heading 'TSpace|Maxed|Used|Space|%'
col TSMaxFreePrct format a6		heading 'TSpace|Maxed|Free|Space|%'

WITH
  ts_total_space AS (SELECT
                       TableSpace_name,
                       SUM(bytes) as bytes,
                       SUM(blocks) as blocks,
                       SUM(maxbytes) as maxbytes
                     FROM dba_data_files
                     GROUP BY TableSpace_name),
  ts_free_space AS (SELECT
                      ddf.TableSpace_name,
                      NVL(SUM(dfs.bytes),0) as bytes,
                      NVL(SUM(dfs.blocks),0) as blocks
                    FROM
                      dba_data_files ddf,
                      dba_free_space dfs
                    WHERE ddf.file_id = dfs.file_id(+)
                    GROUP BY ddf.TableSpace_name),
  ts_total_segments AS (SELECT
                          TableSpace_name,
                          SUM(bytes) as bytes,
                          SUM(blocks) as blocks
                        FROM dba_segments
                        GROUP BY TableSpace_name),
ts_total_extents AS (SELECT
                       TableSpace_name,
                       SUM(bytes) as bytes,
                       SUM(blocks) as blocks
                     FROM dba_extents
                     GROUP BY TableSpace_name)
SELECT
  dt.TableSpace_name as "TSname",
  dt.status as "TSstatus",
  ROUND(ttsp.bytes/1024/1024,0) as "TSSizeMb",
  ROUND((ttsp.bytes-tfs.bytes)/1024/1024,0) as "TSUsedMb",
  ROUND(tfs.bytes/1024/1024,0) as "TSFreeMb",
  ROUND((ttsp.bytes-tfs.bytes)/ttsp.bytes*100,0) as "TSUsedPrct",
  ROUND(tfs.bytes/ttsp.bytes*100,0) as "TSFreePrct",
  ROUND(ttse.bytes/1024/1024,0) as "TSSegUsedMb",
  ROUND(tte.bytes/1024/1024,0) as "TSExtUsedMb",
  CASE
    WHEN ttsp.maxbytes = '0' then 'No' ELSE 'Yes'
  END as "AutoExtFile",
  CASE
    WHEN ttsp.maxbytes = '0' then '-' ELSE TO_CHAR(ROUND(ttsp.maxbytes/1024/1024,0))
  END as "TSMaxSizeMb",
  CASE
    WHEN ttsp.maxbytes = '0' then '-' ELSE TO_CHAR(ROUND((ttsp.bytes-tfs.bytes)/ttsp.maxbytes*100,0))
  END as "TSMaxUsedPrct",
  CASE
    WHEN ttsp.maxbytes = '0' then '-' ELSE TO_CHAR(ROUND((ttsp.maxbytes-(ttsp.bytes-tfs.bytes))/ttsp.maxbytes*100,0))
  END as "TSMaxFreePrct"
FROM
  dba_TableSpaces dt,
  ts_total_space ttsp,
  ts_free_space tfs,
  ts_total_segments ttse,
  ts_total_extents tte
WHERE dt.TableSpace_name = ttsp.TableSpace_name(+)
AND dt.TableSpace_name = tfs.TableSpace_name(+)
AND dt.TableSpace_name = ttse.TableSpace_name(+)
AND dt.TableSpace_name = tte.TableSpace_name(+)
AND dt.TableSpace_name = 'SYSAUX'
;


TSpace                    TSpace       TSpace    TSpace    TSpace    TSpace    TSpace    TSpace    TSpace Auto   TSpace TSpace TSpace
Name                      Status         Size      Used      Free      Used      Free     Segmt    Extent Extend MaxSiz Maxed  Maxed
                                           Mb     Space     Space     Space     Space     Space     Space File   Mb     Used   Free
                                                     Mb        Mb         %         %        Mb        Mb ?             Space  Space
                                                                                                                        %      %
------------------------- --------- --------- --------- --------- --------- --------- --------- --------- ------ ------ ------ ------
SYSAUX                    ONLINE       149103      6724    142379         5        95      6718      6718 Yes    196607 3      97

SQL> SQL>








https://grepora.com/2016/02/08/purge-sysaux-tablespace/

How to Reduce SYSAUX Tablespace Occupancy Due to Fragmented TABLEs and INDEXes (Doc ID 1563921.1)
How to Reduce SYSAUX Tablespace Occupancy Due to Fragmented TABLEs and INDEXes (Doc ID 1563921.1)

Oracle DBA

anuj blog Archive