You are on page 1of 9

Managin The Oracle Instance

MANAGEMENT FRAME WORK


There are three components of the oracle database 10g management framework:
 A Database instance that is being managed
 A Listener that allows connections to the database
 The Management Interface. This may be either a Management Agent running on the database server
(which connects it to oracle enterprise manager grid control) OR The stand-alone Oracle Enterprise
Manager Database Control also called DATABSE CONSOLE
Note: Each of these components must be explicitly started before we can use the service of the component and
must be shutdown cleanly when shutting down the Oracle Database.

STARTING AND STOPPING DATABASE CONTROL


When we install Oracle database, Oracle universal installer also installs Oracle enterprise Manager (OEM). Its
web-based Database Control serves as the primary tool for managing our oracle database
PRACTICAL #
STEP # 1: On DOS Prompt
set oracle_sid= orcl2  database name may change
C:>Emctl start dbconsole
C:>Lsnrctl
STEP # 2: Open Internal Explorer
On Address bar type  http://computer name:port number/em
How to Check Computer Name  Right click on my computer
Then properties
Than click computer name
For Port number  when we start emctl dbconsole we see port number of our database. Normally 1158 is the
port number for ORACLE 10g
STEP # 3: Enter Usernameand password on login screen
User Name  SYS
Password  oracle
As  sysdba
STEP # 4: Now Enterprise Manager Home Page Appear Perform your task

ISQL PLUS PRACTICAL


PRACTICAL #
STEP # 1: On DOS Prompt
Write  isqlplusctl start
STEP # 2: Open Internal Explorer
On Address bar type  http:// host_name:portnumber/isqlplus
How to Check Computer Name  Right click on my computer
Then properties
Than click computer name
For Port number  Port number for isqlplus. Normally 5560
Or manually see the port number  E:\oracle\product\10.1.0\Db_1\install\portlist
STEP # 3: Enter Usernameand password on login screen
User Name  scott
Password  tiger
STEP # 4: Now ISQLPLUS Home Page Appear Perform your task

LOGIN ISQLPLUS AS SYSDBA PRACTICAL

1 Prepared by: Syed Raheel-ur-Rehman


PRACTICAL #
STEP # 1: On DOS Prompt Set Java_Home , Oracle_home, Oracle_Sid
SET JAVA_HOME=D:\ORACLE\PRODUCT\10.2.0\DB_1\JDK
SET ORACLE_HOME=D:\ORACLE\PRODUCT\10.2.0\DB_1
SET ORACLE_SID=ORCL
CD D:\ORACLE\PRODUCT\10.2.0\DB_1\OC4J\J2EE\ISQLPLUS\APPLICATION-
DEPLOYMENTS\ISQLPLUS
We type D: because my oracle install D Drive  enter drive name where oracle install
s> d:\oracle\product\10.2.0\db_3\jdk\bin\java -Djava.security.properties=%ORACLE_HOME
%\oc4j\j2ee\home\config\jazn.security.props -jar %oracle_home%\oc4j\j2ee\home\jazn.jar -user "iSQL*Plus
DBA/admin" -password welcome -shell
Now you enter JAZN:> Prompt write the following steps on JAZN
JAZN:> adduser "iSQL*Plus DBA" xyz xyz
JAZN:> listusers
JAZN:> grantrole WebDba "iSQL*Plus DBA" xyz
JAZN:> exit
STEP # 2: Open Internal Explorer
On Address bar type  http:// host_name:5560/isqlplus
Security window open type username and password xyz/xyz
Now isqlplus started
User Name  SYS
Password  oracle
As  sysdba
STEP # 3: Now ISQLPLUS Home Page Appear Perform your task

USING THE SQL*PLUS


PRACTICAL #
For BLACK screen
RUN  sqlplus
Than enter username and password
For WHITE screen
Program  oracle 10g home 1  application development  sqlplus

CALLING SCRIPT ON SQLPLUS Page # 4-14

