Monday, 5 November 2018

ORA-04031: unable to allocate x bytes of shared memory

Shared pool free space
                            

Summary 
Here is some useful information about Shared Pool size and free space. First of all you can find the parameters related to shared pool with the query:
SELECT NAME, VALUE/(1024*1024) SHARED_POOL_SIZE_MB 
FROM V$PARAMETER WHERE NAME LIKE '%shared_pool%';

NAME                                                    SHARED_POOL_SIZE_MB
---------------------------------------------------- -------------------
shared_pool_size                                          11488
shared_pool_reserved_size                                 574.4
You can find the free space in Shared pool with the query:
SELECT POOL,NAME, ROUND(BYTES/(1024*1024),2) FREE_MB 
FROM V$SGASTAT WHERE POOL='shared pool'
AND NAME='free memory'
ORDER BY BYTES DESC;

POOL         NAME                          FREE_MB
------------ -------------------------- ----------
shared pool  free memory                   8130.13

After oracle 10g the shared pool is divided in subpools. To find how many subpools your instance has you must follow the Metalink note 455179.1 because it depends on cpu number and init parameters.
How To Determine The Default Number Of Subpools Allocated During Startup [ID 455179.1] 

I think the maximum number of subpools that you can have is 7.

Each subpool is protected by a separate shared pool latch and each subpool has its own freelists and LRU list. To monitor how much space each subpool is using execute the query:
SELECT KSMCHIDX "SubPool", ROUND(SUM(KSMCHSIZ)/1024/1024) USED_MBYTES
FROM SYS.X$KSMSP 
GROUP BY KSMCHIDX 
ORDER BY KSMCHIDX ASC;

   SubPool  USED_MBYTES
---------- ----------
         1        944
         2       1424
         3       1216
         4        864

if you want to change the number of subpools from 7 to 4 for example then use the following hidden parameter:_kghdsidx_count = 4

Tip: Actually the subpools are not only as many as the oracle algorithm creates or what ever value the parameter _kghdsidx_count has. There is always one more! The subpool with KSMCHIDX=0. You can check this out with
select distinct ksmdsidx from x$ksmss order by ksmdsidx asc;

  KSMDSIDX
----------
         0
         1
         2
         3
         4
This is why when you startup the database not all memory allocated for shared pool is immediately given to subpool heaps. Some memory stays free allocated to subpool 0 and will be used to feature increases for the other pools. This mechanism allows some subpools to grab more memory than the others. So it is no strange if you monitor subpool imbalances!

From what i know a subpool heap cannot give memory back to some other subpool! I assume that is due to the fact that each subpool is protected by a separate shared pool latch and each subpool has its own freelists and LRU list.

using this query you can monitor all the subpools and 0 subpool free space
SELECT TO_CHAR(SYSDATE,'DD-MM-YYYY HH24:MI:SS') DT, KSMSSNAM NAME, 
       KSMDSIDX SUBPOOL, ROUND(KSMSSLEN/1024/1024) MBYTES 
    FROM X$KSMSS
WHERE KSMSSLEN > (10*1024*1024) OR KSMSSNAM='free memory' --more than 10MBytes
ORDER BY NAME, SUBPOOL;

DT                  NAME                          SUBPOOL     MBYTES
------------------- -------------------------- ---------- ----------
04-05-2011 13:36:43 ASH buffers                         1         68
04-05-2011 13:36:43 CCursor                             1         11
04-05-2011 13:36:43 Checkpoint queue                    1        195
04-05-2011 13:36:43 FileIdentificatonBlock              1         11
04-05-2011 13:36:43 FileOpenBlock                       1         15
04-05-2011 13:36:43 KQR M PO                            1         12
04-05-2011 13:36:43 KTI-UNDO                            1         16
04-05-2011 13:36:43 db_block_hash_buckets               1         45
04-05-2011 13:36:43 event statistics per sess           1         20
04-05-2011 13:36:43 free memory                         0      24112
04-05-2011 13:36:43 free memory                         1         67
04-05-2011 13:36:43 library cache                       1         20
04-05-2011 13:36:43 private strands                     1         31
04-05-2011 13:36:43 sessions                            1         12
04-05-2011 13:36:43 sql area                            1         49

To eliminate imbalances of the subpools you can set the _kghdsidx_count = 1. Then you will only have the 0 subpool and one subpool. If you set _kghdsidx_count = 1 then it is obvious that is working "like an Oracle9i" style.

A very common error related to shared pool misconfiguration or problems is:
ORA-04031: unable to allocate x bytes of shared memory 

To monitor if you have ORA-04031 errors you can use the query:
SELECT KGHLUSHRPOOL "SUBPOOL", KGHLURCR "PINS AND|RELEASES",
KGHLUTRN, KGHLUFSH, KGHLUOPS, KGHLUNFU "ORA-4031|ERRORS",
KGHLUNFS "LAST ERROR|SIZE" 
FROM SYS.X$KGHLU
WHERE INST_ID = USERENV('Instance') ;

                                                     PINS AND
   SUBPOOL PINS AND|RELEASES   KGHLUTRN   KGHLUFSH   RELEASES ORA-4031|ERRORS LAST ERROR|SIZE
