Tuesday 22 August 2017

Taking Cold Backup of Oracle Database

Introduction

Cold backup is consistent backup, as the backup is run when the database is shutdown. Its exact image copy of the database that can be used to clone database on other server. We can take Oracle database cold backup in two ways

  1. Cold backup can be taken using OS command such as cp
  2. Using RMAN utility also we can take cold backups

Taking Cold Backup of Oracle Database - Manual

Step 1:- Check the list of data files, control files and redolog files in the database

SQL> select file_name from dba_data_files;
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/GGDB01/users01.dbf
/u01/app/oracle/oradata/GGDB01/undotbs01.dbf
/u01/app/oracle/oradata/GGDB01/sysaux01.dbf
/u01/app/oracle/oradata/GGDB01/system01.dbf
/u01/app/oracle/oradata/GGDB01/ggdata01.dbf

SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/GGDB01/redo03.log
/u01/app/oracle/oradata/GGDB01/redo02.log
/u01/app/oracle/oradata/GGDB01/redo01.log

SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/GGDB01/control01.ctl
/u01/app/oracle/flash_recovery_area/GGDB01/control02.ctl

Step 2:- Shutdown the database using graceful shutdown

[oracle@prim backups]$ sqlplus "/ as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Tue Aug 22 19:35:45 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> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 


Step 3:- Now manually copy all the data files, control files and redolog files

$ cp /u01/app/oracle/oradata/GGDB01/users01.dbf /u01/app/backups/
$ cp /u01/app/oracle/oradata/GGDB01/undotbs01.dbf /u01/app/backups/
$ cp /u01/app/oracle/oradata/GGDB01/system01.dbf /u01/app/backups/
$ cp /u01/app/oracle/oradata/GGDB01/sysaux01.dbf /u01/app/backups/
$ cp /u01/app/oracle/oradata/GGDB01/ggdata01.dbf /u01/app/backups/
--------------------------------------------------------------------------------
$ cp /u01/app/oracle/oradata/GGDB01/redo01.log /u01/app/backups/
$ cp /u01/app/oracle/oradata/GGDB01/redo02.log /u01/app/backups/
$ cp /u01/app/oracle/oradata/GGDB01/redo03.log /u01/app/backups/
--------------------------------------------------------------------------------
$ cp /u01/app/oracle/oradata/GGDB01/control01.ctl /u01/app/backups/
$ cp /u01/app/oracle/flash_recovery_area/GGDB01/control02.ctl /u01/app/backups/

Step 4:- Go to backup location and list the files. This step is to verify all the files are present 

[oracle@prim backups]$ ls -ltr
total 1898144
-rw-r----- 1 oracle oinstall   5251072 Aug 22 19:36 users01.dbf
-rw-r----- 1 oracle oinstall  31465472 Aug 22 19:36 undotbs01.dbf
-rw-r----- 1 oracle oinstall 702554112 Aug 22 19:37 system01.dbf
-rw-r----- 1 oracle oinstall 503324672 Aug 22 19:38 sysaux01.dbf
-rw-r----- 1 oracle oinstall 524296192 Aug 22 19:38 ggdata01.dbf
-rw-r----- 1 oracle oinstall  52429312 Aug 22 19:39 redo01.log
-rw-r----- 1 oracle oinstall  52429312 Aug 22 19:39 redo02.log
-rw-r----- 1 oracle oinstall  52429312 Aug 22 19:39 redo03.log
-rw-r----- 1 oracle oinstall   9748480 Aug 22 19:40 control01.ctl
-rw-r----- 1 oracle oinstall   9748480 Aug 22 19:40 control02.ctl
[oracle@prim backups]$

Now we have completed the cold backup for Oracle database :)


Step 5:- Once the backup is complete, start the database


Taking Cold Backup of Oracle Database using RMAN

Here we will demonstrate the procedure of taking RMAN cold backup for Oracle database

Step 1:- Shutdown the database and bring it to mount state

SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size                  2217992 bytes
Variable Size             532678648 bytes
Database Buffers          301989888 bytes
Redo Buffers                2396160 bytes
Database mounted.
SQL> 

Step 2:- Connect to RMAN then run full database backup and control file backup