PRACTICAL #
STEP # 1: Create a script file on note pad and write following SQL statement on notepad file
Select * from emp ;
Select * from emp where job=’SALESMAN’;
Select sum(sal), min(sal), max(sal) from emp;
Select * from emp
Where sal > (select sal from emp where ename=’SMITH’);
Update emp Set job=’SALESMAN’;
Select * from emp;
Rollback;
Select * from emp Where ename like ‘&\_%’ escape ‘\’;
Select * from emp Where job in ( select job from emp where empno=7788);
Insert into emp Values
(9999,’RAHEEL’,’SALESMAN’,’’,’’,’’,’’,’’);

Now save the notepad file with sql extension  my_script.sql at any destination
STEP # 2: On Sqlplus or Isqlplus
@path of the file  destination of the file you create above like
@ E:\PRACTICE\Raheel\my_script.sql
2 Prepared by: Syed Raheel-ur-Rehman
INITIALIZATION PARAMETER FILE
In order to start an instance and open the database, we must connect sysdba and enter the startup command. The
oracle server will then read the initialization parameter file and prepare the instance according to the
initialization parameters contained within. For this we must have sysdba privileges
There are two types of parameter files.
Static parameter file, PFILE, commonly referred as init<SID>.ora
Dynamic persistent server parameter file SPFILE, commonly referred as spfile<SID>.ora

Contents Of Parameter File


 A list of instance parameters
 The name of the database the instance is associated with
 Allocation for memory structures of the SGA
 What to do with filled online redo log files. (Archive Destination)
 The names and locations of control files.
 Information about undo tablespace.
Text initialization parameter file: PFILE  init<sid>.ora (sid) means database name
 Text File
 Modified with an operating system editor
 Modification made manually
 Whenever we need to change the value of the parameter file we must shutdown the database.
 The pfile is read only during instance startup. (Changes take effect on next startup)
For oracle 9i  default location C:\oracle\admin\orcl\pfile\initsid.ora
For oracle 10g (R2)  default location E:\oracle\product\10.2.0\Db_1\database\initorcl.ora
Server parameter file: SPFILE :  spfile<sid>.ora  (sid) means database name
- Binary File
- Maintained by the oracle server
- Always resides on the server side having read and write by database server
- Ability to make changes persistent across SHUTDOWN and STARTUP
- Can self-tune parameter values
- Can have RMAN support for backup the initialization parameter
For oracle 9i  default location C:\oracle\ora92\database\spfileorcl.ora
For oracle 10g (R2)  default location E:\oracle\product\10.2.0\Db_1\dbs\spfileorcl.ora
To see which parameter file is running with the current instance.
SQL> show parameter spfile; OR show parameter pfile;
NAME TYPE VALUE
------------ ----------- ------------------------------
spfile string C:\ORACLE\PRODUCT\10.2.0\DB_1\DBS\SPFILEORCL.ORA

VIEWING AND MODIFYING INITILIZATION PARAMETERS


We can use enterprise manager to view and modify initialization parameters by clicking
On Administration Tab  database configuration  All Initialization Parameters
OR
ALTER SYSTEM command is used to change the value of instance parameter.
DESC V$SPPARAMETER
SELECT * FROM V$SPPARAMETER

Startup command behavior

ORDER OF PRECEDENCE:
When the command startup is used, the spfileSID.ora on the server side is used to start up the instance.
If the spfileSID.ora is not found the default Spfile.ora on the server side is used to start up the instance.

3 Prepared by: Syed Raheel-ur-Rehman


If the default spfile.ora is not found, the initSID.ora on the server side will be used to start up the instance.
A specified PFILE can override the use of the default SPFILE to start the instance.

CREATE SPFILE FROM PFILE


FOR ORACLE 9i
SQL> Create SPFILE = 'd:\oracle\ora92\database\spfileorcl.ora'
from pfile = 'd:\oracle\admn\orcl\pfile\initorcl.ora';
This work also be done without defining address and shutdown stage
SQL> Create spfile from pfile ;

