Recovering Dropped tablespace using Flashback Database

Oracle Version :11g
OS: Rhel 6.4

#Turn on flashback and archivelog from mount stage
SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             318769144 bytes
Database Buffers           88080384 bytes
Redo Buffers                4308992 bytes
Database mounted.

SQL>alter database archivelog;
Database altered.

SQL>  alter database flashback on;
Database altered.

SQL> alter database open;

Database altered.

#Now create a tablespace to test the scenario
SQL> create tablespace test datafile '/u01/app/oracle/oradata/prim/testtbs.dbf' size 20m;
Tablespace created.

SQL> create user test identified by test;
User created.

SQL> grant connect , reesource to test;

SQL> alter user test default tablespace test;
User altered.

SQL> conn test/test
Connected.

SQL> create table t1 (id number);

SQL> insert into t1 values(1);
1 row created.

SQL> commit;
Commit complete.

SQL> select * from t1;
        ID
----------
         1


SQL> connect sqlplus as sysdba
Enter password:
Connected.

SQL> select current_scn from v$database;

CURRENT_SCN
-----------
    1075681

#Now drop the tablespace:-
SQL> drop tablespace test including contents and datafiles;
Tablespace dropped.

SQL> shutdown immediate
SQL> startup mount

SQL> flashback database to scn 1075681;
Flashback complete.

SQL> alter database open resetlogs;
Database altered.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/prim/system01.dbf
/u01/app/oracle/oradata/prim/sysaux01.dbf
/u01/app/oracle/oradata/prim/undotbs01.dbf
/u01/app/oracle/oradata/prim/users01.dbf
/u01/app/oracle/oradata/prim/example01.dbf
/u01/app/oracle/product/11.2.0/db_1/dbs/UNNAMED00006

SQL> alter database create datafile '/u01/app/oracle/product/11.2.0/db_1/dbs/UNNAMED00006' as '/u01/app/oracle/oradata/prim/testtbs.dbf';
Database altered.

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/prim/system01.dbf
/u01/app/oracle/oradata/prim/sysaux01.dbf
/u01/app/oracle/oradata/prim/undotbs01.dbf
/u01/app/oracle/oradata/prim/users01.dbf
/u01/app/oracle/oradata/prim/example01.dbf
/u01/app/oracle/oradata/prim/testtbs.dbf

SQL> select name from v$tablespace;

NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
EXAMPLE
TEST

#Login to test schema and verify the data
SQL> conn test/test
Connected.
SQL> select * from t1;

        ID
----------
         1





Cold Backup Steps and restoring it into destination server

Scenario:-Create a new oracle database on your local system(192.168.72.169) from existing database 'prim' on ip (192.168.72.172) using oracle cold backup

Source database ip :-     192.168.72.169
Destination database ip:- 192.168.72.172
Database version:-        Oracle 11g
Os version:-               Rhel 6


IN SOURCE DATABASE :

# To take a cold backup first I have to get location of pfile,datafiles,controlfiles,redolog files from
source database. As I have  got location like below:-

[oracle@server1 ~]$ sqlplus / as sysdba

SQL>select count(*) from dba_objects;

  COUNT(*)
----------
     72476

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
READ WRITE

SQL> show parameter spfile;

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/11.2.0
                                                 /db_1/dbs/spfileprim.ora

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/prim/system01.dbf
/u01/app/oracle/oradata/prim/sysaux01.dbf
/u01/app/oracle/oradata/prim/undotbs01.dbf
/u01/app/oracle/oradata/prim/users01.dbf
/u01/app/oracle/oradata/prim/example01.dbf


SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/prim/control01.ctl
/u01/app/oracle/flash_recovery_area/prim/control02.ctl

SQL> select group#, member from v$logfile;
---------- ----------------------------------------------------------------------
         3 /u01/app/oracle/oradata/prim/redo03.log
         2 /u01/app/oracle/oradata/prim/redo02.log
         1 /u01/app/oracle/oradata/prim/redo01.log


IN DESTINATION DATABASE(192.168.72.172) :

# Install Oracle Binaries only. Don't Create Database on Destination Server.

# Create folder in target database same as source database and give ownership to oracle user and oinstall group.
[oracle@server1 ~]$ mkdir -p /u01/app/oracle/oradata/prim
[oracle@server1 ~]$ mkdir -p /u01/app/oracle/flash_recovery_area/prim
[oracle@server1 ~]$ mkdir -p /u01/app/oracle/admin/prim/adump
[oracle@server1 ~]$ mkdir -p /u01/app/oracle/product/11.2.0/db_1/dbs
[oracle@server1 ~]$ chown -Rf oracle:oinstall  /u01

IN SOURCE DATABASE :
# Shut Down the database.
SQL> shut immediate;

Copy controlfiles, datafiles, logfiles and pfile from source to destination in the same location as oracle user :-

# scp -r /u01/app/oracle/oradata/prim/* oracle@192.168.72.172:/u01/app/oracle/oradata/prim
# scp /u01/app/oracle/flash_recovery_area/prim/control02.ctl oracle@192.168.72.172:/u01/app/oracle/flash_recovery_area/prim/
# scp /u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora oracle@192.168.72.172:/u01/app/oracle/product/11.2.0/db_1/dbs/

IN DESTINATION DATABASE :

# Set Oracle SID
export ORACLE_SID=prim
# Login as sysdba
sqlplus / as sysdba
# Start the database in nomount stage using pfile.
SQL> STARTUP nomount PFILE =/u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora
# Enter in mount stage :-
SQL> alter database mount;
# Open database:-
SQL> alter database open;
# Create spfile from pfile
SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora';
# Restart the database to use default spfile.
SQL> shut immediate;
SQL> startup;

