Pages

Sunday, November 13, 2022

ora_stats.sql

COL tablespace_name FOR A30
COL owner FOR A30
COL segment_name FOR A30
COL USED_MB FOR 9999999999999
SET LINESIZE 140
SET PAGESIZE 200
COL tablespace_name FOR A30
COL file_name FOR A60
COL Mb FOR 9999999999999
COL MAX_MB FOR 9999999999999

spool tbs.txt

SELECT TABLESPACE_NAME, 
  (MAX(MAX_SPACE)-MAX(USED_SPACE)  )AS DBA_FREE_SPACE_MB,                                   
  MAX(USED_SPACE) AS USED_SPACE_MB, 
  MAX(MAX_SPACE) AS MAX_SPACE_MB, 
  ROUND(( (MAX(MAX_SPACE)-MAX(USED_SPACE)  ) /MAX(MAX_SPACE) ) *100) as FREE_PCT, 
  CASE WHEN (ROUND(( (MAX(MAX_SPACE)-MAX(USED_SPACE)  ) /MAX(MAX_SPACE) ) *100)<15)  THEN 'Y' ELSE 'N' END AS ADD_MORE_SPACE 
FROM ( 
SELECT tablespace_name,  
   ROUND(SUM(bytes)/1024/2014) AS FREE_SPACE, 
   0 AS MAX_SPACE, 
   0 AS USED_SPACE   
 FROM DBA_FREE_SPACE
 WHERE 1=1
   --AND tablespace_name LIKE '%IGT%' OR tablespace_name LIKE '%DWH%' OR tablespace_name LIKE '%REPORTS%' OR tablespace_name = 'SYSTEM'  OR tablespace_name = 'SYSAUX' 
 GROUP BY tablespace_name  
 UNION ALL 
 SELECT tablespace_name, 
   0 AS FREE_SPACE, 
   ROUND( SUM(CASE WHEN (bytes>maxbytes)  THEN bytes ELSE maxbytes END)/1024/1024) AS MAX_SPACE, 
     0 AS USED_SPACE 
 FROM DBA_DATA_FILES
  WHERE 1=1
   --AND tablespace_name LIKE '%IGT%' OR tablespace_name LIKE '%DWH%' OR tablespace_name LIKE '%REPORTS%' OR tablespace_name = 'SYSTEM'  OR tablespace_name = 'SYSAUX' 
 GROUP BY tablespace_name 
 UNION ALL 
 SELECT tablespace_name, 
     0 AS FREE_SPACE, 
     0 AS MAX_SPACE, 
     ROUND(SUM(bytes/1024/1024)) AS USED_SPACE 
  FROM DBA_SEGMENTS
 WHERE 1=1
   --AND tablespace_name LIKE '%IGT%' OR tablespace_name LIKE '%DWH%' OR tablespace_name LIKE '%REPORTS%' OR tablespace_name = 'SYSTEM'  OR tablespace_name = 'SYSAUX' 
GROUP BY tablespace_name 
) 
GROUP BY tablespace_name;

spool off



spool segments.txt

SELECT owner, tablespace_name, segment_name, USED_MB 
   FROM ( 
  SELECT owner, tablespace_name, segment_name, ROUND(SUM(bytes)/1024/1024)AS USED_MB FROM DBA_SEGMENTS
   WHERE tablespace_name LIKE '%TABLE%' 
  GROUP BY owner, tablespace_name,segment_name 
  ORDER BY ROUND(SUM(bytes)/1024/1024) DESC 
) WHERE ROWNUM < 11;


SELECT owner, tablespace_name, segment_name, USED_MB 
   FROM ( 
  SELECT owner, tablespace_name, segment_name, ROUND(SUM(bytes)/1024/1024)AS USED_MB FROM DBA_SEGMENTS
   WHERE tablespace_name LIKE '%INDEX%' 
  GROUP BY owner, tablespace_name,segment_name 
  ORDER BY ROUND(SUM(bytes)/1024/1024) DESC 
) WHERE ROWNUM < 11;