FOR ORACLE 10g


SQL> CREATE SPFILE = 'C:\oracle\product\10.2.0\Db_1\dbs\SPFILEORCL1.ORA'
FROM PFILE = 'C:\oracle\product\10.2.0\Db_1\database\INITorcl.ORA'
File created.

This work also be done without defining address and shutdown stage
SQL> Create spfile from pfile ;

STARTING UP THE DATABASE:


There are 4 stages to startup and shutdown the database
When startup database
Shutdown  Nomount  Mount  Open

AT NOMOUNT STAGE:
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.

At this stage following tasks are performed


 Reading initialization parameter file
First spfileSID.ora
if not found then, spfile.ora
If not found then, initsid.ora
specifying the PFILE parameter with STARTUP overrides the default behavior.
 Allocating SGA
 Starting the background Process
 opening the alertSID.log files and trace files

AT MOUNT STAGE:
Mounting a database includes the following tasks:
 Associating a database with instance start at nomount stage.
 Locating and opening the control file specified in the parameter file.
 Reading the control file to obtain the name, status and destination of
DATA FILES AND ONLINE REDO LOG FILES
 To perform special maintenance operations
 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, flashback options.
 Performing full Database Recovery
We usually need to start up a database in mount mode when you’re doing activities such as performing a full
database recovery, changing the archive logging mode of the database, or renaming data files. Note that all
three of these operations require Oracle to access the data files but can’t accommodate any user operations in
the files.

AT OPEN STAGE:
4 Prepared by: Syed Raheel-ur-Rehman
The last stage of the startup process is opening the database. When the database is started in the open mode, all
valid users can connect to the database and perform database operations. Prior to this stage, the general users
can’t connect to the database at all. You can bring the database into the open mode by issuing the ALTER
DATABASE command as follows:
SQL> ALTER DATABASE OPEN;
Database altered.
More commonly, we simply use the STARTUP command to mount and open our database all at once:
SQL> STARTUP
To open the database, the Oracle server first opens all the data files and the online redo log files, and verify that
the database is consistent. If the database isn’t consistent—for example, if the SCNs in the control files don’t
match some of the SCNs in the data file headers—the background process will automatically perform an
instance recovery before opening the database. If media recovery rather than instance recovery is needed,
Oracle will signal that a database recovery is called for and won’t open the database until you perform the
recovery.
IN SHORT
Opening a database includes the following tasks:
 Open online data files
 Open online redo log files
NOTE 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.
STARTUP COMMAND  use to start database
STARTUP NOMOUNT;
to move the database from NOMOUNT TO MOUNT or from
NOMOUNT TO OPEN use
ALTER DATABASE COMMAND
ALTER DATABASE MOUNT;
ALTER DATABASE OPEN;
PRACTICAL #
SQL> startup nomount
ORACLE instance started.
Total System Global Area 171966464 bytes
Fixed Size 787988 bytes
Variable Size 145750508 bytes
Database Buffers 25165824 bytes
Redo Buffers 262144 bytes
SQL>
SQL> alter database mount;
Database altered.
SQL> alter database open;
Database altered.

OPENING A DATABASE IN RESTRICTRED MODE :


A restricted session is useful when you perform structure maintenance or a database import and export.
Then database can be started in restricted mode so that it is available only to users having restricted session /
administrative privileges.
This can be done in two ways
1- Before startup the database

SQL> STARTUP RESTRICT


