Sei sulla pagina 1di 68

UPGRADATION AND TRANSPORTATION

Drishti Gupta(9991148264)
8716113
CSE(5th Sem)

This project is submitted to kurukshetra technical university in the


partial fulfillment of the requirement for the award of degreeof
bachelors of technology

State institute of engg. and technology

Nilokheri,Karnal

Session:2016-2020
ACKNOWLEDGEMENT
First of all I would like to thanks to SLR Infotech Private
Limited - Chandigarh, itself for providing this remarkable
opportunity to be a part of the slr family which is leading
organization in the world.
I would like to thank Mr. Hitender Rana (Oracle DBA
consultant) for considering me capable of doing the tasks that I
have been performing and providing a congenial, friendly,
informal but at the same time a very professional environment to
work in, and for making me a part of his ingenious team.
In fact learning at SLR has been a continuous process
and the process is still in ‘running’ state. Also all my trainee
friends without whom, my first encountering of the corporate
life would not have been full of so much fun. They were simply
wonderful.
Last but not the least, I am grateful to my project guide
Mr. Hitender Rana for imparting their insight in my spectrum
of knowledge and for their inspiration and continual support.

Once again thank you very much to all of you.


drishti gupta
ABSTRACT
About SLR Infotech Pvt. Ltd

SLR Infotech Pvt. Ltd. Having development office in India and Office in California USA is
one of the leading software development company with extensive experience in designing and
development cutting edge software solutions. We are a group of highly motivated it
professionals with an ability to innovate a strong desire to excel.
SLR Infotech is a customer focused company working to provide software solutions, which
are delivered with relability, timeliness, flexibility and low cost customer satisfaction as the
primary aim. The designing solutions are purely based on business and technical requirements
of the project in hand. Software development life cycle is strictly followed to ensure the timely
delivery of the project without compromising on Quality.
SLR Infotech provides a broad range of Offshore Outsourcing Services including application
and systems level programming on leading technologies. It also provides wide range of
networking solutions for Corporates, Industries and Software development Firms.
SLR Infotech has a niche in providing training to Engineering & MCA students. Thousands of
engineering students from Chandigarh, Punjab, Haryana, Rajasthan& Himachal have
successfully completed their industrial and summer Training. The focus of the industrial
training is to facilitate students with live projects on latest technologies like VB.net, ASP.net,
Oracle DBA/developer, J2EE, JDO, Struts, Linux, Networking under the strict guidance of
industry experts.
Our philosophy:-
Consistently Deliverling Ingenious, Comprehensive, Efficient and Cost-effective quality
training solutions.
Our mission:-
To Impart internationally Certified and advanced high-end it training to Engineers,
Professionals, College students in the field of Software, Hardware, Networking &Database
Administration.
Our Core Values:-
We "listen" to our students. Our relationships are based on understanding and mutual respect.
We respect, encourage and promote mutually supportive relationships in achieving common
goals. We believe in open communication, transparency & honesty in all our relationships.we
have, therefore, created a climate which is distinctive in industry. We strive to provide a
thrilling training environment that will bring innovation at work.

SLR INFOTECH is an Internationally recognized Software


Development and IT Consultancy Company. SLR's core Management team is built around
the expertise of top class performance with proven track in software design, development,
testing and implementation for topnotch companies. Our superior methodologies, standard
quality processes, effective project management and a right mix of on-site and off-shore
software teams help us execute projects that often exceed client expectations.
SLR Infotechhas state of art Training Division with more than 8000 sq.ft. Space, which
provides an unrivaled range of high quality Training and Certifications in Software courses
for Engineering/MCA Students and Corporates who seeks a secured career in the IT world.
All the programs are devised to equip the students with unparalleled professional expertise as
you walk out with the Internationally Acclaimed Certifications.
SLR Infotech specializes in providing High Tech Industrial Training (6 Months/6 Weeks) to
all the Engineering and MCA students mainly in Oracle DBA, Red Hat Linux, MCSE,
CISCO, Web Designing Technologies with exposure to Real time.
Upgradation

Upgradation Summary

\*For Database upgradation


Database should not be started before upgradation.*\

\\To check the running process\\


[oracle@localhost ~]$ ps -ef|grep pmon
oracle 9967 8955 0 01:19 pts/1 00:00:00 greppmon
oracle 30356 1 0 01:12 ? 00:00:00 ora_pmon_orcl(No
process is running)

\\ To check the running database\\


[oracle@localhost ~]$ ps -ef|grep sqlplus
oracle 11280 8955 0 01:20 pts/1 00:00:00 grepsqlplus

\\To see that there is any listner is up or not\\


[oracle@localhost ~]$ ps -ef|grep tns
oracle 11283 8955 0 01:20 pts/1 00:00:00 greptns(No listner
is up)

\\To see the status of agents\\


[oracle@localhost ~]$ ps -ef|grep agent
oracle 4520 4481 0 Apr29 ? 00:00:00 /usr/bin/ssh-agent
/bin/sh -c exec -l /bin/bash -c "/usr/bin/dbus-launch --exit-with-
session /etc/X11/xinit/Xclients"
oracle 11286 8955 0 01:20 pts/1 00:00:00 grep agent
\\To kill any running session.'-' is added to close the session
forcefully.\\
[oracle@localhost ~]$ kill -9 9967
bash: kill: (9967) - No such process

\\To call the directory of patchfile\\


[oracle@localhost ~]$ cd
/u01/p5337014_10203_LINUX.zip_FILES/

\\Tocall the disk1 from patchfile directory\\


[oracle@localhost p5337014_10203_LINUX.zip_FILES]$ cd
Disk1/

\\To start the installation of the patch.'nohup' will allow the