SELECT owner, tablespace_name, segment_name, USED_MB 
   FROM ( 
  SELECT owner, tablespace_name, segment_name, ROUND(SUM(bytes)/1024/1024)AS USED_MB FROM DBA_SEGMENTS
   WHERE tablespace_name LIKE '%SYSTEM%' 
  GROUP BY owner, tablespace_name,segment_name 
  ORDER BY ROUND(SUM(bytes)/1024/1024) DESC 
) WHERE ROWNUM < 11;


SELECT owner, tablespace_name, segment_name, USED_MB 
   FROM ( 
  SELECT owner, tablespace_name, segment_name, ROUND(SUM(bytes)/1024/1024)AS USED_MB FROM DBA_SEGMENTS
   WHERE tablespace_name LIKE '%SYSAUX%' 
  GROUP BY owner, tablespace_name,segment_name 
  ORDER BY ROUND(SUM(bytes)/1024/1024) DESC 
) WHERE ROWNUM < 11;

spool off


spool datafile.txt
SELECT tablespace_name, file_name, ROUND(bytes/1024/1024) AS Mb, ROUND(maxbytes/1024/1024) AS MAX_MB
  FROM DBA_DATA_FILES;
spool off

spool temp_file.txt
SELECT tablespace_name, file_name, ROUND(bytes/1024/1024) AS Mb, ROUND(maxbytes/1024/1024) AS MAX_MB
  FROM DBA_TEMP_FILES;
spool off

spool invalid_indexes.txt
col owner for A30
col INDEX_NAME for A30
SET LINESIZE 120
SELECT owner, index_name, status 
  FROM DBA_INDEXES 
 WHERE status <> 'VALID' AND status <> 'N/A';

spool memory_params.txt
col name for A30
col value for A30
SELECT name, value 
  FROM V$PARAMETER 
 WHERE name IN ('memory_target', 'memory_max_target')
ORDER BY name;
spool off

exit;


Fast alternative to Tablespace Calculation - same as ora_stats.sql results!
SELECT 
    m.tablespace_name,
    -- Current Used Space in MB
    ROUND(m.used_space * t.block_size / 1024 / 1024) AS used_mb,
    -- Maximum Possible Size in MB (Accounts for Autoextend)
    ROUND(m.tablespace_size * t.block_size / 1024 / 1024) AS max_size_mb,
    -- Remaining Available Space in MB
    ROUND((m.tablespace_size - m.used_space) * t.block_size / 1024 / 1024) AS free_mb,
    -- Usage Percentage
    100-ROUND(m.used_percent) AS pct_free
FROM DBA_TABLESPACE_USAGE_METRICS M
JOIN DBA_TABLESPACES T 
  ON m.tablespace_name = t.tablespace_name
ORDER BY pct_free ASC;

Thursday, November 10, 2022

Tuning Session Cached Cursors parameter

Session Cached Cursors parameter

Check the maximum value used by Oracle for value of Session Cached Cursors parameter

SELECT MAX(value) max_value
  FROM V$SESSTAT
 WHERE STATISTIC# IN
 (SELECT statistic# 
    FROM V$STATNAME 
   WHERE name = 'session cursor cache count');

max_value
---------
      500

If value has reached the maximum limit, then you can increase the value of this parameter.

Check the usage percentage of Session Cached Cursors

SELECT 'session_cached_cursors' parameter,
       LPAD(value, 5) value,
       DECODE(value, 0, ' N/A', TO_CHAR(100 * used / value, '990') || '%') usage
