DOYENSYS Knowledge Portal




We Welcome you to visit our DOYENSYS KNOWLEDGE PORTAL : Doyensys Knowledge Portal




Tuesday, October 28, 2014

Oracle Application User(s) List With Age Threshold

The Below script will List the Oracle Application users with the specified age limit


select papf.employee_number,papf.full_name, papf.date_of_birth
from per_all_people_f papf,fnd_user fu
where papf.person_id=fu.employee_id 
and substr(papf.date_of_birth,8) <= 56  --year (2014-58=56)
--Here the user with the birth year less than or equal to 56 will be listed
and fu.END_DATE is NULL
--Specify whether to list end dated user or active users
and trunc(sysdate) between papf.effective_start_date and 
papf.effective_end_date order by DATE_OF_BIRTH



For clear view use the query in Toad

Monday, October 27, 2014

Saturday, October 25, 2014

To unlock OID super user !!!


If you are getting the below error in OID while using ldap, then it means the super user is locked. 

[oracle@xyz bin]$ ./ldapsearch -h xyz.oracle.com -p 389 -D cn=orcladmin -w abc -s sub -b dc=na,dc=xyz,dc=net uid=George* 
ldap_bind: DSA is unwilling to perform 
ldap_bind: additional info: Password Policy Error :9001: cn=orcladmin : Your account is locked. Please contact the Administrator. 

Please use the following command to unlock the super user in OID. 

cd $ORACLE_HOME/ldap/bin 

./oidpasswd conn= unlock_su_acct=true 

When you run the above command, it will ask for the super user’s password. 

Please find the below screenshot. 

Wednesday, October 22, 2014

Oracle database 12c - Deprecation of catupgrd.sql and Introduction of catctl.pl Utility

Oracle Database 12c introduces the new Parallel Upgrade Utility, catctl.pl. This utility replaces the catupgrd.sql script that was used in earlier releases.
Although you can still use the catupgrd.sql script, it is deprecated starting with Oracle Database 12c and will be removed in future releases.
Oracle recommends database upgrades be performed with the new Parallel Upgrade Utility, catctl.pl.

If you choose to run the catupgrd.sql script instead of running catctl.pl, doing so now requires an additional input parameter as follows:

SQL> @catupgrd.sql PARALLEL=NO

If you run catupgrd.sql without the parameter, then Oracle displays the following error message:

NOTE:

The catupgrd.sql script is being deprecated in the 12.1 release of Oracle Database. Customers are encouraged to use catctl.pl as the replacement for catupgrd.sql when upgrading the database dictionary.

                cd $ORACLE_HOME/rdbms/admin
                $ORACLE_HOME/perl/bin/perl catctl.pl -n 4 catupgrd.sql

Refer to the Oracle Database Upgrade Guide for more information.



Saturday, October 18, 2014

Query to find out the status of the undo and temp tablespace usage currently at the time of process execution

For undo
------------
set lines 130
col SID_SERIAL format a20
col PROGRAM format a25
col Undo format a30
SELECT TO_CHAR(s.sid)||','||TO_CHAR(s.serial#) sid_serial,
NVL(s.username, 'None') orauser,
s.program,
r.name undoseg,
t.used_ublk * TO_NUMBER(x.value)/1024||'K' "Undo"
FROM sys.v_$rollname r,
sys.v_$session s,
sys.v_$transaction t,
sys.v_$parameter x
WHERE s.taddr = t.addr
AND r.usn = t.xidusn(+)
AND x.name = 'db_block_size';



For Temp
------------

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;

Friday, October 17, 2014

How to clone Oracle 10g and 11g binaries in silent mode

For the purpose of demonstration, I will clone an existing 11.2.0.2 (11gR2) ORACLE_HOME on the source server.



Directories Needed:
------------------------------

Source Server:
-----------------------

hostname=source.com

ORACLE_BASE=/opt/app/oracle
ORACLE_HOME=/opt/app/oracle/product/11.2.0.2
Staging Directory = /home/oracle/clone  [This directory will be used as a staging directory for the binaries]


Target Server:
-------------------

hostname=target.com

Create the following directories if required
------------------------------------------------------------

ORACLE_BASE=/opt/app/oracle
ORACLE_HOME=/opt/app/oracle/product/11.2.0.2 [This should be empty]
Staging Directory= /home/oracle/clone


Procedure to Clone:
----------------------------

Log on to the source server:
--------------------------------------

ssh oracle@source.com

a) Choose the Version of the ORACLE_HOME you intend to clone and ‘cd’ to that directory. In our case it is 11.2.0.2 Home

