Wednesday, March 18, 2009

Cold Backup

In Windows: -
set term off
set head off
set feedback off
set verify off
prompt COLD BACKUP in progress .....
spool c:\startcopy.bat
select 'copy '||name||' c:\DBBACKUP' from v$datafile;
select 'copy '||name||' c:\DBBACKUP' from v$controlfile;
select 'copy '||name||' c:\DBBACKUP' from v$tempfile;
select 'copy '||member||' c:\DBBACKUP' from v$logfile;
spool off
shutdown IMMEDIATE
host c:\startcopy.bat
startup
host del c:\startcopy.bat
prompt COLD BACKUP successfully completed.
set term on
set head on
set feedback on
set verify on

In Linux: -

set term off
set head off
set feedback off
set verify off
prompt COLD BACKUP in progress .....
spool /u01/app/oracle/startcopy.bat
select 'copy '||name||' /uo1/app/oracle/DBBACKUP' from v$datafile;
select 'copy '||name||' /u01/app/oracle/DBBACKUP' from v$controlfile;
select 'copy '||name||' /u01/app/oracle/DBBACKUP' from v$tempfile;
select 'copy '||member||' /u01/app/oracle/DBBACKUP' from v$logfile;
spool off
shutdown IMMEDIATE
host /u01/app/oracle/startcopy.bat
startup
host del /u01/app/oracle/startcopy.bat
prompt COLD BACKUP successfully completed.
set term on
set head on
set feedback on
set verify on

Using free space to create logical volume on LVM partition

[root@igloo ~]# vgdisplay

--- Volume group ---

VG Name VolGroup00

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 5

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 2

Open LV 2

Max PV 0

Cur PV 1

Act PV 1

VG Size 74.41 GB

PE Size 32.00 MB

Total PE 2381

Alloc PE / Size 193 / 6.03 GB

Free PE / Size 2188 / 68.38 GB

VG UUID JoY5DH-S0HV-Q5Dw-b2wC-Rpe0-XeaR-QFbG75



[root@igloo ~]# lvscan

ACTIVE '/dev/VolGroup00/LogVol00' [5.03 GB] inherit

ACTIVE '/dev/VolGroup00/LogVol01' [1.00 GB] inherit



[root@igloo ~]# lvcreate -l 2188 VolGroup00 -n LogVol02

Logical volume "LogVol02" created



[root@igloo ~]# lvscan

ACTIVE '/dev/VolGroup00/LogVol00' [5.03 GB] inherit

ACTIVE '/dev/VolGroup00/LogVol01' [1.00 GB] inherit

ACTIVE '/dev/VolGroup00/LogVol02' [68.38 GB] inherit



[root@igloo ~]# mkfs -t ext3 /dev/VolGroup00/LogVol02

mke2fs 1.36 (05-Feb-2005)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

8962048 inodes, 17924096 blocks

896204 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=20971520

547 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424



Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done



This filesystem will be automatically checked every 21 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.



[root@igloo ~]# e2label /dev/VolGroup00/LogVol02 /oracle



[root@igloo ~]# cat /etc/fstab

# This file is edited by fstab-sync - see 'man fstab-sync' for details

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1

LABEL=/boot /boot ext3 defaults 1 2

LABEL=/realvar /realvar ext3 defaults 1 2

none /dev/pts devpts gid=5,mode=620 0 0

none /dev/shm tmpfs defaults 0 0

none /proc proc defaults 0 0

none /sys sysfs defaults 0 0

/dev/VolGroup00/LogVol01 swap swap defaults 0 0

/dev/VolGroup00/LogVol02 /oracle ext3 defaults 1 2

/dev/hdc /media/cdrom auto pamconsole,exec,noauto,managed 0 0

/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0



Create the partition name with required name in / and mount it:-

[root@igloo ~]#mkdir /oracle

[root@igloo ~]#mount /oracle

Check with the df –h command .

Oracle user script