[oracle@prim ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Aug 22 22:52:34 2017

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

connected to target database: GGDB01 (DBID=1637703886, not open)

RMAN> backup database;

Starting backup at 22-AUG-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
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=/u01/app/oracle/oradata/GGDB01/system01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/GGDB01/ggdata01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/GGDB01/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/GGDB01/undotbs01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/GGDB01/users01.dbf
channel ORA_DISK_1: starting piece 1 at 22-AUG-17
channel ORA_DISK_1: finished piece 1 at 22-AUG-17
piece handle=/u01/app/oracle/flash_recovery_area/GGDB01/backupset/2017_08_22/o1_mf_nnndf_TAG20170822T225245_dsrt35w5_.bkp tag=TAG20170822T225245 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:16
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
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 22-AUG-17
channel ORA_DISK_1: finished piece 1 at 22-AUG-17
piece handle=/u01/app/oracle/flash_recovery_area/GGDB01/backupset/2017_08_22/o1_mf_ncsnf_TAG20170822T225245_dsrt5lvt_.bkp tag=TAG20170822T225245 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-AUG-17

RMAN> backup current controlfile;

Starting backup at 22-AUG-17
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 current control file in backup set
channel ORA_DISK_1: starting piece 1 at 22-AUG-17
channel ORA_DISK_1: finished piece 1 at 22-AUG-17
piece handle=/u01/app/oracle/flash_recovery_area/GGDB01/backupset/2017_08_22/o1_mf_ncnnf_TAG20170822T225457_dsrt7boz_.bkp tag=TAG20170822T225457 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 22-AUG-17

RMAN>


Once the database is complete, open the database


SQL> alter database open;

Now we can successfully completed full :)

Sunday 20 August 2017

DDL - Create, Alter, Drop, Truncate and Rename SQL statements in Oracle

DDL - Data Definition Language

Its used to create and modify database objects such as tables etc. DDL are used to define metadata in the database. By default DDL is auto commit, when ever you a execute a DDL commit is triggered
  • CREATE : Its used to create the table, schema etc
  • ALTER : Modifying existing table by adding column, dropping column
  • DROP : Delete table or any other database objects
  • TRUNCATE : It clears all the data inside a table
  • RENAME : Change the name of the table or any other object

Create SQL Statement

Create statement is used to create the objects. Here we will create the table to demonstrate an example

Create table without primary key or constraints 


SQL> CREATE TABLE hr.emp (
eno NUMBER(10),
ename VARCHAR2(15),
ssn NUMBER(10),
dept VARCHAR2(10),
mgr_id NUMBER(5),
hiredate DATE DEFAULT (sysdate));

Create table with primary key and other constraints


SQL> CREATE TABLE hr.emp (
eno NUMBER(10) PRIMARY KEY,
ename VARCHAR2(15) NOT NULL,
ssn NUMBER(10),
dept VARCHAR2(10),
mgr_id NUMBER(5),
hiredate DATE DEFAULT (sysdate));

Alter SQL Statement 

Alter command is used to modify database objects such as tables etc. Its used to add, drop and rename the columns of the table

Alter table add column

This statement adds column to existing table

SQL> alter table hr.emp add (phone number, email varchar2(35));

Alter table rename column

This statement renames existing column to new column name

SQL> alter table hr.emp rename column phone to mobile_number;

Alter table modify column data type

This statement changes the datatype of a column

SQL>  alter table hr.emp modify email char(50);

Alter table drop column

This statement drops existing column from the table

SQL> alter table hr.emp drop (email, mobile_number);

Drop SQL Statement 

Drop SQL statements are used to drop or delete the database objects

SQL> drop table emp;

Rename SQL Statement

This SQL statement renames an existing table with new table name

SQL> rename emp to employee;

Truncate SQL Statement

This SQL statement deletes all the rows that are present in the table

SQL> truncate table emp;

Saturday 19 August 2017

ORA-01031: insufficient privileges when creating table

Issue

Create table command fails with below mentioned error 
ERROR at line 1:
ORA-01031: insufficient privileges

Here are the list of privileges granted 

SQL> select * from session_privs;

PRIVILEGE
----------------------------------------
CREATE SESSION
UNLIMITED TABLESPACE
CREATE TABLE
CREATE CLUSTER
CREATE SEQUENCE
CREATE PROCEDURE
CREATE TRIGGER
CREATE TYPE
CREATE OPERATOR
CREATE INDEXTYPE

Resolution

