Friday, 26 April 2013

Managing Redo Log Files

 Managing REDO Log Files:
    
     Redo log files record all changes made to data and provide a recovery mechanism from a system or media failure.

• Redo log files are organized into groups.
• An Oracle database requires at least two groups.
• Each redo log within a group is called a member.

How Redo Logs Work
==================

• Redo logs are used in a cyclic fashion.
• When a redo log file is full, LGWR will move to the next log group.
– This is called a log switch
– Checkpoint operation also occurs
– Information is written to the control file


How to add Redo log group:
=====================

SQL> select *from v$log;

SQL> ALTER DATABASE ADD LOGFILE GROUP 3 '/u01/app/oracle/oradata/cts/log3a.rdo' SIZE 4M;


How to add a Redo log member into the redo log group:
=========================================

SQL>select *from v$logfile;

ALTER DATABASE ADD LOGFILE MEMBER
'/u01/app/oracle/oradata/cts/log1b.rdo' to group 1,   
'/u01/app/oracle/oradata/cts/log2b.rdo' to group 2,
'/u01/app/oracle/oradata/cts/log3b.rdo' to group 3;

How to drop a redo log group:
=======================

SQL> ALTER DATABASE DROP LOGFILE GROUP 3;


How to drop a redo log group member:
============================

SQL> ALTER DATABASE DROP LOGFILE MEMBER '/u01/app/oracle/oradata/cts/log1b.rdo';


How to switche logfile and checkpoint force:

SQL> ALTER SYSTEM SWITCH LOGFILE;

SQL> ALTER SYSTEM CHECKPOINT;

       
Note :
=====

* We can't drop the CURRENT and ACTIVE redo log group as well as redo log member.
* We can't Resize the redolog group. If you want to increase the size of the redolog group then add new redolog group with new size and delete old redolog group.
* We can have different size for all redolog groups but have same size for all redolog groups.

Oracle Controlfile Multiplexing

CONTROLFILE MULTIPLXEING
      
 A control file is a small binary file that is part of an Oracle database. The control file is used to keep track of the database's status and physical structure.

We can do controlfile multiplexing in 2 ways

1. Using pfile
2. Using Spfile

1. Using pfile:
===============

1. Shut down the database.

   SQL> shut immediate

2. go to the pfile location and edit the pfile.

   cd /u01/app/oracle/admin/cts/pfile

   vi init.ora

   press "i" to eit
  

control_files='/u01/app/oracle/oradata/cts/controlfile01.ctl','/u01

/app/oracle/oradata/cts/controlfile02.ctl','/u01/app/oracle/oradata

/cts/controlfile03.ctl','/u01/app/oracle/oradata/cts/controlfile04.ctl'

Press ESC+SHIFT + : + wq  --> to save

3. copy the controlfile01.ctl and change the as controlfile04.ctl

  cd /u01/app/oracle/oradata/cts/

  cp controlfile01.ctl controlfile04.ctl

4. start the database using PFILE and check the controfiles

    SQL> startup nomount

pfile='/u01/app/oracle/admin/cts/pfile/init.ora'

    SQL> select *from v$controlfile;

--------------------------------------------------------------------------------------------

2. Using Spfile:
============

1. check the controlfiles and modify the spfile

    SQL> select *from v$controfile

    SQL> alter system set

control_files='/u01/app/oracle/oradata/cts/controlfile01.ctl','/u01

/app/oracle/oradata/cts/controlfile02.ctl','/u01/app/oracle/oradata

/cts/controlfile03.ctl','/u01/app/oracle/oradata/cts/controlfile04.

ctl','/u01/app/oracle/oradata/cts/controlfile05.ctl' scope=spfile;

2. Shut down the database.

   SQL> shut immediate

3. copy the controlfile01.ctl and change as controlfile05.ctl

  cd /u01/app/oracle/oradata/cts/

  cp controlfile01.ctl controlfile05.ctl

4. start the database and check the conrofiles

    SQL> startup

    SQL> select *from v$controlfile;

Friday, 19 April 2013

Tablespaces and Datafiles Management

 TABLESPACES and DATAFILES MANAGEMENT:
 
   Tablespaces are the bridge between certain physical and logical components of the Oracle database. Tablespaces are where you store Oracle database objects such as tables, indexes and rollback segments.  You can think of a tablespace like a shared disk drive in Windows. You can store files on your shared drive, move files around and remove files. The same is true with tablespaces. A tablespace is made up of one or more database datafiles.     

Creating tablespace:
=====================
create tablespace APPSBI datafile '/u01/app/oracle/oradata/cts/appsbi01.dbf' size 200m;

Adding Datafile:
================
alter tablespace APPSBI add datafile '/u01/app/oracle/oradata/cts/appsbi02.dbf' size 200m;

Resizing Datafile:
==================
alter database datafile '/u01/app/oracle/oradata/cts/appsbi02.dbf' resize 300m;