---------- ----------------- ---------- ---------- ---------- --------------- ---------------
         0                 0        559          0       4057               0               0
         1            460039    1147916          0    4562952               0               0
If you want to see what Oracle advises for Shared pool size check this out:
SELECT SHARED_POOL_SIZE_FOR_ESTIMATE || ' MB' SHARED_POOL_SIZE_MB, 
SHARED_POOL_SIZE_FACTOR*100 || '%' RESIZE_SHARED_POOL_PERC, ESTD_LC_SIZE, 
ESTD_LC_MEMORY_OBJECTS, ESTD_LC_TIME_SAVED, ESTD_LC_TIME_SAVED_FACTOR, ESTD_LC_MEMORY_OBJECT_HITS 
FROM V$SHARED_POOL_ADVICE;
To check how much space is free at the shared_pool_reserved use this query:
SELECT ROUND(FREE_SPACE/(1024*1014), 2) SHARED_POOL_RESERVED_FREE_MB, 
ROUND(USED_SPACE/(1024*1024),2) SHARED_POOL_RESERVED_USED_MB 
FROM V$SHARED_POOL_RESERVED;

_____________________________________________________________________________



 Shared Pool Statistics        Begin    End
                              ------  ------
             Memory Usage %:    5.49   43.79
    % SQL with executions>1:   71.54   94.53
  % Memory for SQL w/exec>1:   66.33   94.91

SELECT SQL_ID,EXECUTIONS,DISK_READS,to_char(LAST_LOAD_TIME,'DD-MON-YYYY HH24:MI:SS') FROM V$SQLAREA WHERE SQL_ID in(select SQL_ID from v$sql_plan where options in('FULL SCAN','FULL') AND OBJECT_OWNER NOT IN('SYS','SYSTEM'))  ORDER BY disk_reads desc;


SQL> SQL> desc V$SGA_RESIZE_OPS
 Name                                     Null?    Type
 ---------------------------------------- -------- ---------------------------
 COMPONENT                                         VARCHAR2(64)
 OPER_TYPE                                         VARCHAR2(13)
 OPER_MODE                                         VARCHAR2(9)
 PARAMETER                                         VARCHAR2(80)
 INITIAL_SIZE                                      NUMBER
 TARGET_SIZE                                       NUMBER
 FINAL_SIZE                                        NUMBER
 STATUS                                            VARCHAR2(9)
 START_TIME                                        DATE
 END_TIME                                          DATE

SQL> select  COMPONENT  ,INITIAL_SIZE,TARGET_SIZE,FINAL_SIZE,STATUS from  V$SGA_RESIZE_OPS
  2  ;

SQL> select pool,name,sum(bytes)/1024/1024/1024 from v$sgastat where pool like 'shared%' group by pool,name order by sum(bytes)/1024/1024/1024 desc;

SQL> select pool,name,sum(bytes)/1024/1024/1024 from v$sgastat where pool like 'shared%' group by pool,name order by sum(bytes)/1024/1024/1024 desc;




SQL> desc v$sgastat;
 Name                                                                                Null?    Type
 ----------------------------------------------------------------------------------- -------- --------------------------------------------------------
 POOL                                                                                         VARCHAR2(12)
 NAME                                                                                         VARCHAR2(26)
 BYTES                                                                                        NUMBER

SQL> select * from v$sgastat where pool like 'SHARED%';

no rows selected

SQL> select * from v$sgastat where pool like 'shared%';



SQL> select COMPONENT,sum(CURRENT_SIZE)/1024/1024/1024,sum(MIN_SIZE)/1024/1024/1024  from v$SGA_DYNAMIC_COMPONENTS where component='shared pool' group by COMPONENT;

COMPONENT                      SUM(CURRENT_SIZE)/1024/1024/1024 SUM(MIN_SIZE)/1024/1024/1024
------------------------------ -------------------------------- ----------------------------
DEFAULT 2K buffer cache                                 .109375                      .109375
DEFAULT 4K buffer cache                                       0                            0
shared pool                                            17.53125                     17.53125
DEFAULT 8K buffer cache                                       0                            0
DEFAULT buffer cache                                     2.9375                       2.9375
DEFAULT 16K buffer cache                                      0                            0
ASM Buffer Cache                                              0                            0
streams pool                                            .109375                      .109375
KEEP buffer cache                                      1.765625                     1.765625
large pool                                                  .25                          .25
java pool                                               .140625                      .140625
DEFAULT 32K buffer cache                                      0                            0
RECYCLE buffer cache                                   3.515625                     3.515625

13 rows selected.


 select COMPONENT,sum(CURRENT_SIZE)/1024/1024/1024,sum(MIN_SIZE)/1024/1024/1024  from v$SGA_DYNAMIC_COMPONENTS where component='shared pool' group by COMPONENT;