installation at the back if the session is closed\\
[oracle@localhost Disk1]$ nohup ./runInstaller&
[1] 5770
[oracle@localhost Disk1]$ nohup: appending output to
`nohup.out
UPGRADATION STEPS
Step1:-
Step 2:-
Step3: -
Step 4:-
Step 5:-
Step 6:-

\\Go to root from terminal\\


[oracle@localhost ~]$ su - root

\\Password=redhat\\
Password:

\\Call the installation script on root\\


[root@localhost ~]# /u01/app/oracle/product/10.2.0/db_1/root.sh
Running Oracle10 root.sh script...
The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/10.2.0/db_1
Enter the full pathname of the local bin directory: [/usr/local/bin]:
The file "dbhome" already exists in /usr/local/bin. Overwrite it?
(y/n)
[n]: y
Copying dbhome to /usr/local/bin ...
The file "oraenv" already exists in /usr/local/bin. Overwrite it?
(y/n)
[n]: y
Copying oraenv to /usr/local/bin ...
The file "coraenv" already exists in /usr/local/bin. Overwrite it?
(y/n)
[n]: y
Copying coraenv to /usr/local/bin ...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.

\\To go to terminal\\
[root@localhost ~]# su - oracle
\\To up any particular database if we have multiple database\\
[oracle@localhost ~]$ export ORACLE_SID=orcl

\\Environment in which we will work\\


[oracle@localhost ~]$ sqlplus

SQL*Plus: Release 10.2.0.3.0 - Production on Tue Apr 30


00:25:17 2013

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.


ORACLE instance started.
Enter user-name: / as sysdba
Connected to an idle instance.

SQL> startup upgrade

Total System Global Area 285212672 bytes


Fixed Size 1261372 bytes
Variable Size 96469188 bytes
Database Buffers 184549376 bytes
Redo Buffers 2932736 bytes
Database mounted.
Database opened.
Step 7:-
\\For Database upgradation\\
SQL> @?/rdbms/admin/catupgrd.sql;
Step 8:-
\\For triggers,plsql,procedures validation\\
SQL>@?/rdbms/admin/utlrp.sql;
Step9:-
\\To shut down the session\\
SQL>shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

\\To start the session\\


SQL> startup
ORACLE instance started.

Total System Global Area 285212672 bytes


Fixed Size 1261372 bytes
Variable Size 155189444 bytes
Database Buffers 125829120 bytes
Redo Buffers 2932736 bytes
Database mounted.
Database opened.

\\To describe the columns of the table\\


SQL>descdba_registry
Name Null? Type
----------------------------------------- -------- ----------------------------
COMP_ID NOT NULL VARCHAR2(30)
COMP_NAME VARCHAR2(255)
VERSION VARCHAR2(30)
STATUS VARCHAR2(11)
MODIFIED VARCHAR2(20)
NAMESPACE NOT NULL VARCHAR2(30)
CONTROL NOT NULL VARCHAR2(30)
SCHEMA NOT NULL VARCHAR2(30)
PROCEDURE VARCHAR2(61)
STARTUP VARCHAR2(8)
PARENT_ID VARCHAR2(30)
OTHER_SCHEMAS VARCHAR2(4000)

\\To see the particular or selected columns of the table\\


SQL> select comp_name,status,version from dba_registry;
COMP_NAME
--------------------------------------------------------------------------------
STATUS VERSION
----------- ------------------------------
Oracle Database Catalog Views
VALID 10.2.0.3.0

Oracle Database Packages and Types


VALID 10.2.0.3.0
JServer JAVA Virtual Machine
VALID 10.2.0.3.0

Oracle XDK
VALID 10.2.0.3.0

Oracle Database Java Packages


VALID 10.2.0.3.0

Oracle Expression Filter


VALID 10.2.0.3.0

Oracle Data Mining


VALID 10.2.0.3.0

Oracle Text
VALID 10.2.0.3.0

Oracle XML Database


VALID 10.2.0.3.0

Oracle Rule Manager


VALID 10.2.0.3.0

Oracle interMedia
VALID 10.2.0.3.0

OLAP Analytic Workspace


VALID 10.2.0.3.0

Oracle OLAP API


VALID 10.2.0.3.0

OLAP Catalog
VALID 10.2.0.3.0

Spatial
VALID 10.2.0.3.0

Oracle Enterprise Manager


VALID 10.2.0.3.0

define
DEFINE _DATE = "30-APR-13" (CHAR)
DEFINE _CONNECT_IDENTIFIER = "orcl" (CHAR)
DEFINE _USER = "SYS" (CHAR)
DEFINE _PRIVILEGE = "AS SYSDBA" (CHAR)
DEFINE _SQLPLUS_RELEASE = "1002000300" (CHAR)
DEFINE _EDITOR = "ed" (CHAR)
DEFINE _O_VERSION = "Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 -
Production
With the Partitioning, OLAP and Data Mining options" (CHAR)
DEFINE _O_RELEASE = "1002000300" (CHAR)
DEFINE UTLIP_FILE = "nothing.sql" (CHAR)
DEFINE UPGRADE_FILE = "1002000" (CHAR)
DEFINE WPI_FILE_VAR = "owadummy.sql" (CHAR)
DEFINE OWA_FILE_VAR = "owacomm.sql" (CHAR)
DEFINE PATCH_FILE = "@nothing.sql" (CHAR)
DEFINE COMP_FILE = "@imxreg.sql" (CHAR)
DEFINE INIT_FILE = "@initxqry.sql" (CHAR)
DEFINE XDB_FILE = "@dbmsxdbt.sql" (CHAR)
DEFINE EOSCR_FILE = "@nothing.sql" (CHAR)
DEFINE 1 = "0" (CHAR)
DEFINE 2 = "synonym" (CHAR)
DEFINE 3 = "script" (CHAR)
DEFINE 4 = "for" (CHAR)
DEFINE 5 = "aw" (CHAR)
DEFINE 6 = "create" (CHAR)
DEFINE 7 = "and" (CHAR)
DEFINE 8 = "enable" (CHAR)
DEFINE 9 = "packages" (CHAR)
DEFINE EMDW_HOME = "?" (CHAR)
DEFINE EM_REPOS_USER = "SYSMAN" (CHAR)
DEFINE EM_SQL_ROOT = "?/sysman/admin/emdrep/sql" (CHAR)
DEFINE EM_REPOS_MODE = "SYSAUX" (CHAR)
DEFINE SCHEMA_UPGRADE_FILE =
"?/sysman/admin/emdrep/sql/db/v102010/db_schema_upgrade.sql" (CHAR)
DEFINE IAS_FILE =
"?/sysman/admin/emdrep/sql/core/latest/admin/admin_do_nothing.sql" (CHAR)
DEFINE OCS_FILE =
"?/sysman/admin/emdrep/sql/core/latest/admin/admin_do_nothing.sql" (CHAR)
DEFINE PKGDEF_FILE =
"?/sysman/admin/emdrep/sql/core/latest/core_sysaux_pkgdefs.sql" (CHAR)
DEFINE FUNCS_FILE = "?/sysman/admin/emdrep/sql/core/latest/core_funcs_10g.sql"
(CHAR)
DEFINE VIEWS_FILE =
"?/sysman/admin/emdrep/sql/core/latest/core_sysaux_views.sql" (CHAR)
DEFINE PKGBDYS_FILE =
"?/sysman/admin/emdrep/sql/core/latest/core_sysaux_pkgbodys.sql" (CHAR)
DEFINE TRIGGERS_FILE =
"?/sysman/admin/emdrep/sql/core/latest/core_sysaux_triggers.sql" (CHAR)
DEFINE GUID_RAW_LENGTH = "16" (CHAR)
DEFINE MAX_VARCHAR2_LENGTH = "4000" (CHAR)
DEFINE TARGET_NAME_LENGTH = "256" (CHAR)
DEFINE TARGET_TYPE_LENGTH = "64" (CHAR)
DEFINE DISPLAY_TARGET_NAME_LENGTH = "256" (CHAR)
DEFINE DISPLAY_TARGET_TYPE_LENGTH = "128" (CHAR)
DEFINE SNAPSHOT_TYPE_LENGTH = "64" (CHAR)
DEFINE USER_NAME_LENGTH = "256" (CHAR)
DEFINE NAME_LENGTH = "128" (CHAR)
DEFINE DESCRIPTION_LENGTH = "2000" (CHAR)
DEFINE SHORT_DESCRIPTION_LENGTH = "500" (CHAR)
DEFINE VERSION_LENGTH = "100" (CHAR)
DEFINE TYPE_LENGTH = "100" (CHAR)
DEFINE LOCATION_LENGTH = "1024" (CHAR)
DEFINE INET_ADDRESS_LENGTH = "20" (CHAR)
DEFINE DOMAIN_NAME_LENGTH = "500" (CHAR)
DEFINE IP_LENGTH = "20" (CHAR)
DEFINE P_NAME_LENGTH = "128" (CHAR)
DEFINE P_DESCRIPTION_LENGTH = "2000" (CHAR)
DEFINE P_SHORT_DESCRIPTION_LENGTH = "500" (CHAR)
DEFINE P_CAPTION_LENGTH = "100" (CHAR)
DEFINE P_VERSION_LENGTH = "50" (CHAR)
DEFINE P_TARGET_TYPE_LENGTH = "100" (CHAR)
DEFINE P_RULE_TYPE_LENGTH = "100" (CHAR)
DEFINE P_CATEGORY_LENGTH = "100" (CHAR)
DEFINE P_LARGE_VARCHAR_LENGTH = "4000" (CHAR)
DEFINE P_REASONABLE_NUMBER_LENGTH = "10" (CHAR)
DEFINE P_SQL_NAME_LENGTH = "31" (CHAR)
DEFINE P_VALUE_LENGTH = "1024" (CHAR)
DEFINE P_FILTER_OP_LENGTH = "10" (CHAR)
DEFINE P_SEVERITY_LENGTH = "10" (CHAR)
DEFINE P_RULE_NAME_LENGTH = "128" (CHAR)
DEFINE P_PARAM_NAME_LENGTH = "128" (CHAR)
DEFINE P_ATTRIBUTE_NAME_LENGTH = "31" (CHAR)
DEFINE P_TARGET_NAME_LENGTH = "100" (CHAR)
DEFINE P_PARAM_VALUE_LENGTH = "1024" (CHAR)
DEFINE P_ATTRIBUTE_VALUE_LENGTH = "1024" (CHAR)
DEFINE P_COLUMN_NAME_LENGTH = "31" (CHAR)
DEFINE P_Y_N_LENGTH = "1" (CHAR)
DEFINE P_SNAPSHOT_TYPE_LENGTH = "64" (CHAR)
DEFINE P_AUTHOR_LENGTH = "128" (CHAR)
DEFINE P_URL_LENGTH = "2000" (CHAR)
DEFINE P_DISPLAY_ID_LENGTH = "128" (CHAR)
DEFINE P_CLEAR = "0" (CHAR)
DEFINE ABSTRACT_LENGTH = "1024" (CHAR)
DEFINE DISPLAY_NAME_LENGTH = "128" (CHAR)
DEFINE DATA_UPGRADE_FILE =
"?/sysman/admin/emdrep/sql/db/v102010/db_data_upgrade.sql" (CHAR)
DEFINE UPDATE_TZRGN_SCRIPT =
"?/sysman/admin/emdrep/sql/core/v101050/basic/basic_update_agent_tzrgn.sql" (CHAR)
DEFINE EM_AGENT_TZRGN = "Asia/Calcutta" (CHAR)
SQL>

\*********Our Database is upgraded********\


TRANSPORTATION

CONVERSION OF DATABASE INTO SCRIPT


\I will transport the database named 'prod' from linux to Windows7\

\\Set sid of oracle to prod\\


[oracle@localhost ~]$ export ORACLE_SID=prod

\\Environment in which we have to work\\


[oracle@localhost ~]$ sqlplus

SQL*Plus: Release 10.2.0.3.0 - Production on Tue Apr 30 02:34:47 2013

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

\\Connect to admin\\
Enter user-name: / as sysdba

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL>shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

\* We will start the databse till mount stage only because


the Database should be in read only mode for the transportation *\

SQL> startup mount


ORACLE instance started.

Total System Global Area 285212672 bytes


Fixed Size 1261372 bytes
Variable Size 104857796 bytes
Database Buffers 176160768 bytes
Redo Buffers 2932736 bytes
Database mounted.

\\To set the database to read only mode\\


SQL> alter database open read only;

Database altered.
\\To check the status and name of the database\\
SQL> select open_mode,name from v$database;

OPEN_MODE NAME
---------- ---------
READ ONLY PROD

\\To configure data for transportation\\


SQL> set serveroutput on;
\\To come to the terminal from Session\\
SQL> ho

\***Make the Directory named bkpp in which we will store the information
of control files,data files and pfile***\
[oracle@localhost ~]$ mkdir /u01/bkpp
[oracle@localhost ~]$ exit
exit

\\It will display the operating sysytem where we want to migrate the databse\\
SQL> select * from v$transportable_platform;
PLATFORM_ID PLATFORM_NAME
ENDIAN_FORMAT
----------- ----------------------------------------------------------------------------------------------------- --------------
1 Solaris[tm] OE (32-bit) Big
2 Solaris[tm] OE (64-bit) Big
7 Microsoft Windows IA (32-bit) Little
10 Linux IA (32-bit) Little
6 AIX-Based Systems (64-bit) Big
3 HP-UX (64-bit) Big
5 HP Tru64 UNIX Little
4 HP-UX IA (64-bit) Big
11 Linux IA (64-bit) Little
15 HP Open VMS Little
8 Microsoft Windows IA (64-bit) Little
9 IBM zSeries Based Linux Big
13 Linux 64-bit for AMD Little
16 Apple Mac OS Big
12 Microsoft Windows 64-bit for AMD Little
17 Solaris Operating System (x86) Little
18 IBM Power Based Linux Big

17 rows selected.

SQL> ho

\\Go to rman\\
[oracle@localhost ~]$ rman target/

Recovery Manager: Release 10.2.0.3.0 - Production on Tue Apr 30 02:48:40 2013

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

connected to target database: PROD (DBID=225907708)

\***It helps in control file creation on the platform where we have


to transport the database***\
RMAN> convert database transport script '/u01/bkp/crdb.sql' to platform 'Microsoft
Windows IA (32-bit)' db_file_name_convert='/u01/app/oracle/oradata/orcl', '/u01/bkp';

Starting convert at 30-APR-13


using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK

External table SH.SALES_TRANSACTIONS_EXT found in the database

Directory SYS.ADMIN_DIR found in the database


Directory SYS.WORK_DIR found in the database
Directory SYS.DATA_FILE_DIR found in the database
Directory SYS.LOG_FILE_DIR found in the database
Directory SYS.MEDIA_DIR found in the database
Directory SYS.XMLDIR found in the database
Directory SYS.SUBDIR found in the database
Directory SYS.DATA_PUMP_DIR found in the database

BFILE PM.PRINT_MEDIA found in the database

User SYS with SYSDBA and SYSOPER privilege found in password file
channel ORA_DISK_1: starting datafile conversion
inputdatafilefno=00001 name=/u01/app/oracle/oradata/prod/system01.dbf
converteddatafile=/u01/bkpp/system01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:02:38
channel ORA_DISK_1: starting datafile conversion
inputdatafilefno=00003 name=/u01/app/oracle/oradata/prod/sysaux01.dbf
converteddatafile=/u01/bkpp/sysaux01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:01:23
channel ORA_DISK_1: starting datafile conversion
inputdatafilefno=00005 name=/u01/app/oracle/oradata/prod/example01.dbf
converteddatafile=/u01/bkpp/example01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:38
channel ORA_DISK_1: starting datafile conversion
inputdatafilefno=00002 name=/u01/app/oracle/oradata/prod/undotbs01.dbf
converteddatafile=/u01/bkpp/undotbs01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:11
channel ORA_DISK_1: starting datafile conversion
inputdatafilefno=00004 name=/u01/app/oracle/oradata/prod/users01.dbf
converteddatafile=/u01/bkpp/users01.dbf
channel ORA_DISK_1: datafile conversion complete, elapsed time: 00:00:01
Run SQL script /u01/bkpp/crdb.sql on the target platform to create database
Edit init.ora file /u01/app/oracle/product/10.2.0/db_1/dbs/init_00o8bhe5_1_0.ora. This
PFILE will be used to create the database on the target platform
To recompile all PL/SQL modules, run utlirp.sql and utlrp.sql on the target platform
To change the internal database identifier, use DBNEWID Utility
Finished backup at 30-APR-13

RMAN>

\**Copy the pfile from u01/app/oracle/oradata/admin/prod/init.ora and place it in bkp


directory.
Put the folder in Windows7 and perform further***\
STEPS FOR TRANSPORTATION FROM LINUX
TO WINDOW 7

Step1: Make a folder named as prod in any


drive of your window 7.
Step2: Make adump, bdump, cdump
,udump, create pfile,flash_recovery_area
folders in folder “prod”.
Step3:-Copy all the datafiles from backup
folder to create folder
Step4: Create new text file inside create
folder.
Step 5: Open crdb file and copy the txt from this file
and paste it in new text file present in create folder.
Step 6:Edit the path of datafiles and redologfiles in
new txt file and rename it as “prod”.
Step 7: Edit init file present in pfile folder.
Step 8: After all changes ,opencmd(command prompt) as
administator.
Step 9: Run following different command on
command prompt for instance creation

*oradim -new –sidora (for instance creation)

*Set sid of the database as “prod


Step 10: Run command “sqlplus” for graphical
Representation of database.
Step 11: Login in the database as sys/sys as sysdba.
Step 12: After login as sysdba Oracle sqlplus server
will open.
Step 13:Create spfile from pfile and also create control
file.
Step 14: Connect to user “SCOTT”.Check the status of
create folder ie. Control files and archive files will
generate in this folder.
LITRETURE REVIEW

STRUCTURE QUERY LANGUAGE (SQL)


Each running Oracle database is associated with an Oracle instance. When a database is started
on a database server, the Oracle software allocates a shared memory area called the System
Global Area (SGA) and starts several Oracle background processes. This combination of the
SGA and the Oracle processes is called an Oracle Instance.

What Can SQL do?


After starting an instance, the Oracle software associates the instance with a specific database.
This is called mounting the database. The database is then ready to be opened, which makes it
accessible to authorized users. Multiple instances can execute concurrently on the same
computer, each accessing its own physical database.
• SQL stands for Structured Query Language
• SQL lets you access and manipulate Databases
• SQL is an ANSI (American National Standards Institute) standard

• SQL can execute queries against a Database


• SQL can retrieve data from a Database
• SQL can insert records in a Database
• SQL can update records in a Database
• SQL can delete records from a Database
• SQL can create new Databases
• SQL can create new tables in a Database
• SQL can create stored procedures in a Database
• SQL can create views in a Database
• SQL can set permissions on tables, procedures, and views.
SQL Statements
• Data Retrieval (DR):
• SELECT is the most complex statement in SQL, with optional keywords and
clauses that include:
• The FROM clause which indicates the table(s) from which data is to be retrieved.
The FROM clause can include optional JOIN subclauses to specify the rules for
joining tables.
• The WHERE clause includes a comparison predicate, which restricts the rows
returned by the query. The WHERE clause eliminates all rows from the result set
for which the comparison predicate does not evaluate to True.
• The GROUP BY clause is used to project rows having common values into a
smaller set of rows. GROUP BY is often used in conjunction with SQL
aggregation functions or to eliminate duplicate rows from a result set.
The WHERE clause is applied before the GROUP BY clause.
• The HAVING clause includes a predicate used to filter rows resulting from
the GROUP BY clause. Because it acts on the results of the GROUP BY clause,
aggregation functions can be used in the HAVING clause predicate.
• The ORDER BY clause identifies which columns are used to sort the resulting
data and in which direction they should be sorted (options are ascending or
descending). Without an ORDER BY clause, the order of rows returned by an SQL
query is undefined.

• Data Manipulation Language (DML):


The Data Manipulation Language (DML) is the subset of SQL used to add, update
and delete data:

• INSERT adds rows to an existing table, e.g:

INSERT INTO My_table


(field1, field2, field3)
VALUES ('test', 'N', NULL);

• UPDATE modifies a set of existing table rows, e.g.:


UPDATE My_table
SET field1 = 'updated value'
WHERE field2 = 'N';

• DELETE removes existing rows from a table, e.g.:


DELETE FROM My_table
WHERE field2 = 'N';
• MERGE is used to combine the data of multiple tables. It combines
the INSERT and UPDATE elements.

• Data Definition Language:


The Data Definition Language (DDL) manages table and index structure. The most
basic items of DDL are the CREATE, ALTER, RENAME, DROP and TRUNCATE
statements:

• CREATE creates an object (a table, for example) in the database, e.g:CREATE


TABLE My_table
(
my_field1 INT,
my_field2 VARCHAR(50),
my_field3 DATE NOT NULL,
PRIMARY KEY (my_field1, my_field2)
);
• ALTER modifies the structure of an existing object in various ways, for example,
adding a column to an existing table or a constraint, e.g.:ALTER TABLE
My_table ADD my_field4 NUMBER(3) NOT NULL;

• TRUNCATE deletes all data from a table in a very fast way, deleting the data
inside the table and not the table itself. It usually implies a subsequent COMMIT
operation, i.e., it cannot be rolled back.TRUNCATE TABLE My_table;

• DROP deletes an object in the database, usually irretrievably, i.e., it cannot be


rolled back, e.g.:DROP TABLE My_table;

• Data Control Language:-


• The Data Control Language (DCL) authorizes users and groups of users to
access and manipulate data. Its two main statements are:

• GRANT authorizes one or more users to perform an operation or a set of


operations on an object.

• REVOKE eliminates a grant, which may be the default grant.

Example:
GRANT SELECT, UPDATE
ON My_table
TO some_user, another_user;

REVOKE SELECT, UPDATE


ON My_table
FROM some_user, another_user;

• Transaction Control Language:


Transactions, if available, wrap DML operations:

• START TRANSACTION marks the start of a database transaction, which either


completes entirely or not at all.

• SAVE TRANSACTION (or SAVEPOINT ) save the state of the database at the
current point in transaction

• COMMIT causes all data changes in a transaction to be made permanent.

• ROLLBACK causes all data changes since the last COMMIT or ROLLBACK to
be discarded, leaving the state of the data as it was prior to those changes
SQL FUNCTIONS
Single row function:-
Single row or Scalar functions return a value for every row that is processed in a query. Here are
four types of single row functions. They are:

 Numeric Functions: These are functions that accept numeric input and return
numeric values. Numeric functions are used to perform operations on numbers. They
accept numeric values as input and return numeric values as output.

 Character or Text Functions: These are functions that accept character


input and can return both character and number values. Character or text functions are
used to manipulate text strings. They accept strings or characters as input and can return
both character and number values as output.

Function Name Examples Return Value


LOWER(string_value) LOWER('Good Morning') good morning
GOOD
UPPER(string_value) UPPER('Good Morning')
MORNING
INITCAP(string_value) INITCAP('GOOD MORNING') Good Morning
LTRIM(string_value,
LTRIM ('Good Morning', 'Good’) Morning
trim_text)
RTRIM (string_value, RTRIM ('Good Morning', '
Good
trim_text) Morning')
TRIM (trim_text FROM
TRIM ('o' FROM 'Good Morning') GdMrning
string_value)
SUBSTR (string_value,
SUBSTR ('Good Morning', 6, 7) Morning
m, n)
LENGTH (string_value) LENGTH ('Good Morning') 12
LPAD (string_value, n,
LPAD ('Good', 6, '*') **Good
pad_value)
RPAD (string_value, n,
RPAD ('Good', 6, '*') Good**
pad_value)

Character Functions
 Date Functions: These are functions that take values that are of datatype
DATE as input and return values of datatype DATE, except for the
MONTHS_BETWEEN function, which return a number.
The below table provides the examples for the above functions:-

Return
Function Name Examples
Value
ADD_MONTHS ( ) ADD_MONTHS ('16-Sep-81', 3) 16-Dec-81
MONTHS_BETWEEN( MONTHS_BETWEEN ('16-Sep-81',
3
) '16-Dec-81')
NEXT_DAY( ) NEXT_DAY ('01-Jun-08', 'Wednesday') 04-JUN-08
LAST_DAY( ) LAST_DAY ('01-Jun-08') 30-Jun-08
NEW_TIME( ) NEW_TIME ('01-Jun-08', 'IST', 'EST') 31-May-08
DATE Functions

 Conversion Functions:These are functions that help us to convert a


value in one form to another form. For Example: a null value into an actual value, or a
value from one datatype to another datatype like NVL, TO_CHAR, TO_NUMBER,
TO_DATE etc.

The below table provides the examples for the above functions.
Function
Examples Return Value
Name
TO_CHAR (3000, '$9999') $3000
TO_CHAR
TO_CHAR (SYSDATE, 'Day, Month Monday, June
()
YYYY') 2008
TO_DATE
TO_DATE ('01-Jun-08') 01-Jun-08
()

NVL () NVL (null, 1) 1


Conversion Function
• Multiple Row Function: These functions group the rows of data based
on the values returned by the query. The Group functions are used to calculate aggregate
values like total or average, which return just one total or one average value after
processing a group of rows.
These functions are: COUNT, MAX, MIN, AVG, SUM, DISTINCT

 SQL COUNT (): This function returns the number of rows in the table that
satisfies the condition specified in the WHERE condition. If the WHERE condition is not
specified, then the query returns the total number of rows in the table.
For Example: If you want the number of employees in a particular
department, the query would be:
SELECT COUNT (*) FROM employee.
WHERE dept = 'Electronics';

 SQL DISTINCT (): This function is used to select the distinct rows.
For Example: If you want to select all distinct department names from
employee table, the query would be:
SELECT DISTINCT dept FROM employee;

 SQL MAX (): This function is used to get the maximum value from a column.
To get the maximum salary drawn by an employee, the query would be:
SELECT MAX (salary) FROM employee;

 SQL MIN (): This function is used to get the minimum value from a column.
To get the minimum salary drawn by an employee, he query would be:
SELECT MIN (salary) FROM employee;

 SQL AVG (): This function is used to get the average value of a numeric column.
To get the average salary, the query would be:
SELECT AVG (salary) FROM employee;
 SQL SUM(): This function is used to get the sum of a numeric column
To get the total salary given out to the employees,
SELECT SUM (salary) FROM employee;

SQL Joins:
SQL Joins are used to relate information in different tables. A Join condition is a part of the SQL
query that retrieves rows from two or more tables. A SQL Join condition is used in the SQL
WHERE Clause of select, update, delete statements.
The Syntax for joining two tables is:
SELECT col1, col2, col3
FROM table_name1, table_name2
WHERE table_name1.col2 = table_name2.col1;

If a SQL join condition is omitted or if it is Invalid the join operation will result in a Cartesian
product. The Cartesian product returns a number of rows equal to the product of all rows in all
the tables being joined. For example, if the first table has 20 rows and the second table has 10
rows, the result will be 20 * 10 or 200 rows. This query takes a long time to execute.

SQL Equi Joins:-


It is a simple sql join condition which uses the equal sign as the comparison operator. Two types
of equi joins are SQL Outer join and SQL Inner join.
For example: You can get the information about a customer who purchased a product and the
quantity of product.
An equi-join is further classified into two categories:
a) SQL Inner Join
b) SQL Outer Join

SQL Inner Join:-


All the rows returned by the SQL query satisfy the SQL join condition specified. The query for
this type of SQL joins would be like,
SELECT order_id, product_name, unit_price, supplier_name, total_units
FROM product, order_items
WHERE order_items.product_id = product.product_id;
SQL Outer Join:-
This SQL join condition returns all rows from both tables which satisfy the join condition along
with rows which do not satisfy the join condition from one of the tables. The SQL outer join
operator in Oracle is ( + ) and is used on one side of the join condition only.
If you want to display all the product data along with order items data, with null values displayed
for order items if a product has no order item, the SQL query for outer join would be as shown
below:
SELECT p.product_id, p.product_name, o.order_id, o.total_units
FROM order_items o, product p
WHERE o.product_id (+) = p.product_id;

SQL Non Equi Join:-


A Non Equi Join is a SQL Join whose condition is established using all comparison operators
except the equal (=) operator. Like >=, <=, <, >
For example: If you want to find the names of students who are not studying either Economics,
the SQL query would be like:
SELECT first_name, last_name, subject
FROM student_details
WHERE subject != 'Economics' ;

SQL Integrity Constraints:-


Integrity Constraints are used to apply business rules for the database tables.
The constraints available in SQL are Primary Key, Foreign Key, Not Null, Unique, Check.
Constraints can be defined in two ways:
1) The constraints can be specified immediately after the column definition. This is called
column-level definition.
2) The constraints can be specified after all the columns are defined. This is called table-level
definition.
1.Primary key:-
This constraint defines a column or combination of columns which uniquely identifies each row
in the table.
• Syntax to define a Primary key at column level:
column name datatype [CONSTRAINT constraint_name] PRIMARY KEY
• Syntax to define a Primary key at table level:
[CONSTRAINT constraint_name] PRIMARY KEY (column_name1,column_name2,..)
2.Foreign key or Referential Integrity:-
This constraint identifies any column referencing the PRIMARY KEY in another table. It
establishes a relationship between two columns in the same table or between different tables. For
a column to be defined as a Foreign Key, it should be a defined as a Primary Key in the table
which it is referring. One or more columns can be defined as Foreign key.
Syntax to define a Foreign key at column level:
[CONSTRAINT constraint_name] REFERENCES Referenced_Table_name(column_name);

Syntax to define a Foreign key at table level:


[CONSTRAINT constraint_name] FOREIGN KEY(column_name) REFERENCES
referenced_table_name(column_name);

3.Not Null Constraint :


This constraint ensures all rows in the table contain a definite value for the column which is
specified as not null. Which means a null value is not allowed.
Syntax to define a Not Null constraint:-
[CONSTRAINT constraint name] NOT NULL

1.Unique Key:- This constraint ensures that a column or a group of columns in each row
have a distinct value. A column(s) can have a null value but the values cannot be duplicated.
Syntax to define a Unique key at column level:
[CONSTRAINT constraint_name] UNIQUE
Syntax to define a Unique key at table level:
[CONSTRAINT constraint_name] UNIQUE(column_name)

2.Check Constraint: -This constraint defines a business rule on a column. All the
rows must satisfy this rule. The constraint can be applied for a single column or a group of
columns.
Syntax to define a Check constraint:
[CONSTRAINT constraint_name] CHECK (condition)
SQL VIEW
SQL VIEW is a virtual table, through which a selective portion of the data from one or more
tables can be seen. Views do not contain data of their own. They are used to restrict access to the
database or to hide data complexity. A view is stored as a SELECT statement in the database.
DML operations on a view like INSERT, UPDATE, DELETE affects the data in the original
table upon which the view is based.
The Syntax to create a SQL view is:-
CREATE VIEW view_name
AS
SELECT column_list
FROM table_name [WHERE condition];

Benefits of using views:-


• You can restrict database access because views can restrict access to selective portions of
database tables.
• Views can make complex queries easy. They allow you to make simple queries to
retrieve the results from complicated queries.
• Views can be used to allow data independence for ad hoc users and application programs.
• You can present different views of the same data according to their particular criteria.
• You can use views instead of creating temporary tables and dropping them daily. This
avoids data file fragmentation.

Creating a view:-
CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view name [alias[, alias]…)]
AS subquery
[WITH CHECK OPTION [CONSTRAINT constraint] ]
[WITH READ ONLY]

Modifying views:-
You cannot modify a view using the ALTER .. MODIFY clause. To modify the view you have
to drop it and create another one, or you can simply use the [OR REPLACE] clause and replace
the existing view.
SQL> CREATE OR REPLACE VIEW myview
AS SELECT empno EMPLOYEE_NO, ename NAME, sal SALARY
FROM emp
WHERE deptno=10;
Rules for performing DML Operations on a view:-
• You can perform DML operations on Simple views.
• You cannot remove a row if the view contains the following:
• Group functions such as SUM, MIN, MAX, AVG, …
• A GROUP BY clause.
• The DISTINCT keyword.
• You cannot modify data in a view if it contains:
• Group functions such as SUM, MIN, MAX, AVG, …
• A GROUP BY clause.
• The DISTINCT keyword.
• Columns defined by expressions (i.e, SAL * 12).
• The ROWNUM pseudo column.
• You cannot add data if:
• The view contains any of the conditions mentioned above.
• There are NOT NULL columns in the base tables that are not selected by the view.

Using the WITH CHECK OPTION clause:-


You can ensure that DML on the view stays within the domain of the view by using the WITH
CHECK OPTION clause.
SQL> CREATE OR REPLACE VIEW myview
AS SELECT * FROM emp
WHERE deptno=20
WITH CHECK OPTION CONSTRAINT myview_ck;

Any attempt to change the department number for any row in the view fails because it violates
the WITH CHECK OPTION constraint.

Denying DML Operations:-


You can ensure that no DML operations occur by adding the WITH READ ONLY option to
your view definition.
Example:
SQL> CREATE OR REPLACE VIEW myview2
AS SELECT empno, ename, sal
FROM emp
WHERE deptno=10
WITH READ ONLY OPTION;

Any attempt to perform DML on any row in the view results in an Oracle server error: ORA-
01725

Removing a view:-
Remove the view without losing data because a view is based on underlying tables in the
database:
DROP VIEW view;

SQL Index
When there are thousands of records in a table, retrieving information will take a long time.
Therefore indexes are created on columns which are accessed frequently, so that the information
can be retrieved quickly. Indexes can be created on a single column or a group of columns.
When a index is created, it first sorts the data and then it assigns a ROWID for each row.
Syntax to create Index:
CREATE INDEX index_name
ON table_name (column_name1,column_name2...);
Syntax to create SQL unique Index:
CREATE UNIQUE INDEX index_name
ON table_name (column_name1,column_name2...);

In Oracle there are two types of SQL index namely, implicit and explicit.
Implicit Indexes:
They are created when a column is explicity defined with PRIMARY KEY, UNIQUE KEY
Constraint.
Explicit Indexes:
They are created using the "create index.. " syntax.

.
Privileges and Roles
Privileges: Privileges defines the access rights provided to a user on a database object.
There are two types of privileges.
1) System privileges - This allows the user to CREATE, ALTER, or DROP database objects.
2) Object privileges - This allows the user to EXECUTE, SELECT, INSERT, UPDATE, or
DELETE data from database objects to which the privileges apply.

System Privileges Description


Allows users to create the specified object in their own
CREATE object
schema.
CREATE ANY
Allows users to create the specified object in any schema.
object

System Privileges

Object
Description
Privileges
INSERT Allows users to insert rows into a table.
SELECT Allows users to select data from a database object.
UPDATE Allows user to update data in a table.
EXECUTE Allows user to execute a stored procedure or a function.

Object Privileges

Roles: Roles are a collection of privileges or access rights. When there are many users in a
database it becomes difficult to grant or revoke privileges to users. Therefore, if you define roles,
you can grant or revoke privileges to users, thereby automatically granting or revoking
privileges. You can either create Roles or use the system roles pre-defined by oracle.
Some of the privileges granted to the system roles are as given below:
System Role Privileges Granted to the Role
CREATE TABLE, CREATE VIEW, CREATE SYNONYM, CREATE
CONNECT
SEQUENCE, CREATE SESSION etc.
CREATE PROCEDURE, CREATE SEQUENCE, CREATE TABLE,
RESOURCE CREATE TRIGGER etc. The primary usage of the RESOURCE role is to
restrict access to database objects.

Privileges Granted to the Role


Creating Roles
The Syntax to create a role is:
CREATE ROLE role_name
[IDENTIFIED BY password];
It's easier to GRANT or REVOKE privileges to the users through a role rather than assigning a
privilege directly to every user. If a role is identified by a password, then, when you GRANT or
REVOKE privileges to the role, you definitely have to identify it with the password.
We can GRANT or REVOKE privilege to a role as below.
For example:
To grant CREATE TABLE privilege to a user by creating a testing role:
• First, create a testing Role
CREATE ROLE testing
• Second, grant a CREATE TABLE privilege to the ROLE testing. You can add more
privileges to the ROLE.
GRANT CREATE TABLE TO testing;
• Third, grant the role to a user.
GRANT testing TO user1;

To revoke a CREATE TABLE privilege from testing ROLE, you can write:
REVOKE CREATE TABLE FROM testing;
The Syntax to drop a role from the database is as below:
DROP ROLE role_name;

Database Structures
Each running Oracle database is associated with an Oracle instance. When a database is started
on a database server, the Oracle software allocates a shared memory area called the System
Global Area (SGA) and starts several Oracle background processes. This combination of the
SGA and the Oracle processes is called an Oracle instance.

After starting an instance, the Oracle software associates the instance with a specific database.
This is called mounting the database. The database is then ready to be opened, which makes it
accessible to authorized users. Multiple instances can execute concurrently on the same
computer, each accessing its own physical database.

Automatic Storage Management spreads database data across all disks, creates and maintains a
storage grid, and provides the highest input/output (I/O) throughput with minimal management
costs. As disks are added or dropped, ASM redistributes the data automatically. (There is no
need for a logical volume manager to manage the file system.) Data availability increases with
optional mirroring, and you can add or drop disks online. For more information, see the lesson
titled “Managing Database Storage Structures.”

Fig. 3.1 Oracle Architecture.

With the advent of so many big enterprises, the need to create a more sophisticated DBMS has
also increased. For appointment as a DBA, a high level of skill and expertise is required. The
major tasks that should be performed by a DBA are as follows:
• Judging what server hardware will be required to run the Oracle 10g database software
• Installing and configuring the Oracle 10g database software on the server hardware
• Creating a database and managing tables and other database objects
• Creating and managing database users
• Configuring backup and recovery processes for the database
• Monitoring and tuning the database performance
Now, the point is how a DBA can perform the above-mentioned tasks. To perform all these tasks
in an efficient manner, a DBA must be very well versed with the underlying Oracle architecture.

The Oracle server architecture:


The Oracle server architecture is basically categorized as follows:
• Logical layer
• Physical layer
The logical layer comprises one or more tablespaces and the database schema. The database
schema consists of tables, clusters, indexes, views, procedures, sequences, and so on. The
database schema is a collection of schema objects.
The relationship between segments, extents, and data blocks
The hierarchy of Oracle disk-space management is as follows:
• Tablespaces: These are at the highest level of Oracle disk-space management.
• Segments
• Extents
• Data blocks: These are at the lowest level of Oracle disk-space management.
The figure below depicts the relationship between segments, extents, and data blocks:

Fig. 3.2 Segment Extent


The physical layer comprises the following files:

The Control File: Though it is the smallest file (1MB-5MB) of the database, it is the
most crucial and critical file. The criticality of this file is ascribed to the fact that if it is damaged
then the database recovery operation becomes tedious. It contains the requisite information to
start the database. The names and locations of all the control files of the database can be obtained
from the V$CONTROLFILE dynamic performance view.

Data files: These hold data that is stored in tables of a database. They are usually the
largest files in the database, ranging in size from MB, GB, to TB.

Redo Log files: These files contain information that helps in recovery in the event of
system failure. It contains information stored in the Redo Log Buffer. The information in the
Redo Log Buffer is written into Redo Log files by the LGWR background process. The Redo
Log files are generally multiplexed and copied for recovery purposes. Sets of redo Log files are
known as Redo Log groups. Each database has minimum of two Redo Log groups. Redo Log
groups are used in a circular fashion.
The figure below depicts the use of Redo Log files in circular fashion:

Fig.
3.3 Redo Log Buffer

The figure above shows three Redo Log groups. Each group consists of two members. The first
member of each Redo Log group is stored in directory D1 and the second member is stored in
directory D2.
Note:
• The V$LOGFILE dynamic performance view is used to obtain information about the
names and locations of the Redo Log groups and their members.
• LGWR writes every three seconds to a Redo Log group in the case of the following
events:
• Whenever a user commits a transaction
• Whenever the Redo Log Buffer is one-third (1/3) full
The Oracle memory structure
The most basic components of Oracle memory are:

• SGA- It stands for System Global Area. SGA is allocated whenever an Oracle instance
starts and gets de-allocated when the Oracle instance is shutdown.
• Components of SGA:
• The Database Buffer Cache
• The Redo Log Buffer
• The Shared Pool

• PGA- It stands for Program Global Area. It is a region in memory that contains data
and control information for a single process. This can be either a server or a background process.
A PGA is allocated whenever an Oracle database user connects to a database and a session is
created for him/her.

Oracle processes
There are two categories of processes that run with an Oracle database. They are mentioned
below:
• User processes
• Server processes

Fig. 3.4 The relationship between user processes, server processes, PGA, and session.
The first interaction with the Oracle-based application comes from the user computer that creates
a user process. The user process then communicates with the server process on the host
computer. Here, PGA is used to store session specific information.

Oracle background processes


Oracle has a large number of background processes. The background processes are categorized
into:
• Required Oracle background processes
• Optional Oracle background processes
Some of the background processes are:
• DBWR – It writes data blocks from SGA to data files.
• LGWR – It writes data from the Log Buffer to the redo log.
• CKPT – It timestamps all the data files and the control files whenever a checkpoint
occurs.
• PMON – It stands for process monitor. It keeps track of database processes. It also cleans
up the process that has died pre-maturely. The result is that all the cache and the resources are
freed up. It also restarts those dispatcher processes that might have failed.
Some of the main functions of background processes are:
• Communication among Oracle instances
• Performing computer maintenance
• Writing the dirty blocks to disk
• SMON – It stands for system monitor. It performs instance recovery at instance startup.

The Oracle Instance


The Oracle instance consists of SGA and all the Oracle background processes. To manage the
size of SGA, two initialization parameter files known as PFILE and SPFILE are used. There are
a total of 250-initialization parameters. PFILE holds 30 of those 250 initialization parameters.
Oracle does not recommend modifying the rest of the 220 initialization parameters.
Modes of Database
We have the option of running the database in archive log or no- archive log (default). The
difference between archive log and no-archive log is that in no-archive log the online redo log
group which are used in cyclic manner and not backup up. In archive log, the redo logs are
archived and for each redo log an archive log file is created.
The advantage of archive log is that the backup of database along with archive logs provides the
complete recovery of database. Also, hot/online backups are possible only if the database is in
archive log mode. However in no-archive log mode, the database can be recovered only till the
last available backup. All the changes done after the backup was taken needs to be redone.

Non Archive Mode


When you run your database in NOARCHIVELOG mode, you disable the archiving of the
online redo log. The database's control file indicates that filled groups are not required to be
archived. Therefore, when a filled group becomes inactive after a log switch, the group is
available for reuse by LGWR.
The choice of whether to enable the archiving of filled groups of online redo log files depends on
the availability and reliability requirements of the application running on the database. If you
cannot afford to lose any data in your database in the event of a disk failure, use ARCHIVELOG
mode. Note that the archiving of filled online redo log files can require you to perform extra
administrative operations.
NOARCHIVELOG mode protects a database only from instance failure, but not from media
failure. Only the most recent changes made to the database, which are stored in the groups of the
online redo log, are available for instance recovery. In other words, if you are using
NOARCHIVELOG mode, you can only restore (not recover) the database to the point of the
most recent full database backup. You cannot recover subsequent transactions.
Also, in NOARCHIVELOG mode you cannot perform online tablespace backups. Furthermore,
you cannot use online tablespace backups previously taken while the database operated in
ARCHIVELOG mode. You can only use whole database backups taken while the database is
closed to restore a database operating in NOARCHIVELOG mode. Therefore, if you decide to
operate a database in NOARCHIVELOG mode, take whole database backups at regular, frequent
intervals.

Archive Mode
When you run a database in ARCHIVELOG mode, you enable the archiving of the online redo
log. The database control file indicates that a group of filled online redo log files cannot be used
by LGWR until the group is archived. A filled group is immediately available for archiving after
a redo log switch occurs.
The archiving of filled groups has these advantages:

• A database backup, together with online and archived redo log files, guarantees that you
can recover all committed transactions in the event of an operating system or disk failure.
• You can use a backup taken while the database is open and in normal system use if you
keep an archived log.
• You can keep a standby database current with its original database by continually
applying the original's archived redo logs to the standby.
Decide how you plan to archive filled groups of the online redo log. You can configure an
instance to archive filled online redo log files automatically, or you can archive manually. For
convenience and efficiency, automatic archiving is usually best. Figure 5 illustrate how the
process archiving the filled groups (ARC0 in this illustration) generates the database's online
redo log.

Fig. 3.5 Online Redo Log File Use in ARCHIVELOG Mode


If all databases in a distributed database operate in ARCHIVELOG mode, you can perform
coordinated distributed database recovery.
3.2.3 Database Storage Hierarchy

• A database is made up of one or more tablespaces.

• A tablespaceis made up of one or more data files. These files might be cooked files in a
file system, raw partitions, ASM managed database files, or a file on a clustered file system. A
tablespace contains segments.

Fig. 3.6 Data Hierarchy in Oracle

• A segment (TABLE, INDEX, and so on) is made up of one or more extents. A segment
exists in a tablespace, but may have data in many data files within that tablespace.
• An extent is a logically contiguous set of blocks on disk. An extent is in a single
tablespace and, furthermore, is always in a single file within that tablespace.

• A block is the smallest unit of allocation in the database. A block is the smallest unit of
I/O used by a database.

Fig 3.7 Logical and Physical Database Structures

Tablespace
A tablespace is a logical storage unit within an Oracle database. It is logical because a tablespace
is not visible in the file system of the machine on which the database resides. A tablespace, in
turn, consists of at least one datafile which, in turn, are physically located in the file system of
the server. Btw, a datafile belongs to exactly one tablespace.
Each table, index and so on that is stored in an Oracle database belongs to a tablespace. The
tablespace builds the bridge between the Oracle database and the filesystem in which the table's
or index' data is stored.
There are three types of tablespaces in Oracle:
• Permanent Tablespaces
• Undo Tablespaces
• Temporary Tablespaces
A tablespace is created with the Create Tablespace SQL command.
A database running in automatic Undo Management mode transparently creates and manages
undo segments. Oracle DBA can create an Undo tablespace and determine the maximum
retention time for undo data kept in that tablespace.

Temporary Tablespaces improve the concurrence of multiple sort operations, reduce their
overhead, or avoid Oracle space management operations altogether. Temporary tablespaces are
the most efficient tablespaces for disk sorts. Space management (extent allocation and de-
allocation) is locally managed. After temporary tablespaces, tablespaces of type TEMPORARY
are the next best tablespaces to use for sort operations. Space management is dictionary
managed.
Permanent Tablespaces (which are not of type TEMPORARY) are least efficient for
performance of disk sorts.
Temporary and Permanent Tablespaces can be assigned at the user level. Oracle DBA can create
a default temporary tablespace at database creation time. This tablespace is used as the default
temporary tablespace for users who are not otherwise assigned a temporary tablespace.

In Oracle Enterprise Manager:


Oracle DBA can see all tablespaces in your database. From the Administration page, click
Tablespaces under Storage. This takes you to the Tablespaces page.

The Results page shows all tablespaces, including the following information about each: type of
tablespace, type of extent management, type of segment management, status, size, and percent
used. Click the tablespace name for more information

3.2.5 Starting up an Oracle Database Instance


It consists of 4 steps:
• Shutdown
• Nomount
• Mount
• Open
Nomount:
An instance is typically started only in NOMOUNT mode during database creation, During re-
creation of control files, or during certain backup and recovery scenarios

Fig 3.8 Starting Up an Oracle Database Instance

Mount:
Mounting a database includes the following tasks:
• Associating a database with a previously started instance
• Locating and opening the control files specified in the parameter file
• Reading the control files to obtain the names and statuses of the data files and online redo
log files. However, no checks are performed to verify the existence of the data files and online
redo log files at this time.
• To perform specific maintenance operations, start an instance and mount a database, but
do not open the database.
• For example, the database must be mounted but must not be opened during the following
tasks:
• Renaming data files (Data files for an offline tablespace can be renamed when the
database is open.)
• Enabling and disabling online redo log file archiving options
• Performing full database recovery

Open:
A normal database operation means that an instance is started and the database is mounted and
opened. With a normal database operation, any valid user can connect to the database and
perform typical data access operations.
Opening the database includes the following tasks:
• Opening the online data files
• Opening the online redo log files

If any of the data files or online redo log files are not present when you attempt to open the
database, then the Oracle server returns an error. During this final stage, the Oracle server
verifies that all the data files and online redo log files can be opened and checks the consistency
of the database. If necessary, the System Monitor (SMON) background process initiates instance
recovery.
You can start up a database instance in restricted mode so that it is available to users with
administrative privileges only. To start an instance in restricted mode, select the "Restrict access
to database" option on the Advanced Startup Options page.

Shutdown Modes of Database


To shut down a database and instance, you must first connect as SYSOPER or SYSDBA. There
are several modes for shutting down a database.

1. Shutdown NORMAL / Shutdown


• The NORMAL clause is optional. This is the default shutdown method if no clause is
provided.
• No new connections are allowed after the statement is issued.
• Before the database is shut down, the database waits for all currently connected users to
disconnect from the database. Until they press exit database waits.
• SHUTDOWN IMMEDIATE
• No new connections are allowed, nor are new transactions allowed to be started, after the
statement is issued.
• Any uncommitted transactions are rolled back.
• The database implicitly rolls back active transactions and disconnects all connected
users.
• SHUTDOWN TRANSACTIONAL
• No new connections are allowed, nor are new transactions allowed to be started, after the
statement is issued.
• After all transactions have completed, any client still connected to the instance is
disconnected.

• SHUTDOWN ABORT
• No new connections are allowed, nor are new transactions allowed to be started, after the
statement is issued.
• Current client SQL statements being processed by Oracle Database are immediately
terminated.
• Uncommitted transactions are not rolled back.
• Oracle Database does not wait for users currently connected to the database to
disconnect. The database implicitly disconnects all connected users.
-The next startup of the database will require instance recovery procedures.

• Shutdown Transactional LOCAL


• The LOCAL mode specifies a transactional shutdown on the local instance only, so that it
only waits on local transactions to complete, not all transactions. In RAC environment it is
useful.
REFERENCES

Books and Journals

• Oracle Database 10g: SQL Fundamental 1


• Oracle Database 10g: SQL Fundamental 2
• Oracle10g Administration Workshop 1.
• Documentation of Oracle 10g.

Websites

• www.oracle.com/pls/db102/homepage
• www.sqlasia.com
• http://faq.programmerworld.net/database/installing-oracle-10g.html
• http://www.oracle.com/technetwork/database/database10g/documentation/database10gr2-
087366.html
• http://www.oracle.com/technetwork/database/database10g/documentation/index.html

Potrebbero piacerti anche