FROM (SELECT MAX(S.value) used
        FROM SYS.V_$STATNAME N, 
     SYS.V_$SESSTAT S
       WHERE N.name = 'session cursor cache count'
         AND S.statistic# = N.statistic#),
     (SELECT value
        FROM SYS.V_$PARAMETER
       WHERE name = 'session_cached_cursors');

PARAMETER                   VALUE    USAGE
------------------------ -------- --------
session_cached_cursors        500     100%


Note: If usage is above 95% percent than you can also increase the value.

Increase or Decrease the value by setting with alter command
To change this parameter need to restart the Database.

ALTER SYSTEM SET session_cached_cursors = 1000 SCOPE=SPFILE;
SHUTDOWN IMMEDIATE;
STARTUP;

This parameter can also be changed at Session level

ALTER SESSION SET session_cached_cursors = 1000;

To get info about query+session:

SELECT C.user_name, C.sid, VSQL.sql_text
  FROM V$OPEN_CURSOR C, V$SQL VSQL
 WHERE C.sql_id = VSQL.sql_id 
   AND VSQL.sql_text LIKE 'MERGE into SGA_W_IPN_SUBSCRIBER%';


SELECT sql_text, 
       SUM(executions)  executions,
       SUM(end_of_fetch_count) end_of_fetch_count,
       SUM(parse_calls) parse_calls,
       SUM(invalidations) invalidations,
       SUM(cpu_time) cpu_time
  FROM V$SQL
WHERE sql_text LIKE 'MERGE into SGA_W_IPN_SUBSCRIBER%'
GROUP BY sql_text
HAVING SUM(parse_calls) > 1
ORDER BY SUM(parse_calls) DESC;

Wednesday, November 9, 2022

Example - sftp file from windows

Example - sftp file from windows server

scheduled task 
 -> sftp_check.bat 
    -> sftp_check.pl 
        -> send_SFTP.bat -> send_SFTP.sh -> SEND_SFTP.ini
        -> sendSFTPMail.bat


sftp_check.bat
perl sftp_check.pl

perl sftp_check.pl
#!/usr/bin/perl

use Time::gmtime;
use File::Copy;
use Net::FTP;

############################################################################
#####A subroutine to get the current date ##################################
############################################################################
sub getDate
{
  use Time::gmtime;
  $tm=gmtime;
  ($day,$month,$year) = (gmtime) [3,4,5];
  my $locDate=sprintf("%04d%02d%02d",$tm->year+1900,($tm->mon)+1,$tm->mday);
  return $locDate;
}

############################################################################
#####A subroutine to get the current time ##################################
############################################################################
sub getTime
{
 use Time::gmtime;
 $lt=gmtime;
 ($hour,$minute,$seconds)=(gmtime) [1,2];
 my $LocTime = sprintf ("%02d%02d%02d",$lt->hour,$lt->min,$lt->sec);
 return $LocTime
}

#######################################################################################
#####A subroutine to send a file using SCP ############################################
#######################################################################################
sub SFTP_FILE
{
  local($FileNameText)=($_[0]);
  ##call the batch file
  my @SendArg=("D:\\SFTP_CHECK\\send_sftp.bat",$FileNameText);
  my $locRetCode;
  $locRetCode=system(@SendArg);
  if ($locRetCode==0)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}

my $runDate=getDate;
my $runTime=getTime;

my $logFile="D:\\sftp_check\\Logs\\runLog_".$runDate."_".$runTime.".txt";
unlink $logFile;
open (MyLog,">>".$logFile);

print MyLog "### Strating sftp monitor process for date: ".$runDate." ".$runTime." ###";
print MyLog "\n";

 $retCode=SFTP_FILE;
         if ($retCode !=1 )
         {
            print MyLog "----E---- cannot SFTP ".$FileNameText." to the SFTP Server \n";
            print MyLog "\n";
            close(MyLog);
            @mailArg=("D:\\SFTP_CHECK\\sendSFTPMail.bat",$logFile);
            system(@mailArg);
            die;
         }
         else
         {
            print MyLog "File successfully sent to server.";
            print MyLog "\n";

         }

print MyLog "### End SFTP Check process ###";
print MyLog "\n";
close(MyLog); 


send_SFTP.bat
d:\software\cygwin\bin\bash.exe --login /cygdrive/D/SFTP_CHECK/send_SFTP.sh

send_SFTP.sh
sftp -b /cygdrive/d/SFTP_CHECK/SEND_SFTP.ini smart-phl@111.222.333.444

SEND_SFTP.ini
cd incoming
put /cygdrive/d/SFTP_CHECK/a.txt
bye 


sendSFTPMail.bat
blat SFTPMailBody.txt -to some.user1@domain.com, some.user2@domain.com -i some.user3@domain.com -subject "SFTP FROM BDS Failure" 

Tuesday, November 8, 2022

Make Linux user password never expire

Make Linux user password never expire

chage -l oracle
Last password change                               : Sep 23, 2021
Password expires                                   : Dec 22, 2021
Password inactive                                  : never
Account expires                                    : never
Minimum number of days between password change     : 7
Maximum number of days between password change     : 90
Number of days of warning before password expires  : 7

chage -M -1 oracle

passwd oracle

chage -l oracle
Last password change                               : Nov 08, 2022
Password expires                                   : never
Password inactive                                  : never
Account expires                                    : never
Minimum number of days between password change     : 7
Maximum number of days between password change     : -1
Number of days of warning before password expires  : 7

Monday, November 7, 2022

SQL Tuning I- get explain plan

SET AUTOTRACE OFF
No AUTOTRACE report is generated. This is the default.

SET AUTOTRACE ON EXPLAIN
The AUTOTRACE report shows only the optimizer execution path.

SET AUTOTRACE ON STATISTICS
The AUTOTRACE report shows only the SQL statement execution statistics.

SET AUTOTRACE ON
Execute the SQL + display the execution plan.
The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.

SET AUTOTRACE TRACEONLY
Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any.


SET AUTOTRACE ON EXPLAIN ERROR:
ORA-01039: insufficient privileges on underlying objects of the view
GRANT PLUSTRACE TO <USER>;


Example for SET AUTOTRACE ON EXPLAIN output
Execution Plan
----------------------------------------------------------
Plan hash value: 2393427686

--------------------------------------------------------------------------------
-----------------

| Id  | Operation                | Name                 | Rows  | Bytes | Cost (
%CPU)| Time     |

--------------------------------------------------------------------------------
-----------------

|   0 | SELECT STATEMENT         |                      |   436K|    77M|   309K
  (1)| 00:00:13 |

|   1 |  HASH GROUP BY           |                      |   436K|    77M|   309K
  (1)| 00:00:13 |

|*  2 |   HASH JOIN              |                      |   436K|    77M|   309K
  (1)| 00:00:13 |

|   3 |    TABLE ACCESS FULL     | IPN_PROFILES         |   713 | 12121 |     6
  (0)| 00:00:01 |

|*  4 |    HASH JOIN             |                      |   436K|    70M|   309K
  (1)| 00:00:13 |

|   5 |     INDEX FULL SCAN      | SGA_OUT_COMM_PK      |     6 |    18 |     1
  (0)| 00:00:01 |

|*  6 |     HASH JOIN RIGHT OUTER|                      |   436K|    69M|   309K
  (1)| 00:00:13 |

|   7 |      TABLE ACCESS FULL   | SGA_SUBSCRIBER_SFI   |     2 |   106 |     3
  (0)| 00:00:01 |

|*  8 |      HASH JOIN           |                      |   436K|    47M|   309K
  (1)| 00:00:13 |

|*  9 |       INDEX SKIP SCAN    | SHM_ACTIVE_SITE_PK   |     4 |    28 |     1
  (0)| 00:00:01 |

|* 10 |       TABLE ACCESS FULL  | SGA_W_IPN_SUBSCRIBER |   498K|    50M|   309K
  (1)| 00:00:13 |

--------------------------------------------------------------------------------
-----------------

Predicate Information (identified by operation id):
---------------------------------------------------
   2 - access("S"."IPN_CURR_IPN_PROFILE_ID"="PROF"."PROFILE_ID")
   4 - access("S"."IPN_CURRENT_COMMUNITY"="COMM"."COMMUNITY_ID")
   6 - access("S"."IMSI"="SSSA"."IMSI"(+) AND
              "S"."AFFILIATE_ID"="SSSA"."AFFILIATE_ID"(+))
   8 - access("S"."AFFILIATE_ID"="AFFILIATE_ID")
   9 - access("VNFC_ID"=32)
       filter("VNFC_ID"=32)
  10 - filter("S"."CURRENT_NETWORK_ID"<>(-999))

Sunday, November 6, 2022

How to see Oracle Hidden Parameters

================
General
================
Ho to see Oracle Hidden parameters

COL PARAMETER FOR A30
COL "Session Value" FOR A30
COL "Instance Value" FOR A30
SET LINESIZE 140
SET PAGESIZE 100
SELECT PARAM.ksppinm "Parameter",
       SESS.ksppstvl "Session Value",
       INST.ksppstvl "Instance Value"
  FROM x$ksppi PARAM,
       x$ksppcv SESS,
       x$ksppsv INST
WHERE  PARAM.indx = SESS.indx
  AND  PARAM.indx = INST.indx
  AND  PARAM.ksppinm LIKE '/_%' escape '/'
  AND  PARAM.ksppinm LIKE '_optimizer_invalidation_period'
ORDER BY PARAM.ksppinm;

Parameter                      Session Value Instance Value
------------------------------ ------------- --------------
_optimizer_invalidation_period         18000          18000


Sunday, October 23, 2022

How to create a Service Request with Oracle Support

===========================
General
===========================
Short description of steps how to create SR for Oracle support

===========================
Steps in Short
===========================
Login to metalink
Service Requests (on top)
Create SR

===========================
Craete SR Steps
===========================
The Create SR consists of four screens:
Problem Summary - Issue description + product versions
Solutions - Proposed known solution for the issue.
More Details - Option to attach file
Contact information - Option to update phone and additional contact details.

Problem Summary screen
Problem Summary: Archive files are not cleaned up by RMAN due to "stuck" OGG caption process.

Problem Description:
We have an environment with OGG between two instances.
Per each schema there is a dedicated process of CAPTION, EXTRACT, REPLICATION.
On 3rd Aug, OGG was removed for some of the schemas.
Since then, archive files stopped to be deleted by RMAN.
For one of the schemas, we still can see the caption process in DBA_CAPTIONS, in status DISABLED.
But this process is not visible in GGSCI.

We need help to drop this process.
And to resolve issue of archive files not being deleted by RMAN process.

Error Codes:
N/A


Product: Oracle Database, Oracle GoldenGate, etc.
Product Version: 12.1.2.0.0
Product Languages: English
Operating System/Version: Red Hat Enterprise Linux Server release 6.5 (Santiago) (from  /etc/redhat-release)
Database/Version: 11.2.0.4.0
Database Platform/Version: Red Hat Enterprise Linux Server release 6.5 (Santiago) (from  /etc/redhat-release)
Problem Type:  Select from dropdown.


Solutions Screen: 
Review the following documents to troubleshoot this issue:
Goldengate Extract v11.1.1.0.0_78 Abended without Any Errors When Processing Direct Load Records (1254514.1)
Extract Crashing without Any Error on OGG 11.2.1.0.5 When the Source Oracle DB Is on a RAC Environment (1550356.1)
If the solutions above do not resolve your issue, follow the steps detailed in the document below:
SRDC - Information to Collect When GoldenGate Extract/Replicat Abends without Error (1906071.1)
We recommend saving this session as a draft Service Request (SR). Once data gathering is complete, proceed with the next step to upload requested data and submit SR.

More Details Screen
Attach files option

Personal Contact Screen
Not possible to change mail
Only to update phone, and add additional contact details.