Tuesday, August 8, 2017

Oracle SOA Suite 11g Instances Purge Data from SOAINFRA Schema

This post has step by step procedure to Purge/Delete all Closed and Completed SOA composite service instances for given specified period. This document is created on Virtual Machine which has SOA Suite, Webcenter Portal and Webcenter Content installed and integrated.

SOAINFRA Database schema will be created by running rcu utility provided by Oracle. SOAINFRA is contains instance and metadata objects for Oracle SOA Suite Components and it will be stored in the database table space. We can purge or delete the instances if we notice that table space size is increasing with huge volume and it is affecting database performances or making any size issue as we are deleting the instances with below category only.

Instances which will get deleted after Applying Script                                                         

v  Faulted
v  Terminated by user
v  Stale
v  Unknown

Instances which will NOT get deleted after Applying Script

v  Running
v  Suspended
v  Pending Recovery

I have categorized the entire activities into lists and the main activity will be done on step. If we want to delete the instances later, please follow the activities mentioned in the step onwards only.

Step 1:  Stop all managed servers and admin server
Step 2:  Copy purge script to Database Server
Step 3:  Connect to the Database Server as sysdba
Step 4:  Grant required privileges to SOAINFRA schema
Step 5:  Connect SOAINFRA Schema
Step 6:  Execute SOA Purge Script by SOAINFRA user
Step 7:  Create Purge Logs Directory
Step 8:  Assign Purge Directory Created for SOAINFRA Schema
Step 9:  Execute Purge Procedure
Step 10: Check the Instances after deleting the instances

Step 1: Stop all managed servers and admin server

Stop all running Managed servers (SOA, Spaces, UCM, BAM etc.) along with Admin Server.
[oracle@sit ~]$ cd /u01/app/oracle/product/fmw11g/user_projects/domains/<domain_name>/bin/
[oracle@sit bin]$ ./stopManagedWebLogic.sh WC_Spaces
[oracle@sit bin]$ ./stopManagedWebLogic.sh soa_server1
[oracle@sit bin]$ ./stopManagedWebLogic.sh WC_Collaboration
[oracle@sit bin]$ ./stopManagedWebLogic.sh UCM_server1


[oracle@sit bin]$ ./stopWebLogic.sh

Connect the database with sysdba and execute the below command to check the instances before executing the purge.

[oracle@db soa_purge]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 8 09:47:40 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> SELECT (CASE
WHEN STATE=1 THEN 'OPEN AND RUNNING'
WHEN STATE=2 THEN 'OPEN AND SUSPENDED'
WHEN STATE=3 THEN 'OPEN AND FAULTED'
WHEN STATE=4 THEN 'CLOSED AND PENDING'
WHEN STATE=5 THEN 'CLOSED AND COMPLETED'
WHEN STATE=6 THEN 'CLOSED AND FAUTED'
WHEN STATE=7 THEN 'CLOSED AND CANCELLED'
WHEN STATE=8 THEN 'CLOSED AND ABORTED'
WHEN STATE=9 THEN 'CLOSED AND STALE'
WHEN STATE=10 THEN 'NON-RECOVERABLE'
ELSE 'NON-RECOVERABLE'  END)

AS STATE,COMPOSITE_NAME, COUNT(*) AS NUM_OF_CUBE_INST FROM <SCHEMA_NAME>.CUBE_INSTANCE GROUP BY STATE,COMPOSITE_NAME;

Step 2:  Copy purge script to Database Server

Copy soa_purge.zip file on some location like ' /u01' and extract this soa_purge zip file. After extraction it should give you below files inside folder.

Download the soa_purge.zip from below location. 
[oracle@sit u01]$ chmod a+x soa_purge.zip
[oracle@sit u01]$ unzip soa_purge.zip

b2b
casemgmt
common
decision
fabric
mediator
orabpel
soa
workflow
README
soa_purge_scripts.sql



Step 3:  Connect to the Database Server as sysdba