Grant the below mentioned privileges to the user then re login to database. Now execute the create table statement, it must run successfully. In case you face any issue, please write the comment below
SQL> grant resource to hr;

Grant succeeded.

SQL Language in Oracle: DDL, DML, DRL, DCL and TCL Statements

Overview

SQL stands for Structured Query Language and its basically divided into 5 types of language statements i.e. DDL, DML, DRL, DCL and TCL. These languages are used to create, modify, load, control and retrieve the data from the database

Types of SQL Statements

DDL - Data Definition Language

Its used to create and modify database objects such as tables etc. DDL are used to define metadata in the database. By default DDL is auto commit, when ever you a execute a DDL commit is triggered

  • CREATE : Its used to create the table, schema etc
  • ALTER : Modifying existing table such as adding column, dropping column
  • DROP : Delete table or any other database objects
  • TRUNCATE : It clears all the data inside a table
  • RENAME : Change the name of the table or any other object

DML - Data Manipulation Language

Its used to insert, update and delete the data from the tables, hence its called as Data manipulation language

  • INSERT : It adds rows or records to the table
  • UPDATE : Its used to modify information of rows in table
  • DELETE : It delete records or rows from the table
  • MERGE : It allows to join data source and perform action on target table 

DRL - Data Retreival Language 

This language is used to fetch the records from the table

  • SELECT : Retrieves the data from the tables

DCL - Data Control Language 

This language is used to control the level of access to users on the database objects

  • GRANT : Allows users to access particular object in the database
  • REVOKE : Prohibits user from accessing particular object in the database

TCL - Transaction Control Language

This language is used to manage transactions within the database 

  • COMMIT : Used to save the data
  • ROLLBACK : Used to revert the changes made
  • SAVEPOINT : Its used to identify point in transaction, where we can rollback

Tuesday 15 August 2017

Configure Oracle 11gR2 Data Guard Physical Standby

Synopsis

In this exercise we will configure Oracle Data Guard for Oracle 11gR2 database. We have two virtual machines configured where we have built Linux machines and installed Oracle 11gR2 database. Please refer below mentioned link to build Linux virtual machine and install Oracle 11gR2 database software
  • Primary Database
    • hostname : prim.localdomain
    • db_name : PRODPRIM
    • db_unique : PRODPRIM
  • Standby Database
    • hostname : stby.localdomain
    • db_name : PRODPRIM
    • db_unique : PRODSTBY

Configuration on the Primary Database :-

Step 1 :- Enable archivelog mode

SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
SQL> ALTER DATABASE ARCHIVELOG;
SQL> ALTER DATABASE OPEN;
SQL> archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2

Step 2 :- Enable force logging

SQL> ALTER DATABASE FORCE LOGGING;

Database altered.

Step 3 :- Set database parameters to configure the data guard

Here are the list of parameters to be set to configure the dataguard
  • db_unique_name
  • log_archive_config  
  • log_archive_dest_2  
  • remote_login_passwordfile
  • fal_server
  • fal_client
  • standby_file_management
SQL> ALTER SYSTEM SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(PRODPRIM,PRODSTBY)';

System altered.

SQL> ALTER SYSTEM SET LOG_ARCHIVE_DEST_2='SERVICE=PRODSTBY NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PRODSTBY';

System altered.

SQL> alter system set log_archive_dest_state_2=enable;

System altered.

SQL> alter system set log_archive_format='%t_%s_%r.arc' scope=spfile;

System altered.

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

System altered.

SQL> alter system set fal_server=PRODSTBY;

System altered.

SQL> alter system set fal_client='PRODPRIM';

System altered.

SQL> alter system set standby_file_management=auto;

System altered.

Step 4 :- Create and start the Listener

We need to create and start the listener on both primary and standby servers 

Step 5 :- Add tnsnames for services of primary and standby database

This step has to be performed on both primary and standby database servers. You can update the tnsnames.ora file to add service or service can be added using netca utility. Go to $ORACLE_HOME/network/admin/tnsnames.ora add the below mentioned line to the file
In case you want to add service using netca utility refer this link 

PRODPRIM =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = prim.localdomain)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRODPRIM)
    )
  )

PRODSTBY =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = stby.localdomain)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = PRODSTBY)
    )
  )

Step 6 :- Check the services if its been configured properly using tnsping on both the servers

