How to extend root partition on linux using lvm

Here my partition is on lvm (Logical volume manager)

Check physical volume

Check Volume group

here you can see i have only one disk sda

Now i will add new disk to my virtual machine
right click on the virtual machine and select settings
then click on add select hard disk from the above list
click on next
select scsi and click next
create new disk and click next
specify disk capacity in my case i am adding 15g and click on split virtual disk into multiple files and click next
provide the diskname.vmdk and specify the location where it should be saved and click on finish
click on ok to exit the virtual machine settings

no need to restart the running virtual machine just type the below command so that system scans the new disk

new disk is added /dev/sde

now follow the step to extend the root partition

create physical volume & check /dev/sde1 has 19.99G free space.

we have only one volume group VolGroup00 so we will extend our volume group first

you can see Free PE is 639 / 19.97GB available

we have to extend our root partition which is  /dev/VolGroup00/LogVol00

if you have any doubts or need help please feel free to email me at sunil@sunilthetechfreak.com

 

 

How to move VMware Workstation 11 virtual machine to ESXI 6.0 Server

Step by Step guide download document here

Upgrade non asm oracle database 11.2.0.1 to 11.2.0.4 using dbua

Step by step guide to upgrade non asm database 11.2.0.1 to 11.2.0.4 using dbua Download

Upgrade oracle database 10.2.0.4 to 11.2.0.1

Download document

Hot clone oracle database on same server

Hot cloning oracle database on the same server

source database : ora10gdb01
clone  database : clone2

database is up and running
[oracle@db10g /]$ ps -ef | grep pmon
oracle    6603     1  0 Jun20 ?        00:00:02 ora_pmon_clone1
oracle   10339     1  0 16:28 ?        00:00:00 ora_pmon_ora10gdb01
oracle   10484 10300  0 16:36 pts/4    00:00:00 grep pmon

