Sunday 27 July 2014

What is Checkpoint

What is a Checkpoint?

•      A synchronization event at a specific point in time
•      Causes some or all dirty block images to be written to the database thereby guaranteeing that blocks dirtied prior to that point in time gaet written
•      Brings administration up to date
•      Several types of checkpoint exist

What happens when Checkpoint occurs:
A checkpoint performs the following three operations:

•      DBWR gets the signal from CKPT.
•      DBWRn checks redo log entries are written to online redolog files and writes dirty block in the buffer cache is written to the Data files. That is, it synchronizes.
•      The latest SCN is written (updated) into the Datafile header and control files.

When checkpoint occurs:

The following events trigger a checkpoint.
•      While clean shutdown.
•      While tablespace is offline normally.
•      Redo log switch
•      LOG_CHECKPOINT_TIMEOUT has expired
•      LOG_CHECKPOINT_INTERVAL has been reached
•      DBA requires so (alter system checkpoint)

Additionally, if a tablespace is hot backuped, a checkpoint for the tablespace in question is taking place.


Time and SCN of last checkpoint

The date and time of the last checkpoint can be found in
checkpoint_time in v$datafile_header

The SCN of the last checkpoint can be found in

checkpoint_change#  in v$database.

Types of Checkpoints?
•      Full Checkpoint
•      Thread Checkpoint
•      File Checkpoint
•      Object “Checkpoint”
•      Parallel Query Checkpoint
•      Incremental Checkpoint
•      Log Switch Checkpoint

Full Checkpoint

 Writes block images to the database for all dirty buffers from all instances

• Caused by:
– Alter system checkpoint [global]
– Alter database close
– Shutdown

• Statistics updated:
– DBWR checkpoints
– DBWR checkpoint buffers written
– DBWR thread checkpoint buffers written

• Controlfile and datafile headers are updated
– CHECKPOINT_CHANGE#


Thread Checkpoint

Writes block images to the database for all dirty buffers from one instance

• Caused by:
– Alter system checkpoint local

• Statistics updated:
– DBWR checkpoints
– DBWR checkpoint buffers written
– DBWR thread checkpoint buffers written

• Controlfile and datafile headers are updated
– CHECKPOINT_CHANGE#

File Checkpoint

Writes block images to the database for all dirty buffers for all files of a tablespace from all instances

• Caused by:
– Alter tablespace XXX offline
– Alter tablespace XXX begin backup
– Alter tablespace XXX read only

• Statistics updated:
– DBWR tablespace checkpoint buffers written
– DBWR checkpoint buffers written
– DBWR checkpoints

• Controlfile and datafile headers are updated
– CHECKPOINT_CHANGE#

Parallel Query Checkpoint

Writes block images to the database for all dirty buffers belonging to objects accessed by the query from all instances

• Caused by:
– Parallel Query
– Parallel Query component of PDML or PDDL
– Mandatory for consistency

• Statistics updated:
– DBWR checkpoint buffers written
– DBWR checkpoints

Object Checkpoint

Writes block images to the database for all dirty buffers belonging to an object from all instances
• Caused by:
– Drop table XXX
– Drop table XXX purge
– Truncate table XXX

• Statistics updated:
– DBWR object drop buffers written
– DBWR checkpoints

• Mandatory for media recovery purposes

Incremental Checkpoint

Writes the contents of “some” dirty buffers to the database from CKPT-Q

• Block images written in SCN order
• Checkpoint RBA updated in SGA

• Statistics updated:
– DBWR checkpoint buffers written

• Controlfile is updated every 3 seconds by CKPT
– Checkpoint progress record

Log Switch Checkpoint

Writes the contents of “some” dirty buffers to the database

• Caused by:
– alter system log switch.

• Statistics updated:
– DBWR checkpoints
– DBWR checkpoint buffers written
– background checkpoints started
– background checkpoints completed

• Controlfile and datafile headers are updated
– CHECKPOINT_CHANGE#


Useful views:-


