Friday, July 30, 2010

Basic RMAN Script

configure controlfile autobackup on;

run {
     shutdown immediate;
     startup mount;
     configure retention policy to redundancy 2;
     backup full database tag "_FULL";
     configure retention policy to redundancy 1;
     delete noprompt obsolete;
     alter database open;
     }

list backup;

Thursday, July 29, 2010

Install on Oracle Enterprise Edition 5

As root execute the following commands:

#Add groups
/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/groupadd oper

#Create the operating system user oracle:
/usr/sbin/useradd -g oinstall -G dba,oper -d /home/oracle oracle

#Enter the following command to set the password of the oracle user:
/usr/bin/passwd

#With an editor of your choice, edit /home/oracle/.bash_profile  to include the following entries:
PATH=$PATH:$HOME/bin
umask 022
PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
LD_LIBRARY_PATH=/usr/lib:/usr/X11R6/lib
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.1.0/db_1
ORACLE_SID=orcl
$ORACLE_HOME/jdk/jre/lib/i386/server:
$ORACLE_HOME/rdbms/lib:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
PATH=$ORACLE_HOME/bin:$PATH
ORACLE_LABS=/home/oracle/labs

export PATH LD_LIBRARY_PATH
export ORACLE_BASE ORACLE_HOME ORACLE_SID
export PATH

#Create the directory for the software installation and assign ownership to oracle:oinstall.
mkdir -p /u01/app/oracle
chown -R oracle:oinstall /u01/app
chmod -R 775 /u01/app

#Open the /etc/sysctl.conf file in any text editor and add lines similar to the following:

#The maximum number and size of semaphore sets that can be allocate
kernel.sem = 250 32000 100 128

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 2097152

# Controls the maximum shared segment size, in bytes
kernel.shmmax = 2147483648

#The maximum number of shared memory segments.
kernel.shmmni = 4096

#The maximum number of file-handles that the Linux kernel will allocate
fs.file-max = 65536

#The local port range that is used by TCP and UDP traffic
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144

#Issue the following command to set the kernel parameters:
/sbin/sysctl -p

Finally, ensure that the following packages are installed off the OEL cd’s.

#INSERT DISC 1
mount -t auto /dev/cdroom /media/cdrom
cd /media/cdrom/Server
rpm -Uvh binutils-2.*
rpm -Uvh elfutils-libelf-0.*
rpm -Uvh glibc-2.*
rpm -Uvh glibc-common-2.*
rpm -Uvh libgcc-3.*
rpm -Uvh libstdc++-3.*
rpm -Uvh compat-libstdc++-33*
rpm -Uvh make-3.*
rpm -Uvh unixODBC-2.*
cd /
eject

#INSERT DISC 2mount -t auto /dev/cdroom /media/cdrom
cd /media/cdrom/Server
rpm -Uvh glibc-devel-2.*
rpm -Uvh gcc-3.*
rpm -Uvh gcc-c++-3.*
rpm -Uvh libstdc++-devel-3.*
cd /
eject

#INSERT DISC 3
mount -t auto /dev/cdrom /media/cdrom
cd /media/cdrom/Server
rpm -Uvh libaio-0.*
rpm -Uvh libaio-devel-0.*
rpm -Uvh sysstat-5.*
cd /
eject

#INSERT DISC 4
mount -t auto /dev/cdroom /media/cdrom
cd /media/cdrom/Server
rpm -Uvh elfutils-libelf-devel-0.*
rpm -Uvh unixODBC-devel-2.*
cd /
eject

oracle 11g is ready to be installed.

You can install VM client tools to help share the iso across the network.
Use the vmplayer to do the install as putty can be disconnected.
Mount the VM Iso from the program files vmplayer  directory on the host.
gunzip the VMwareTools-8.1.3-203739.tar.gz file into the staging area under /u01/stage
then untar the file using tar -xvf VMwareTools-8.1.3-203739.tar.,
navigate to the vmware-tools-distrib sub directory and execut
./vmware-install.pl
Confirm all installer prompts messages.
Once installed you can start tools by running /usr/bin/vmware-toolbox.

To use adv GUI features, run /usr/bin/vmware-user and open and close your gui.