create user a identified by a;
create user b identified by b;
create user c identified by c;
create user d identified by d;
create user e identified by e;
create user f identified by f;
create user g identified by g;
create user h identified by h;
create user i identified by i;
create user j identified by j;
create user k identified by k;
create user l identified by l;
create user m identified by m;
create user n identified by n;
create user o identified by o;
create user p identified by p;
create user q identified by q;
create user r identified by r;
create user s identified by s;
create user t identified by t;
create user u identified by u;
create user v identified by v;
create user w identified by w;
create user x identified by x;
create user y identified by y;
create user z identified by z;
create user aa identified by aa;
create user ab identified by ab;
create user ac identified by ac;
create user ad identified by ad;
create user ae identified by ae;
create user af identified by af;
create user ag identified by ag;
create user ah identified by ah;
create user ai identified by ai;
create user aj identified by aj;
create user ak identified by ak;
create user al identified by al;
create user am identified by am;
create user an identified by an;
create user ao identified by ao;
create user ap identified by ap;
create user aq identified by aq;
create user ar identified by ar;
create user at identified by at;
create user au identified by au;
create user av identified by av;
create user aw identified by aw;
create user ax identified by ax;
create user ay identified by ay;
create user az identified by az;
create user ba identified by ba;
create user bb identified by bb;
create user bc identified by bc;
create user bd identified by bd;
create user be identified by be;
create user bf identified by bf;
create user bg identified by bg;
create user bh identified by bh;
create user bi identified by bi;
create user bj identified by bj;
create user bk identified by bk;
create user bl identified by bl;
create user bm identified by bm;
create user bn identified by bn;
create user bo identified by bo;
create user bp identified by bp;
create user bq identified by bq;
create user br identified by br;
create user bs identified by bs;
create user bt identified by bt;
create user bu identified by bu;
create user bv identified by bv;
create user bw identified by bw;
create user bx identified by bx;
create user bz identified by bz;
create user ca identified by ca;
create user cb identified by cb;
create user cc identified by cc;
create user cd identified by cd;
create user ce identified by ce;
create user cf identified by cf;
create user cg identified by cg;
create user ch identified by ch;
create user ci identified by ci;
create user cj identified by cj;
create user ck identified by ck;
create user cl identified by cl;
create user cm identified by cm;
create user cn identified by cn;
create user co identified by co;
create user cp identified by cp;
create user cq identified by cq;
create user cr identified by cr;
create user cs identified by cs;
create user ct identified by ct;
create user cu identified by cu;
create user cv identified by cv;
create user cw identified by cw;
create user cx identified by cx;
create user cy identified by cy;
create user cz identified by cz;
create user da identified by da;
create user db identified by db;
create user dc identified by dc;
create user dd identified by dd;
create user de identified by de;
create user df identified by df;
create user dg identified by dg;
create user dh identified by dh;
grant connect,resource to a;
grant connect,resource to b;
grant connect,resource to c;
grant connect,resource to d;
grant connect,resource to e;
grant connect,resource to f;
grant connect,resource to g;
grant connect,resource to h;
grant connect,resource to i;
grant connect,resource to j;
grant connect,resource to k;
grant connect,resource to l;
grant connect,resource to m;
grant connect,resource to n;
grant connect,resource to o;
grant connect,resource to p;
grant connect,resource to q;
grant connect,resource to r;
grant connect,resource to s;
grant connect,resource to t;
grant connect,resource to u;
grant connect,resource to v;
grant connect,resource to w;
grant connect,resource to x;
grant connect,resource to y;
grant connect,resource to z;
grant connect,resource to aa;
grant connect,resource to ab;
grant connect,resource to ac;
grant connect,resource to ad;
grant connect,resource to ae;
grant connect,resource to af;
grant connect,resource to ag;
grant connect,resource to ah;
grant connect,resource to ai;
grant connect,resource to aj;
grant connect,resource to ak;
grant connect,resource to al;
grant connect,resource to am;
grant connect,resource to an;
grant connect,resource to ao;
grant connect,resource to ap;
grant connect,resource to aq;
grant connect,resource to ar;
grant connect,resource to at;
grant connect,resource to au;
grant connect,resource to av;
grant connect,resource to aw;
grant connect,resource to ax;
grant connect,resource to ay;
grant connect,resource to az;
grant connect,resource to ba;
grant connect,resource to bb;
grant connect,resource to bc;
grant connect,resource to bd;
grant connect,resource to be;
grant connect,resource to bf;
grant connect,resource to bg;
grant connect,resource to bh;
grant connect,resource to bi;
grant connect,resource to bj;
grant connect,resource to bk;
grant connect,resource to bl;
grant connect,resource to bm;
grant connect,resource to bn;
grant connect,resource to bo;
grant connect,resource to bp;
grant connect,resource to bq;
grant connect,resource to br;
grant connect,resource to bs;
grant connect,resource to bt;
grant connect,resource to bu;
grant connect,resource to bv;
grant connect,resource to bw;
grant connect,resource to bx;
grant connect,resource to bz;
grant connect,resource to ca;
grant connect,resource to cb;
grant connect,resource to cc;
grant connect,resource to cd;
grant connect,resource to ce;
grant connect,resource to cf;
grant connect,resource to cg;
grant connect,resource to ch;
grant connect,resource to ci;
grant connect,resource to cj;
grant connect,resource to ck;
grant connect,resource to cl;
grant connect,resource to cm;
grant connect,resource to cn;
grant connect,resource to co;
grant connect,resource to cp;
grant connect,resource to cq;
grant connect,resource to cr;
grant connect,resource to cs;
grant connect,resource to ct;
grant connect,resource to cu;
grant connect,resource to cv;
grant connect,resource to cw;
grant connect,resource to cx;
grant connect,resource to cy;
grant connect,resource to cz;
grant connect,resource to da;
grant connect,resource to db;
grant connect,resource to dc;
grant connect,resource to dd;
grant connect,resource to de;
grant connect,resource to df;
grant connect,resource to dg;
grant connect,resource to dh;