cd /opt/app/oracle/product/11.2.0.2/


b) Create a tar ball of the source ORACLE_HOME in the staging directory /home/oracle/clone

tar -cvf /home/oracle/clone/source_11202.tar ./


c) Once a tar file is created scp the file on to the remote server target.com

scp /home/oracle/clone/source_11202.tar oracle@target.com:/home/oracle/clone/


d) After the copying is done, logon to the target server

ssh oracle@target.com


e) Go to the staging directory where you have copied the tar ball. In our case it is /home/oracle/clone on the target server

cd /home/oracle/clone


f) Make sure you have the ORACLE_HOME directory created on the target server. untar the tar file

i) cd /opt/app/oracle/product/11.2.0.2

ii) tar -xvf /home/oracle/clone/source_11202.tar


g) Once untar is done, run the runInstaller command in silent mode

/opt/app/oracle/product/11.2.0.2/oui/bin/runInstaller -silent -clone ORACLE_HOME="/opt/app/oracle/product/11.2.0.2" ORACLE_HOME_NAME="ANY NAME" ORACLE_BASE="/opt/app/oracle"


h)The above step takes a while, once the setup is successful switch to root user and run the following configuration script

/opt/app/oracle/product/11.2.0.2/root.sh

Creating private database links without user credentials


The following process can be followed to create private database link for an user whose login credentials are unknown,

Here in this example the user "6543" password is unknown,

In order to create a private database link for "6543" we have to first create a procedure for him as SYS user and grant create database link privilege to the "6543" user and execute the procedure. This would create a database link. After that revoke the grant given to "6543" user.

CREATE PROCEDURE "6543".cre_db_lnk AS
BEGIN
    EXECUTE IMMEDIATE 'CREATE DATABASE LINK DATABASELINKNAME '
            ||'CONNECT TO username IDENTIFIED BY password '
            ||'USING ''HOST''';
END cre_db_lnk;
/

GRANT create database link TO "6543";

execute "6543".cre_db_lnk;

revoke create database link from "6543";

DROP PROCEDURE "6543".cre_db_lnk;

select * from dba_db_links where db_link='DATABASELINKNAME' and owner ='6543';
To copy files from one server to another without promting/giving the password.


For example there are two servers hosta and hostb

to enable passwordless scp from hosta to hostb do the followings,


a. login to hosta server and from the home directory go to .ssh/ directory

    cd .ssh/

b. open and copy the content of the file "id_dsa.pub"

c. Login to the hostb server(navigate to .ssh/ directory ) and paste the content copied from hosta server to the file "authorized_keys" in the hostb server.

d. try the copy process

Note : - if .ssh directory is missing in the server create it using "ss h-keygen -t dsa" command, this would create the .ssh directory in the home location.Then proceed with step a, b,c and d.


Recovering a standby database from missing archive logs


There would be scenarios where the standby database lags far behind from the primary database leading to Archive Gap. It could be due to archive logs getting missed out on the primary database or the archives getting corrupted and there would be no valid backups.

In such cases where the standby lags far behind from the primary database, incremental backups can be used as one of the  methods to roll forward the physical standby database to have it in sync with the primary database.


Step 1: Take a note of the Current SCN of the Physical Standby Database.

Standby Database:

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
991247