[oracle@db10g ~]$ . oraenv
ORACLE_SID = [oracle] ? ora10gdb01
[oracle@db10g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 – Production on Sat Jun 21 16:44:16 2014

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

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – 64bit Production
With the Partitioning, OLAP and Data Mining options

SYS@ora10gdb01>select name from v$database;

NAME
———
ORA10GDB

Check the datafiles in your database
SYS@ora10gdb01>select name from v$datafile;

NAME
——————————————————————————–
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/system01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/undotbs01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/sysaux01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/users01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/users02.dbf

create pfile so you can edit for your clone2 database
SYS@ora10gdb01>create pfile=’/$ORACLE_HOME/dbs/initclone2.ora’ from spfile;

File created.

[oracle@db10g ~]$ vi $ORACLE_HOME/dbs/initclone2.ora
[oracle@db10g ~]$

contents after changing initclone2.ora
[oracle@db10g ~]$ cat $ORACLE_HOME/dbs/initclone2.ora
clone2.__db_cache_size=872415232
clone2.__java_pool_size=16777216
clone2.__large_pool_size=16777216
clone2.__shared_pool_size=285212672
clone2.__streams_pool_size=0
*.audit_file_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone2/adump’
*.background_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone2/bdump’
*.compatible=’10.2.0.1.0′
*.control_files=’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/control01.ctl’,’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/control02.ctl’,’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/control03.ctl’
*.core_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone2/cdump’
*.db_block_size=8192
*.db_create_file_dest=’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2′
*.db_domain=”
*.db_file_multiblock_read_count=16
*.db_name=’clone2′
*.db_recovery_file_dest_size=2147483648
*.db_recovery_file_dest=’/u03/clone2/flash_recovery_area’
*.db_unique_name=’clone2′
*.dispatchers='(PROTOCOL=TCP) (SERVICE=clone2XDB)’
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=402653184
*.processes=150
*.remote_login_passwordfile=’EXCLUSIVE’
*.sga_target=1207959552
*.undo_management=’AUTO’
*.undo_tablespace=’UNDOTBS1′
*.user_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone2/udump’
[oracle@db10g ~]$

create required directories
[oracle@db10g tmp]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone2/adump
[oracle@db10g tmp]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone2/bdump
[oracle@db10g tmp]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone2/udump
[oracle@db10g tmp]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone2/cdump
[oracle@db10g tmp]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/
[oracle@db10g tmp]$ mkdir -p /u03/clone2/flash_recovery_area

backup controlfile
SYS@ora10gdb01>alter database backup controlfile to trace as ‘/tmp/control_script.sql’;

Database altered.

SYS@ora10gdb01>alter system switch logfile;

System altered.

SYS@ora10gdb01>archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     45
Next log sequence to archive   47
Current log sequence           47

SYS@ora10gdb01>alter database begin backup;

Database altered.

SYS@ora10gdb01>!
[oracle@db10g ~]$ cp /u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/*.dbf $ORACLE_HOME/oradata/clone2/

updated few data
SUNIL@ora10gdb01>update emp set sal=&sal where empno=&empno
2  /
Enter value for sal: 1500
Enter value for empno: 7934
old   1: update emp set sal=&sal where empno=&empno
new   1: update emp set sal=1500 where empno=7934

1 row updated.

SUNIL@ora10gdb01>/
Enter value for sal: 7500
Enter value for empno: 7839
old   1: update emp set sal=&sal where empno=&empno
new   1: update emp set sal=7500 where empno=7839

1 row updated.

SUNIL@ora10gdb01>/
Enter value for sal: 2000
Enter value for empno: 7900
old   1: update emp set sal=&sal where empno=&empno
new   1: update emp set sal=2000 where empno=7900

1 row updated.

SUNIL@ora10gdb01>commit;

Commit complete.

SYS@ora10gdb01>alter database end backup;

Database altered.

SYS@ora10gdb01>alter system switch logfile;

System altered.

SYS@ora10gdb01>archive log list;
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     47
Next log sequence to archive   49
Current log sequence           49
SYS@ora10gdb01>
SYS@ora10gdb01>exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 – 64bit Production
With the Partitioning, OLAP and Data Mining options

edit the controlfile
[oracle@db10g ~]$ vi /tmp/control_script.sql
CREATE CONTROLFILE SET DATABASE “clone2” RESETLOGS  ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/redo01.log’  SIZE 50M,
GROUP 2 ‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/redo02.log’  SIZE 50M,
GROUP 3 ‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/redo03.log’  SIZE 50M
DATAFILE
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/system01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/undotbs01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/sysaux01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/users01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone2/users02.dbf’
CHARACTER SET WE8ISO8859P1
;

[oracle@db10g ~]$ export ORACLE_SID=clone2
[oracle@db10g ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/10.2.0.1/db01
[oracle@db10g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 – Production on Sat Jun 21 17:45:14 2014

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

Connected to an idle instance.

SYS@clone2>startup nomount
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size                  2020352 bytes
Variable Size             318770176 bytes
Database Buffers          872415232 bytes
Redo Buffers               14753792 bytes
SYS@clone2>@/tmp/control_script.sql

Control file created.

SYS@clone2>

Now recover the database using backup control file

SYS@clone2>recover database using backup controlfile until cancel;

you will be prompted for archive log files. Specify the full path and file name from your source database as you have not copied the
archive log files on the target because we are cloning on the same server. you have to keep specifying the archive log till you cross the
last old sequence then type cancel to end the media recovery

SYS@clone2>alter database open resetlogs;

Also update the /etc/oratab file for new cloned database

for any queries feel free to write to me at sunil@sunilthetechfreak.com

Cold cloning oracle database on the same server

Cold cloning oracle database on the same server

Source database SID : ora10gdb01
Clone database SID  : clone1

First connect to the database which you are planning to clone

[oracle@db10g ~]$ . oraenv
ORACLE_SID = [ora10gdb01] ? ora10gdb01

[oracle@db10g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 – Production on Fri Jun 20 21:25:06 2014

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

Connected to an idle instance.

SYS@ora10gdb01>startup
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size                  2020352 bytes
Variable Size             318770176 bytes
Database Buffers          872415232 bytes
Redo Buffers               14753792 bytes
Database mounted.
Database opened.
SYS@ora10gdb01>

SYS@ora10gdb01>select name from v$datafile;

NAME
——————————————————————————–
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/system01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/undotbs01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/sysaux01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/users01.dbf
/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/users02.dbf

SYS@ora10gdb01>create pfile=’$ORACLE_HOME/dbs/initclone1.ora’ from spfile;

File created.

SYS@ora10gdb01>alter database backup controlfile to trace as ‘/tmp/control_script.sql’;

Database altered.

edit pfile for clone1 database

[oracle@db10g ~]$ vi $ORACLE_HOME/dbs/initclone1.ora

contents before change
ora10gdb01.__db_cache_size=872415232
ora10gdb01.__java_pool_size=16777216
ora10gdb01.__large_pool_size=16777216
ora10gdb01.__shared_pool_size=285212672
ora10gdb01.__streams_pool_size=0
*.audit_file_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/ora10gdb01/adump’
*.background_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/ora10gdb01/bdump’
*.compatible=’10.2.0.1.0′
*.control_files=’/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/control01.ctl’,’/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/control02.ctl’,’/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01/control03.ctl’
*.core_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/ora10gdb01/cdump’
*.db_block_size=8192
*.db_create_file_dest=’/u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01′
*.db_domain=”
*.db_file_multiblock_read_count=16
*.db_name=’ora10gdb’
*.db_recovery_file_dest_size=2147483648
*.db_recovery_file_dest=’/u03/ora10gdb01/flash_recovery_area’
*.db_unique_name=’ora10gdb01′
*.dispatchers='(PROTOCOL=TCP) (SERVICE=ora10gdb01XDB)’
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=402653184
*.processes=150
*.remote_login_passwordfile=’EXCLUSIVE’
*.sga_target=1207959552
*.undo_management=’AUTO’
*.undo_tablespace=’UNDOTBS1′
*.user_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/ora10gdb01/udump’

contents after change
clone1.__db_cache_size=872415232
clone1.__java_pool_size=16777216
clone1.__large_pool_size=16777216
clone1.__shared_pool_size=285212672
clone1.__streams_pool_size=0
*.audit_file_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone1/adump’
*.background_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone1/bdump’
*.compatible=’10.2.0.1.0′
*.control_files=’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/control01.ctl’,’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/control02.ctl’,’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/control03.ctl’
*.core_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone1/cdump’
*.db_block_size=8192
*.db_create_file_dest=’/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1′
*.db_domain=”
*.db_file_multiblock_read_count=16
*.db_name=’ora10gdb’
*.db_recovery_file_dest_size=2147483648
*.db_recovery_file_dest=’/u03/clone1/flash_recovery_area’
*.db_unique_name=’clone1′
*.dispatchers='(PROTOCOL=TCP) (SERVICE=clone1XDB)’
*.job_queue_processes=10
*.open_cursors=300
*.pga_aggregate_target=402653184
*.processes=150
*.remote_login_passwordfile=’EXCLUSIVE’
*.sga_target=1207959552
*.undo_management=’AUTO’
*.undo_tablespace=’UNDOTBS1′
*.user_dump_dest=’/u01/app/oracle/product/10.2.0.1/db01/admin/clone1/udump’

make changes to the controlfile the contents should be

vi /tmp/control_script.sql
CREATE CONTROLFILE SET  DATABASE  “clone1” RESETLOGS  ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/redo01.log’  SIZE 50M,
GROUP 2 ‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/redo02.log’  SIZE 50M,
GROUP 3 ‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/redo03.log’  SIZE 50M
DATAFILE
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/system01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/undotbs01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/sysaux01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/users01.dbf’,
‘/u01/app/oracle/product/10.2.0.1/db01/oradata/clone1/users02.dbf’
CHARACTER SET WE8ISO8859P1
;

create directories as referred in pfile
[oracle@db10g ~]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone1/adump
[oracle@db10g ~]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone1/bdump
[oracle@db10g ~]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone1/cdump
[oracle@db10g ~]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/admin/clone1/udump
[oracle@db10g ~]$ mkdir -p /u01/app/oracle/product/10.2.0.1/db01/oradata/clone1
[oracle@db10g ~]$ mkdir -p /u03/clone1/flash_recovery_area

copy all datafile to clone directory
[oracle@db10g ~]$ cd /u01/app/oracle/product/10.2.0.1/db01/oradata/ora10gdb01
[oracle@db10g ora10gdb01]$ ll
total 1373152
-rw-r—–  1 oracle oinstall   7061504 Jun 20 21:30 control01.ctl
-rw-r—–  1 oracle oinstall   7061504 Jun 20 21:30 control02.ctl
-rw-r—–  1 oracle oinstall   7061504 Jun 20 21:30 control03.ctl
drwxr-x—  3 oracle oinstall      4096 Jun  4 20:16 ORA10GDB01
-rw-r—–  1 oracle oinstall  52429312 Jun 20 21:30 redo01.log
-rw-r—–  1 oracle oinstall  52429312 Jun 20 21:25 redo02.log
-rw-r—–  1 oracle oinstall  52429312 Jun 20 21:25 redo03.log
-rw-r—–  1 oracle oinstall 272637952 Jun 20 21:30 sysaux01.dbf
-rw-r—–  1 oracle oinstall 503324672 Jun 20 21:30 system01.dbf
-rw-r—–  1 oracle oinstall  27271168 Jun 14 06:00 temp01.dbf
-rw-r—–  1 oracle oinstall 429924352 Jun 20 21:30 undotbs01.dbf
-rw-r—–  1 oracle oinstall   6561792 Jun 20 21:30 users01.dbf
-rw-r—–  1 oracle oinstall  10493952 Jun 20 21:30 users02.dbf

[oracle@db10g ora10gdb01]$ cp -v *.dbf $ORACLE_HOME/oradata/clone1

[oracle@db10g ora10gdb01]$ export ORACLE_SID=clone1
[oracle@db10g ora10gdb01]$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0.1/db01

[oracle@db10g ora10gdb01]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 – Production on Fri Jun 20 21:47:18 2014

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

Connected to an idle instance.

SYS@clone1>startup nomount
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size                  2020352 bytes
Variable Size             318770176 bytes
Database Buffers          872415232 bytes
Redo Buffers               14753792 bytes
SYS@clone1>

SYS@clone1>@/tmp/control_script.sql

Control file created.

SYS@clone1>alter database open resetlogs;

Database altered.

SYS@clone1>select name from v$database;

NAME
———
CLONE1

Edit the oratab file for clone database

[oracle@db10g dbs]$ vi /etc/oratab

[oracle@db10g dbs]$ cat /etc/oratab
#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ‘:’, is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, ‘#’, are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , “Y”, or should not,
# “N”, be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
ora10gdb01:/u01/app/oracle/product/10.2.0.1/db01:N
10gdb02:/u01/app/oracle/product/10.2.0.1/db01:N
clone1:/u01/app/oracle/product/10.2.0.1/db01:N

for any queries write to me at sunil@sunilthetechfreak.com

How to setup environment variables in oracle to sucessfuly connect to a particular database/instance

Oracle environment variable is set to inform your operating system about the Oracle software installation directory and which oracle software/binaries should interact with which database/instance.

The most important environment variable are listed below
ORACLE_HOME : setting oracle home means which oracle product/software or installation you will be using to associate with your databasehaving oracle home environment variable makes easier for maintenance and management of oracle software.As per Oracle optimal flexible architecture (OFA)
/u01/app/oracle/product/10.2.0.1/dbhome_1

ORACLE_SID : The oracle system identifier is a unique identifier which is set to interact with a particular instance. You may have multiple oracle database on a single machine by setting this variable we are information oracle software to connect to that particular instance.

we will learn various way to set this variable

firstly we will check oracle home and how many databases are installed on the machine

[oracle@db10g /]$ cat /etc/oratab
#
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.

# A colon, ‘:’, is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, ‘#’, are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , “Y”, or should not,
# “N”, be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
ora10gdb01:/u01/app/oracle/product/10.2.0.1/db01:N
10gdb02:/u01/app/oracle/product/10.2.0.1/db01:N

In the above out put we can see we have two databases ora10gdb01 & 10gdb02

now let see if our environment variable is not set correctly what will happen

Login: oracle
Last login: Sat May 31 18:12:45 2014 from 192.168.1.1
[oracle@db10g ~]$ sqlplus
-bash: sqlplus: command not found
[oracle@db10g ~]$

the operating system doesn’t know what is sqlplus command

setting oracle home and sid for ora10gdb01 manually

set oracle_sid by giving below command
[oracle@db10g /]$ export ORACLE_SID=ora10gdb01

check if the environment variable is set correctly
[oracle@db10g /]$ echo $ORACLE_SID

set oracle_home by giving below command
[oracle@db10g /]$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0.1/db01

check if the environment variable is set correctly
[oracle@db10g /]$ echo $ORACLE_HOME
/u01/app/oracle/product/10.2.0.1/db01

now you can connect to the database issuing below
[oracle@db10g /]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 – Production on Sat May 31 20:07:18 2014

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

Connected to an idle instance.

SQL>

using .oraenv script provided by oracle, installed during software installation

[oracle@db10g ~]$ . oraenv
ORACLE_SID = [ora10gdb01] ? ora10gdb01
[oracle@db10g ~]$ echo $ORACLE_SID
ora10gdb01
[oracle@db10g ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/10.2.0.1/db01

let us again login as oracle user and check the environment variables

Login: oracle
Last login: Sat May 31 20:10:07 2014 from 192.168.1.1
[oracle@db10g ~]$ echo $ORACLE_HOME

[oracle@db10g ~]$ echo $ORACLE_SID

[oracle@db10g ~]$

as you can see not output our environment variables are not set

now we will again use .oraenv to set environment variable for our second database

[oracle@db10g ~]$ . oraenv
ORACLE_SID = [oracle] ? 10gdb02
[oracle@db10g ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/10.2.0.1/db01
[oracle@db10g ~]$ echo $ORACLE_SID
10gdb02
[oracle@db10g ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 – Production on Sat May 31 20:27:10 2014

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1207959552 bytes
Fixed Size                  2020352 bytes
Variable Size             318770176 bytes
Database Buffers          872415232 bytes
Redo Buffers               14753792 bytes
Database mounted.
Database opened.
SQL> select name from v$database;

NAME
———
10GDB02

SQL>

third way  to set the environment variable in user’s .bash_profile

our user is oracle so we will set the variable as shown below

[oracle@db10g ~]$ vi .bash_profile

[oracle@db10g ~]$ cat .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 ORACLE_HOME=/u01/app/oracle/product/10.2.0.1/db01    [this line is added]
export ORACLE_SID=ora10gdb01                    [this line is added]    

export PATH
unset USERNAME

set the variable set running the .bash_profile file (. .bash_profile)
or by login back again with user oracle

it is not recommended to set the environment variable in bash_profile because we have more then one database on a single machine.