Wednesday, 7 June 2017

How to identify current consumption of memory (UGA and PGA) ?

UGA - User Global Area or Session memory
PGA - Process Global Area


select name, sum(value/1024/1024) "MB" from v$statname n, v$session s, v$sesstat t  where s.sid = t.sid
and n.statistic# = t.statistic# and s.TYPE = 'USER' and s.USERNAME is not null and n.name in ('session pga memory', 'session uga memory')
group by name

Thursday, 1 June 2017

reason for ORA-12008: error in materialized view refresh path ORA-01652: unable to extend temp segment by 128 in tablespace TEMP


ORA-12008: error in materialized view refresh path

ORA-01652: unable to extend temp segment by 128 in tablespace TEMP



The above error is due to lack of TEMP space ...



To identify the used and free space




SELECT   A.tablespace_name tablespace, D.mb_total,
 SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
 D.mb_total - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
 FROM     v$sort_segment A,
 (
 SELECT   B.name, C.block_size, SUM (C.bytes) / 1024 / 1024 mb_total
 FROM     v$tablespace B, v$tempfile C
 WHERE    B.ts#= C.ts#
 GROUP BY B.name, C.block_size
 ) D
 WHERE    A.tablespace_name = D.name
 GROUP by A.tablespace_name, D.mb_total;





To fix it need to increase the size...



.  Temporary fix

a) Resize temporary file as
SQL> ALTER DATABASE TEMPFILE ‘/u01/oradata/VIS11i/temp01.dbf’ RESIZE 3072M;

or

b) Add temp datafile to temporary tablespace as

SQL> ALTER TABLESPACE TEMP ADD TEMPFILE ‘/u01/oradata/VIS11i/temp02.dbf’
SIZE 1024M REUSE AUTOEXTEND ON NEXT 50M  MAXSIZE 1024M;

.

Root Cause Analysis

1.  Identify temp segment usages per session


— Temp segment usage per session.

SQL> SELECT   S.sid || ‘,’ || S.serial# sid_serial, S.username, S.osuser, P.spid, S.module,
P.program, SUM (T.blocks) * TBS.block_size / 1024 / 1024 mb_used, T.tablespace,
COUNT(*) statements
FROM     v$sort_usage T, v$session S, dba_tablespaces TBS, v$process P
WHERE    T.session_addr = S.saddr
AND      S.paddr = P.addr
AND      T.tablespace = TBS.tablespace_name
GROUP BY S.sid, S.serial#, S.username, S.osuser, P.spid, S.module,
P.program, TBS.block_size, T.tablespace
ORDER BY mb_used;

2. Identify temp segment usages per statement

— Temp segment usage per statement.

SQL> SELECT  S.sid || ‘,’ || S.serial# sid_serial, S.username, Q.hash_value, Q.sql_text,
T.blocks * TBS.block_size / 1024 / 1024 mb_used, T.tablespace
FROM    v$sort_usage T, v$session S, v$sqlarea Q, dba_tablespaces TBS
WHERE   T.session_addr = S.saddr
AND     T.sqladdr = Q.address
AND     T.tablespace = TBS.tablespace_name
ORDER BY mb_used;
Depending on outcome of temp segment usage per session and per statement focus on problematic session/statement.


reference : http://onlineappsdba.com/index.php/2009/07/27/ora-1652-unable-to-extend-temp-segment-by-128-in-tablespace-temp/

Monday, 22 May 2017

How to grant SYSDBA privilege to an user?

grant connect ,resource,DBA to USER
How to resove PLS-00201: identifier 'JSON' must be declared error in oracle?

1. Need to install the PL/JSON package
2. GRANT EXECUTE ON JSON TO <user>;
How to parse JSON in oracle?

 In 11g, we need to install the utilities for  JSON
1.
APEX_JSON


https://docs.oracle.com/cd/E59726_01/doc.50/e39149/apex_json.htm#AEAPI29635

2.

PL/JSON

https://sourceforge.net/p/pljson/wiki/Home/


3. upgrade to 12c

After the installation we can use the JSON, JSON_LIST type we can parse the JSON files...
HOW TO GRANT THE JSON OBJECT TYPE TO USER IN ORACLE?

SQL> GRANT EXECUTE ON JSON TO MURUGA;
Grant succeeded


SQL> GRANT EXECUTE ON JSON_LIST TO MURUGA;
Grant succeeded

SQL> GRANT EXECUTE ON JSON_VALUE TO MURUGA;
Grant succeeded


SQL> GRANT EXECUTE ON JSON_VALUE_ARRAY TO MURUGA;
Grant succeeded
HOW TO LIST THE JSON OBJECT TYPES IN ORACLE?


SQL> SELECT * FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TYPE' AND OBJECT_NAME LIKE '%JSON%'
  2  ;
OBJECT_NAME                                                                      SUBOBJECT_NAME                  OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE         CREATED     LAST_DDL_TIME TIMESTAMP           STATUS  TEMPORARY GENERATED SECONDARY  NAMESPACE EDITION_NAME
-------------------------------------------------------------------------------- ------------------------------ ---------- -------------- ------------------- ----------- ------------- ------------------- ------- --------- --------- --------- ---------- ------------------------------
JSON                                                                                                                443607                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:57 VALID   N         N         N                  1
JSON_LIST                                                                                                           443606                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:57 VALID   N         N         N                  1
JSON_TAB                                                                                                            439925                TYPE                5/18/2017 4 5/18/2017 4:3 2017-05-18:16:33:19 VALID   N         N         N                  1
JSON_VALUE                                                                                                          443604                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:56 VALID   N         N         N                  1
JSON_VALUE_ARRAY                                                                                                    443605                TYPE                5/19/2017 9 5/19/2017 9:2 2017-05-19:09:23:57 VALID   N         N         N                  1