Wednesday 23 April 2014

Oracle Apps and FND Password Decryption

This one I just found in some old emails. There are many blogs available on this topic, I just tried to compile it in a simpler way. Anyways it's really handy if you have lost apps, sysadmin or any FND user password and would like to retrieve it without resetting. 

These SQLs work in Oracle E-Business Suite R12 environments. 

 Log in as APPS  on any E-Business Suite instance:

SQL> SELECT USER, NAME FROM V$DATABASE;

USER                           NAME
------------------------------ ---------
APPS                           DBA1


Only thing you need to do is to create a function (you can drop it later).

SQL> CREATE OR REPLACE FUNCTION NAVDECRYPT (KEY IN VARCHAR2, VALUE IN VARCHAR2) RETURN VARCHAR2
  2  AS LANGUAGE JAVA
  3  NAME 'oracle.apps.fnd.security.WebSessionManagerProc.decrypt(java.lang.String,java.lang.String) return java.lang.String';
  4  /

Function created.


That's it. You are now ready to read passwords. 


How to get apps Password ?

SQL> (SELECT (SELECT NAVDECRYPT(FND_WEB_SEC.GET_GUEST_USERNAME_PWD,A.ENCRYPTED_FOUNDATION_PASSWORD) FROM DUAL) FROM FND_USER A WHERE A.USER_NAME='GUEST');

(SELECTNAVDECRYPT(FND_WEB_SEC.GET_GUEST_USERNAME_PWD,A.ENCRYPTED_FOUNDATION_PASS
--------------------------------------------------------------------------------
APPS

SQL>



How to get FND user password ?

SQL> SELECT (SELECT NAVDECRYPT((SELECT (SELECT NAVDECRYPT(FND_WEB_SEC.GET_GUEST_USERNAME_PWD,A.ENCRYPTED_FOUNDATION_PASSWORD) FROM DUAL) FROM FND_USER A WHERE A.USER_NAME='GUEST'),B.ENCRYPTED_USER_PASSWORD) FROM DUAL) FROM FND_USER B WHERE B.USER_NAME='&USER_NAME';

Enter value for user_name: SYSADMIN

old   1: A.USER_NAME='GUEST'),B.ENCRYPTED_USER_PASSWORD) FROM DUAL) FROM FND_USER B WHERE B.USER_NAME='&USER_NAME'
new   1: A.USER_NAME='GUEST'),B.ENCRYPTED_USER_PASSWORD) FROM DUAL) FROM FND_USER B WHERE B.USER_NAME='SYSADMIN'