SQL>select count(*) from dba_objects;

  COUNT(*)
----------
     72476

IN SOURCE DATABASE :
# Start the source Database
SQL> startup;


Hence we can say the database has been successfully restored from source database using cold backup.

Restrict User access to database within certain limit of time


We need to create a trigger for this purpose.

[oracle@server1 ~]$ sqlplus /  as sysdba

SQL> create user sam identified by sam;

User created.

SQL> grant connect , resource to sam;

Grant succeeded.

SQL> conn sam/sam
Connected.
SQL> exit

[oracle@server1 ~]$ sqlplus /  as sysdba
SQL> CREATE OR REPLACE TRIGGER limit_connection
         AFTER LOGON ON DATABASE
       BEGIN
          IF USER = 'SAM' THEN
             IF to_number(TO_CHAR (SYSDATE, 'hh24')) BETWEEN 20 AND 22
             THEN
                RAISE_APPLICATION_ERROR(-20998,' Dear user '||USER||'! You can''t login between 20hrs to 22hrs');
             END IF;
          END IF;
      END limit_connection;
      /

Trigger created.

SQL> select to_char(sysdate,'hh24') from dual;

TO
--
21

SQL> conn sam/sam
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20998:  Dear user SAM! You can't login between 20hrs to 22hrs
ORA-06512: at line 5
Warning: You are no longer connected to ORACLE.

Done...

How to Multiplex Redo Log Files in Oracle 11g



Step 1:- List all the current redo log file in database
SQL> Select * from v$logfile;

    GROUP#   TYPE    MEMBER                      
---------- ------- ------- --------------------------------------
         1   ONLINE  /u01/app/oracle/oradata/prim/redo01.log
         2   ONLINE  /u01/app/oracle/oradata/prim/redo02.log
         3   ONLINE  /u01/app/oracle/oradata/prim/redo03.log



Step-2: Add redo log file members for different location

ALTER DATABASE ADD LOGFILE MEMBER '/home/oracle/redolog/redo01.log' TO GROUP 1;
Database altered.

SQL> ALTER DATABASE ADD LOGFILE MEMBER '/home/oracle/redolog/redo02.log' TO GROUP 2;

Database altered.

SQL> ALTER DATABASE ADD LOGFILE MEMBER '/home/oracle/redolog/redo03.log' TO GROUP 3;

Database altered.

SQL> alter system switch logfile;

SQL> select GROUP#,SEQUENCE#,(BYTES/1024/1024)MB,MEMBERS from v$log;

    GROUP#  SEQUENCE# (BYTES/1024/1024)MB    MEMBERS
----------          ----------           -----------------                 ----------
         1                7                         50                                  2
         2                5                         50                                  2
         3                6                         50                                  2


SQL> Select * from v$logfile;

   GROUP# STATUS  TYPE    MEMBER                                             IS_
---------- ------- ------- -------------------------------------------------- ---
         3         ONLINE  /u01/app/oracle/oradata/prim/redo03.log            NO
         2         ONLINE  /u01/app/oracle/oradata/prim/redo02.log            NO
         1         ONLINE  /u01/app/oracle/oradata/prim/redo01.log            NO
         1         ONLINE  /home/oracle/redolog/redo01.log                    NO
         2         ONLINE  /home/oracle/redolog/redo02.log                    NO
         3         ONLINE  /home/oracle/redolog/redo03.log      


Done..

How to Multiplex Control Files in Oracle 11g

Step 1:-Backup your current control file with a trace option
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE;

Database altered.

Step-2: List all the controlfiles

SQL> select name from v$controlfile;

NAME
---------------------------------------------------------
/u01/app/oracle/oradata/prim/control01.ctl
/u01/app/oracle/flash_recovery_area/prim/control02.ctl


Step-3 Shutdown the database
SQL> shut immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.

Step 4:-Add one more controlfile
[oracle@server1 prim]$cp /u01/app/oracle/oradata/prim/control01.ctl /home/oracle/Multiplexed_control_files/control03.ctl

Step-5: Create PFILE using SPFILE
[oracle@server1 dbs]$ sqlplus / as sysdba
SQL> create pfile from spfile;

File created.

[oracle@server1 prim]$ cd /u01/app/oracle/product/11.2.0/db_1/dbs/
##Add the newly created control file.
[oracle@server1 dbs]$ vi initprim.ora
*.control_files='/u01/app/oracle/oradata/prim/control01.ctl','/u01/app/oracle/flash_recovery_area/prim/control02.ctl','/home/oracle/Multiplexed_control_files/control03.ctl'

:wq

Step 5:-Create SPFILE using PFILE
SQL> create spfile from pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initprim.ora';
File created.

Step 6:- Start the database
SQL> startup
ORACLE instance started.

Total System Global Area  413372416 bytes
Fixed Size                  2213896 bytes
Variable Size             327157752 bytes
Database Buffers           79691776 bytes
Redo Buffers                4308992 bytes
Database mounted.
Database opened.

SQL> select name from v$controlfile;

NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/prim/control01.ctl
/u01/app/oracle/flash_recovery_area/prim/control02.ctl
/home/oracle/Multiplexed_control_files/control03.ctl

Done...

What's View and Synonym?