SQL> select NAMESPACE,GETHITS,GETHITRATIO,RELOADS,INVALIDATIONS from V_$LIBRARYCACHE;

NAMESPACE          GETHITS GETHITRATIO    RELOADS INVALIDATIONS
--------------- ---------- ----------- ---------- -------------
SQL AREA          10264686  .898111808      21751          1540
TABLE/PROCEDURE    1143854  .993568774       1146             0
BODY                204106  .998757095        122             0
TRIGGER             254492  .998250555        163             0
INDEX                 7880  .982176243          9             0
CLUSTER                391  .970223325          1             0
OBJECT                   0           1          0             0
PIPE                 91517  .996320287          0             0
JAVA SOURCE              0           1          0             0
JAVA RESOURCE            0           1          0             0
JAVA DATA                0           1          0             0

11 rows selected.

select * from emp 
select * from EMP 


NAME_COL_PLUS_SHOW_PARAM
------------------------------------------------------------------------------
TYPE
-----------
VALUE_COL_PLUS_SHOW_PARAM
------------------------------------------------------------------------------
cursor_sharing
string
EXACT
select sum(value)/1024/1024 from v$sga;



SQL> SQL> rem
SQL> rem FUNCTION: Generate a report of SQL Area Memory Usage
SQL> rem           showing SQL Text and memory catagories
SQL> rem
SQL> rem sqlmem.sql
SQL> rem
SQL> COLUMN sql_text      FORMAT a60   HEADING Text word_wrapped
SQL> COLUMN sharable_mem               HEADING Shared|Bytes
SQL> COLUMN persistent_mem             HEADING Persistent|Bytes
SQL> COLUMN loads                      HEADING Loads
SQL> COLUMN users         FORMAT a15   HEADING "User"
SQL> COLUMN executions                 HEADING "Executions"
SQL> COLUMN users_executing            HEADING "Used By"
SQL> START title132 "Users SQL Area Memory Use"
SP2-0310: unable to open file "title132.sql"
SQL> SPOOL rep_out\&db\sqlmem
Enter value for db: SET LONG 2000 PAGES 59 LINES 132
SP2-0768: Illegal SPOOL command
Usage: SPOOL { <file> | OFF | OUT }
where <file> is file_name[.ext] [CRE[ATE]|REP[LACE]|APP[END]]
SQL> BREAK ON users
SQL> COMPUTE SUM OF sharable_mem ON USERS
SQL> COMPUTE SUM OF persistent_mem ON USERS
SQL> COMPUTE SUM OF runtime_mem ON USERS
SQL> SELECT
  2  username users, sql_text, Executions, loads, users_executing,
  3  sharable_mem, persistent_mem
  4  FROM
  5  sys.v_$sqlarea a, dba_users b
  6  WHERE
  7  a.parsing_user_id = b.user_id
  8  ;






SELECT  username users, Executions, loads, users_executing, sharable_mem, persistent_mem  FROM  sys.v_$sqlarea a, dba_users b  WHERE  a.parsing_user_id = b.user_id
  2  ;


 SQL> desc stats$sql_summary

 select sql_fulltext from v$sqlarea where sql_fulltext like '%ALLOCATION_OWNER_TYPE in%';

 select sql_fulltext from v$sqlarea where sql_fulltext like '%ALLOCATION_OWNER_TYPE in%' and rownum<=2
SQL> select sql_fulltext from v$sqlarea where sql_fulltext like '%ALLOCATION_OWNER_TYPE in%' and rownum<=5;

 select  'sga heap('||KSMCHIDX||',0)'sga_heap,ksmchcom ChunkComment,
  2  decode(round(ksmchsiz/1000),0,'0-1K', 1,'1-2K', 2,'2-3K',
  3  3,'3-4K',4,'4-5K',5,'5-6k',6,'6-7k',7,'7-8k',8,'8-9k', 9,'9-10k','> 10K')
  4  "Size",
  5  count(*), ksmchcls "Status", sum(ksmchsiz) "Bytes" from x$ksmsp
  6  where KSMCHCOM = 'free memory' group by 'sga heap('||KSMCHIDX||',0)',
  7  ksmchcom, ksmchcls, decode(round(ksmchsiz/1000),0,'0-1K', 1,'1-2K', 2,'2-3K',
  8   3,'3-4K',4,'4-5K',5,'5-6k',6,'6-7k',7,'7-8k',8,'8-9k', 9,'9-10k','> 10K');




SQL> select NAMESPACE,RELOADS,INVALIDATIONS from v$librarycache;

NAMESPACE          RELOADS INVALIDATIONS
--------------- ---------- -------------
SQL AREA             30938          1613
TABLE/PROCEDURE       2100             0
BODY                   189             0
TRIGGER                315             0
INDEX                   15             0
CLUSTER                  2             0
OBJECT                   0             0
PIPE                     0             0
JAVA SOURCE              0             0
JAVA RESOURCE            0             0
JAVA DATA                0             0

