Pages

Sunday, November 27, 2022

ora_fbda process is consuming CPU

==================
General 
==================
ora_fdba is the process for Oracle FDA
FDA - Flashback Data Archive
Flashback Data Archive was introduced in Oracle 11gR2 as a seamless way for providing a mechanism that tracks transactional changes to database tables.

This feature is often implemented to satisfy regulatory and compliance requirements for sensitive data such as financial, health, and data deemed to be sensitive requiring scrutiny at a later time.

Flashback Data Archive leverages existing technologies already in place within the Oracle RDBMS  software.  
The core piece that is leveraged is the rollback (aka undo) segments that are used to provide read consistency when queries are executed.  
Undo segments hold transaction information and the “before image” of rows that have been modified.  Instead of using a BEFORE change type trigger to collect the values of a row that is about to be modified, we can directly use the undo segments to capture that information.  
Once the transaction is captured, it is then archived into the FBDA history tables along with metadata.

To see if the feature is enabled:

SHOW PARAMETER flashback
NAME                           VALUE
------------------------------ ------------------------------
db_flashback_retention_target  1440
_disable_flashback_archiver    0


==================
Issues
==================
Errors in igt_fbda_99999.trc
igt_fbda_29055.trc:FBDA: Error ORA-4030 in SQL "select count(FA#) from SYS_FBA_FA where bitand(FLAGS, 2) != 0"
igt_fbda_29055.trc:FBDA: Error ORA-4030 in SQL "select count(FA#) from SYS_FBA_FA where bitand(FLAGS, 2) != 0"
igt_fbda_29055.trc:FBDA: Error ORA-4030 in SQL "select count(FA#) from SYS_FBA_FA where bitand(FLAGS, 2) != 0"
igt_fbda_29055.trc:FBDA: Error ORA-4030 in SQL "select count(FA#) from SYS_FBA_FA where bitand(FLAGS, 2) != 0"
igt_fbda_29055.trc:FBDA: Error ORA-4030 in SQL "select count(FA#) from SYS_FBA_FA where bitand(FLAGS, 2) != 0"
igt_fbda_29055.trc:Error: ORA-4030 [ORA-04030: out of process memory when trying to allocate 63904 bytes (kxs-heap-f,frame segment)
igt_fbda_29055.trc:   ORA-04030: out of process memory when trying to allocate 63904 bytes (kxs-heap-f,frame segment)
igt_fbda_29055.trc:ORA-04030: out of process memory when trying to allocate 63904 bytes (kxs-heap-f,frame segment)


Error in alert.log
2022-11-24T08:46:35.507803+00:00
DDE: Problem Key 'ORA 4030' was completely flood controlled (0x6)
Further messages for this problem key will be suppressed for up to 10 minutes


top
top - 09:54:57 up 254 days,  1:05,  4 users,  load average: 2.21, 2.00, 1.81
Tasks: 880 total,   3 running, 877 sleeping,   0 stopped,   0 zombie
%Cpu(s): 10.0 us,  6.2 sy,  0.0 ni, 83.0 id,  0.5 wa,  0.0 hi,  0.3 si,  0.0 st
KiB Mem : 19791907+total, 11285169+free, 47707760 used, 37359616 buff/cache
KiB Swap: 10485756 total, 10485756 free,        0 used. 12048308+avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
18778 oracle    20   0   64.5g 285720 280120 R  90.8  0.1   0:16.22 ora_fbda_igt
18541 oracle    20   0   64.5g  52280  49364 S  27.5  0.0   0:03.82 ora_lg00_igt
18533 oracle    20   0   64.5g 138716 133848 S  17.4  0.1   0:02.59 ora_lgwr_igt
19481 oracle    20   0   64.5g  49644  44864 S   5.6  0.0   0:00.50 oracle_19481_ig
 7900 root      20   0       0      0      0 S   4.9  0.0   1737:19 drbd_s_db1
18466 oracle    -2   0   64.5g  19856  16916 S   2.6  0.0   0:00.90 ora_vktm_igt
19557 oracle    20   0   64.5g  51952  46952 S   2.6  0.0   0:00.21 oracle_19557_


ora_fbda has out of memory errors.
But FBA tables are empty.

SELECT * FROM DBA_FLASHBACK_ARCHIVE - Empty
SELECT * FROM DBA_FLASHBACK_ARCHIVE_TS - Empty
SELECT * FROM DBA_FLASHBACK_ARCHIVE_TABLES - Empty
SELECT * FROM DBA_FLASHBACK_ARCHIVE; - Empty





Per oracle technote: HIGH CPU USE BY THE FBDA PROCESS EVEN AFTER FULLY DISABLING THE FLASHBACK ARCHIVER (Doc ID 2559595.1)

There is a know issue where there is high CPU consumption by the FBDA process in the production instance due to the background process FBDA


The FBDA enabled tables were disabled but the FBDA bg process started and consumed high CPU attempting to archive nothing since no tables are enabled.
There are no SYS_FBA_TCRV_% or SYS_FBA_HIST_% tables which are the internal history tables for FBDA enabled tables. There is nothing showing enabled but the FBDA process continues to start and run.  It's expected the process cannot be stopped when there are enabled tables.

SELECT segment_name, partition_name, bytes 
FROM DBA_SEGMENTS 
WHERE segment_name like 'SYS_FBA_HIST%'
ORDER BY segment_name;
no rows selected

SELECT segment_name,segment_type,bytes/1024/1024 MB
FROM DBA_SEGMENTS 
WHERE segment_type='TABLE' and segment_name LIKE 'SYS_FBA_TCRV%';
no rows selected

SELECT T.FLASHBACK_ARCHIVE_NAME,
       T.TABLE_NAME,
       P.PARTITION_NAME,
       P.NUM_ROWS,
       ROUND ( (P.BLOCKS * 8) / 1024) SIZE_MB
 FROM DBA_FLASHBACK_ARCHIVE_TABLES T, 
      DBA_TAB_PARTITIONS P
 WHERE T.archive_table_name = P.table_name 
   AND partition_name='HIGH_PART'
 ORDER BY T.flashback_archive_name, T.table_name, P.num_rows DESC;
no rows selected

SELECT MAX(ROUND ( (BLOCKS * 8) / 1024)) SIZE_MB 
FROM DBA_TAB_PARTITIONS
 WHERE PARTITION_NAME='HIGH_PART';
 
   SIZE_MB
----------


SELECT p.spid "SPID",
       b.name "Background Process",
       s.status "STATUS",
       s.sid "Session ID",
       s.serial# "Serial No."
  FROM V$PROCESS P, 
       V$BGPROCESS B, 
       V$SESSION S
  WHERE s.paddr = p.addr
  AND b.paddr(+) = p.addr
  AND b.name = 'FBDA';
  
  
SPID               Backg STATUS        Session ID Serial No.
------------------ ----- ------------- ---------- ----------
18778                    FBDA  ACTIVE        2272 9338


set linesize 120
set numwidth 20
SELECT * FROM SYS_FBA_BARRIERSCN;

INST_ID BARRIERSCN   ACTIVESCN STATUS    SPARE
------- ------------ --------- --------- ---------
      0 54983371892  54983371892       
   
   
col owner format a20
col table_name format a25
col tablespace_name format a20
SELECT owner, table_name, tablespace_name
FROM DBA_TABLES
WHERE table_name LIKE 'SYS_FBA%';


OWNER                TABLE_NAME                TABLESPACE_NAME
-------------------- ------------------------- --------------------
SYS                  SYS_FBA_FA                SYSTEM
SYS                  SYS_FBA_TSFA              SYSTEM
SYS                  SYS_FBA_TRACKEDTABLES     SYSTEM
SYS                  SYS_FBA_PARTITIONS        SYSTEM
SYS                  SYS_FBA_USERS             SYSTEM
SYS                  SYS_FBA_BARRIERSCN        SYSTEM
SYS                  SYS_FBA_DL                SYSTEM
SYS                  SYS_FBA_CONTEXT           SYSTEM
SYS                  SYS_FBA_CONTEXT_AUD       SYSTEM
SYS                  SYS_FBA_CONTEXT_LIST      SYSTEM
SYS                  SYS_FBA_APP               SYSTEM
SYS                  SYS_FBA_APP_TABLES        SYSTEM
SYS                  SYS_FBA_COLS              SYSTEM
SYS                  SYS_FBA_PERIOD            SYSTEM

There are no TCRV or HIST tables

To force FBDA to be disabled follow this process.

Disable flashback archiving.

alter system set "_disable_flashback_archiver"=1;
System altered.

COL NAME FOR A30
COL VALUE FOR A30
SELECT name, value FROM V$PARAMETER 
WHERE name = '_disable_flashback_archiver';

NAME                           VALUE
------------------------------ ----------
_disable_flashback_archiver    1


SELECT p.spid "SPID",
b.name "Background Process",
s.status "STATUS",
s.sid "Session ID",
s.serial# "Serial No."
FROM v$process p, v$bgprocess b, v$session s
WHERE s.paddr = p.addr
AND b.paddr(+) = p.addr
AND b.name = 'FBDA'; 

SPID                     Backg STATUS                                     Session ID           Serial No.
------------------------ ----- -------------------------------- -------------------- --------------------
18778                    FBDA  ACTIVE                                          2272                  9338

kill -9 18778


Alternative to kill process - would be to bounce the instance

Once done - ora_fbda process is gone.

==================
script to kill fdba process
==================

#!/bin/bash

. /etc/sh/orash/oracle_login.sh igt

sqlplus / as sysdba << EOF
SET HEADING OFF
SET PAGESIZE 0
spool tmp_cmd_kill_fdba.sh
SELECT 'kill -9 '||p.spid
FROM v$process p, v$bgprocess b, v$session s
WHERE s.paddr = p.addr
AND b.paddr(+) = p.addr
AND b.name = 'FBDA';
EXIT;
EOF

less tmp_cmd_kill_fdba.sh | grep kill | grep -v SELECT > cmd_kill_fdba.sh
chmod 744 cmd_kill_fdba.sh
./cmd_kill_fdba.sh
rm -f tmp_cmd_kill_fdba.sh >/dev/null
exit

Saturday, November 19, 2022

Golden Gate Datapump not working after crash start. "Showing Current status: In recovery[2]: At EOF" and "No active extraction maps."

================
Issue
================
Database server was stopped and was restarted
After that , Golden Gate Datapump Extract is not running.
There is no error, but the Datapump Extract is constantly in recovery.
And it not updating the second node.


================
In General
================
When running
INFO DPM_EXTRACT DETAIL and checking the log file:

 
Switching to next trail file /software/ogg/191/dirdat/01/out/ei000009314
Rolling over remote file /software/ogg/191/dirdat/01/in/ei000009159

dirdat/01/out/ei000009314 - It is s the file on THIS server. It is written by EXTRACT process. Can double check by looking into the report file for EXTRACT(Recovery completed for target file /software/ogg/191/dirdat/01/out/ei000009314, at RBA 1538)

191/dirdat/01/in/ei000009159 - It is the file on REMOTE server. It is written by the DATAPUMP on the REMOTE server, and read by REPLICAT on the REMOTE server as well.
Can double check by looking into the REPLICAT report file on remote server: 
Switching to next trail file /software/ogg/191/dirdat/01/in/ei000009159

================
By Example
================
> SEND DPM_S_01 STATS

Sending STATS request to EXTRACT DPM_S_01 ...

No active extraction maps.

> SEND DPM_S_01 STATUS

Sending STATUS request to EXTRACT DPM_S_01 ...
EXTRACT DPM_S_01 (PID 9275)
  Current status: In recovery[2]: At EOF

  Current read position:
  Sequence #: 10177
  RBA: 212360562
  Timestamp: 2022-11-19 13:10:36.000000
  Extract Trail: /software/ogg/191/dirdat/01/out/es

  Current write position:
  Sequence #: 10177
  RBA: 0
  Timestamp: 2022-11-14 16:19:13.265526
  Extract Trail: /software/ogg/191/dirdat/01/in/es

================
Solution
================
In General:

1. Query the main extract for current Sequence and RBA.

2. Update the Data Pump Extract with the values from step 1.

3. In case it still does not work, do ALTER EXTRACT MAIN_EXTRACT ETROLLOVER and repeat steps 1+2.

ALTER EXTRACT MAIN_EXTRACT ETROLLOVER instructs main extract to switch writing to a new file. It might be that the previous file got somehow corrupted during database server sudden shutdown. 

================
By Example
================
EXT_S_01 - is the main extract
DPM_S_01 - is the data pump extract

> INFO EXT_S_01 SHOWCH

EXTRACT    EXT_S_01  Last Started 2022-11-19 13:09   Status RUNNING
Checkpoint Lag       00:00:02 (updated 00:00:04 ago)
Process ID           12516
Log Read Checkpoint  Oracle Integrated Redo Logs
                     2022-11-19 20:02:51
                     SCN 6.1510356821 (27280160597)


Current Checkpoint Detail:

Read Checkpoint #1

  Oracle Integrated Redo Log

  Startup Checkpoint (starting position in the data source):
    Timestamp: 2022-09-04 06:54:43.000000
    SCN: 0.0 (0)

  Recovery Checkpoint (position of oldest unprocessed transaction in the data source):
    Timestamp: 2022-11-19 20:02:43.000000
    SCN: 6.1510354581 (27280158357)

  Current Checkpoint (position of last record read in the data source):
    Timestamp: 2022-11-19 20:02:51.000000
    SCN: 6.1510356821 (27280160597)

  BR Previous Recovery Checkpoint:
    Timestamp: 2022-11-19 13:09:17.917578
    SCN: 0.0 (0)

  BR Begin Recovery Checkpoint:
    Timestamp: 2022-11-19 17:08:13.000000
    SCN: 6.1507821110 (27277624886)

  BR End Recovery Checkpoint:
    Timestamp: 2022-11-19 17:09:32.000000
    SCN: 6.1507838612 (27277642388)

Write Checkpoint #1

  GGS Log Trail

  Current Checkpoint (current write position):
    Sequence #: 10177
    RBA: 212375522
    Timestamp: 2022-11-19 20:02:53.678942
    Extract Trail: /software/ogg/191/dirdat/01/out/es
    Seqno Length: 9
    Flip Seqno Length: No
    Trail Type: EXTTRAIL

Header:
  Version = 2
  Record Source = A
  Type = 18
  # Input Checkpoints = 1
  # Output Checkpoints = 1

Configuration:
  Data Source = 3
  Transaction Integrity = 1
  Task Type = 0

Status:
  Start Time = 2022-11-19 13:09:25
  Last Update Time = 2022-11-19 20:02:53
  Stop Status = A
  Last Result = 0

STOP EXTRACT DPM_S_01
> ALTER EXTRACT DPM_S_01 EXTSEQNO 10177
> ALTER EXTRACT DPM_S_01 EXTRBA 212375522
> START EXTRACT DPM_S_01

Datapump still showing that it is not working.
SEND DPM_S_01 STATS
Sending STATS request to EXTRACT DPM_S_01 ...
No active extraction maps.


In case it still does not work, do ALTER EXTRACT MAIN_EXTRACT ETROLLOVER and repeat steps 1+2.

> STOP  EXTRACT EXT_S_01
ALTER EXTRACT EXT_S_01 ETROLLOVER
START EXTRACT EXT_S_01
> INFO EXTRACT EXT_S_01 SHOWCH
  Current Checkpoint (current write position):
    Sequence #: 10178
    RBA: 1464
    Timestamp: 2022-11-19 20:50:25.993536
    Extract Trail: /software/ogg/191/dirdat/01/out/es
    Seqno Length: 9
    Flip Seqno Length: No
    Trail Type: EXTTRAIL

> STOP EXTRACT DPM_S_01
> ALTER EXTRACT DPM_S_01 EXTSEQNO 10178
> ALTER EXTRACT DPM_S_01 EXTRBA 1464
> START EXTRACT DPM_S_01
> INFO EXTRACT DPM_S_01

EXTRACT    DPM_S_01  Last Started 2022-11-19 20:51   Status RUNNING
Checkpoint Lag       00:00:00 (updated 00:00:03 ago)
Process ID           16893
Log Read Checkpoint  File /software/ogg/191/dirdat/01/out/es000010178
                     First Record  RBA 1464

> INFO ALL
Program     Status      Group       Lag at Chkpt  Time Since Chkpt

MANAGER     RUNNING
EXTRACT     RUNNING     DPM_I_01    00:00:00      00:00:07
EXTRACT     RUNNING     DPM_P_01    00:00:00      00:00:01
EXTRACT     RUNNING     DPM_S_01    00:00:00      00:00:07
EXTRACT     RUNNING     EXT_I_01    00:00:02      00:00:04
EXTRACT     RUNNING     EXT_P_01    00:00:02      00:00:01
EXTRACT     RUNNING     EXT_S_01    00:00:03      00:00:01
REPLICAT    RUNNING     REP_I_01    00:00:00      00:00:03
REPLICAT    RUNNING     REP_P_01    00:00:05      00:00:02
REPLICAT    RUNNING     REP_S_01    00:00:07      00:00:01
> SEND DPM_S_01 STATS

Sending STATS request to EXTRACT DPM_S_01 ...

Start of Statistics at 2022-11-19 21:46:50.

Output to /software/ogg/191/dirdat/01/in/es:

Extracting from SOME_USER.SGA_W_PSMS_SUBSCRIBER to SOME_USER.SGA_W_PSMS_SUBSCRIBER:

*** Total statistics since 2022-11-19 21:12:34 ***
        Total inserts                                      0.00
        Total updates                                      2.00
        Total deletes                                      0.00
        Total upserts                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00

*** Daily statistics since 2022-11-19 21:12:34 ***
        Total inserts                                      0.00
        Total updates                                      2.00
        Total deletes                                      0.00
        Total upserts                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00

*** Hourly statistics since 2022-11-19 21:12:34 ***
        Total inserts                                      0.00
        Total updates                                      2.00
        Total deletes                                      0.00
        Total upserts                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00

*** Latest statistics since 2022-11-19 21:12:34 ***
        Total inserts                                      0.00
        Total updates                                      2.00
        Total deletes                                      0.00
        Total upserts                                      0.00
        Total discards                                     0.00
        Total operations                                   2.00

End of Statistics.

Thursday, November 17, 2022

ora-01720 undefined grant option does not exist

===================
General
===================
User B has a permission to do SELECT from USER_A.TABLE_A.
But is getting an error when trying to create a view with 
USER_A.TABLE_A.

ORA-01720 means that the grantor doesn't have the right privilege to grant a view to the third user.

===================
Example and Solution
===================
USER_A
GRANT SELECT ON TABLE_A TO USER_B;

USER_B
SELECT * FROM USER_A.TABLE_A;
--OK

CREATE OR REPLACE VIEW VIEW_A AS SELECT * FROM USER_A.TABLE_A;
ORA-01720 undefined grant option does not exist for

Solution:
USER_A
GRANT SELECT ON TABLE_A TO USER_B WITH GRANT OPTION;

USER_B
CREATE OR REPLACE VIEW VIEW_A AS SELECT * FROM USER_A.TABLE_A;
--OK;

Monday, November 14, 2022

RMAN ORA-27037: unable to obtain file status

===============
General
===============
After running RMAN, archive files are not deleted
In RMAN log, there is an error:

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 11/14/2022 15:00:44
RMAN-06059: expected archived log not found, loss of archived log compromises recoverability
ORA-19625: error identifying file /oracle_db/db1/db_igt/arch/arch0001_2710_1084024359.arc
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 7

===============
General
===============
The solution would be to :

rman  target / 
crosscheck archivelog all;
delete expired archivelog all;

===============
Example
===============

rman target /

RMAN> LIST EXPIRED ARCHIVELOG ALL; specification does not match any archived log in the recovery catalog 

RMAN> LIST ARCHIVELOG ALL;
A list of archive several days old is listed.


Now run RMAN backup

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of backup command at 09/11/2017 17:12:54
RMAN-06059: expected archived log not found, lost of archived log compromises recoverability
ORA-19625: error identifying file /oracle_db/db2/db_igt/arch/arch0001_100463_669127092.arc
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


This was because some arch files were already deleted.

CROSSCHECK ARCHIVELOG ALL;
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101016_669127092.arc RECID=101005 STAMP=954426612
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101017_669127092.arc RECID=101006 STAMP=954428414
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101018_669127092.arc RECID=101007 STAMP=954430213
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101019_669127092.arc RECID=101008 STAMP=954432013
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101020_669127092.arc RECID=101009 STAMP=954433815
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101021_669127092.arc RECID=101010 STAMP=954435614
validation succeeded for archived log
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_101022_669127092.arc RECID=101011 STAMP=954436373
Crosschecked 560 objects

LIST EXPIRED ARCHIVELOG ALL;  
Now many files are listed
100806  1    100817  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100817_669127092.arc

100807  1    100818  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100818_669127092.arc

100808  1    100819  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100819_669127092.arc

100809  1    100820  X 07-SEP-17
        Name: /oracle_db/db2/db_igt/arch/arch0001_100820_669127092.arc


DELETE EXPIRED ARCHIVELOG ALL;  
Many files are deleted, some are kept
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100816_669127092.arc thread=1 sequence=100816
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100817_669127092.arc thread=1 sequence=100817
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100818_669127092.arc thread=1 sequence=100818
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100819_669127092.arc thread=1 sequence=100819
RMAN-08137: WARNING: archived log not deleted as it is still needed
archived log file name=/oracle_db/db2/db_igt/arch/arch0001_100820_669127092.arc thread=1 sequence=100820


Now run RMAN backup again

./rman target / log=/backup/ora_online/logs/$1_backup_$DATE.log << EOF sql 'alter system archive log current'; run { allocate channel C1 type disk; allocate channel C2 type disk; backup AS COMPRESSED BACKUPSET tag whole_database_open format '/backup/ora_online/$1/$1_$DATE/db_%T_%t_s%s_p%p.bak' (DATABASE); BACKUP format '/backup/ora_online/$1/$1_$DATE/AR_%d_%s_%p.bak' TAG 'Arch_backup' ARCHIVELOG ALL NOT BACKED UP DELETE ALL INPUT; #BACKUP format '/backup/ora_online/$1/$1_$DATE/AR_%d_%s_%p.bak' TAG 'Arch_backup' ARCHIVELOG ALL; backup current controlfile format '/backup/ora_online/$1/$1_$DATE/cntc_%T_%t_s%s_p%p'; release channel C1; release channel C2; } crosscheck archivelog all; crosscheck backup; delete noprompt obsolete; EOF

or
run { configure controlfile autobackup on; configure backup optimization on; set controlfile autobackup format for device type disk to '/backup/ora_online/20170911_1718/%F'; allocate channel 'dev_0' type disk format = '/backup/ora_online/20170911_1718/dbf_%d_%T_%U'; backup full database; backup archivelog from time = "TO_DATE('2017:09:11:17:18','YYYY:MM:DD:HH24:MI')-20" format '/backup/ora_online/20170911_1718/arch_%d_%T_%U'; release channel 'dev_0'; }



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;

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"