As the root, unzip or mount the Oracle 11g intall into a staging area.
Log in as the oracle user.
Navigate to the stage point and either execute ./runInstaller from the oracle user desktop
or xwindows.

To execute Oracle Universal Installer in the host environment, install cygwin xwindows,
open up an xwindows session and input xhost +
From the server, as the oracle user input the following into a terminal

export DISPLAY=:0.0

Finally execute ./runInstaller

After a minute, the oracle universal installer (OUI) should bubble up to the client desktop.

Wednesday, July 28, 2010

File Types and Locations

Control Files

A control file is the root file which  maps out the other files which make up the the physical structure of the database.
Information stored includes:

  • Database name and DBID

  • Tablespace information

  • Path information about datafiles, online redo log files, and archived redo log files

  • Timestamp of creation

  • RMAN backups


This file is required to open the database and serves to keep track of structural changes such as adding,  renaming, and dropping datafiles.
The file contains metadata which is required when the database is not open.
This data includes important checkpoints (stored SCN Number) which holds the point from where database can recover from in event of failure.
Commited transactions occuring before the checkpoint(SCN ###) will have been safely written to datafile.

Every 3 seconds, the control file is updated with the latest checkpoint position in the online redo logs.

Diagram - Control File

Data Files
Oracle stores user and application data in datafiles. A datafile can constitute a single tablespace.
A tablespace can be made up of multiple datafiles.
A segment can span many datafiles but only one tablespace.
A database MUST have a SYSTEM and SYSAUX table space.
Oracle usually assigns the first datafiles to these tablespaces.
The SYSTEM holds  the datadictionary, while the SYSAUX holds statistic information

Mount

mount /dev/cdrom /media/cdrom

Linux Network Commands

#Get current IP
ifconfig

#Release
dhclient -r

#Get new ip
dhclient

#Restart network
/etc/init.d/networking restart

Monday, July 26, 2010

SGA Buffer Cache States

Buffer Cache blocks can be in the following states

  • Pinned: Prevent writing to the same block from multiple sessions

  • Clean: Unpinned, candidate for aging

  • Free or Unused: Empty because instance just started

  • Dirty: Buffer not pinned, content changed, DBWn will write to disc


A more details view of the buffer cache can be seen using the v$bh view.
SELECT b.block#,
b.class#,
b.status,
object_name,
object_type,
dirty Dirty
FROM v$bh b,
dba_objects o

WHERE b.objd = o.data_object_id
AND o.owner = 'RAY';

BLOCK# CLASS# STATUS OBJECT_NAME OBJECT_TYPE DIRTY
51425      4 xcur   STF         TABLE       N

51427      1 xcur   STF         TABLE       N

51426      1 xcur   STF         TABLE       N

49328      1 xcur   NOTES       TABLE       N

49325      4 xcur   NOTES       TABLE       N

49327      1 xcur   NOTES       TABLE       N

49326      1 xcur   NOTES       TABLE       N

XCUR state means the instance has exclusive access to the 
buffer block and can modify it.
CR state means the instance has older version of the block
and can perform a consistent read of the block
SCUR state means the instance has shared access to the block
and can read only
PI state means the instance has made changes to the block
but holds copies of the block prior to changes.

Network Services

Oracle features an active background process called a 'Listener' which can be configured through listener.ora found at the default location $ORACLE_HOME/network/admin/

A service request packet is sent from the client to the address specified in the calling clients TNSNAMES.ORA file. If a listener exists at the destination address, the listener searches through its own list of available services and if the requested service is valid, the LISTENER spawns a server process to handle the request from there on. The server process proceeds to authenticate the call, pass on parameters and spawn a oracle session for the calling client.

From here on, the server process acts as the clients agent on the server by performing:
-SQL Parsing
-Checking the DB Buffer cache for blocks required to perform actions
-Reading data blocks from data files
-Managing Sorting
-Returning results to the user process
-Reading auditing options and reporting

Processes

Oracle Instance Management - Processes

-(SMON) System Monitor : Crash recovery

-(PMON) Process Monitor : Clean up resources

-(DBWn)  Database Writer : Write buffer cache to database file

-(CKPT)  Write the latest checkpoint to data file header and control files

-(LGWR) Write the log buffers to redo log files on disc. In RAC, each RAC has its own
LGWR process

-(ARCH) Writes filled redo logs to archive log locations.