#!/usr/bin/ksh
# whatsharedmemory ()
#------------------------------------------------------------------------------#
#    Module Name:  whatsharedmemory                                            #
#                                                                              #
#    Purpose:      Report on Database Shared Memory.                           #
#                                                                              #
#    Maintenance                                                               #
#    Date          Author        Description                                   #
#    -----------   ------------  --------------------------------------------  #
#    10-Oct-2009   M.Barone      Module design/creation                        #
#------------------------------------------------------------------------------#
{
        DIRNAM=$(dirname $0)
        ORASID=$(echo $CONTEXT_NAME | cut -f1 -d'_')
        HNAME=$(uname -n)

	clear
	echo
	echo  " #--------------------------------------------------------#"
	echo  " # whatsharedmemory:                  Oracle SharedMemory #"
	echo  " #--------------------------------------------------------#"
	echo
	echo  " Connecting as SYSDBA"
	sleep 2

	clear
	ORANAM=${ORASID}

#------------------------------------------------------------------------------#
#  SQL*Plus ("Here-Document")                                                  #
#------------------------------------------------------------------------------#
sqlplus  -s  /nolog  <<-END_FILE

	CONNECT /  AS SYSDBA

        clear   BREAKS
        clear   BUFFER
        clear   COLUMNS
        clear   COMPUTES
        clear   SCREEN
        clear   SQL
        clear   TIMING

        set     feedback        off
        set     flush           on
        set     heading         on
        set     pause           off
        set     space           1
        set     termout         on
        set     verify          on
        set     linesize        80
        set     pagesize        999

        SPOOL /tmp/whatsharedmemory_$$.txt

        prompt ================================================================
        prompt == Automated SGA Memory Management -- Dynamic-Components      ==
        prompt ================================================================

        BREAK   ON  pool  skip 1 ON owner skip 1

        BREAK   ON  owner       skip 2  ON REPORT
        COMPUTE SUM LABEL 'Total'  OF shareable_mem    ON REPORT

        BREAK   ON  REPORT
        COMPUTE SUM LABEL 'Total'  OF shareable_mem    ON REPORT

        COLUMN  datevalue       NOPRINT NEW_VALUE       DATEVAR
        COLUMN  timevalue       NOPRINT NEW_VALUE       TIMEVAR
	COLUMN  owner           FORMAT A8
	COLUMN  namespace       FORMAT A18
	COLUMN  type            FORMAT A8
	COLUMN  name            FORMAT A30
	COLUMN  shareable_mem   FORMAT 99999999999

        TTITLE	CENTER  'Oracle Shared Memory Usage'                        -
		LEFT    DATEVAR                                             -
                RIGHT   'Page:'         FORMAT 999 SQL.pno      skip 1	    -
                CENTER  'whatsharedmemory -- Sorted by Component'	    -
                LEFT    TIMEVAR					skip 1

  	SELECT	owner,
	        namespace,
		type,
		name,
		sharable_mem
	  FROM  v\$db_object_cache
	  ORDER BY owner, sharable_mem;

        EXIT;
END_FILE

print
print "Please see /tmp/whatsharedmemory_$$.txt"
print
}