Log into the Database host server (SQL * Plus) where SOA INFRA Schema is present. For login user Sys DBA Username and password.

[oracle@db soa_purge]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 8 09:47:40 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>

Step 4:  Grant required privileges to SOAINFRA schema

You must know the DB schema name of your SOAINFRA setup. Usually it will be like <VAR>_SOAINFRA where <VAR> hold value like DEV, PROD, STG, etc.

Now we need to grant some LOCKING and JOB Creation authorization to <VAR>_SOAINFRA schema.
Here is the syntax for first one.

Syntax: 'GRANT EXECUTE ON DBMS_LOCK TO <VAR>_SOAINFRA;'
Syntax: ' GRANT CREATE JOB TO <VAR>_SOAINFRA;'
Syntax: ' GRANT CREATE EXTERNAL JOB TO <VAR>_SOAINFRA;'

SQL> GRANT EXECUTE ON DBMS_LOCK TO SIT_SOAINFRA;
Grant succeeded.
SQL> GRANT CREATE JOB TO SIT_SOAINFRA;
Grant succeeded.
SQL> GRANT CREATE EXTERNAL JOB TO SIT_SOAINFRA;
Grant succeeded.
SQL>

Step 5: Connect SOAINFRA Schema

Connect to <VAR>_SOAINFRA schema

Now you will get connected to SQL *Plus as show in below screen.
[oracle@db bin]$ cd /u01/soa_purge
[oracle@db soa_purge]$ ls
b2b  casemgmt  common  decision  fabric  mediator  orabpel  README  soa  soa_purge_scripts.sql  workflow
[oracle@db soa_purge]$
[oracle@db soa_purge]$ sqlplus SIT_SOAINFRA
SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 8 10:04:38 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Enter password:
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>

Step 6: Execute SOA Purge Script by SOAINFRA user

Now in same SQL plus session we will run 'soa_purge_scripts.sql' script file which will create internal procedures, functions, types,pachakes etc for purge script to run.
Syntax: @soa_purge_scripts.sql
SQL> @soa_purge_scripts.sql


Step 7: Create Purge Logs Directory

Now Exit from SQL * Plus using 'exit' command and we will create folder where purge logs will be stored in case any error occurs. Our purge logs folder will be '/oracle/PurgeLogs'
Syntax: mkdir –p /u01/PurgeLogs
[oracle@db /]$ mkdir –p /u01/PurgeLogs
[oracle@db u01]$ cd PurgeLogs/
[oracle@db PurgeLogs]$ ls
[oracle@db PurgeLogs]$

And finally exit terminal

Step 8: Assign Purge Directory Created for SOAINFRA Schema

Open SQL * Plus with System DBA username to grant read and write permissions to Purge logs folder which we created in earlier step.
[oracle@db PurgeLogs]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 8 10:31:13 2017
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>

This will connect to DB with DBA privilege

Now, create SOA_PURGE_DIRECTORY
Syntax: CREATE OR REPLACE DIRECTORY SOA_PURGE_DIR AS '/u01/PurgeLogs';

SQL> CREATE OR REPLACE DIRECTORY SOA_PURGE_DIR AS '/u01/PurgeLogs';
Directory created.
SQL>
Then, Grant Read and write permission to SIT_SOAINFRA user to this directory.
Syntax: GRANT READ, WRITE ON DIRECTORY SOA_PURGE_DIR TO SIT_SOAINFRA;

SQL> GRANT READ, WRITE ON DIRECTORY SOA_PURGE_DIR TO SIT_SOAINFRA;
Grant succeeded.
SQL>

Step 9: Execute Purge Procedure

In this step, we will actually run Delete Procedure to delete instances for specified time.
 While running procedure we need to specify  'From Date'  in min_creation_date  and 'To Date' in max_creation_date.

Also we need to specify Retention_Period: This parameter checks for and deletes records in the cube_instance table. The value for this parameter must be greater than or equal to max_creation_date. The default value is null. Specify a retention period if you want to retain the composite instances based on the modify_date of the BPEL instances.