[oracle@prim dbhome_1]$ tnsping PRODPRIM

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 15-AUG-2017 14:17:41

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = prim.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRODPRIM)))
OK (0 msec)

[oracle@prim dbhome_1]$ tnsping PRODSTBY

TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 15-AUG-2017 14:18:51

Copyright (c) 1997, 2009, Oracle.  All rights reserved.

Used parameter files:

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = stby.localdomain)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = PRODSTBY)))
OK (20 msec)

Step 7 :- Backup primary database using RMAN utility

[oracle@prim dbhome_1]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Aug 15 14:20:28 2017

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

connected to target database: PRODPRIM (DBID=881986728)

RMAN> backup database plus archivelog;

Step 8 :- Create standby control file 

SQL> alter database create standby controlfile as '/u01/app/oracle/oradata/PRODPRIM/stbycontrol1.ctl';

Database altered.

Step 9 :- Create pfile of primary database

SQL> create pfile from spfile;

File created.

Step 10 :- Update the newly created pfile with below mentioned changes

  • log_archive_dest_2 = 'SERVICE=PRODPRIM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=PRODPRIM'
  • fal_client = PRODSTBY
  • fal_server = PRODPRIM
  • db_unique_name = PRODSTBY

Step 11 :- Copy newly created pfile, standby controlfile, password file and RMAN backup pieces to standby database server

[oracle@prim dbs]$ scp initPRODPRIM.ora oracle@stby.localdomain:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
The authenticity of host 'stby.localdomain (192.168.10.2)' can't be established.
RSA key fingerprint is a3:a6:ed:66:82:ad:bf:9b:6b:a7:59:4d:27:f6:f0:a0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'stby.localdomain,192.168.10.2' (RSA) to the list of known hosts.
oracle@stby.localdomain's password:
initPRODSTBY.ora                                                                                                                                                   100% 1286     1.3KB/s   00:00
--------------------------------------------------------------------
[oracle@prim PRODPRIM]$ scp stbycontrol1.ctl oracle@STBY.localdomain:/u01/app/oracle/oradata/PRODSTBY/control01.ctl
oracle@stby.localdomain's password:
stbycontrol1.ctl                                                                                                                                                   100% 9520KB   9.3MB/s   00:00
--------------------------------------------------------------------
 [oracle@prim PRODPRIM]$ scp stbycontrol1.ctl oracle@STBY.localdomain:/u01/app/oracle/flash_recovery_area/PRODSTBY/control02.ctl
oracle@stby.localdomain's password:
stbycontrol1.ctl                                                                                                                                                   100% 9520KB   9.3MB/s   00:00
--------------------------------------------------------------------
[oracle@prim dbs]$ scp orapwPRODPRIM oracle@stby.localdomain:/u01/app/oracle/product/11.2.0/dbhome_1/dbs
oracle@stby.localdomain's password:
orapwPRODPRIM                                                                                                                                                      100% 1536     1.5KB/s   00:00
--------------------------------------------------------------------
[oracle@prim 2017_08_15]$ scp * oracle@stby.localdomain:/u01/app/oracle/flash_recovery_area/PRODSTBY/backup
oracle@stby.localdomain's password:
o1_mf_annnn_TAG20170815T142041_ds5fh218_.bkp                                                                                                                       100%   29MB  29.4MB/s   00:00
o1_mf_annnn_TAG20170815T142204_ds5fknfn_.bkp                                                                                                                       100%   23KB  22.5KB/s   00:00
o1_mf_ncsnf_TAG20170815T142045_ds5fklmm_.bkp                                                                                                                       100% 9600KB   9.4MB/s   00:00
o1_mf_nnndf_TAG20170815T142045_ds5fh5fc_.bkp                                                                                                                       100%  921MB  31.8MB/s   00:29

Configuration on the Standby Database :-

Step 1 :- Set the environment variables and start the database in mount state

$export ORACLE_HOME = /u01/app/oracle/product/11.2.0/dbhome_1
$export ORACLE_SID = PRODPRIM
$export PATH = $ORACLE_SID/bin:$PATH
Create the necessary directories before starting the database
$mkdir -p /u01/app/oracle/admin/PRODSTBY/adump

SQL> startup mount
ORACLE instance started.

Total System Global Area  839282688 bytes
Fixed Size                  2217992 bytes
Variable Size             494929912 bytes
Database Buffers          339738624 bytes
Redo Buffers                2396160 bytes
Database mounted.