ORACLE instance started.
Total System Global Area 612368384 bytes
Fixed Size 1250452 bytes
Variable Size 281021292 bytes
5 Prepared by: Syed Raheel-ur-Rehman
Database Buffers 327155712 bytes
Redo Buffers 2940928 bytes
Database mounted.
Database opened.
OR
2- After database open use alter system command
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SYSTEM ALTERED
After placing an instance in restricted mode, we may want to kill all current users before performing
administrative tasks.
This can be done by the following
SQL> ALTER SYSTEM KILL SESSION 'integer1,integer2'
where
integer1: value of the SID column in the V$SESSION view
integer2: value of the SERIAL# column in the V$SESSION view
Effects of terminating session :
Alter system kill session command causes the background process PMON to perform the following steps
1- Rollback the user current transactions
2- Release all currently held table or row lock
3- Free all resources currently reserved by the user
PRACTICAL #
SQL> STARTUP RESTRICT;
OR
After database open
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION ;
SYSTEM ALTERED;
TERMINATE SESSION
STEP # 1: Create 2 User and give necessary privileges
SQL> CREATE USER ABC IDENTIFIED BY ABC ;
User created.
SQL> CONN ABC/ABC;
ERROR:
ORA-01045: user ABC lacks CREATE SESSION privilege; logon denied
Warning: You are no longer connected to ORACLE.
When we connect database an error occurred because this user has no right to connect with database.
SQL> CONN SYS/ORACLE AS SYSDBA;
Connected.
SQL> GRANT CONNECT , RESOURCE TO ABC IDENTIFIED BY ABC;
Grant succeeded.
SQL> CREATE USER XYZ IDENTIFIED BY XYZ;
User created.
SQL> GRANT CONNECT, RESOURCE TO XYZ IDENTIFIED BY XYZ;
Grant succeeded.
STEP # 2: Open 3 more SQL session and connect to 3 different user
abc/abc  session 2
xyz/xyz  session 3
scott/tiger  session 4
STEP # 3: On Session 1 SCOTT perform some query
SQL> SELECT * FROM EMP ;
SQL> UPDATE EMP SET SAL=1000;
6 Prepared by: Syed Raheel-ur-Rehman
SQL> SELECT * FROM EMP;
Now SCOTT grant select right to abc and xyz
SQL> GRANT SELECT ON SCOTT.EMP TO ABC;
Grant succeeded.
SQL> GRANT SELECT ON SCOTT.EMP TO XYZ;
Grant succeeded.
STEP # 4: On Session 2 ABC perform some query
SELECT * FROM SCOTT.EMP;
STEP # 5: On Session 3 XYZ perform some query
SELECT * FROM SCOTT.EMP;
STEP # 6: Now on SYS session kill the connected users
Find username , SID, serial# from v$session view
SQL> select USERNAME, SID, SERIAL#
from V$SESSION;
Then
Use Alter system kill session ‘integer1, integer2’;
Where Integer 1 = SID
Integer 2 = serial #
Find the SID, Serial number of SCOTT user
SQL> AFTER SYSTEM KILL THE SESSION ‘123,23’;
SYSTEM ALTERED
STEP # 7: Now on Session 1 SCOTT perform query we got an error
SQL> Select * from scott.emp;
An error occurred
--------------------------------------------------------------
SQL> SELECT * FROM EMP;
SELECT * FROM EMP
*
ERROR at line 1:
ORA-00028: your session has been killed
---------------------------------------------------------------
ERROR:
ORA-01012: not logged on
This means the session of this user has been killed he is not able to work with the database.

OPENING A DATABASE IN READ ONLY MODE


To prevent data from being modified by user transactions database can be open at read only mode.
SQL> ALTER DATABASE OPEN READ ONLY;
In this mode of database no DDL, DML operation perform
READ ONLY session can be used :
 Execute query
 Execute disk sort using locally manage tablespaces
 Take datafiles offline and online, but not tablespaces
 Perform recovery of offline datafiles and tablespaces.

SHUTDOWN THE DATABASE:


There are 4 ways to shutdown database

1- SHUTDOWN NORMAL:
 No new connection can be made
 Oracle server waits all users to disconnect
 database and redo buffer written to the disk
7 Prepared by: Syed Raheel-ur-Rehman
 Background process terminated and SGA remove from memory
 Oracle closes and dismount database before shutdown
 Next startup does not require recovery