Execute below Procedure and wait for Response. If Number of instances to be deleted are more than successful execution of procedure take 5-10 Minutes.

Syntax:  DECLARE
max_creation_date timestamp;
min_creation_date timestamp;
batch_size integer;
max_runtime integer;
retention_period timestamp;
BEGIN
min_creation_date := to_timestamp('2015-01-01','YYYY-MM-DD');
max_creation_date := to_timestamp('2017-08-08','YYYY-MM-DD');
max_runtime := 60;
retention_period := to_timestamp('2017-08-10','YYYY-MM-DD');
batch_size := 10000;
soa.delete_instances(
min_creation_date => min_creation_date,
max_creation_date => max_creation_date,
batch_size => batch_size,
max_runtime => max_runtime,
retention_period => retention_period);
END;





Step 10: Check the Instances after deleting the instances

In this step, after running delete procedure we will see how many instances got deleted in CUBE Engine.
Run below SELECT SQL on SOAINFRA DB connection we made in step 9, it will fetch all instances along with their state, composite name and count.
You can compare the instance count in step 10 and Step 12 that means Before execution of delete procedure and after execution of delete procedure.

Syntax: SELECT (CASE
WHEN STATE=1 THEN 'OPEN AND RUNNING'
WHEN STATE=2 THEN 'OPEN AND SUSPENDED'
WHEN STATE=3 THEN 'OPEN AND FAULTED'
WHEN STATE=4 THEN 'CLOSED AND PENDING'
WHEN STATE=5 THEN 'CLOSED AND COMPLETED'
WHEN STATE=6 THEN 'CLOSED AND FAUTED'
WHEN STATE=7 THEN 'CLOSED AND CANCELLED'
WHEN STATE=8 THEN 'CLOSED AND ABORTED'
WHEN STATE=9 THEN 'CLOSED AND STALE'
WHEN STATE=10 THEN 'NON-RECOVERABLE'
ELSE 'NON-RECOVERABLE'  END)
AS STATE,COMPOSITE_NAME, COUNT(*) AS NUM_OF_CUBE_INST FROM <SCHEMA>.CUBE_INSTANCE GROUP BY STATE,COMPOSITE_NAME;

Example

SELECT (CASE
WHEN STATE=1 THEN 'OPEN AND RUNNING'
WHEN STATE=2 THEN 'OPEN AND SUSPENDED'
WHEN STATE=3 THEN 'OPEN AND FAULTED'
WHEN STATE=4 THEN 'CLOSED AND PENDING'
WHEN STATE=5 THEN 'CLOSED AND COMPLETED'
WHEN STATE=6 THEN 'CLOSED AND FAUTED'
WHEN STATE=7 THEN 'CLOSED AND CANCELLED'
WHEN STATE=8 THEN 'CLOSED AND ABORTED'
WHEN STATE=9 THEN 'CLOSED AND STALE'
WHEN STATE=10 THEN 'NON-RECOVERABLE'
ELSE 'NON-RECOVERABLE'  END)
AS STATE,COMPOSITE_NAME, COUNT(*) AS NUM_OF_CUBE_INST FROM SIT_SOAINFRA.CUBE_INSTANCE GROUP BY STATE,COMPOSITE_NAME;


Tuesday, July 18, 2017

Oracle Database 12c Installation and Configuration

Oracle has release Oracle Database 12c and we are covering Oracle Database 12.2.1.0 for the installation and configuration in this post.  Below are software versions that we are using.

Virtualization: Oracle Virtual Box

Operating System: Oracle Enterprise Linux 6.9

Database: Oracle Database 12.2.1.0

We can us this post as initial step to turn into Oracle DBA.

1.       Oracle DBA Tasks: General Oracle DBA Tasks
a.       Install Oracle Database
b.      Create Oracle Database instances
c.       Upgrade Database to newer versions
d.      Start Oracle Database instance
e.       Shutdown Oracle Database instance
f.        Manage storage structures of Oracle Database
g.      Manage users and security
h.      Manage database objects – indexes, tables, views etc.
i.         Backup database
j.         Recover database
k.       Monitor the state of the database instance and performance
l.         Tune database
m.    Diagnose and Report critical errors