What is a view?
A view is a virtual table. Every view has a Query attached to it. (The Query is a SELECT statement that identifies the columns and rows of the table(s) the view uses.)
A view is based on a table or another view and acts as a window through which data on tables can be viewed or changed. A view does not contain data. The definition of the view is stored in the data dictionary. You can see definition of view in user_view data dictionary table.
A view is a logical representation of another table or combination of tables. A view derives its data from the tables on which it is based. These tables are called base tables.
What is a synonym and what types it has?
A synonym is an alias for a schema object. Synonyms can provide a level of security by masking the name and owner of an object and by providing location transparency for remote objects of a distributed database. Also, they are convenient to use and reduce the complexity of SQL statements for database users.
Synonyms allow underlying objects to be renamed or moved, where only the synonym needs to be redefined and applications based on the synonym continue to function without modification.
You can create both public and private synonyms. A public synonym is owned by the special user group named PUBLIC and is accessible to every user in a database. A private synonym is contained in the schema of a specific user and available only to the user and the user’s grantees.

Create oracle 11g database manually on linux

Make sure oracle binaries are installed.We will proceed with database installation if binaries are already installed.

Step 1:Create Directory structure with Oracle ownership and permission as below:

[oracle@localhost ~]$ cd /u01

[oracle@localhost u01]$ mkdir testdb