Useful checkpoint administration views:
– V$INSTANCE_RECOVERY
– V$SYSSTAT
– V$DATABASE
– V$INSTANCE_LOG_GROUP
– V$THREAD
– V$DATAFILE
– V$DATAFILE_HEADER

Database creation using script


#su - oracle




$. db.env
$ cd $ORACLE_HOME

db_1]$ pwd
/u01/app/oracle/product/11.1.0.6/db_1
db_1]$ cd dbs

dbs]$ dir
hc_prod.dat  initdw.ora  init.ora  initprod.ora  lkPROD


dbs]$ vi initprod.ora

db_name=prod
compatible=11.1.0.6
sga_target=300m
control_files= '/u01/oradata/control01.ctl', '/u01/oradata/control02.ctl'
log_buffer=2000
undo_tablespace='undots'
undo_management='auto'
diagnostic_dest='/u01/trace'

:wq


dbs]$ cat createdb.sql
create database prod
datafile '/u01/oradata/system.dbf' size 300m
sysaux 
datafile '/u01/oradata/sysaux.dbf' size 200m
undo tablespace undots 
datafile '/u01/oradata/undots.dbf' size 50m
default temporary tablespace temp1 
tempfile '/u01/oradata/temp1.dbf' size 10m
logfile
group 1 '/u01/oradata/redo1.log' size 8m,
group 2 '/u01/oradata/redo2.log' size 8m,
group 3 '/u01/oradata/redo3.log' size 8m
character set UTF8
;
:wq


#export ORACLE_SID=prod
#echo  $ORACLE_SID


#sqlplus / as sysdba

sql>startup nomount


To create Database
@/u01/oradata/createdb.sql

Database created.


To create views
@?/rdbms/admin/catalog.sql

To create procedures
@?/rdbms/admin/catproc.sql


conn system/manager

@?/sqlplus/admin/pupbld.sql






Sunday 20 July 2014

Shutdown commands for Oracle Database

Shutdown Commands:

Shutdown [normal]
1.    Issues checkpoint
2.    Does not allow new sessions.
3.    Waits until all transactions and active sessions to close.


Shutdown transactional
1.    Issues checkpoint
2.    Does not allow new sessions.
3.    Waits until current transactions to close and close all sessions.


Shutdown immediate
1.    Issues checkpoint
2.    Does not allow new sessions.
3.    Waits for committed transactions to close and close all sessions.

Shutdown abort
NO  checkpoint and closes all sessions immediately. So needs recovery when restarts.

Wednesday 16 July 2014

How the Database will Start


SQL> STARTUP NOMOUNT;

1.     Server process checks the parameter file at default location   "ORACLE_HOME/dbs". If spfile<sid>.ora is available Server process reads the spfile otherwise it will read init<sid>.ora file.
2.     If DB_NAME and CONTROL_FILES parameter is present in parameter file and the other optional parameters then Server process will allocate memory to the SGA.
3.     Server process creates entries in the trace file and alert log file.
4.     Instance creates and goes to nomount state and all the background processes will be started.

SQL> ALTER DATABASE MOUNT;

1.     It checks for the control files at location specified in parameter file. If control files are present it reads data files location and redo log files location and SCN number.
2.     Database goes to mount state.

SQL> ALTER DATABASE OPEN;

1.     It checks for the data files first and redo log files at location specified in control files. If present it checks the control file SCN number with data files and redo log files SCN number.


2.     If SCN number matches then database goes to open state.






Intalling Oracle 11g on RedHat Linux Server

Prerequisites:
  • Checking the Hardware Requirements
  • Checking the Software Requirements
  • Preinstallation Requirements for Oracle Configuration Manager
  • Checking the Network Setup
  • Creating Required Operating System Groups and Users
  • Configure Oracle Installation Owner Shell Limits
  • Configuring Kernel Parameters
  • Identifying Required Software Directories
  • Identifying or Creating an Oracle Base Directory
  • Choosing a Storage Option for Oracle Database and Recovery Files
  • Creating Directories for Oracle Database or Recovery Files
  • Preparing Disk Groups for an Automatic Storage Management Installation
  • Configuring Disk Devices for Oracle Database
  • Stopping Existing Oracle Processes
  • Configuring the oracle User's Environment