2.     Tools for administering oracle database
a.       Oracle universal installer – to install oracle database.
b.      Oracle Database Configuration Assistant (DBCA) – to create database from templates (oracle supplied or own templates)
c.       Database Upgrade Assistant (DBUA) – Upgrade Oracle Database to Newer Versions
d.      Net Configuration Assistant – Configure listeners and naming methods
e.       Oracle Enterprise Manager Database Express (EM Express) – Web based interface for managing the database
f.        SQL Developer – Supports Oracle Database developments

3.     Oracle Database Installation

a.       Pre-requisites: All these pre-requisites need to be done before starting the Oracle Database 12c installation.

                                                               i.      Display Cards resolution – 1024x768

                                                             ii.      RAM – 2 GB RAM
[root@fmwdb12c ~]# grep MemTotal /proc/meminfo
MemTotal:        8512592 kB
[root@fmwdb12c ~]#  grep SwapTotal /proc/meminfo
SwapTotal:       3145724 kB
[root@fmwdb12c ~]#  df -h /tmp
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_ohs12c-lv_root
                       26G  7.1G   18G  29% /
[root@fmwdb12c ~]# free
             total       used       free     shared    buffers     cached
Mem:       8512592    4865736    3646856       4076      29176    4287356
-/+ buffers/cache:     549204    7963388
Swap:      3145724          0    3145724
[root@fmwdb12c ~]# uname -m
x86_64
[root@fmwdb12c ~]# df -h /dev/shm
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           4.1G   84K  4.1G   1% /dev/shm

                                                            iii.      OS – OEL 6.4 to OEL 7.2
[oracle@fmwdb12c ~]$ cat /etc/oracle-release
Oracle Linux Server release 6.9

                                                           iv.      Install Oracle Pre-Installation RPM. This will install the required os libraries for Oracle Database installation.

1.        Login with root user
2.       Execute the below command and make sure that internet connection is available.
#yum install oracle-database-server-12cR2-preinstall

                                                             v.      Check ssh installed

[root@fmwdb12c ~]# rpm -qa | grep ssh
openssh-server-5.3p1-122.el6.x86_64
openssh-clients-5.3p1-122.el6.x86_64
openssh-5.3p1-122.el6.x86_64
openssh-askpass-5.3p1-122.el6.x86_64
libssh2-1.4.2-2.el6_7.1.x86_64
[root@fmwdb12c ~]#

                                                           vi.      Create Operating System Groups, Assign to user and create the installation directory

[root@fmwdb12c ~]# groupadd oper
[root@fmwdb12c ~]# groupadd dba
[root@fmwdb12c ~]# groupadd oinstall
[root@fmwdb12c ~]# usermod -g oinstall -G dba,oper oracle
[root@fmwdb12c ~]# mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
[root@fmwdb12c ~]# chown -R oracle:oinstall /u01
[root@fmwdb12c ~]# chmod -R 775 /u01

                                                          vii.      Set Environment Parameters

[root@fmwdb12c ~]# su - oracle
[oracle@fmwdb12c ~]$ cd /home/oracle/
[oracle@fmwdb12c ~]$ vi .bash_profile

TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=fmwdb12c; export ORACLE_HOSTNAME
ORACLE_UNQNAME=FMW12CDB; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1; export ORACLE_HOME
ORACLE_SID=FMW12CDB; export ORACLE_SID
PATH=$ORACLE_HOME/bin:$PATH; export PATH



                                                        viii.      Check the resource limits

[oracle@fmwdb12c ~]$ ulimit -Sn
1024
[oracle@fmwdb12c ~]$ ulimit -Hn
65536
[oracle@fmwdb12c ~]$ ulimit -Su
16384
[oracle@fmwdb12c ~]$ ulimit -Hu
16384
[oracle@fmwdb12c ~]$ ulimit -Ss
10240
[oracle@fmwdb12c ~]$ ulimit -Hs
32768
[oracle@fmwdb12c ~]$