[oracle@localhost u01]$ chmod -R 777 /u01/testdb/*

[oracle@localhost u01]$ chown -R oracle:oinstall /u01/testdb/*

[oracle@localhost u01] cd testdb

[oracle@localhost testdb]$ mkdir adump diag flash_recovery_area

[oracle@localhost u01]$ chmod -Rf 777 /u01/testdb/*

[oracle@localhost u01]$ chown -Rf oracle:oinstall /u01/testdb/*


Step 2:Create Parameter file in $ORACLE_HOME/dbs location:

[oracle@localhost testdb]$ cd $ORACLE_HOME/dbs

[oracle@localhost dbs]$ vi init_testdb.ora

db_name='testdb'
memory_target=1G
processes = 150
audit_file_dest='/u01/testdb/adump'
audit_trail ='db'
db_block_size=8192
db_domain=''
db_recovery_file_dest='/u01/testdb/flash_recovery_area'
db_recovery_file_dest_size=2G
diagnostic_dest='/u01/testdb/diag'
dispatchers='(PROTOCOL=TCP) (SERVICE=testdb)'
open_cursors=300
remote_login_passwordfile='EXCLUSIVE'
undo_tablespace='UNDOTBS1'
# You may want to ensure that control files are created on separate physical
# devices
control_files = (/u01/testdb/ora_control1.ctl,/u01/testdb/ora_control2.ctl)
compatible ='11.2.0'


Step 3:Prepare Create Database script :

[oracle@localhost u01]$ cd /u01/testdb/

[oracle@localhost testdb]$ vi createdb_test.sql

CREATE DATABASE testdb
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
LOGFILE
GROUP 1 '/u01/testdb/redo1.log' SIZE 10M,
GROUP 2 '/u01/testdb/redo2.log' SIZE 10M,
GROUP 3 '/u01/testdb/redo3.log' SIZE 10M
DATAFILE
'/u01/testdb/system.dbf' size 200M REUSE
sysaux datafile '/u01/testdb/sysaux.dbf' size 100m
undo tablespace UNDOTBS1
datafile '/u01/testdb/undo1.dbf' size 100m
DEFAULT TEMPORARY TABLESPACE temp1
TEMPFILE '/u01/testdb/temp01.dbf'
SIZE 100M REUSE
CHARACTER SET AL32UTF8
;
:wq

Step 4:Set the Oracle ENVIRONMENT and SID of Database in the Operating System:

[root@localhost testdb]# su - oracle

[oracle@localhost ~]$ vi .bash_profile


# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export ORACLE_SID=testdb
export TNS_ADMIN=/u01/app/oracle/product/11.2.0/dbhome_1/network/admin

:wq
[oracle@localhost ~]$ . .bash_profile
     This will set the Oracle Environment variables in Unix-based operating system.

[oracle@localhost ~]$ export ORACLE_SID=testdb
     This will set the SID of the current Database in Unix-based operating system.


Step 5:Create the Password file.

[oracle@localhost ~]$orapwd file=$ORACLE_HOME/dbs/orapwtestdb password=Oracle entries=10


Step 6:Create server parameter file.

[oracle@localhost dbs]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Wed Mar 28 14:08:02 2012

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

Connected to an idle instance.

SQL>create spfile from pfile='$ORACLE_HOME/dbs/init_testdb.ora';


step 7:Start the Database in nomount State.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 1071333376 bytes
Fixed Size                  1341312 bytes
Variable Size             620759168 bytes
Database Buffers          444596224 bytes
Redo Buffers                4636672 bytes
SQL> select status from v$instance;

STATUS
------------
STARTED



Step 8:Execute Create Database script created in Step 3

SQL> @/u01/testdb/createdb_test.sql

Database created

Step 9:Execute the catalog.sql,catproc.sql and pupbld.sql scripts:
a)catalog.sql =>Creates dictionary tables and views
b)catproc.sql =>Creates PL/SQL procedures,functions and packages necessary.
c)pupbld.sql  =>Creates user profiles.


So our database is created. Now just run the catalog.sql,catproc.sql and pupbld.sql scripts.
WE will find catalog.sql and catproc.sql in $ORACLE_HOME/rdbms/admin path and pupbld.sql in $ORACLE_HOME/sqlplus/admin path.

SQL> @$ORACLE_HOME/rdbms/admin/catalog.sql
SQL> @$ORACLE_HOME/rdbms/admin/catproc.sql
conn system/manager

SQL>@$ORACLE_HOME/sqlplus/admin/pupbld.sql

SQL> alter user system identified by manager;

User altered.

SQL> conn system
Enter password:
Connected.
SQL> @$ORACLE_HOME/sqlplus/admin/pupbld.sql
DROP SYNONYM PRODUCT_USER_PROFILE
             *
ERROR at line 1:
ORA-01434: private synonym to be dropped does not exist


  DATE_VALUE FROM PRODUCT_USER_PROFILE
                  *
ERROR at line 3:
ORA-00942: table or view does not exist


DROP TABLE PRODUCT_USER_PROFILE
           *
ERROR at line 1:
ORA-00942: table or view does not exist


ALTER TABLE SQLPLUS_PRODUCT_PROFILE ADD (LONG_VALUE LONG)
*
ERROR at line 1:
ORA-00942: table or view does not exist



Table created.

DROP TABLE PRODUCT_PROFILE
           *
ERROR at line 1:
ORA-00942: table or view does not exist


DROP VIEW PRODUCT_PRIVS
*
ERROR at line 1:
ORA-00942: table or view does not exist



View created.


Grant succeeded.

DROP PUBLIC SYNONYM PRODUCT_PROFILE
                    *
ERROR at line 1:
ORA-01432: public synonym to be dropped does not exist



Synonym created.

DROP SYNONYM PRODUCT_USER_PROFILE
             *
ERROR at line 1:
ORA-01434: private synonym to be dropped does not exist



Synonym created.

DROP PUBLIC SYNONYM PRODUCT_USER_PROFILE
                    *
ERROR at line 1:
ORA-01432: public synonym to be dropped does not exist

Synonym created.


Step 10:Verify the Dictionary views created.


SQL> select name from v$database;
NAME
---------
TESTDB

Step 11:Change the Database mode from noarchive log to archive log mode
Changing to archive log mode:

--------------------------------


SQL> archive log list
Database log mode              No Archive Mode
Automatic archival             Disabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     1
Current log sequence           3
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 1071333376 bytes
Fixed Size                  1341312 bytes
Variable Size             620759168 bytes
Database Buffers          444596224 bytes
Redo Buffers                4636672 bytes
Database mounted.
SQL> alter database archivelog;

Database altered.

SQL> select status from v$instance;

STATUS
------------
MOUNTED

SQL> alter database open;

Database altered.

SQL> select status from v$instance;

STATUS
------------
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   3
Current log sequence           3

This completes the manual Database creation on Unix based Operating system....

Enjoy learning...





Please share your ideas and opinions about this topic.

If you like this post, then please share with others.
Please subscribe on email for every updates on mail.


ORA-00054: resource busy and acquire with NOWAIT specified

ORA-00054: resource busy and acquire with NOWAIT specified
Cause: The NOWAIT keyword forced a return to the command prompt
because a resource was unavailable for a LOCK TABLE or SELECT FOR
UPDATE command.
Action: Try the command after a few minutes or enter the command without
the NOWAIT keyword.


Example:
SQL> alter table emp add (mobile varchar2(15));
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified


How to avoid the ORA-00054:
    - Execute DDL at off-peak hours, when database is idle.
    - Execute DDL in maintenance window.
    - Find and Kill the session that is preventing the exclusive lock.


Other Solutions:

Solution 1:
In Oracle 11g you can set ddl_lock_timeout i.e. allow DDL to wait for the object to
become available, simply specify how long you would like it to wait:

SQL> alter session set ddl_lock_timeout = 600;
Session altered.

SQL> alter table emp add (mobile varchar2(15));
Table altered.


Solution 2:
Also In 11g, you can mark your table as read-only to prevent DML:
SQL> alter table emp read only;
Session altered.

SQL> alter table emp add (mobile varchar2(15));
Table altered.


Solution 3 (for 10g):
DECLARE
 MYSQL VARCHAR2(250) := 'alter table emp add (mobile varchar2(15))';
 IN_USE_EXCEPTION EXCEPTION;
 PRAGMA EXCEPTION_INIT(IN_USE_EXCEPTION, -54);
BEGIN
 WHILE TRUE LOOP
  BEGIN
   EXECUTE IMMEDIATE MYSQL;
   EXIT;
  EXCEPTION
   WHEN IN_USE_EXCEPTION THEN
    NULL;
  END;
  DBMS_LOCK.SLEEP(1);
 END LOOP;
END;


Solution 4:

Step 1: Identify the session which is locking the object
select a.sid, a.serial#
from v$session a, v$locked_object b, dba_objects c
where b.object_id = c.object_id
and a.sid = b.session_id
and OBJECT_NAME='EMP';


Step 2: kill that session using
alter system kill session 'sid,serial#' immediate;

ORA-00027 cannot kill current session


How to kill session:
1. identify which session to kill using following query:
SQL>  select
  s.sid,
  s.serial#,
  spid,
  trim(s.machine) machine,
  trim(s.module) module,
  status
 from
  v$session s,
  v$process p
 where
  paddr=addr
  and module is not null
 order by 1,2

      SID    SERIAL# SPID                 MACHINE              MODULE                                           STATUS
---------- ---------- -------------------- -------------------- ------------------------------------------------ --------------------
         1          5 2311                 server1.soumya.com   sqlplus@server1.soumya.com (TNS V1-V3)           ACTIVE
        29          1 2323                 server1.soumya.com   STREAMS                                          ACTIVE
        35         14 2457                 server1.soumya.com   sqlplus@server1.soumya.com (TNS V1-V3)           INACTIVE
        37         16 2450                 server1.soumya.com   KTSJ                                             ACTIVE
        40          2 2359                 server1.soumya.com   STREAMS                                          ACTIVE
        44         27 2448                 server1.soumya.com   KTSJ                                             ACTIVE
        47          2 2361                 server1.soumya.com   STREAMS                                          ACTIVE

2. Killing a session
SQL> ALTER SYSTEM KILL SESSION '35,14' immediate;

System altered.

How to shutdown / startup rac instances

How to shutdown / startup rac instances:-
1. Shutdown Oracle Home process accessing database.
2. Shutdown RAC Database Instances on all nodes.
3. Shutdown Node applications running on nodes.
4. Shut down the Oracle Cluster ware or CRS.

#Stopping enterprise manager:-
[oracle@rac1 ~]$ emctl stop dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.2.0
Copyright (c) 1996, 2010 Oracle Corporation.  All rights reserved.
https://rac1.soumya.com:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
 ...  Stopped.

#Stopping and checking status of listener:-
[oracle@rac1 ~]$ srvctl stop listener -n rac1

oracle@rac1 ~]$ srvctl status listener -n rac1
Listener LISTENER is enabled on node(s): rac1
Listener LISTENER is not running on node(s): rac1

[oracle@rac1 ~]$ srvctl status database -d rac
Instance rac1 is running on node rac1
Instance rac2 is running on node rac2

#Shutting down Rac database instance in all nodes:-
[oracle@rac1 ~]$ srvctl status database -d rac
Instance rac1 is  running on node rac1
Instance rac2 is  running on node rac2

[oracle@rac1 ~]$ srvctl stop database -d rac

[oracle@rac1 ~]$ srvctl status database -d rac
Instance rac1 is not running on node rac1
Instance rac2 is not running on node rac2


#Shutdown Node applications running on nodes:-
[oracle@rac1 ~]$ srvctl stop nodeapps -n rac1 -f
[oracle@rac1 ~]$ srvctl status nodeapps -n rac1
-n <node_name> option has been deprecated.
VIP rac1-vip is enabled
VIP rac1-vip is not running
Network is enabled
Network is not running on node: rac1
GSD is disabled
GSD is not running on node: rac1
ONS is enabled
ONS daemon is not running on node: rac1
eONS is enabled
eONS daemon is not running on node: rac1

#Shut down the Oracle Clusterware or CRS:-
This command would work from root user.
[root@rac1 ]# cd /u01/app/11.2.0/grid/bin
[root@rac1 bin]# ./crsctl check cluster -all
**************************************************************
rac1:
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************
rac2:
CRS-4537: Cluster Ready Services is online
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online

To stop the CRS:-
[root@rac1 ]# cd /u01/app/11.2.0/grid/bin
[root@rac1 bin]# ./crsctl stop crs
CRS-2791: Starting shutdown of Oracle High Availability Services-managed resources on 'rac1'
CRS-2673: Attempting to stop 'ora.crsd' on 'rac1'
CRS-2677: Stop of 'ora.crsd' on 'rac1' succeeded
CRS-2673: Attempting to stop 'ora.cssdmonitor' on 'rac1'
CRS-2673: Attempting to stop 'ora.ctssd' on 'rac1'
CRS-2673: Attempting to stop 'ora.evmd' on 'rac1'
CRS-2673: Attempting to stop 'ora.mdnsd' on 'rac1'
CRS-2677: Stop of 'ora.cssdmonitor' on 'rac1' succeeded
CRS-2677: Stop of 'ora.evmd' on 'rac1' succeeded
CRS-2677: Stop of 'ora.mdnsd' on 'rac1' succeeded
CRS-2677: Stop of 'ora.ctssd' on 'rac1' succeeded
CRS-2673: Attempting to stop 'ora.cssd' on 'rac1'
CRS-2677: Stop of 'ora.cssd' on 'rac1' succeeded
CRS-2673: Attempting to stop 'ora.gpnpd' on 'rac1'
CRS-2673: Attempting to stop 'ora.diskmon' on 'rac1'
CRS-2677: Stop of 'ora.gpnpd' on 'rac1' succeeded
CRS-2673: Attempting to stop 'ora.gipcd' on 'rac1'
CRS-2677: Stop of 'ora.gipcd' on 'rac1' succeeded
CRS-2677: Stop of 'ora.diskmon' on 'rac1' succeeded
CRS-2793: Shutdown of Oracle High Availability Services-managed resources on 'rac1' has completed
CRS-4133: Oracle High Availability Services has been stopped.


#Start Oracle Clusterware or CRS:-
[root@rac1 ]# cd /u01/app/11.2.0/grid/bin
[root@rac1 bin]# ./crsctl start crs
CRS-4123: Oracle High Availability Services has been started.

To check cluster status:-
[root@rac1 bin]# ./crsctl check cluster -all
**************************************************************
rac1:
CRS-4535: Cannot communicate with Cluster Ready Services
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************
rac2:
CRS-4535: Cannot communicate with Cluster Ready Services
CRS-4529: Cluster Synchronization Services is online
CRS-4533: Event Manager is online
**************************************************************

#Start Node applications running on nodes:-
[oracle@rac1 ~]$ srvctl start nodeapps -n node1
oracle@rac1 ~]$ srvctl status nodeapps -n rac1
-n <node_name> option has been deprecated.
VIP rac1-vip is enabled
VIP rac1-vip is running on node: rac1
Network is enabled
Network is running on node: rac1
GSD is disabled
GSD is not running on node: rac1
ONS is enabled
ONS daemon is running on node: rac1
eONS is enabled
eONS daemon is running on node: rac1


#Start RAC Database Instances on all nodes:-
[oracle@rac1 ~]$ srvctl start database -d rac

To check rac instance status:-
oracle@rac1 ~]$ srvctl status database -d rac
Instance rac1 is running on node rac1
Instance rac2 is running on node rac2

#Start Oracle Home process accessing database:-
oracle@rac1 ~]$ srvctl start listener -n rac1

[oracle@rac1 ~]$ srvctl status listener -n rac1
Listener LISTENER is enabled on node(s): rac1
Listener LISTENER is running on node(s): rac1

[oracle@rac1 ~]$ srvctl status listener -n rac2
Listener LISTENER is enabled on node(s): rac2
Listener LISTENER is running on node(s): rac2

#To start enterpriese manager:-
[oracle@rac1 ~]$emctl start dbconsole

Step by step Oracle Database 11g Release 2 RAC installation On RHEL 5.4 Using NFS in Vmware

Oracle Database 11g Release 2 RAC On RHEL 5.4 Using NFS:-

NFS is an abbreviation of Network File System, a platform independent technology created by Sun Microsystems that
allows shared access to files stored on computers via an interface called the Virtual File System (VFS) that runs on
top of TCP/IP.Computers that share files are considered NFS servers, while those that access shared files are considered
NFS clients. An individual computer can be either an NFS server, a NFS client or both.We can use NFS to provide shared
storage for a RAC installation. In a production environment we would expect the NFS server to be a NAS, but for
testing it can just as easily be another server, or even one of the RAC nodes itself. To cut costs, this articles uses
one of the RAC nodes as the source of the shared storage. Obviously, this means if that node goes down the whole database
is lost, so it's not a sensible idea to do this if you are testing high availability.If you have access to a NAS or a
third server you can easily use that for the shared storage,making the whole solution much more resilient.
Whichever route you take, the fundamentals of the installation are the same.

The Single Client Access Name (SCAN) should really be defined in the DNS or GNS and round-robin between one of 3 addresses,
which are on the same subnet as the public and virtual IPs. In this article I've defined it as a single IP address in
the "/etc/hosts" file,which is wrong and will cause the cluster verification to fail, but it allows me to complete
the install without the presence of a DNS.


Server Hardware Requirements:-

Each node must meet the following minimum hardware requirements:
We have 2 Node configured on Virtual Box(VMWARE).
1.Virtual Machine name:- RAC1 or RAC2
2.At least 2 GB of Physical RAM
3.Swap space equivalent to the multiple of the available RAM : 3 GB
4.Atleast 1gb space on /tmp location.
5.Upto 4 GB of free space for oracle Software.


Download the following software:-

http://www.oracle.com/technetwork/database/enterprise-edition/downloads/112010-linx8664soft-100572.html
a} Oracle Database 11g Release 2 (11.2.0.1.0) for Linux x86-64
b) Oracle Grid Infrastructure 11g Release 2 (11.2.0.1.0) for Linux x86-64
c) Redhat Linux 5.4

on RAC1:-
vi /etc/sysconfing/network
NETWORKING=yes
HOSTNAME=rac1.soumya.com
:wq
#hostname rac1.soumya.com

HOSTNAME=rac1.soumya.com
IP Address eth0: 192.168.2.110 (public address)
IP Address eth1: 192.168.3.110 (private address)
Default Gateway eth0: 192.168.2.1 (public address)
Default Gateway eth1: none
Virtual ip : 192.168.2.150


on RAC2:-
vi /etc/sysconfing/network
NETWORKING=yes
HOSTNAME=rac2.soumya.com
:wq
#hostname rac2.soumya.com

IP Address eth0: 192.168.2.111 (public address)
IP Address eth1: 192.168.3.111 (private address)
Default Gateway eth0: 192.168.2.1 (public address)
Default Gateway eth1: none
Virtual ip : 192.168.2.151


SCAN IP:192.168.2.192

Ip concept in RAC :-
Please keep in mind that Public ip ,Virtual ip and SCAN IP should in same subnet.Where the
private ip is used for interconnects.

Public IP:  The public IP address is for the server.  This is the same as any server IP address,
a unique address with exists in /etc/hosts.
Private IP: Oracle RAC requires "private IP" addresses to manage the CRS, the clusterware heartbeat process and the cache fusion layer.
Virtual IP:  Oracle uses a Virtual IP (VIP) for database access.  The VIP must be on the same subnet as the public IP address.
The VIP is used for RAC failover (TAF).

Scan IP:-Single Client Access Name (SCAN) is an Oracle Real Application Clusters (Oracle RAC)
feature that provides a single name for clients to access Oracle Databases running in a cluster.

To add an additional Ethernet Card in VM:-

Open VMWARE Workstation.
VM -> Settings -> Select Network Adapter -> Click on Add option below ->Network Adapter -> Bridge Only -> Finish

On both nodes(Rac1 and Rac2):-

vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
#Public Network (eth0)
192.168.2.110   rac1.soumya.com rac1
192.168.2.111   rac2.soumya.com rac2

#NFS Storage
192.168.2.102   racstorage.soumya.com   racstorage

#Private interconnect (eth1)
192.168.3.110   rac1-pvt.soumya.com     rac1-pvt
192.168.3.111   rac2-pvt.soumya.com     rac2-pvt


#Public Virtual IP(VIP) address for-  (eth0)
192.168.2.150   rac1-vip.soumya.com     rac1-vip
192.168.2.151   rac2-vip.soumya.com     rac2-vip


#SCAN IP
192.168.2.192   rac-scan.soumya.com     rac-scan



Install the following rpms:-

binutils-2.17.50.0.6-2.el5
compat-libstdc++-33-3.2.3-61
elfutils-libelf-0.125-3.el5
elfutils-libelf-devel-0.125
gcc-4.1.1-52
gcc-c++-4.1.1-52
glibc-2.5-12
glibc-common-2.5-12
glibc-devel-2.5-12
glibc-headers-2.5-12
libaio-0.3.106
libaio-devel-0.3.106
libgcc-4.1.1-52
libstdc++-4.1.1
libstdc++-devel-4.1.1-52.e15
make-3.81-1.1
sysstat-7.0.0
unixODBC-2.2.11
unixODBC-devel-2.2.11
libXp-1.0.0-8
oracleasmlib-2.0.4-1 (download from http://www.oracle.com/technetwork/server-storage/linux/downloads/rhel5-084877.html)



On both nodes perform the following activities:-

Add or amend the following lines to the "/etc/sysctl.conf" file.
# vi /etc/sysctl.conf

fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1054504960
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048586

:wq


Run the following command to change the current kernel parameters.
# /sbin/sysctl -p

Add the following lines to the "/etc/security/limits.conf" file. on both nodes:-
#vi /etc/security/limits.conf

oracle               soft    nproc   2047
oracle               hard    nproc   16384
oracle               soft    nofile  1024
oracle               hard    nofile  65536

:wq

Add the following lines to the "/etc/pam.d/login" file, if it does not already exist.
# vi /etc/pam.d/login
session    required     pam_limits.so

:wq

Create the new groups and users on both nodes:-

groupadd -g 1000 oinstall
groupadd -g 1200 dba
useradd -u 1100 -g oinstall -G dba oracle
passwd oracle:<Provide oracle user's password>

Create the directories in which the Oracle software will be installed on both nodes:-

# mkdir -p  /u01/app/11.2.0/grid
# mkdir -p /u01/app/oracle/product/11.2.0/db_1
# chown -Rf oracle:oinstall /u01
# chmod -Rf 775 /u01/


On both node(Rac1 & Rac2) :-
Install the following package from the Oracle grid media after you've defined groups.

I have transferred linux.x64_11gR2_grid_2.zip in /u01 location.
# cd /u01
# unzip linux.x64_11gR2_grid_2.zip
# cd grid/rpm
# rpm -Uvh cvuqdisk*


Change the setting of SELinux to permissive by editing the "/etc/selinux/config" file, making sure the SELINUX flag is set as follows on both nodes:-

SELINUX=permissive
# sestatus
# service iptables stop
# chkconfig iptables off

Either configure NTP, or make sure it is not configured so the Oracle Cluster Time Synchronization Service (ctssd) can synchronize the times of the RAC nodes. If you want to deconfigure NTP do the following.
# service ntpd stop
Shutting down ntpd:                                        [  OK  ]
# chkconfig ntpd off



In node1:-
Login as oracle user and ad the following lines  at the end of the "/home/oracle/.bash_profile" file.
 [oracle@rac1]$ vi /home/oracle/.bash_profile

# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=rac1.soumya.com; export ORACLE_HOSTNAME
ORACLE_UNQNAME=RAC; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
GRID_HOME=/u01/app/11.2.0/grid; export GRID_HOME
DB_HOME=$ORACLE_BASE/product/11.2.0/db_1; export DB_HOME
ORACLE_HOME=$DB_HOME; export ORACLE_HOME
ORACLE_SID=rac1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
BASE_PATH=/usr/sbin:$PATH; export BASE_PATH
PATH=$ORACLE_HOME/bin:$BASE_PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
    ulimit -p 16384
    ulimit -n 65536
  else
    ulimit -u 16384 -n 65536
  fi
fi

alias grid_env='. /home/oracle/grid_env'
alias db_env='. /home/oracle/db_env'

:wq

 Re-execute the the bash shell :-
#. ./home/oracle/.bash_profile

Create a file called "/home/oracle/grid_env" with the following contents in node1:-

[oracle@rac1 ]$ vi /home/oracle/grid_env

ORACLE_HOME=$GRID_HOME; export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$BASE_PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

:wq

Create a file called "/home/oracle/db_env" with the following contents in node1:-

[oracle@rac1 ]$ vi /home/oracle/db_env

ORACLE_SID=RAC1; export ORACLE_SID
ORACLE_HOME=$DB_HOME; export ORACLE_HOME
PATH=$ORACLE_HOME/bin:$BASE_PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

:wq

[oracle@rac1 ]$ chmod 775 /home/oracle/db_env
[oracle@rac1 ]$ chmod 775 /home/oracle/grid_env


Once the "/home/oracle/grid_env" has been run, you will be able to switch between environments as follows.
$ grid_env
$ echo $ORACLE_HOME
/u01/app/11.2.0/grid
$ db_env
$ echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/db_1

We've made a lot of changes, so it's worth doing a reboot of the servers at this point to make sure all the changes have taken effect.
# reboot

On Storage Node(Racstorage):-
Hostname : racstorage.soumya.com
IP Address eth0: 192.168.2.102 (public address)
Default Gateway eth0: 192.168.2.1 (public address)

# service iptables stop
# chkconfig iptables off
# sestatus
make sure selinux is disabled too.


# vi /etc/hosts
#Public IP
192.168.2.110   rac1.soumya.com rac1
192.168.2.111   rac2.soumya.com rac2
192.168.2.102   racstorage.soumya.com   racstorage

:wq

Create Shared Disks:-
First we need to set up some NFS shares. In this case we will do this on a different server(racstorage.soumya.com).

mkdir /shared_config
mkdir /shared_grid
mkdir /shared_home
mkdir /shared_data

Add the following lines to the "/etc/exports" file. on racstorage node.

/shared_config               *(rw,sync,no_wdelay,insecure_locks,no_root_squash)
/shared_grid                 *(rw,sync,no_wdelay,insecure_locks,no_root_squash)
/shared_home                 *(rw,sync,no_wdelay,insecure_locks,no_root_squash)
/shared_data                 *(rw,sync,no_wdelay,insecure_locks,no_root_squash)

# chkconfig nfs on
# service nfs restart


On both RAC1 node and RAC2 node create the directories in which the Oracle software will be installed:-

# mkdir -p /u01/app/11.2.0/grid
# mkdir -p /u01/app/oracle/product/11.2.0/db_1
# mkdir -p /u01/oradata
# mkdir -p /u01/shared_config
# chown -Rf oracle:oinstall /u01/app /u01/app/oracle /u01/oradata /u01/shared_config
# chmod -Rf 775 /u01/app /u01/app/oracle /u01/oradata /u01/shared_config


Add the following lines to the "/etc/fstab" file of node1 and node2:-

#vi /etc/fstab

racstorage.soumya.com:/shared_config /u01/shared_config  nfs  rw,bg,hard,nointr,tcp,vers=3,timeo=600,rsize=32768,wsize=32768,actimeo=0  0 0

racstorage.soumya.com:/shared_grid   /u01/app/11.2.0/grid  nfs  rw,bg,hard,nointr,tcp,vers=3,timeo=600,rsize=32768,wsize=32768,actimeo=0  0 0

racstorage.soumya.com:/shared_home   /u01/app/oracle/product/11.2.0/db_1  nfs  rw,bg,hard,nointr,tcp,vers=3,timeo=600,rsize=32768,wsize=32768,actimeo=0  0 0

racstorage.soumya.com:/shared_data   /u01/oradata  nfs  rw,bg,hard,nointr,tcp,vers=3,timeo=600,rsize=32768,wsize=32768,actimeo=0  0 0

:wq

Mount the NFS shares on both servers(node1 and node2):-

# mount /u01/shared_config
# mount /u01/app/11.2.0/grid
# mount /u01/app/oracle/product/11.2.0/db_1
# mount /u01/oradata

Make sure the permissions on the shared directories are correct.(on node1 and node2):-
# chown -R oracle:oinstall /u01/shared_config
# chown -R oracle:oinstall /u01/app/11.2.0/grid
# chown -R oracle:oinstall /u01/app/oracle/product/11.2.0/db_1
# chown -R oracle:oinstall /u01/oradata

Start both RAC nodes, login to RAC1 as the oracle user and start the Oracle installer.
$ cd /u01/grid
$ sh runInstaller

Steps of grid installation:-

1.Select the "Install and Configure Grid Infrastructure for a Cluster" option, then click the "Next" button.
2.Select the "Advanced Installation" option, then click the "Next" button.
3.Select the the required language support, then click the "Next" button.
4.Enter cluster information and uncheck the "Configure GNS" option, then click the "Next" button.
cluster-name:-rac-cluster
scan name:- rac-scan.soumya.com [This is hostname of rac-scan ip]
scan port:1521

5.On the "Specify Node Information" screen, click the "Add" button.
6.Enter the details of the second node in the cluster, then click the "OK" button.
Hostname:- rac2.soumya.com
Virtual IP Name:- rac2-vip.soumya.com

7.Click the "SSH Connectivity..." button and enter the password for the "oracle" user. Click the "Setup" button to to configure SSH connectivity, and the "Test" button to test it once it is complete. Click the "Next" button.
8.Check the public and private networks are specified correctly, then click the "Next" button.
9.In network interface usage screen click on next.
10.In storage option screen Select the "Shared File System" option, then click the "Next" button.
11.In OCR Storage screen select External Redundancy and provide OCR File location.
path location : /u01/shared_config/ocr_configuration
12.In Voting disk screen choose external Redundancy
path location: /u01/shared_config/voting_disk

13.On failure isolation screen select option "Do not use Intelligent Platform management interface (IPMI)
14.On operating system group screen select group as "dba" for three given groups.While pressing Next it might promot a warning
as "Possible invalid choice for OSASM, OSDBA , OSOPER etc... group". Please select Yes to coninue.
15.On installation location screen select path for Oracle Base :-/u01/app/oracle
and path for software location :- /u01/app/11.2.0/grid
16.On Create Inventory screen  path for intentory Directory is : /u01/app/oraInventory
17.while the prerequisite checks complete. If you have any issues, either fix them or check the "Ignore All" checkbox and click the "Next" button. If there are no issues, you will move directly to the summary screen. If you are happy with the summary information, click the "Finish" button
18.Wait while the setup takes place.
When prompted, run the configuration scripts on each node.Run them one after one:-
/u01/app/oraInventory/orainstRoot.sh
/u01/app/11.2.0/grid/root.sh

Wait for the configuration assistants to complete.
[INS-20802]Oracle Cluster verification utility failed.
We expect the verification phase to fail with an error relating to the SCAN, assuming you are not using DNS.
Provided this is the only error, it is safe to ignore this and continue by clicking the "Next" button.

Click the "Close" button to exit the installer.


Install Binaries and create the Database:-

In node1:-

Start all the RAC nodes, login to RAC1 as the oracle user and start the Oracle installer.
[oracle@rac1 database]$ cd /u01/linux.x64_11gR2_database_1of2_2/database
[oracle@rac1 database]$ ./runInstaller
Uncheck the security updates checkbox and click the "Next" button.
Accept the "Create and configure a database" option by clicking the "Next" button.
Accept the "Server Class" option by clicking the "Next" button.
Make sure both nodes are selected, then click the "Next" button.
Accept the "Typical install" option by clicking the "Next" button.
oracle base :/u01/app/oracle
software location: /u01/app/oracle/product/11.2.0/db_1
storage type: file system
database file location : /u01/oradata
Database edition : enterprise edition
osdba group: dba
global database name : rac.soumya.com
enter administrative password: ******
Wait for the prerequisite check to complete. If there are any problems either fix them, or check the "Ignore All" checkbox and click the "Next" button.
Thats it..We have successfully setup 2 node Rac Cluster.



Related Posts Plugin for WordPress, Blogger...