11 rows selected.


SQL> rem FUNCTION: Generate a library cache report
SQL> column namespace                        heading "Library Object"
SQL> column gets             format 9,999,999 heading "Gets"
SQL>
SQL> column gethitratio      format 999.99   heading "Get Hit%"
SQL> column pins             format 9,999,999 heading "Pins"
SQL> column pinhitratio      format 999.99   heading "Pin Hit%"
SQL> column reloads          format 99,999   heading "Reloads"
SQL> column invalidations    format 99,999   heading  "Invalid"
SQL> column db format a10
SQL> set pages 58 lines 80
SQL> ttitle "Library Caches Report"
SQL> define output = lib_cache
SQL> spool &output


SQL> select  namespace,   gets,  gethitratio*100 gethitratio,   pins, pinhitratio*100 pinhitratio,  reloads,  invalidations  from   v$librarycache;

Mon May 31                                                             page    1
                             Library Caches Report

Library Object        Gets Get Hit%       Pins Pin Hit% Reloads Invalid
--------------- ---------- -------- ---------- -------- ------- -------
SQL AREA        ##########    89.19 ##########    98.63  31,014   1,613
TABLE/PROCEDURE  1,702,941    99.45 ##########    99.98   2,100       0
BODY               246,756    99.88 ##########   100.00     189       0
TRIGGER            320,823    99.83  5,608,778    99.98     315       0
INDEX                8,205    97.85     19,379    98.96      15       0
CLUSTER                560    97.50      1,121    98.57       2       0
OBJECT                   0   100.00          0   100.00       0       0
PIPE               114,550    99.63    118,975    99.65       0       0
JAVA SOURCE              0   100.00          0   100.00       0       0
JAVA RESOURCE            0   100.00          0   100.00       0       0
JAVA DATA                0   100.00          0   100.00       0       0


SQL>  select POOL, NAME,BYTES/1024/1024 from  v$sgastat where name = 'free memory';

POOL         NAME                       BYTES/1024/1024
------------ -------------------------- ---------------
shared pool  free memory                     9088.51419
large pool   free memory                         255.75
java pool    free memory                            144
streams pool free memory                            112


SQL> select sid,serial#,event from v$session where type='USER' and status='ACTIVE';


SQL> select NAMESPACE,RELOADS,INVALIDATIONS from v$librarycache;

NAMESPACE          RELOADS INVALIDATIONS

18004258448

select sum(value) from v$sga;

select sum(bytes) from v$sgastat;

select sum(current_size) from v$sga_dynamic_components;

select * from v$sga_dynamic_free_memory;


 SQL> show parameter statistics_level

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
statistics_level                     string      TYPICAL
SQL> select count(1) from v$shared_pool_advice;

  COUNT(1)
----------
         0
SQL> select count(1) from V$SGA_TARGET_ADVICE ;

  COUNT(1)
----------
         0
SQL> SELECT NAME, BYTES
FROM v$sgainfo;  2

NAME                                  BYTES
-------------------------------- ----------
Fixed SGA Size                      2137568
Redo Buffers                       14639104
Buffer Cache Size                9059696640
Shared Pool Size                 1.8707E+10
Large Pool Size                   268435456
Java Pool Size                    150994944
Streams Pool Size                 117440512
Granule Size                       16777216
Maximum SGA Size                 2.9360E+10
Startup overhead in Shared Pool   738197504
Free SGA Memory Available        1040187392

11 rows selected.

SQL> select sum(bytes) from v$sgastat where pool='shared pool';

SUM(BYTES)
----------
1.8707E+10

SELECT SQL_ID,EXECUTIONS,DISK_READS,to_char(LAST_LOAD_TIME,'DD-MON-YYYY HH24:MI:SS') FROM V$SQLAREA WHERE SQL_ID in(select SQL_ID from v$sql_plan where options in('FULL SCAN','FULL') AND OBJECT_OWNER NOT IN('SYS','SYSTEM'))  ORDER BY disk_reads desc;

select count(1) from x$ksmlru;

rem FUNCTION: Generate a report of SQL Area Memory Usage
rem           showing SQL Text and memory catagories
rem
rem sqlmem.sql 
rem
COLUMN sql_text      FORMAT a60   HEADING Text word_wrapped
COLUMN sharable_mem               HEADING Shared|Bytes
COLUMN persistent_mem             HEADING Persistent|Bytes
COLUMN loads                      HEADING Loads
COLUMN users         FORMAT a15   HEADING "User"
COLUMN executions                 HEADING "Executions"
COLUMN users_executing            HEADING "Used By"
START title132 "Users SQL Area Memory Use"
SPOOL rep_out\&db\sqlmem
SET LONG 2000 PAGES 59 LINES 132
BREAK ON users
COMPUTE SUM OF sharable_mem ON USERS
COMPUTE SUM OF persistent_mem ON USERS
COMPUTE SUM OF runtime_mem ON USERS
SELECT 
username users, sql_text, Executions, loads, users_executing, 
sharable_mem, persistent_mem 
FROM 
sys.v_$sqlarea a, dba_users b
WHERE 
a.parsing_user_id = b.user_id