b.      Database file location

                                                               i.      File System – Operating system file system. We are following File System for the database installation in this post.

                                                             ii.      Automatic Storage Management – Oracle ASM disk group. Oracle ASM need to be installed and create the disk groups before starting the Oracle Installation.

c.       Installation Steps

[oracle@fmwdb12c tmp]$ cd /u01/sw/
[oracle@fmwdb12c sw]$ unzip linuxx64_12201_database.zip
[oracle@fmwdb12c sw]$ cd database/
[oracle@fmwdb12c sw]$./runInstaller



























Install the scripts using root user in a separate terminal.

[oracle@fmwdb12c database]$ su -
Password:
[root@fmwdb12c ~]# sh /u01/app/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.
The execution of the script is complete.

[root@fmwdb12c ~]# sh /u01/app/oracle/product/12.2.0.1/db_1/root.sh
Performing root user operation.

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/12.2.0.1/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]: /usr/local/bin
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root script.
Now product-specific root actions will be performed.
Do you want to setup Oracle Trace File Analyzer (TFA) now ? yes|[no] :
yes
Installing Oracle Trace File Analyzer (TFA).
Log File: /u01/app/oracle/product/12.2.0.1/db_1/install/root_fmwdb12c_2017-07-18_13-19-42-504748751.log
Finished installing Oracle Trace File Analyzer (TFA)
[root@fmwdb12c ~]#



d.      Post Installation Checking

[oracle@fmwdb12c sw]$ sqlplus "/as sysdba"

SQL*Plus: Release 12.2.0.1.0 Production on Tue Jul 18 13:51:09 2017

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> select instance_name from v$instance;

INSTANCE_NAME
----------------
FMW12CDB

SQL> select name,open_mode from v$pdbs;

NAME
--------------------------------------------------------------------------------
OPEN_MODE
----------
PDB$SEED
READ ONLY

FMW12CPDB
READ WRITE


SQL> alter session set container=FMW12CPDB;

Session altered.

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/FMW12CDB/fmw12cpdb/system01.dbf
/u01/app/oracle/oradata/FMW12CDB/fmw12cpdb/sysaux01.dbf
/u01/app/oracle/oradata/FMW12CDB/fmw12cpdb/undotbs01.dbf
/u01/app/oracle/oradata/FMW12CDB/fmw12cpdb/users01.dbf

SQL> shutdown immediate;
Pluggable Database closed.

SQL> startup
Pluggable Database opened.

e.      Restart the Virtual Machine and start the database
[oracle@fmwdb12c ~]$ lsnrctl start

LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 18-JUL-2017 14:08:18

Copyright (c) 1991, 2016, Oracle.  All rights reserved.

Starting /u01/app/oracle/product/12.2.0.1/db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 12.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/12.2.0.1/db_1/network/admin/lis                                                                                        tener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/fmwdb12c/listener/alert/log                                                                                        .xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fmwdb12c)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fmwdb12c)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date                18-JUL-2017 14:08:19
Uptime                    0 days 0 hr. 0 min. 1 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/12.2.0.1/db_1/network/admin/li                                                                                        stener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/fmwdb12c/listener/alert/l                                                                                        og.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fmwdb12c)(PORT=1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
[oracle@fmwdb12c ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 12.2.0.1.0 Production on Tue Jul 18 14:08:31 2017
Copyright (c) 1982, 2016, Oracle.  All rights reserved.
Connected to an idle instance.
SQL> select instance_name from v$instance;
select instance_name from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0
SQL> startup
ORACLE instance started.

Total System Global Area 2617245696 bytes
Fixed Size                  8796192 bytes
Variable Size             687867872 bytes
Database Buffers         1912602624 bytes
Redo Buffers                7979008 bytes
Database mounted.
Database opened.
SQL>


Oracle Database 12c has been installed and successfully configured to use.