COPY ALL RPM FILES FROM LINUX CD
-------------------------------------------------------
copy all rpm files to local disk in folder "repo"
$cp /oracle/server/*.rpm   /u02/repo

CREATE A REPOSITORY FOR RPM
---------------------------------------------------
#cd /U02
#createrepo  -v repo

#cd  /etc/yum.repos.d

#vi reposcript.repo
[mainrepo]
name=mainrepo
baseurl=file:///mnt/repo
enabled=1
gpgcheck=0
:wq

#yum clean all
#yum list

install required rpm:
---------------------

Goto ”repo” folder
#cd  /u02/repo

rpm -Uvh binutils-2.*
rpm -Uvh compat-libstdc++-33*
rpm -Uvh compat-libstdc++-33*.i386.rpm
rpm -Uvh elfutils-libelf*
rpm -Uvh gcc-4.*
rpm -Uvh gcc-c++-4.*
rpm -Uvh glibc-2.*
rpm -Uvh glibc-common-2.*
rpm -Uvh glibc-devel-2.*
rpm -Uvh glibc-headers-2.*
rpm -Uvh ksh*
rpm -Uvh libaio-0.*
rpm -Uvh libaio-devel-0.*
rpm -Uvh libgomp-4.*
rpm -Uvh libgcc-4.*
rpm -Uvh libstdc++-4.*
rpm -Uvh libstdc++-devel-4.*
rpm -Uvh make-3.*
rpm -Uvh sysstat-7.*
rpm -Uvh unixODBC-2.*
rpm -Uvh unixODBC-devel-2.*
rpm -Uvh numactl-devel-*


Manual Setup

Oracle recommend the following minimum parameter settings.

#vi     /etc/sysctl.conf

fs.suid_dumpable = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 268435456
kernel.shmmax = 536870912
kernel.shmmni = 4096
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

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

#vi    /etc/security/limits.conf

oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  4096
oracle              hard    nofile  65536
oracle              soft    stack   10240


Set secure Linux to permissive by editing the     "/etc/selinux/config" file
#vi   /etc/selinux/config
SELINUX=disable

Create the new groups and users.
#groupadd dba
#useradd -g dba oracle
#passwd oracle


Create the directories in which the Oracle software will be installed.
#mkdir -p /u01/app/oracle/product/11.2.0/db_1
#chown -R oracle:dba /u01
#chmod -R 775 /u01

Copy Oracle Database Software into /u02 mount point.
#chown -R oracle:dba /u02
#chmod -R 777 /u02


Login as root and issue the following command.
#xhost +

Login as the oracle user and add the following lines at the end of the ".bash_profile" file, remembering to adjust them for your specific installation.

#su – oracle

$vi  db.env
export ORACLE_BASE=/u01/app/oracle;
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1;
export PATH=/usr/sbin:$PATH;
export PATH=$ORACLE_HOME/bin:$PATH;
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export ORACLE_SID=ORCL;
:wq

$.   db.env

Installation
$cd   /u02/db
$ . /runInstaller

At the end run the scripts given
Root.sh   and oraInstRoot.sh

# yum install oracle-database-server-12cR2-preinstall -y

groupadd -g 54323 oper
groupadd -g 54324 backupdba
groupadd -g 54325 dgdba
groupadd -g 54326 kmdba
groupadd -g 54327 asmdba
groupadd -g 54328 asmoper
groupadd -g 54329 asmadmin
groupadd -g 54330 racdba

usermod -u 54321 -g oinstall -G dba,oper,backupdba,dgdba,kmdba  oracle

useradd -u 54322 -g oinstall -G asmdba,asmoper,asmadmin   grid

Optimizer Access Paths using Indexes

Introduction In this tutorial you will use the Optimizer Access Paths for the following cases (scenarios): Case 1: With and Without Index Ca...