rem FUNCTION: Generate a summary of SQL Area Memory Usage
rem FUNCTION: uses the sqlsummary view.
rem           showing user SQL memory usage 
rem
rem sqlsum.sql 
rem
column areas                              heading Used|Areas
column sharable   format 999,999,999      heading Shared|Bytes
column persistent format 999,999,999      heading
Persistent|Bytes
column runtime    format 999,999,999      heading Runtime|Bytes
column username   format a15              heading "User" 
column mem_sum    format 999,999,999      heading Mem|Sum
start title80 "Users SQL Area Memory Use"
spool rep_out\&db\sqlsum
set pages 59 lines 80 
break on report 
compute sum of sharable on report
compute sum of persistent on report
compute sum of runtime on report
compute sum of mem_sum on report
select 
username, 
sum(sharable_mem) Sharable, 
sum( persistent_mem) Persistent, 
sum( runtime_mem) Runtime , 
count(*) Areas,
sum(sharable_mem+persistent_mem+runtime_mem) Mem_sum
from 
sql_summary 
group by username
order by 2;
spool off


 SELECT  username users, Executions, loads, users_executing, sharable_mem, persistent_mem  FROM  sys.v_$sqlarea a, dba_users b  WHERE  a.parsing_user_id = b.user_id  
select POOL, NAME,BYTES/1024/1024 from  v$sgastat where name = 'free memory';


rem
rem FUNCTION: Generate a summary of SQL Area Memory Usage
rem FUNCTION: uses the sqlsummary view.
rem           showing user SQL memory usage 
rem
rem sqlsum.sql 
rem
column areas                              heading Used|Areas
column sharable   format 999,999,999      heading Shared|Bytes
column persistent format 999,999,999      heading
Persistent|Bytes
column runtime    format 999,999,999      heading Runtime|Bytes
column username   format a15              heading "User" 
column mem_sum    format 999,999,999      heading Mem|Sum
start title80 "Users SQL Area Memory Use"
spool rep_out\&db\sqlsum
set pages 59 lines 80 
break on report 
compute sum of sharable on report
compute sum of persistent on report
compute sum of runtime on report
compute sum of mem_sum on report
select 
sum(sharable_mem) Sharable, 
sum( persistent_mem) Persistent, 
sum( runtime_mem) Runtime , 
count(*) Areas,
sum(sharable_mem+persistent_mem+runtime_mem) Mem_sum
from 
stats$sql_summary 



alter system flush shared_pool;

select COMPONENT,sum(CURRENT_SIZE)/1024/1024/1024,sum(MIN_SIZE)/1024/1024/1024  from v$SGA_DYNAMIC_COMPONENTS where component='shared pool' group by COMPONENT;
select COMPONENT,sum(CURRENT_SIZE)/1024/1024/1024,sum(MIN_SIZE)/1024/1024/1024  from v$SGA_DYNAMIC_COMPONENTS group by COMPONENT
select POOL, NAME,BYTES/1024/1024 from  v$sgastat where name = 'free memory'

Friday, 2 November 2018

Migration from 10g to 18c using datapump

on new server
++++++++++++

1)change the database in no archive mode
2) drop the users
3)new_sql_objects
4)dbmon_create_initial
5)create dssadmin.sql
5-1)create user password
5-2)database link
6)impdp.par
7)compile invalid objects and stats
8)make_statements.sql
8.1)grant special
9)check constraints
10 grant omnixpress
11 check partition
12 change_user password
13)archive mode


coming soon ....

Refreshing table with one year data from production user datapume

please do refresh for below tables from production(PX_USER) to QA (DWDB) environment.


step one :


script location :  /home/oracle/work.ravi

expdp

USERID = "/ as sysdba"
DIRECTORY=EXPDP_TEST_DIR
tables=OMEDW.WPART_NUMBER_D
dumpfile=expdp_p_SRI_USER_part.dmp
logfile=expdp_pwdb_SRI_USER_part.log
parallel=1


impdp.par


USERID = "/ as sysdba"
DIRECTORY=EXPDP_DIR
dumpfile=expdp_pdb_SRI_USER_112.dmp
logfile=IMP_pdb_SRI_USER_112.log
tables=OMEDW.W_RT_NUMBER_D
table_exists_action=truncate
parallel=1

-------------------------------------------------------------------------------------------------------------------------
select count(*) from OMEDW.ENT_DETAILS_F where PLAN_DATE > '01-MAY-18';

expdp.par

