Tuesday, January 15, 2013

Understanding RMAN

Recovery manager (RMAN) is an oracle tool for backing up, restoring and recovering oracle databases. The major task of an oracle dba is to make sure data is available for use anytime and everytime the need arise. Availability and reliability is the key responsibility of a dba.

Connection
Logging into RMAN is very easy. Use this command “RMAN TARGET /” or “rman target my_db”

set ORACLE_SID=orcl
C:\Users\kelebute>rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Fri Dec 21 11:48:33 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1328927802)
RMAN>

or

rman
RMAN> connect target sys/****@orcl

You don't have to specify the "as sysdba" because it is silently implied when you log into RMAN.

To view all the configurations in rman for a particular database, you can use “show all” command.

RMAN> show all;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ORCL are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 2;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOA
D TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO 'C:\APP\KELEBUTE\PRODUCT\11.2.0\DBHOME_1\
DATABASE\SNCFORCL.ORA'; # default

checking your configuration

v$rman_configuration

This view provides the summary of RMAN configuration. You could also use show all to retrieve RMAN configuration.

SQL> SELECT * FROM V$RMAN_CONFIGURATION;
CONF# NAME VALUE
---------- ------------------------------ ------------------------
1 RETENTION POLICY TO REDUNDANCY 3
2 BACKUP OPTIMIZATION ON
3 DEFAULT DEVICE TYPE TO Disc
4 CONTROLFILE AUTOBACKUP ON
5 DEVICE TYPE DISK PARALLELISM 1

Backing up a database in noarchivelog mode

rman target /

run {
shutdown immediate;
startup mount;
backup database;
alter database open;
shutdown immediate;
}

Backing up a database in archivelog mode

man target /
RMAN> backup database plus archivelog;


Backup with archivelog delete input

backup database plus archivelog delete input;


Deleting archivelogs
delete expired archivelog all;

or

CROSSCHECK ARCHIVELOG ALL;
delete noprompt ARCHIVELOG UNTIL TIME 'SYSDATE-5';

You can change the date as you want.

incremental backup every night Mon - Sat
This is for updates on only the blocks that changed since last backup.

RMAN> backup incremental level 0 database tag="SUNDAY";
RMAN> backup incremental level 3 database tag="MONDAY";
RMAN> backup incremental level 3 database tag="TUESDAY";
RMAN> backup incremental level 3 database tag="WEDNESDAY";
RMAN> backup incremental level 2 database tag="THURSDAY";
RMAN> backup incremental level 3 database tag="FRIDAY";
RMAN> backup incremental level 3 database tag="SATURDAY";

According to Oracle documentation, RMAN is still the best way to backup database and also restore it. We will talk about restoring and recovery databases next time.

Here is the script I presently use. You can adapt to whatever will suit you. Remember to change the ORACLE_SID and location.

script for rman

set ORACLE_SID=ORCL
export ORACLE_SID
RMAN target / log=/home/oracle/rman.log
run{
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '$ORACLE_BASE/backups/datafiles/%d_%T_s%s_s%p' MAXPIECESIZE 4G;
crosscheck backup;
CROSSCHECK ARCHIVELOG ALL;
delete noprompt ARCHIVELOG UNTIL TIME 'SYSDATE-7';
delete noprompt expired backup;
delete noprompt expired archivelog all;
sql 'alter system switch logfile';
backup database plus archivelog delete all input format '/disk1/backup/full_%U.bkp';
delete noprompt obsolete;
BACKUP VALIDATE DATABASE ARCHIVELOG ALL;
}

Thanks for visiting!

Thursday, January 10, 2013

10 easy steps to configure Datagurad on Windows 7

Hey folks! I am not going to bore you with stories on dataguard; it is 90% practical. If you need definitions or explanations of why you need dataguard, please visit this oracle site

Here is the step by step guide on how to configure dataguard on a Windows 7 environment.

Version: Oracle 11.2.0
Hardware: Windows 7

Prerequisite:

a.) Archivelog mode. Here is the step to put your database in archivelog mode

SQL> shutdown immediate
startup mount;
alter database archivelog;
alter database force logging;
alter database open;

b.) Start your listener


c:\> LSNRCTL START

c.) create TNSNAMES.ORA

use netca to create tnsnames for 'orcl1' and 'orclstby'

Please Note:

1. You have to take a backup of your database before you start, otherwise you will get an error

c:\> set ORACLE_SID=orcl1
c:\> rman target /
RMAN> backup database including archivelog;

2. You need to create ORACLE_SID using oradim utility. Please use this command:

create instance
---------------------
C:\app\kelebute\product\11.2.0\dbhome_1\BIN>oradim -NEW -SID orclstby -SYSPWD oracle -pfile initorclstby.ora
Instance created.

3. Use NetMgr to register the databases ('orcl1' and 'orclstby'):

click Start
Click All Programs
Click Oracle Dbhome_1
Click Configuration and Migration tools
Then click "Net Mgr"

NOTE: NetMgr will not accept ORACLE_SID name that is more than 8 characters.

Make sure you verify your TNSNAMES registration in NetMgr.

4. Create a pfile using this command on primary:

SQL> create pfile='c:\app\kelebute\initorclstby.ora' from spfile;

5. create pfile for standby

C:\Windows\system32>sqlplus sys/oracle@psi as sysdba
SQL> create pfile='c:\APP\KELEBUTE\PRODUCT\11.2.0\DBHOME_1\DATABASE\INITPSI2.ORA
' from spfile;

6. Add standby redo log files on primary
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
C:\APP\KELEBUTE\ORADATA\PSI\REDO03.LOG
C:\APP\KELEBUTE\ORADATA\PSI\REDO02.LOG
C:\APP\KELEBUTE\ORADATA\PSI\REDO01.LOG

SQL> alter database add standby logfile
2 'C:\APP\KELEBUTE\ORADATA\PSI\REDO04.LOG' size 50m;
Database altered.
SQL> alter database add standby logfile
2 'C:\APP\KELEBUTE\ORADATA\PSI\REDO05.LOG' size 50m;
Database altered.
SQL> alter database add standby logfile
2 'C:\APP\KELEBUTE\ORADATA\PSI\REDO06.LOG' size 50m;
Database altered.

7. Set parameters on primary

SQL> alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(psi,psi2)';
SQL> alter system set LOG_ARCHIVE_DEST_2='SERVICE=psi2 async VALID_FOR=(ONLINE_L
OGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=psi2';
SQL> Alter system set standby_file_management=auto;
SQL> Alter system set fal_client =psi;
SQL> Alter system set fal_server=psi2;

8. Take a backup
C:\Windows\system32>rman target psi
RMAN> backup database plus archivelog;

9. Make sure you connect to both SIDs on RMAN
c:\>rman
RMAN> connect target sys/oracle@orcl1
RMAN> connect auxiliary sys/oracle@orclstby
RMAN> @c:\k\dataguard.txt

-------------------
Here is the script
-------------------

run {
allocate channel prmy1 type disk;
allocate channel prmy2 type disk;
allocate auxiliary channel stby type disk;
DUPLICATE TARGET DATABASE
FOR STANDBY
DB_FILE_NAME_CONVERT=('\ORCL1\','\ORCLSTBY\')
SPFILE
PARAMETER_VALUE_CONVERT '\ORCL1','\ORCLSTBY'
set db_unique_name='orclstby'
SET LOG_FILE_NAME_CONVERT '\ORCL1\','\ORCLSTBY\'
SET SGA_MAX_SIZE '200M'
SET SGA_TARGET '125M'
set control_files='c:\app\kelebute\oradata\orclstby\orclstby01.ctl'
set log_archive_max_processes='5'
set fal_client='orclstby'
set fal_server='orcl1'
set standby_file_management='AUTO'
SET LOG_ARCHIVE_CONFIG='DG_CONFIG=(ORCL1,ORCLSTBY)'
SET LOG_ARCHIVE_DEST_2='SERVICE=ORCL1 NOAFFIRM ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=ORCL1'
NOFILENAMECHECK;
}
-------------------------------------

10. Put standby in recovery mode

sqlplus sys/oracle@psi2 as sysdba
SQL> Alter database recover managed standby database using current logfile disco
nnect from session;
SQL> Alter database recover managed standby database cancel;

Dataguard is configured!


Friday, December 21, 2012

ORACLE 10g/11g installation steps

download software at http://www.oracle.com/downloads or use CD


$ unzip 10201_database_linux32.zip

Note: You must unzip both files at the same location for oracle 11gR1 or 2. The output will be just 1 directory named 'database'. If you don't have just 1 directory, please redo this step because you will get an error during installation!

------------------------
check host configuration
------------------------
vi /etc/hosts

----------------------
set kernel parameters
----------------------
vi /etc/sysctl.conf

add this line:

#kernel.shmall = 2097152
#kernel.shmmax = 2147483648
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
#fs.file-max = 65536
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

------
run
------
/sbin/sysctl -p

--------------------------
vi /etc/security/limits.conf
--------------------------
add this line:

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

----------------------
vi /etc/pam.d/login
----------------------
add line:

session required pam_limits.so

--------------------
Disable selinux by:
--------------------
vi /etc/selinux/config

add this line:
SELINUX=disabled

---------------------------------------
Install packages if you don't have them:
---------------------------------------
# From RedHat AS5 Disk 1
cd /media/cdrom/Server
rpm -Uvh setarch-2*
rpm -Uvh make-3*
rpm -Uvh glibc-2*
rpm -Uvh libaio-0*
cd /
eject

# From RedHat AS5 Disk 2
cd /media/cdrom/Server
rpm -Uvh compat-libstdc++-33-3*
rpm -Uvh compat-gcc-34-3*
rpm -Uvh compat-gcc-34-c++-3*
rpm -Uvh gcc-4*
rpm -Uvh libXp-1*
cd /
eject

# From RedHat AS5 Disk 3
cd /media/cdrom/Server
rpm -Uvh openmotif-2*
rpm -Uvh compat-db-4*
cd /
eject

NOTE: Your system engineer should be able to do this for you. Most firms will not give you root access, so you may have to work with your System Engineer to get the packages installed.

------------------------------
create group and user:
------------------------------
groupadd oinstall
groupadd dba
groupadd oper

useradd -g oinstall -G dba oracle
passwd oracle

-------------------------------
create directories
-------------------------------
mkdir -p /u01/app/oracle/product/10.2.0/db_1
chown -R oracle.oinstall /u01

----------------------
Login as Oracle and
----------------------

vi .bash_profile

add this line:

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

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=TSH1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$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


Note: This will help you set the environmental variables and avoid errors from these variables.
----------------------
set display variable
----------------------

DISPLAY=(machine-name):0.0; export DISPLAY

Note: If you don't export display, you may have a shaking screen output or may even get an error specifying the display problem.

----------------
lauch installer
----------------
change directory to database and locate runInstaller.exe

./runInstaller

----------------------------
run post installation script
----------------------------
vi /etc/oratab
add :Y to the instance line (i.e. TSH1:/u01/app/oracle/product/10.2.0/db_1:Y)

Note: This is optional.

Saturday, December 1, 2012

common Oracle DBA interview questions and answer

Here is a small list of questions and answers for junior and mid-level Oracle DBA jobs. Mastery of these questions and answers will help you survive most interview session, and also expose you to some basic and advanced tips you need on the job.

What is the relationship between Control files and V$view?
V$views are kept in the control file. This is why v$ views are always accessible even when the database is in a lesser state.

Can you access V$view while the database is not open?
Yes. V$view can be accessed even when the database is in nomount mode or in a lesser state.

How many stages are involved in getting the database open and running?
3 stages namely: Nomount, Mount and Open stage

What are the Mandatory processes in Oracle?
The processes are the backgound processes. The mandatory ones are Checkpoint, PMON, SMON, Log Writer and Database Writer.

What is an instance?
A combination of memory structure and background processes.

Where can I monitor the Retore job that my colleague did to check if it went well or done properly?
Alert log. Alert log is in background dump. From SQL prompt issue: 'show parameter background dump'

I discovered that my control files are missing, what are my option?
Create another control file from the existing one (multiplex). If there is no existing one, create/build Control file from scratch with a text file. Always back up control file to Trace so that you can have a text file to create a fresh control file.

What is RAC?
Real Application Clusters. A combination of multiple instances accessing a database. The node represents each instance in the cluster.

Why should a client use RAC?
To avoid a single port failure. When there is only one instance, reliability and fault tolerance is low.

What are the demerits of RAC?
It is expensive to maintain. It requires lot of resources (hardware and manpower) as well as maintenance costs. Most firms now use VMware to reduce hardware costs.

What is ASM?
Automatic Storage Management

What would you use ASM?
It is free and more convenient for file management. It helps with load balancing as well as improves reliability and availability.

What is the difference between full and incremental backup?
Full backup is when you backup the whole database and the database is not in open mode. Incremental backup is when you copy the changes that has occured after the last full backup. This is usually done when the database is open and running, and in ARCHIVELOG mode.

Can you use RMAN without database in archivelog mode?
Yes, you can take a cold backup when the database is cleanly shut down.

What is DATAPUMP?
It is a new features that oracle introduced to enhance import and export of database, tablespace, schema and tables. Prior to Datapump, DBAs used regular imp and exp.

What are the basic features that differentiate Datapump from Import and Export?
Datapump allows remaping of database, tablespace, schema and tables. Datapump is also very fast. You can increase parallelism by increasing the workers that will execute the job.
Please note that parallelism is only compatible with Enterprise edition of oracle 10g and 11g.

Best of luck in your interviews and shoot me an email if you have questions.
Cheers!

Saturday, June 2, 2012

Career changer


"Change is the only permanent factor"

Oracle DBA is indeed a career changer. No matter where you are currently in your profession, you can still join the league of high-earners in the Information Technology field. One of the most popular units of the IT field is Database Administration. As a DBA, you will be expected to handle resource or capacity planning, grant user access to the database, manage and repair the database, monitor connections to and secure the database, and also train users. This surely sounds easy but it involves a lot of work.

One of the questions I answer everyday is: "How can I become an Oracle DBA?"

I've answered this question more than 100 times in less than 2 months! This shows that many people are interested in becoming database administrators but do not presently have an idea how they can become one. Becoming a DBA is very simple if you follow the key steps I will provide on this blog. For simplicity of this particular post, I will outline 3 areas you can work on as a 'new-comer' in the DBA field.

1. Attend an Oracle class, or database management seminar;
2. Get obsessed with the field (talk about it);
3. Read independently and practice;
4. Build confidence through networking (with other DBAs); and
5. Get certified.


The essence of this post is not to discuss these steps because it will be exhausting. I will pick these topics one after the other and also bring in writers to contribute.

I believe this blog will help someone out there to change career or build a new career in Database administration. This blog will also serve as an avenue of exchanging ideas with my peers in the field. Just for introduction, my name is Kunle Elebute and I am an Oracle DBA with many years of experience.

Thanks for reading.



MySQL




Acknowledgement: Picture credit to Lenovo
Content: Facet Technical Institute