2- SHUTDOWN TRANSACTIONAL:
 No new connection can be made
 User automatically disconnect after completing the transaction in progress
 When all transaction finished shutdown occur immediately
 Next startup does not require recovery
3- SHUTDOWM IMMEDIATE:
 Current SQL statement being processed is not completed
 Oracle server does not wait for the user who are currently connected to the database
 Oracle closes and dismount database before shutdown.
 Next startup does not require recovery

4- SHUTDOWN ABORT:
 Oracle does not wait for user currently connected to the database
 Database and redo buffers are not written to the disks
 The instance terminated without closing the files
 The database is not close or dismounts
 Next startup requires instance recovery.

MONITORING AN INSTANCE USING ALERT LOG FILES :


Each oracle instance has an alert<sid>.log file. The file is on the server with the database and is stored in the
directory specified with the background_dump_dest initialization parameter.
The file must manage by DBA
It continuous grow while the database continuous to work
Alert log file should be the first place we look when diagnostic day-to-day operations or errors.
The alert file keeps a record of the following information

 When the database was STARTED and SHUTDOWN


 When the database ARCHIVELOG, and RECOVER
 a list of non default initialization parameters
 The startup backgroud process
 The thread used by the instance
 The log sequence number LGWR is writting to
 Information regarding to log switch
 Administrative operations, such as the SQL statements CREATE, ALTER, DROP
DATABASE, and TABLESPACE creation of tablespace and undo segments
 Information regarding error massages such as ORA-600 and extent errors.
 Block corruption errors (ORA-1578), and deadlock errors (ORA-60)
The alertSID.log location is defined by the BACKGROUND_DUMP_DEST initialization parameter.
DESTINATION: for ORACLE 10g
E:\oracle\product\10.1.0\admin\ORCL\bdump
NOTE : This file can grow to an unmanageable size. If alert log file delete during database open it must be re-
created automatically. And re-create every time instance started.

DYNAMIC PERFORMANCE VIEWS:


The oracle database also maintains a more dynamic set of data about the operation and performance of database
instance. This data stored in dynamic performance views.
These views provide access to information about changing states and condition in the database.
These views are based on virtual tables that are built from memory structure inside the database server. That is
they are not true tables.
These views are owned by the sys user. Any other user cannot access these views. However DBA grant
privileges on them.
These views are often referred as “V DOLLOR” V$ views.

8 Prepared by: Syed Raheel-ur-Rehman


We can query V$ FIXED_TABLE to see all view names.
SQL>SELECT * FROM V$FIXED_TABLE ;
Read consistency is not granted on these views because the data is dynamic.
Some dynamic performance views contain that is not applicable to all states of an instance or database. That is
why some of them can show you data before a database is mounted or open.
For example:
If an instance has been started, but no database is mounted we can query
V$BGPROCESS to see the list of background process that are running
SQL>SELECT * FROM V$BGPROCESS;
But we cannot query V$DATAFILE to see the status of data files. Because database is not mounted.
Dynamic Performance Views include information about:
 Session
 File States
 Progress of Jobs and Tasks
 Locks
 Backup States
 Memory Usage and Allocation
 System and Session Parameter
 SQL execution
 Statistics and Metrics

LIST OF COMMON DYNAMIC VIEWS


V$CONTROLFILE
List the name of control files
V$DATAFILE
Contain datafile information from the control file
V$DATABASE
Contains database information from the control file
V$INSTANCE
Display the state of current instance
V$PARAMETER
List parameter and values currently in effect fro the session
V$SESSION
List session information for each current session
V$SGA
Contain summary information on the system global area (SGA)
V$SPPARAMETER
List the contents of SPFILE
V$TABLESPACE
Display the tablespace information from the control file
V$THREAD
Contain thread information from the control file
V$VERSION
Version numbers of core library components in the oracle server.

9 Prepared by: Syed Raheel-ur-Rehman

You might also like