USERID = "/ as sysdba"
DIRECTORY=EXPDP_TEST_DIR
tables=OMEDW.W_RP_MED_ASSIENT_DETAILS_F
QUERY=OMEDW.W_RP_MED_ASSMENT_DETAILS_F:"WHERE PLAN_DATE > '01-MAY-18'"
dumpfile=expdp_W_RP_MED_ASSINT_DETAILS_F.dmp
logfile=expdp_W_RP_MED_ASSINT_DETAILS_F.log
parallel=1
compression=all


nohup expdp parfile=exp_oneyear.par &


impdp



USERID = "/ as sysdba"
DIRECTORY=EXPDP_D
tables=OMEDW.W_RP_MED_ASSMENT_DETAILS_F
dumpfile=expdp_W_RP_MED_ASSMENT_DETAILS_F.dmp
logfile=impdp_W_RP_MED_ASSENT_DETAILS_F.log
table_exists_action=truncate
parallel=1



nohup impdp parfile=imp_oneyear.par &



11/14/2018


++++++++++++++++++++++++++++++++++++++++++
kill the job


select * from dba_directories;
SELECT owner_name, job_name, operation, job_mode, state FROM dba_datapump_jobs


expdp \'/ as sysdba\' attach=" filename"


kill_job

SELECT owner_name, job_name, operation, job_mode, state FROM dba_datapump_jobs


Errors:
______

1)ORA-39120: Table "OMEDW"."W_RP_MED_ASSIGNMENT_F" can't be truncated, data will be skipped. Failing error
is:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
ORA-00955: name is already used by an existing object
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Processing object type TABLE_EXPORT/TABLE/GRANT/OWNER_GRANT/OBJECT_GRANT



solution : Due to some table update by the end user , import was not happening.
reran it will run successfully after some times.

2)

error:
ORA-31693: Table data object "OMEDW"."W_OMNI_PART_NUMBER_D" failed to load/unload and is being skipped due to error:
ORA-29913: error in executing ODCIEXTTABLEFETCH callout
ORA-20000: PART_NUMBER AND ORIGINAL_PART_NUMBER ARE NOT EQUAL
ORA-06512: at "OMEDW.SRI_PART_CHANGES", line 6
ORA-04088: error during execution of trigger 'OMEDW.SRI_PART_CHANGES'


solution : disable the trigger and try to import.


alter trigger OMEDW.S_PART_CHANGES disable;
alter trigger OMEDW.S_PART_CHANGES enable;


Wednesday, 24 October 2018

Restore point

Check DiskGroup Name ...

select listagg (name, ' | ') within group (order by name) "     DiskGroupName"  from v$asm_diskgroup;

     DiskGroupName
--------------------------------------------------------------------------------
DATA | ALOG



select name,database_role,open_mode,flashback_on,log_mode from v$database;

NAME      DATABASE_ROLE    OPEN_MODE            FLASHBACK_ON       LOG_MODE
--------- ---------------- -------------------- ------------------ ------------
  RAC     PRIMARY          READ WRITE           NO                 ARCHIVELOG


show parameter recovery

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest                string
db_recovery_file_dest_size           big integer 0
recovery_parallelism                 integer     0
remote_recovery_file_dest            string


ALTER SYSTEM set db_recovery_file_dest_size=40G scope=both sid='*' ; 
ALTER SYSTEM SET db_recovery_file_dest='+LOGS' sid='*';

ALTER SYSTEM set db_recovery_file_dest_size=40G scope=both sid='*' ; 
System altered.


SQL> ALTER SYSTEM SET db_recovery_file_dest='+LOGS' sid='*';
System altered.

CREATE RESTORE POINT test_anuj GUARANTEE FLASHBACK DATABASE;


CREATE RESTORE POINT test_anuj GUARANTEE FLASHBACK DATABASE;SQL>
Restore point created.



SQL> 
set linesize 300 pagesize 300
 select * from v$flash_recovery_area_usage;

FILE_TYPE               PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES     CON_ID
----------------------- ------------------ ------------------------- --------------- ----------
CONTROL FILE                             0                         0               0          0
REDO LOG                                 0                         0               0          0
ARCHIVED LOG                             0                         0               0          0
BACKUP PIECE                             0                         0               0          0
IMAGE COPY                               0                         0               0          0
FLASHBACK LOG                          .98                         0               2          0
FOREIGN ARCHIVED LOG                     0                         0               0          0
AUXILIARY DATAFILE COPY                  0                         0               0          0

8 rows selected.



SQL> select flashback_on from v$database;

FLASHBACK_ON
------------------
RESTORE POINT ONLY    <<<<<<<<<<if FLASHBACK_ON - NO 



set pagesize 200 linesize 300
col scn for 999,999,999,999,999
col incar for 99
col name for a25
col time for a40
col storage_size for 999,999,999,999
col guarantee_flashback_database for a35
select 
      database_incarnation# as incar,
      scn,
      name,
      time,
      storage_size,
      guarantee_flashback_database
from  v$restore_point
order by 4;