Friday, March 13, 2009

Some scripts which can be used in automation

To allow Oracle start on boot-up, create a file called oracledb (or whatever name you want to call it) and put it in /etc/init.d with the contents below. This script was copied and pasted from a tutorial by Graham Williams. It will read the /etc/oratab and fire up any instances it finds.
#!/bin/bash
#
# /etc/init.d/oracledb
#
# Run-level Startup script for the Oracle Instance, Listener, and Web Interface

export ORACLE_HOME=/oracle/app/product/10.2.0/db_1/
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=cjperf
ORA_OWNR="oracle"

# if the executables do not exist -- display error

if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
su $ORA_OWNR -c $ORACLE_HOME/bin/dbstart
touch /var/lock/oracle

su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl start dbconsole"
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
su $ORA_OWNR -c $ORACLE_HOME/bin/dbshut
rm -f /var/lock/oracle

su $ORA_OWNR -c "$ORACLE_HOME/bin/emctl stop dbconsole"
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo "Usage: `basename $0` start|stop|restart|reload"
exit 1
esac

exit 0


vi /etc/oratab

database_sid:oracle_home_dir:Y|N

change entry from N to Y

and if you want, make it run at every boot:
# update-rc.d oracledb defaults 99
Adding system startup for /etc/init.d/oracledb ...
ln -s /etc/init.d/oracledb /etc/rc.d/rc0.d/K01oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc0.d/S99oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc2.d/K01oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc2.d/S99oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc3.d/K01oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc3.d/S99oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc4.d/K01oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc4.d/S99oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc5.d/K01oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc5.d/S99oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc6.d/K01oracledb
ln -s /etc/init.d/oracledb /etc/rc.d/rc6.d/S99oracledb
Before finishing, add the following lines to your /etc/.bash_profile . Be careful, since these values are valid system-wide. So make sure the paths are set according to your particular setup (if you have been doing everything according to this text, you should be fine).
export ORACLE_BASE/oracle/app/product/10.2.0/db_1/
export ORACLE_HOME=/oracle/app/oracle/product/10.2.0/db_1
export ORACLE_SID=cjperf
export PATH=$PATH:/oracle/app/oracle/product/10.2.0/db_1/bin
Last operation: add yourself to the dba group. You can use usermod or just edit the /etc/group file and add your username at the end of the line that starts with dba (my username is ‘harsha’):
dba:x:1002:oracle,harsha
If you chose to not create a starter database during your install, you’ll have to do two extra steps. You should create a listener (with netca) and after that, create the starter database (also with netca). If you chose to have the installer create a database for you, then you should be fine, since when doing that, it asks for a password for the default accounts (SYS, SYSTEM, and DBSNMP, SYSMAN if you choose to install it with the enterprise manager option selected).
If everything has gone well, open a terminal window and, as the oracle user, type:
$ sqlplus

SQL*Plus: Release 10.2.0.1.0 - Beta on Wed Jul 11 17:11:53 2007

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

Enter user-name:
If you see these messages (and I sincerely hope you do) you’re all set! That means that you have finished a quite long install of Oracle 10g and you are ready to begin destroying it.
Harshavardhan.
NOTE:
Release 2 bug:
Inside $ORACLE_HOME/bin/dbstart there is a bug that will prevent the listener to start
(Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr);
to solve change line 78 from
ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle/bin/tnslsnr
to
ORACLE_HOME_LISTNER=$ORACLE_HOME

Platform
Symbolic Links Commands
AIX
# ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
# ln -s /etc/dbora /etc/rc.d/rc2.d/K01dbora
HP-UX
# ln -s /sbin/init.d/dbora /sbin/rc3.d/S990dbora
# ln -s /sbin/init.d/dbora /sbin/rc3.d/K001dbora
Linux
# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
Solaris
# ln -s /etc/init.d/dbora /etc/rc3.d/K01dbora
# ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora

Tru64 UNIX
# ln -s /sbin/init.d/dbora /sbin/rc3.d/S99dbora
# ln -s /sbin/init.d/dbora /sbin/rc3.d/K01dbora