(SELECTNAVDECRYPT((SELECT(SELECTNAVDECRYPT(FND_WEB_SEC.GET_GUEST_USERNAME_PWD,A.
--------------------------------------------------------------------------------
sysadmin

SQL>

And finally drop the function when the job is done :)  

For Release 11i replace  FND_WEB_SEC.GET_GUEST_USERNAME_PWD by FND_PROFILE.VALUE ('GUEST_USER_PWD').


And oh yes, how would you login to apps schema if you don't have the password ? The sql will give you apps password only when you're in as apps.  

Well there is a way, Login to database sqlplus  '/as sysdba' and run

SQL> alter session set current_schema=apps; 

before creating function.


Hope you enjoy it J

Regards,
N@v

Tuesday 25 February 2014

Datafiles Shrink


With respect to data file on Oracle, files keeping growing in size. But over a period of time actual file size differs significantly from the amount of data within the file. Obviously and it is expected with all RDBMS operations there will always be free space in the file.

There are many possible ways to reclaim free unused space, but I like this one. It does reclaims all the free space like export/import but the main advantage is it can be done online while users are using the system. It truncates the file at the end and reclaims entire space above high water mark for auto-extensible files. It does not affect maxsize, but just reduces the size to minimum possible value. Oracle can increase the size anyways as and when required.

Here you go ..

1.       Calculate Database Size : 

SELECT ( (SELECT SUM (BYTES) FROM V$DATAFILE) + (SELECT SUM (BYTES) FROM V$TEMPFILE) + (SELECT SUM(8192*BLOCK_SIZE) FROM V$CONTROLFILE) + (SELECT SUM (MEMBERS*BYTES) FROM V$LOG))/1024/1024/1024 AS DATABASE_SIZE FROM DUAL;

2.       Get the parameter value for DB_BLOCK_SIZE : 

That is 8192 for EBS installations

3.  Calculate HWM for each file. Create temporary table for HWM : 

create table nav_hwm_tmp as (select file_id, max(BLOCK_ID + BLOCKS)* &DB_BLOCK_SIZE / 1024 / 1024 hwm from dba_extents group by file_id );

4.  Generate report for possible space reclaim: 

set verify off
set line 200
column file_name format a60 word_wrapped
column smallest format 999,990 heading "Smallest|Size|Poss."
column maxsize format 999,990 heading "Max|autoextend|size."
column currsize format 999,990 heading "Current|Size"
column savings format 999,990 heading "Poss.|Savings"
break on report
compute sum of savings on report
select a.file_name, a.bytes/1024/1024 currsize, a.maxbytes/1024/1024 maxsize, ceil (b.HWM) smallest, (a.bytes/1024/1024 - ceil (b.HWM)) savings from dba_data_files a, nav_hwm_tmp b where a.autoextensible='YES' and a.file_id=b.file_id order by savings;


5.  Spool commands for space reclaim: 

spool space_reclaim.txt
col COMM for a110
column savings format 999,990
set line 140
select 'ALTER DATABASE DATAFILE '''||a.file_name||''' RESIZE '||ceil (b.HWM)||'M ;' COMM, (a.bytes/1024/1024 - ceil (b.HWM)) savings from dba_data_files a, nav_hwm_tmp b where a.autoextensible='YES' and a.file_id=b.file_id order by savings;


6.  Review and run commands generated in the spool file space_reclaim.txt.

7.  Calculate database size after exercise : 

SELECT ( (SELECT SUM (BYTES) FROM V$DATAFILE) + (SELECT SUM (BYTES) FROM V$TEMPFILE) + (SELECT SUM(8192*BLOCK_SIZE) FROM V$CONTROLFILE) + (SELECT SUM (MEMBERS*BYTES) FROM V$LOG))/1024/1024/1024 AS DATABASE_SIZE FROM DUAL; 


Do you want to do it for a single file?

1. Get HWM : select ceil (max(BLOCK_ID + BLOCKS)* &DB_BLOCK_SIZE / 1024 / 1024 ) hwm from dba_extents where file_id=&file_id ;


2.  select file_name, bytes/1024/1024 currsize, maxbytes/1024/1024 maxsize, HWM, (bytes/1024/1024) - HWM savings from dba_data_files where file_id=&file_id;

Thursday 23 January 2014

Memory and SGA : Target vs Max Sizes


With recent talks with Jonno and Mark over last few days on parameters memory_target and memory_max_target (Automatic Memory Management), here are few scenario’s.

Please do reply with your valuable comments.

Scene 1 :

Current init.ora settings

#*.memory_max_target=2G
#*.memory_target=2G
*.sga_max_size=1200M
*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 0
memory_target                        big integer 0
sga_max_size                         big integer 1200M
sga_target                           big integer 800M
pga_aggregate_target                 big integer 900M


Obviously, sga_max_size equals the value set explicitly.


Scene 2 :

Current init.ora settings

#*.memory_max_target=2G
#*.memory_target=2G
*.sga_max_size=1200M
#*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 0
memory_target                        big integer 0
sga_max_size                         big integer 1200M
sga_target                           big integer 0
pga_aggregate_target                 big integer 900M


Well, all expected.


Scene 3 :

Current init.ora settings

#*.memory_max_target=2G
#*.memory_target=2G
#*.sga_max_size=1200M
*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 0
memory_target                        big integer 0
sga_max_size                         big integer 800M
sga_target                           big integer 800M
pga_aggregate_target                 big integer 900M

Okay, sga_max_size equals to value set for sga_target.



Scene 4 :

Current init.ora settings

*.memory_max_target=2G
*.memory_target=2G
*.sga_max_size=1200M
*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 2G
sga_max_size                         big integer 1200M
sga_target                           big integer 800M
pga_aggregate_target                 big integer 900M

All parameters are defined.


Scene 5 :

Current init.ora settings

*.memory_max_target=2G
#*.memory_target=2G
*.sga_max_size=1200M
*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 0
sga_max_size                         big integer 1200M
sga_target                           big integer 800M
pga_aggregate_target                 big integer 900M


Looks okay. Right ?


Scene 6 :

Current init.ora settings

#*.memory_max_target=2G
*.memory_target=2G
*.sga_max_size=1200M
*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 2G
sga_max_size                         big integer 1200M
sga_target                           big integer 800M
pga_aggregate_target                 big integer 900M

So, if not set, memory_max_target gets value from memory_target.


Scene 7 :

Current init.ora settings

*.memory_max_target=2G
*.memory_target=1600M
#*.sga_max_size=1200M
#*.sga_target=800M
#*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 1600M
sga_max_size                         big integer 2G
sga_target                           big integer 0
pga_aggregate_target                 big integer 0

And here is my point, if sga_max_size is not set, it defaults to the value set for memory_max_target.


Scene 8 :

Current init.ora settings

*.memory_max_target=2G
#*.memory_target=1600M
#*.sga_max_size=1200M
#*.sga_target=800M
#*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 0
sga_max_size                         big integer 2G
sga_target                           big integer 0
pga_aggregate_target                 big integer 1632M

To add to the statement from sc. 7, if sga_max_size is not set, it defaults to the value set for memory_max_target irrespective of the values of memory_target and sga_target.



Scene 9 :

Current init.ora settings

#*.memory_max_target=1200M
*.memory_target=1600M
#*.sga_max_size=1200M
#*.sga_target=800M
#*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 1600M
memory_target                        big integer 1600M
sga_max_size                         big integer 1600M
sga_target                           big integer 0
pga_aggregate_target                 big integer 0


If memory_target is not set, it defaults to 0, but if memory_max_target is not set and memory_target is defined, it defaults to memory_target.


Scene 10 :

Current init.ora settings

#*.memory_max_target=1200M
*.memory_target=2G
#*.sga_max_size=1200M
*.sga_target=800M
*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 2G
sga_max_size                         big integer 2G
sga_target                           big integer 800M
pga_aggregate_target                 big integer 900M

Hmmm.., when max values are not set for sga and memory, both (memory_max_target and sga_max_size) equals to memory_target ??
In other words, if sga_max_size is not set, memory_target takes precedence over sga_target to define sga_max_size.


Scene 11 :

Current init.ora settings

*.memory_max_target=2G
*.memory_target=2G
*.sga_max_size=0
*.sga_target=800M
*.pga_aggregate_target=900M


Any guesses ?
.
.
.
.

Starting up ..

ORA-01078: failure in processing system parameters
ORA-00823: Specified value of sga_target greater than sga_max_size



Scene 12 :

Current init.ora settings

*.memory_max_target=2G
*.memory_target=2G
*.sga_max_size=0
#*.sga_target=800M
#*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 2G
sga_max_size                         big integer 1228M
sga_target                           big integer 0
pga_aggregate_target                 big integer 0

Well, this looks better Automatic Memory Management to me. Oracle calculates sga_max_size during start up.


Scene 13 :

Current init.ora settings

*.memory_max_target=2G
*.memory_target=1600M
*.sga_max_size=0
#*.sga_target=800M
#*.pga_aggregate_target=900M

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 2G
memory_target                        big integer 1600M
sga_max_size                         big integer 960M
sga_target                           big integer 0
pga_aggregate_target                 big integer 0

When memory_target is reduced, Oracle also reduces sga_max_size and my observation (could be wrong) is that Oracle calculates sga_max_size's value from SGA Advisor.

I always found that the ratio of PGA/SGA for given memory_target is in sync with v$sga_target_advice and v$pga_target_advice.

Hope this helps,

Regards,

N@vin


One more reply ...


From: Navin
Subject: RE: Memory and SGA : Target vs Max Sizes

Okay Jonathan, Now consider this one,

Current init.ora settings

*.memory_max_target=320M
*.memory_target=300M
#*.sga_max_size=0
*.sga_target=0
*.pga_aggregate_target=140

Parameter values on the instance

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
memory_max_target                    big integer 320M
memory_target                        big integer 300M
sga_max_size                         big integer 320M
sga_target                           big integer 0
pga_aggregate_target                 big integer 140


Running some heavy load on the database .. and here is the scenario

PGA used is 60 M.

SQL> SELECT SUM(PGA_USED_MEM)/1024/1024 FROM V$PROCESS;

SUM(PGA_USED_MEM)/1024/1024
---------------------------
                 60.1974182

And SGA usage is:

SQL> /

CURRENT_SGA_SIZE CURRENT_PGA_SIZE
---------------- ----------------
        282.5625       60.1974182

SQL> SELECT NAME, BYTES/1024/1024, RESIZEABLE FROM V$SGAINFO ORDER BY 2 ;

NAME                             BYTES/1024/1024 RES
-------------------------------- --------------- ---
Shared IO Pool Size                            0 Yes
Fixed SGA Size                        2.12313843 No
Java Pool Size                                 4 Yes
Granule Size                                   4 No
Large Pool Size                                4 Yes
Streams Pool Size                              8 Yes
Redo Buffers                             12.4375 No
Free SGA Memory Available                     36
Startup overhead in Shared Pool               88 No
Buffer Cache Size                            116 Yes
Shared Pool Size                             136 Yes
Maximum SGA Size                        318.5625 No

12 rows selected.

Maximum SGA Size is 318.5625 M (memory_max_target) and free SGA is just 36 M and total SGA size in use on the instance is 282.5625.

So total SGA+PGA = 342.75M which is more than memory_max_target.

If sga_max_size is not set , entire memory_max_target is allocated to SGA and memory used by PGA can be on top of memory_max_target if required by the instance. This is what happened with ..T T.n..rs where memory_max_target was set to 9G but oracle.exe was using 10.8G memory on the server.

Also please note that Oracle is just brilliant to name this parameter as memory_max_target and not memory_max_size :)

I guess, we found something very interesting :)

Regards,

N@vin

Tuesday 17 December 2013

Using wget to download via edelivery.oracle.com

Using wget to download via edelivery.oracle.com

Downloading heavy installation DVDs and/or Oracle VM templates has always been time consuming task. For various license and export control reasons, Oracle Software Delivery Cloud downloads are only available via Hypertext Transfer Protocol (HTTP)

I found wget very useful to download by scripting command line instructions and to run it in the background.

It doesn't seem difficult since it started working. I tried a lot with different browsers like chrome, IE on Windows etc but finally It worked with Firefox on Linux.

Login to edelivery.oracle.com and while the browser session is active export cookies. You need to install and enable add-on available at https://addons.mozilla.org/en-US/firefox/addon/export-cookies



[root@msukovs01 ~]# cd /stage/EBS12.2.2/
[root@msukovs01 EBS12.2.2]# pwd
/stage/EBS12.2.2
[root@msukovs01 EBS12.2.2]# ls -1
cookies.txt
[root@msukovs01 EBS12.2.2]# 

Next, get the URL's for downloads e.g. I downloaded 12.2. OVM template

https://edelivery.oracle.com/EPD/Download/process_download/V41235-01_2of2.zip?file_id=66039499&aru=16956873&userid=5950655&egroup_aru_number=16973780&country_id=999&patch_file=V41235-01_2of2.zip


Use wget to download via command line. Note '\' is added before each '&' in the URL, without '\' it did not work. This might sound stupid, but took a complete day for me to realise :)




[root@msukovs01 EBS12.2.2]# wget -O V41235-01_1of2.zip --load-cookies=cookies.txt --no-check-certificate https://edelivery.oracle.com/EPD/Download/process_download/V41235-01_1of2.zip?file_id=66039498\&aru=16956873\&userid=5197557\&egroup_aru_number=16973780\&country_id=999\&patch_file=V41235-01_1of2.zip
--2013-12-13 12:06:33--  https://edelivery.oracle.com/EPD/Download/process_download/V41235-01_1of2.zip?file_id=66039498&aru=16956873&userid=5197557&egroup_aru_number=16973780&country_id=999&patch_file=V41235-01_1of2.zip
Resolving edelivery.oracle.com... 172.228.182.140
Connecting to edelivery.oracle.com|172.228.182.140|:443... connected.
WARNING: certificate common name `www.oracle.com' doesn't match requested host name `edelivery.oracle.com'.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://epd-akam-intl.oracle.com/adcarurepos/vol/patch28/EPD/V41235-01_1of2.zip?FilePath=/adcarurepos/vol/patch28/EPD/V41235-01_1of2.zip&File=V41235-01_1of2.zip&params=NUhxZ0F2L2Z4RTFWSUVzKzRibTVtdzphcnU9MTY5NTY4NzMmZW1haWw9c2VydmljZWRlc2tAaGl0YWNoaWNvbnN1bHRpbmcuY29tJmZpbGVfaWQ9NjYwMzk0OTgmcGF0Y2hfZmlsZT1WNDEyMzUtMDFfMW9mMi56aXAmdXNlcmlkPWVwZC1zZXJ2aWNlZGVza0BoaXRhY2hpY29uc3VsdGluZy5jb20mc2l6ZT00MDgyOTIxNTAzJmNvbnRleHQ9QUAxNStIQGFhcnV2bXRwMDgub3JhY2xlLmNvbStQQDE2OTczNzgwJmRvd25sb2FkX2lkPTk4MTEyMDM1&AuthParam=1386938257_8b631f39939d2bc7cc3558d32007813c [following]
--2013-12-13 12:06:33--  http://epd-akam-intl.oracle.com/adcarurepos/vol/patch28/EPD/V41235-01_1of2.zip?FilePath=/adcarurepos/vol/patch28/EPD/V41235-01_1of2.zip&File=V41235-01_1of2.zip&params=NUhxZ0F2L2Z4RTFWSUVzKzRibTVtdzphcnU9MTY5NTY4NzMmZW1haWw9c2VydmljZWRlc2tAaGl0YWNoaWNvbnN1bHRpbmcuY29tJmZpbGVfaWQ9NjYwMzk0OTgmcGF0Y2hfZmlsZT1WNDEyMzUtMDFfMW9mMi56aXAmdXNlcmlkPWVwZC1zZXJ2aWNlZGVza0BoaXRhY2hpY29uc3VsdGluZy5jb20mc2l6ZT00MDgyOTIxNTAzJmNvbnRleHQ9QUAxNStIQGFhcnV2bXRwMDgub3JhY2xlLmNvbStQQDE2OTczNzgwJmRvd25sb2FkX2lkPTk4MTEyMDM1&AuthParam=1386938257_8b631f39939d2bc7cc3558d32007813c
Resolving epd-akam-intl.oracle.com... 84.53.134.136, 84.53.134.138
Connecting to epd-akam-intl.oracle.com|84.53.134.136|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4082921503 (3.8G) [application/zip]
Saving to: `V41235-01_P1of2.zip'

78% [=========================================================>                      ] 3,200,136,730 --.-K/s  eta 13m 32s


Write a script for multiple files, and run it in the back ground.

Simple !