INCAR                  SCN NAME                      TIME                                         STORAGE_SIZE GUARANTEE_FLASHBACK_DATABASE
----- -------------------- ------------------------- ---------------------------------------- ---------------- -----------------------------------
    3          263,845,411 TEST_ANUJ                 01-JUN-18 02.07.57.000000000 PM               209,715,200 YES

alter session set nls_date_format='dd-mm-yyyy hh24:mi' ;
col name for a50
select * from v$flashback_database_logfile;

NAME                                                     LOG#    THREAD#  SEQUENCE#      BYTES FIRST_CHANGE# FIRST_TIME       TYPE          CON_ID
-------------------------------------------------- ---------- ---------- ---------- ---------- ------------- ---------------- --------- ----------
+LOGS/IRAC/FLASHBACK/log_1.678.977666877                   1          2          1  209715200     263845409 01-06-2018 14:07 NORMAL             0
+LOGS/IRAC/FLASHBACK/log_2.677.977666883                   2          2          1  209715200             0                  RESERVED           0



SQL> create table test_anuj as select * from scott.emp ;

Table created.


CREATE RESTORE POINT test_anuj1 GUARANTEE FLASHBACK DATABASE;

CREATE RESTORE POINT test_anuj1 GUARANTEE FLASHBACK DATABASE;SQL>
Restore point created.




set pagesize 200 linesize 300
col scn for 999,999,999,999,999
col incar for 99
col name for a25
col time for a40
col storage_size for 999,999,999,999
col guarantee_flashback_database for a35
select 
      database_incarnation# as incar,
      scn,
      name,
      time,
      storage_size,
      guarantee_flashback_database
from  v$restore_point
order by 4;


INCAR                  SCN NAME                      TIME                                         STORAGE_SIZE GUARANTEE_FLASHBACK_DATABASE
----- -------------------- ------------------------- ---------------------------------------- ---------------- -----------------------------------
    3          263,845,411 TEST_ANUJ                 01-JUN-18 02.07.57.000000000 PM                         0 YES
    3          263,846,069 TEST_ANUJ1                01-JUN-18 02.16.28.000000000 PM               209,715,200 YES


PROMPT How Far Back Can We Flashback To (Time)?
PROMPT


select to_char(oldest_flashback_time,'dd-mon-yyyy hh24:mi:ss') "Oldest Flashback Time" from v$flashback_database_log;


PROMPT

PROMPT How Far Back Can We Flashback To (SCN)?

PROMPT



col oldest_flashback_scn format 99999999999999999999999999
select oldest_flashback_scn from v$flashback_database_log;

PROMPT
PROMPT Flashback Area Usage
SELECT * FROM V$FLASH_RECOVERY_AREA_USAGE;






PROMPT

col round(space_limit/1048576) heading "space allocated (mb)" format 999999
col round(space_used/1048576)  heading "space used (mb)"      format 99999
col name                       heading "flashback location"   format a50
select name, round(space_limit/1048576),round(space_used/1048576) from v$recovery_file_dest;



create table test_anuj1 as select * from scott.emp ;

SQL> create table test_anuj1 as select * from scott.emp ;
Table created.




SQL>startup mount;
SQL> flashback database to restore point TEST_ANUJ1;

Flashback complete.


SQL> alter database open resetlogs;

Database altered.



SQL> select * from test_anuj1;    <<<< this table gone 
select * from test_anuj1
              *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from test_anuj;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.



Via Rman ...

RUN {
        STARTUP MOUNT;
        FLASHBACK DATABASE TO RESTORE POINT 'TEST_ANUJ';
        ALTER DATABASE OPEN RESETLOGS;
        SHUTDOWN IMMEDIATE;
}



RMAN>

RUN {
        STARTUP MOUNT;
        FLASHBACK DATABASE TO RESTORE POINT 'TEST_ANUJ';
        ALTER DATABASE OPEN RESETLOGS;
        SHUTDOWN IMMEDIATE;
}


RMAN>
RMAN> 

Oracle instance started
database mounted

Total System Global Area    4294967296 bytes

Fixed Size                     8628936 bytes
Variable Size               1577059640 bytes
Database Buffers            2701131776 bytes
Redo Buffers                   8146944 bytes

Starting flashback at 01-JUN-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=372 instance=ibrac2 device type=DISK


starting media recovery

archived log for thread 2 with sequence 440 is already on disk as file +DATA/IBRAC/ARCHIVELOG/2018_06_01/thread_2_seq_440.688.977670083
media recovery complete, elapsed time: 00:00:01
Finished flashback at 01-JUN-18

Statement processed

database closed
database dismounted
Oracle instance shut down



set pagesize 200 linesize 300
col scn for 999,999,999,999,999
col incar for 99
col name for a25
col time for a40
col storage_size                 for 999,999,999,999
col guarantee_flashback_database for a35
select 
      database_incarnation# as incar,
      scn,
      name,
      time,
      storage_size,
      guarantee_flashback_database
from  v$restore_point
order by 4;