SQL> create spfile from pfile;

File created.

Step 2 :- Restore and recover the database using RMAN

[oracle@stby dbs]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Tue Aug 15 14:54:22 2017

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

connected to target database: PRODPRIM (DBID=881986728, not open)

RMAN> list backup of database summary;

using target database control file instead of recovery catalog

List of Backups
===============
Key     TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
2       B  F  A DISK        15-AUG-17       1       1       NO         TAG20170815T142045

RMAN> restore database;

......

Finished restore at 15-AUG-17

RMAN> recover database;

Starting recover at 15-AUG-17
using channel ORA_DISK_1

starting media recovery
......
unable to find archived log
archived log thread=1 sequence=7
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of recover command at 08/15/2017 14:56:46
RMAN-06054: media recovery requesting unknown archived log for thread 1 with sequence 7 and starting SCN of 980859

Here in this step recovery will fail, it would expect for a archivelog file, this can be ignored

Step 3 :- Add standby redolog file on primary database (one additional redolog group to be created)

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby1.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby2.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby3.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby4.log') size 51M;

Database altered.

Step 4 :- Add standby redolog file on standby database (one additional redolog group to be created)

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby1.log') size 51M;

Database altered.

SQL>  ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby2.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby3.log') size 51M;

Database altered.

SQL> ALTER DATABASE ADD STANDBY LOGFILE('/u01/app/oracle/oradata/PRODPRIM/stndby4.log') size 51M;

Database altered.

Step 5 :- Start apply process on standby database

SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE nodelay DISCONNECT FROM SESSION;

Database altered.

If you want to cancel the apply process use below mentioned command
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;

After successful execution of apply process we have completed configuration of physical standby database

Step 6 :- Verify if dataguard is working fine

Switch logs multiple times on primary database using below mentioned command
SQL> alter system switch logfile;

System altered.