Note down the CURRENT_SCN value of the standby database (991247) to proceed further.


Step 2 : Cancel the Managed Recovery Process on the Standby database.

Standby Database:

SQL>alter database recover managed standby database cancel;


Step 3: On the Primary database, take the incremental SCN backup from the SCN that is currently recorded on the standby database (991247)

Connect to the primary database and take the incremental SCN backup.

Primary Database:

[oracle@dev ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Mar 2515:44:45 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: SSPM (DBID=1624493265)

RMAN> backup incremental from scn 991247 database format '/u02/bkp/stnd_backp_%U.bak';

Starting backup at 25-MAR-12

using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=39 device type=DISK
backup will be obsolete on date 01-APR-12
archived logs will not be kept or backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=+DATA_NEW/sspm/datafile/system.256.778803539
input datafile file number=00002 name=+DATA_NEW/sspm/datafile/sysaux.257.778803541
input datafile file number=00003 name=+DATA_NEW/sspm/datafile/undotbs1.258.778803541
input datafile file number=00004 name=+DATA_NEW/sspm/datafile/users.259.778803543
channel ORA_DISK_1: starting piece 1 at 25-MAR-12
channel ORA_DISK_1: finished piece 1 at 25-MAR-12
piece handle=/u02/bkp/stnd_backp_10n6p3nl_1_1.bak tag=TAG20120325T154639 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45

using channel ORA_DISK_1
backup will be obsolete on date 01-APR-12
archived logs will not be kept or backed up
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 25-MAR-12
channel ORA_DISK_1: finished piece 1 at 25-MAR-12
piece handle=/u02/bkp/stnd_backp_11n6p3p4_1_1.bak tag=TAG20120325T154639 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 25-MAR-12


Step 4: Take the standby controlfile backup of the Primary database controlfile.

Connect to the Primary database and create the standby controlfile backup.

Primary Database :

RMAN> backup current controlfile for standby format '/u02/stnd_%U.ctl';

Starting backup at 25-MAR-12
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including standby control file in backup set
channel ORA_DISK_1: starting piece 1 at 25-MAR-12
channel ORA_DISK_1: finished piece 1 at 25-MAR-12
piece handle=/u02/stnd_12n6p3qt_1_1.ctl tag=TAG20120325T154845 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 25-MAR-12

Step 5: Transfer the backups from the Primary Server to the Standby Server.


Step 6: On the standby server, connect the Standby Database through RMAN and catalog the copied incremental backups so that the Controlfile of the Standby Database would be aware of these incremental backups.

I had the incremental backuppieces copied to the location ‘/u02/bkp‘ on the standby server.

Standby Database:

[oracle@uat ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Sun Mar 2515:51:02 2012

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

connected to target database: SSPM (DBID=1624493265, not open)

RMAN> catalog start with '/u02/bkp';
Starting implicit crosscheck backup at 25-MAR-12
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=37 device type=DISK
Crosschecked 15 objects
Finished implicit crosscheck backup at 25-MAR-12

Starting implicit crosscheck copy at 25-MAR-12
using channel ORA_DISK_1
Crosschecked 2 objects
Finished implicit crosscheck copy at 25-MAR-12

searching for all files in the recovery area
cataloging files...
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_200.453.778846881
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_201.454.778846881
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_202.455.778846881
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_203.456.778846881
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_137.457.778846881
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_204.458.778846881
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_205.459.778846883
.
.
.
.

File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_856.947.778861691
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_858.949.778861709
File Name: +arch/SSSB/ARCHIVELOG/2012_03_25/thread_1_seq_857.950.778861719

searching for all files that match the pattern /u02/bkp

List of Files Unknown to the Database
=====================================
File Name: /u02/bkp/stnd_backp_10n6p3nl_1_1.bak
File Name: /u02/bkp/stnd_backp_11n6p3p4_1_1.bak

Do you really want to catalog the above files (enter YES or NO)? YES
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u02/bkp/stnd_backp_10n6p3nl_1_1.bak
File Name: /u02/bkp/stnd_backp_11n6p3p4_1_1.bak


Step 7: Recover the standby database with the cataloged incremental backup pieces.


RMAN> recover database noredo;

Starting recover at 25-MAR-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=32 device type=DISK
channel ORA_DISK_1: starting incremental datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
destination for restore of datafile 00001: +DATA/sssb/datafile/system.274.778865099
destination for restore of datafile 00002: +DATA/sssb/datafile/sysaux.275.778865193
destination for restore of datafile 00003: +DATA/sssb/datafile/undotbs1.276.778865259
destination for restore of datafile 00004: +DATA/sssb/datafile/users.277.778865273
channel ORA_DISK_1: reading from backup piece /u02/bkp/stnd_backp_10n6p3nl_1_1.bak
channel ORA_DISK_1: piece handle=/u02/bkp/stnd_backp_10n6p3nl_1_1.bak tag=TAG20120325T154639
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01

Finished recover at 25-MAR-12


Step 8 : Shutdown the physical standby database, start it in nomount stage and restore the standby controlfile backup that we had taken from the primary database.

Standby Database:

RMAN> shutdown immediate

database dismounted
Oracle instance shut down

RMAN> startup nomount

connected to target database (not started)
Oracle instance started

Total System Global Area     659730432 bytes

Fixed Size                     2216264 bytes
Variable Size                398462648 bytes
Database Buffers             255852544 bytes
Redo Buffers                   3198976 bytes

RMAN> restore standby controlfile from '/u02/stnd_12n6p3qt_1_1.ctl';

Starting restore at 25-MAR-12
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=21 device type=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:04
output file name=+DATA/sssb/controlfile/current.273.778864875
Finished restore at 25-MAR-12
Step 9: Shutdown the standby database and mount the standby database, so that the standby database would be mounted with the new controlfile that was restored in the previous step.

Standby Database:

RMAN> shutdown immediate

Oracle instance shut down

RMAN> startup mount

connected to target database (not started)
Oracle instance started
database mounted

Total System Global Area     659730432 bytes

Fixed Size                     2216264 bytes
Variable Size                398462648 bytes
Database Buffers             255852544 bytes
Redo Buffers                   3198976 bytes



Step 11: On the standby database, start the Managed Recovery Process.

Standby Database:


SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL> select process,status,sequence# from v$managed_standby;

PROCESS   STATUS        SEQUENCE#
--------- ------------ ----------
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
ARCH      CONNECTED             0
RFS       IDLE                  0
RFS       IDLE                  0
RFS       IDLE               1010
RFS       IDLE                  0
MRP0      WAIT_FOR_LOG          0

9 rows selected.


Step 12: On the Primary database, check the Maximum Archivelog Sequence generated.

Primary Database:

SQL> select thread#,max(sequence#) from v$archived_log group bythread#;

THREAD# MAX(SEQUENCE#)
------- ----------------
1       1009


Step 13: Check the maximum archivelog sequence that is applied on the Physical standby database.


SQL> select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;

THREAD# MAX(SEQUENCE#)
------- ----------------
1       1009

So, here we can see from Steps 12 and 13 that the maximum archivelog sequence generated on the Primary database is sequence# 1009 and that applied on the Physical Standby Database is also 1009 which means that the Standby database is in sync with the Primary Database. You can check it out by generating an archive sequence on the Primary database and check if its shipped and applied on the standby database.

Primary Database:

SQL> alter system switch logfile;

System altered.

SQL> select thread#,max(sequence#) from v$archived_log group bythread#;

THREAD# MAX(SEQUENCE#)
------- ----------------
1       1010

Standby Database:


SQL> select thread#,max(sequence#) from v$archived_log where applied='YES' group by thread#;

THREAD# MAX(SEQUENCE#)
------- ----------------
1       1010


Now standby database is in sync with the Primary Database.

Here you go !!