INCAR                  SCN NAME                      TIME                                         STORAGE_SIZE GUARANTEE_FLASHBACK_DATABASE
----- -------------------- ------------------------- ---------------------------------------- ---------------- -----------------------------------
    3          263,845,411 TEST_ANUJ                 01-JUN-18 02.07.57.000000000 PM                         0 YES
    3          263,846,069 TEST_ANUJ1                01-JUN-18 02.16.28.000000000 PM               209,715,200 YES




SQL> drop restore point TEST_ANUJ1;

Restore point dropped.



set pagesize 200 linesize 300
col scn for 999,999,999,999,999
col incar for 99
col name for a25
col time for a40
col storage_size for 999,999,999,999
col guarantee_flashback_database for a35
SELECT 
      database_incarnation# as Incar,
      scn,
      name,
      time,
      storage_size,
      guarantee_flashback_database
FROM  v$restore_point
ORDER BY 4


INCAR                  SCN NAME                      TIME                                         STORAGE_SIZE GUARANTEE_FLASHBACK_DATABASE
----- -------------------- ------------------------- ---------------------------------------- ---------------- -----------------------------------
    3          263,845,411 TEST_ANUJ                 01-JUN-18 02.07.57.000000000 PM               209,715,200 YES



col ROUND(SPACE_LIMIT/1048576) heading "Space Allocated (MB)" format 999999
col round(space_used/1048576) heading "Space Used (MB)" format 99999
col name Heading "Flashback Location" format a50

select name, round(space_limit/1048576),round(space_used/1048576) from v$RECOVERY_FILE_DEST;

Flashback Location                                 Space Allocated (MB) Space Used (MB)
-------------------------------------------------- -------------------- ---------------
+LOGS                                                             40960             402



PROMPT How Far Back Can We Flashback To (Time)?
PROMPT

select to_char(oldest_flashback_time,'dd-mon-yyyy hh24:mi:ss') "Oldest Flashback Time" from v$flashback_database_log;

SQL> How Far Back Can We Flashback To (Time)?

Oldest Flashback Time
-----------------------------
01-jun-2018 14:08:03

col oldest_flashback_scn format 99999999999999999999999999
select oldest_flashback_scn from v$flashback_database_log;

       OLDEST_FLASHBACK_SCN
---------------------------
                  263845411

Wednesday, 10 October 2018

schema refresh

Tuesday, 8 December 2015


Schema Refresh step by step


Below are the details step for schema refresh . The below steps are very helpful when you want to refresh schemas in QA/DEV and want to keep all the previous grants and privileges after refresh .

1. Take the backup of the schema in target database.


expdp directory=<directory_name> dumpfile=backup_%U.dmp logfile=Backup.log parllel=<n> compression=all
schemas=Schema_name

2. sys_privs.sql :
---------------

set echo off
set head off
set pagesize 0
set feedback off
set linesize 200
spool sys_privs.sql
select 'grant '||privilege||' to '||grantee||' ; '  from dba_sys_privs where grantee in ('schema_name');
spool off

3.owner.sql :
-----------

spool owner.sql
select 'grant '||privilege||' on '||OWNER||'.'||table_name||' to  '||grantee||' ; ' from dba_tab_privs WHERE OWNER in ('schema_name');
spool off

4.pre_refresh_role_privs.sql :
----------------------------

set echo off
set head off
set pagesize 0
set feedback off
set linesize 200
spool pre_refresh_role_privs.sql
select 'grant '||granted_role||' to '||grantee||' ; '  from dba_role_privs where grantee in ('schema_name');
spool off

5.Check the object count in the database under that schema
 SELECT object_type,COUNT(*) FROM DBA_OBJECTS WHERE OWNER in ('schema_name') group by object_type ;

6. check the table count
SELECT COUNT(*) FROM DBA_tables WHERE OWNER in ('schema_name');

7.drop all the object under that schema
select 'drop '||object_type||' '||owner||'."'||object_name||'";' from dba_objects where owner in ('schema_names');

8.drop all the tables under that schema
select 'drop table  '||owner||'.'||table_name||' cascade constraints;' from dba_tables where owner in('schema_names');

9.purge the recyclebin
select 'purge table '||owner||'."'||object_name||'";' FROM dba_RECYCLEBIN where owner='schema_name' ;

10.now import data into target database from source dumpfile.
 impdp dumpfile=<dumpfile_name> logfile=import.log directory=<directory_name> schemas=schema_name parallel=<n>

11.check the count of objects after refresh for each schema
SELECT COUNT(*) FROM DBA_OBJECTS WHERE OWNER in ('schema_name');

12.check the table count
SELECT COUNT(*) FROM DBA_tables WHERE OWNER='schema_name';

13.run the spool file
@sys_privs.sql

14. run the spool file
@owner.sql

15.run the spool file
pre_refresh_role_privs.sql

-------------- Schema refresh is complete ----------------------

Featured post

Restircted session due to sync filed with ora-65177

Application is unable to connect the database due to restricted session. sql> show pdbs; SQL> show con_name CON_NAME -----------------...