To create UNDO tablepsace
=========================
create undo tablespace APP_UNDO datafile '/u01/app/oracle/oradata/cts/appundo01.dbf' size 200m;

To add UNDO datafile:
=====================
alter tablespace APP_UNDO add datafile '/u01/app/oracle/oradata/cts/appundo02.dbf' size 100m;

To Resize UNDO datafile:
========================
alter database datafile '/u01/app/oracle/oradata/cts/appundo02.dbf' resize 150m;

To Create TEMPORARY TABLESPACE:
===============================
create temporary tablespace app_temp tempfile '/u01/app/oracle/oradata/cts/apptemp01.dbf' size 100m;

select file_name,bytes/1024/1024 from dba_temp_files where tablespace_name='APP_TEMP';

To ADD Tempfile:
================
alter tablespace app_temp add tempfile '/u01/app/oracle/oradata/cts/apptemp02.dbf' size 200m;

To Resize Tempfile:
===================

alter database tempfile '/u01/app/oracle/oradata/cts/apptemp01.dbf' resize 150m;


To Check Free space of all the tablespaces:
================================

 select TABLESPACE_NAME,sum(bytes/1024/1024) from DBA_FREE_SPACE group by tablespace_name;

To check allocated Space of all the tablespaces:
====================================

 select TABLESPACE_NAME,sum(bytes/1024/1024) from DBA_DATA_FILES group by tablespace_name;

To Check used space of all the tablespaces:
================================
 select TABLESPACE_NAME,sum(bytes/1024/1024) from DBA_SEGMENTS group by tablespace_name;

To check all the datafiles with allocated size in particular tablespace:
==================================================
select file_name,bytes/1024/1024 from dba_data_files where tablespace_name='APPSBI';

Tablespace related operations:
=============================
offline/online
datafile add/resize
read/write mode
create/drop tablespace
logging/nologging

Related views:
=============
dba_tablespaces
dba_data_files
dba_temp_files
dba_temp_free_space
v$tempfile
v$datafile

Note:

1. We can create a table with particular tablespace spacification

create table test(eno number) tablespace appsbi;

2. We can allocate the datafile to  particular table

alter table test allocate extent (size 10k datafile '/u01/app/oracle/oradata/algates/appsbi02.dbf');

Tuesday, 9 April 2013

ORACLE DATABASE MANNUAL CREATION STEPS - For Beginners! Easy 10 Steps!
================================================================
Database Name: cts                         ||
OS: LINUX/AIX                             ||         RAFFEEK :)
Oracle S/W : 10g                             ||
================================================================
1. cd /u01/app/oracle/admin

ls -lrt
mkdir cts
cd cts

mkdir adump bdump cdump udump pfile

2.cd /u01/app/oracle/oradata

mkdir cts

3. pfile creation steps

 cd /u01/app/oracle/admin

ls -lrt

cd <EXISTING DATABASE>/pfile

ls -lrt

cp init.ora /u01/app/oracle/admin/cts/pfile

cd /u01/app/oracle/admin/cts/pfile

ls -lrt

vi init.ora

press "i" to edit

change database name,audit/background/core/user dump locations, controlfile locations and dispatchers name

esc+shift+:+wq  --> to save


4. password file creation steps

cd /u01/app/oracle/product/10.2.0/db_1/dbs

pwd

orapwd file='/u01/app/oracle/product/10.2.0/db_1/dbs/orapwcts.ora' password=sys entries=5

ls -lrt

5. edit the oratab entry

 vi /etc/oratab

Press "i" to edit

cts:/u01/app/oracle/product/10.2.0/db_1:N

esc+shift+:+wq  --> to save


6. . oraenv  --> Set the oracle environment

? cts

  (or)

export ORACLE_SID=cts
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1

echo $ORACLE_SID   --> just to check the database name
echo $ORACLE_HOME  --> just to check the oracle home path

sqlplus "/as sysdba"

7.SQL> startup nomount pfile='/u01/app/oracle/admin/cts/pfile/init.ora';


8. SQL> create database cts
datafile '/u01/app/oracle/oradata/cts/system01.dbf' size 250m
sysaux datafile '/u01/app/oracle/oradata/cts/sysaux01.dbf' size 300m
default temporary tablespace temp tempfile '/u01/app/oracle/oradata/cts/tmp01.dbf' size 40m
undo tablespace undotbs1 datafile '/u01/app/oracle/oradata/cts/undo01.dbf' size 40m
logfile
 group 1 '/u01/app/oracle/oradata/cts/log1.dbf' size 40m,
 group 2 '/u01/app/oracle/oradata/cts/log2.dbf' size 40m
/

9. spfile creation

SQL> create spfile from pfile='/u01/app/oracle/admin/cts/pfile/init.ora';

SQL> select status from v$instance;


10.SQL> @?/rdbms/admin/catalog.sql

SQL> @?/rdbms/admin/catproc.sql

SQL>conn system/manager

SQL> @?/sqlplus/admin/pupbld.sql

exit

ps -ef|grep pmon