Compare the archivelog sequence in primary and standby database 
Primary Database
SQL> select max(sequence#) from v$archived_log;
Standby Database
SQL> select max(sequence#) from v$archived_log;

You can also verify the database role on both primary and standby database
SQL> select name,open_mode,database_role from v$database;

NAME      OPEN_MODE            DATABASE_ROLE
--------- -------------------- ----------------
PRODPRIM  READ WRITE           PRIMARY

SQL> select name,open_mode,database_role from v$database;

NAME      OPEN_MODE            DATABASE_ROLE
--------- -------------------- ----------------
PRODPRIM  MOUNTED              PHYSICAL STANDBY

Monday 14 August 2017

OGG-00664 OCI Error beginning session (status = 1034-ORA-01034: ORACLE not available ORA-27101: shared memory realm does not exist Linux-x86_64 Error: 2: No such file or directory).

Problem Statement

ERROR   OGG-00664  OCI Error beginning session (status = 1034-ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory).

ERROR   OGG-01668  PROCESS ABENDING.

Problem Detail Report

GGSCI (stby.localdomain as ggowner@GGTGT) 6> view report GGREPL01

***********************************************************************
                 Oracle GoldenGate Delivery for Oracle
    Version 12.2.0.1.1 OGGCORE_12.2.0.1.0_PLATFORMS_151211.1401_FBO
   Linux, x64, 64bit (optimized), Oracle 11g on Dec 12 2015 01:27:04

Copyright (C) 1995, 2015, Oracle and/or its affiliates. All rights reserved.


                    Starting at 2017-08-14 02:27:21
***********************************************************************

Operating System Version:
Linux
Version #1 SMP Sat Jun 23 02:39:07 EDT 2012, Release 2.6.39-200.24.1.el6uek.x86_64
Node: stby.localdomain
Machine: x86_64
                         soft limit   hard limit
Address Space Size   :    unlimited    unlimited
Heap Size            :    unlimited    unlimited
File Size            :    unlimited    unlimited
CPU Time             :    unlimited    unlimited

Process id: 9311

Description:

2017-08-14 02:27:21  WARNING OGG-02904  Replication of PARTIAL XML containing NCHAR/NVARCHAR/NCLOB data may cause divergence.

***********************************************************************
**            Running with the following parameters                  **
***********************************************************************

2017-08-14 02:27:21  INFO    OGG-03059  Operating system character set identified as US-ASCII.

2017-08-14 02:27:21  INFO    OGG-02695  ANSI SQL parameter syntax is used for parameter parsing.
REPLICAT GGREPL01
USERID ggowner, PASSWORD ***

Source Context :
  SourceModule            : [ggdb.ora.sess]
  SourceID                : [/scratch/aime/adestore/views/aime_adc4150408/oggcore/OpenSys/src/gglib/ggdbora/ocisess.c]
  SourceFunction          : [oci_try]
  SourceLine              : [871]
  ThreadBacktrace         : [18] elements
                          : [/u01/app/oracle/product/11.2.0/goldengate/libgglog.so(CMessageContext::AddThreadContext()+0x1b)
[0x7fc03d57df1b]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/libgglog.so(CMessageFactory::CreateMessage(CSourceCont
ext*, unsigned int, ...)+0x134) [0x7fc03d5780a4]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/libgglog.so(_MSG_ERR_ORACLE_OCI_ERROR_WITH_DESC(CSourc
eContext*, int, char const*, char const*, CMessageFactory::MessageDisposition)+0x41) [0x7fc03d563007]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(OCISESS_context_def::oci_try(int, char const*
, ...)+0x47e) [0x7290de]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(OCISESS_context_def::logon(ggs::gglib::ggapp:
:CLoginName const&, ggs::gglib::ggapp::CDBObjName<(DBObjType)12> const&, ggs::gglib::ggunicode::UString const&, int, bool, in
t)+0x732) [0x726602]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(ggs::gglib::ggdbora::OraConnUtil::initConnect
ionLogon(ggs::gglib::ggdbapi::DBAuthParams const&)+0x1c8) [0x753958]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(ggs::gglib::ggdbora::OraConnUtil::openDataSou
rce(ggs::gglib::ggdbapi::DBAuthParams const&)+0x28) [0x753d08]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(ggs::gglib::ggdbora::OraRepConnUtil::openData
Source(ggs::gglib::ggdbapi::DBAuthParams const&)+0x9) [0x755309]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat() [0x6f2732]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(odbc_param(char*, char*)+0x263) [0x6f2a73]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(get_infile_params(time_elt_def*, time_elt_def
*, char**, ggs::gglib::ggdatasource::DataSourceParams&, ggs::Heartbeat::MapGeneratorParams&)+0x1870) [0x5a7fc0]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat() [0x621150]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(ggs::gglib::MultiThreading::MainThread::ExecM
ain()+0x60) [0x6d9d50]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(ggs::gglib::MultiThreading::Thread::RunThread
(ggs::gglib::MultiThreading::Thread::ThreadArgs*)+0x14d) [0x6dacdd]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(ggs::gglib::MultiThreading::MainThread::Run(i
nt, char**)+0xb1) [0x6dadc1]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat(main+0x3b) [0x624a6b]]
                          : [/lib64/libc.so.6(__libc_start_main+0xfd) [0x3aeea1ecdd]]
                          : [/u01/app/oracle/product/11.2.0/goldengate/replicat() [0x55b0a9]]

2017-08-14 02:27:21  ERROR   OGG-00664  OCI Error beginning session (status = 1034-ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux-x86_64 Error: 2: No such file or directory).

2017-08-14 02:27:21  ERROR   OGG-01668  PROCESS ABENDING.

Solution :

This issue occurs were more than once oracle instances are running on to the database
Solution 1:- Provide the tnsname of instance which you want to connect
USERID ggowner@GGTGT, PASSWORD ggowner

Solution2:- Add setevn parameters to set Oracle SID and Oracle Home
SETENV (ORACLE_SID=GGTGT)
SETENV (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_home)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
REPLICAT GGREPL01
USERID ggowner@GGTGT, PASSWORD ggowner
DISCARDFILE /u01/app/oracle/product/11.2.0/goldengate/dirrpt/ggext01.dsc
ASSUMETARGETDEFS
MAP GGOWNER.EMPLOYEE, TARGET GGOWNER.EMPLOYEE;

REPLICAT GGREPL01
SETENV (ORACLE_SID=GGTGT)
SETENV (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_home)
USERID ggowner, PASSWORD ggowner
DISCARDFILE /u01/app/oracle/product/11.2.0/goldengate/dirrpt/ggext01.dsc
ASSUMETARGETDEFS
MAP GGOWNER.EMPLOYEE, TARGET GGOWNER.EMPLOYEE;