How Can I Tell If An Oracle Database Is Mounted and Activated?

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Every running Oracle database is associated with an Oracle

instance. When a database is started on a database server


(regardless of the type of computer), Oracle allocates a memory
area called the System Global Area (SGA) and starts one or more
Oracle processes. This combination of the SGA and the Oracle
processes is called an Oracle instance. The memory and processes
of an instance manage the associated database's data efficiently
and serve the one or multiple users of the database.
After starting an instance, Oracle associates the instance with the
specified database. This is called mounting the database. The
database is then ready to be opened, which makes it accessible to
authorized users.

How can I tell if an Oracle database is mounted and


activated?
1 - Is the database mounted (as in, has someone done "alter database mount standby
database")
2 - How can I tell if the database is activated (as in, "alter database activate standby
database")?

SQL> SELECT INSTANCE_NAME, DATABASE_STATUS, INSTANCE_ROLE from v$instance;


INSTANCE_NAME DATABASE_STATUS INSTANCE_ROLE
---------------- ----------------- -----------------RGR01
ACTIVE
PRIMARY_INSTANCE

When the instance is started, the init*.ora file is read by the system and SGA is allocated as
per the initialization parameters. No database is associated with this instance.
Once you Mount the database, it is asoociated with the instance. The contol file of the DB is
read and db files, redo log files and rollback segments, all are associated with the instance.
(these files are not yet 'open') That is why this state is used for moving around the db files.

When the database is started or opened, all these files are open and available for use to
the users

Startup Nomount : Read the parameter file and start the instance.
Instance name identified by ORACLE_SID env parameter.
The parameter file controls such things as SGA size, database name that can connect to this
instance.
Database not associated with instance yet.
As an example, you may need to do this if you will mount a standby database.
Mount : Associates database with the instance.
Open and read control files
Establish physical files associated with database. i.e location, size, amount of redo log files.
Physical database file names and locations.
DBA may need to be in mount state for all kinds of DBA activity.
examples :
rename/move system datafile.
put database in archivelog mode.
Database not yet available for user connections.
Opened/started
Ensure physical files exist.
make available for normal operations.
open online datafiles, redo logs.
acquire rollback segments.
These states are useful in many situations to a DBA, main areas where these are useful are ;
Architecture/Admin
Backup/Recovery.

*********************************************************************************

Starting Up a Database Using SQL*Plus


You can start a SQL*Plus session, connect to Oracle Database with administrator privileges, and
then issue the STARTUP command. Using SQL*Plus in this way is the only method described in
detail in this book.

Starting Up an Instance
You use the SQL*Plus STARTUP command to start up an Oracle Database instance. You can start an
instance in various modes:

Start the instance without mounting a database. This does not allow access to
the database and usually would be done only for database creation or the recreation of control files.

Start the instance and mount the database, but leave it closed. This state allows
for certain DBA activities, but does not allow general access to the database.

Start the instance, and mount and open the database. This can be done in
unrestricted mode, allowing access to all users, or in restricted mode, allowing
access for database administrators only.

Force the instance to start after a startup or shutdown problem, or start the
instance and have complete media recovery begin immediately.

*************************************************************************************

In this example from a Windows XP server, we set the ORACLE_SID to the name of
the database and we log into SQL*Plus using the ?sys as sysdba? login. This gives us
the privileges we need to be able to startup the database. Finally, after we enter our
password, we issue the startup command to startup the database. Oracle displays its
progress as it opens the database, and then returns us to the SQL*Plus prompt once
the startup has been completed.
When Oracle is trying to open your database, it goes through three distinct stages, and
each of these is listed in the startup output listed previously. These stages are:
* Startup (nomount)
* Mount
* Open
Let?s look at these stages in a bit more detail.

The Startup (nomount) Stage


When you issue the startup command, the first thing the database will do is enter the
nomount stage. During the nomount stage, Oracle first opens and reads the
initialization parameter file (init.ora) to see how the database is configured. For
example, the sizes of all of the memory areas in Oracle are defined within the
parameter file.
After the parameter file is accessed, the memory areas associated with the database
instance are allocated. Also, during the nomount stage, the Oracle background
processes are started. Together, we call these processes and the associated allocated
memory the Oracle instance. Once the instance has started successfully, the database
is considered to be in the nomount stage. If you issue the startup command, then
Oracle will automatically move onto the next stage of the startup, the mount stage.

Starting the Oracle Instance (Nomount Stage)


There are some types of Oracle recovery operations that require the database to be in
nomount stage. When this is the case, you need to issue a special startup command:
startup nomount, as seen in this example:
SQL> startup nomount

The Mount Stage


When the startup command enters the mount stage, it opens and reads the control file.
The control file is a binary file that tracks important database information, such as the
location of the database datafiles.
In the mount stage, Oracle determines the location of the datafiles, but does not yet
open them. Once the datafile locations have been identified, the database is ready to
be opened.

Mounting the Database


Some forms of recovery require that the database be opened in mount stage. To put
the database in mount stage, use the startup mount command as seen here:
SQL> startup mount
If you have already started the database instance with the startup nomount command,
you might change it from the nomount to mount startup stage using the alter database
command:
SQL> alter database mount;

The Open Oracle startup Stage


The last startup step for an Oracle database is the open stage. When Oracle opens the
database, it accesses all of the datafiles associated with the database. Once it has
accessed the database datafiles, Oracle makes sure that all of the database datafiles are
consistent.
Opening the Oracle Database
To open the database, you can just use the startup command as seen in this example
SQL> startup
If the database is mounted, you can open it with the alter database open command as
seen in this example:
SQL> alter database open;

Opening the Database in Restricted Mode


You can also start the database in restricted mode. Restricted mode will only allow
users with special privileges (we will discuss user privileges in a later chapter) to
access the database (typically DBA?s), even though the database is technically open.
We use the startup restrict command to open the database in restricted mode as seen in
this example.
SQL> startup restrict
You can take the database in and out of restricted mode with the alter database
command as seen in this example:
-- Put the database in restricted session mode.
SQL> alter system enable restricted session;
-- Take the database out of restricted session mode.
SQL> alter system disable restricted session;
Note: Any users connected to the Oracle instance when going into restricted mode
will remain connected; they must be manually disconnected from the database by
exiting gracefully or by the DBA with the ?alter system kill session? command.

Problems during Oracle Startup


The typical DBA life is like that of an airline pilot, ?Long moments of boredom
followed by small moments of sheer terror?, and one place for sheer terror is an error
during a database startup.
The most typical reason for a database not starting up is a prior database crash, a data
corruption, disk failure or some other catastrophic event from which the database
cannot recover. In these cases, you have to go into database recovery mode to start
your instance. There is a chapter on recovery later in this book and we will discuss
what to do when Oracle will not startup

*************************************************************************************

ORACLE: NOMOUNT, MOUNT And OPEN MODES in Oracle


Lets take a look at the different OPEN_MODES in Oracle and Analyse what happens at
every step.
SQL> SHUTDOWN IMMEDIATE
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> STARTUP NOMOUNT
PFILE=C:\oracle\product\10.2.0\admin\HARRY\pfile\init.ora.5182011155654
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers
In NOMOUNT MODE we create

591396864 bytes
1291916 bytes
167774580 bytes
415236096 bytes
7094272 bytes
1. DB's and 2. CONTROLFILES.

SQL> DESC V$INSTANCE


Name
Null?
----------------------------------------------------- ------------------------------------------INSTANCE_NUMBER
INSTANCE_NAME
HOST_NAME
VERSION
STARTUP_TIME
STATUS

Type

NUMBER
VARCHAR2(16)
VARCHAR2(64)
VARCHAR2(17)
DATE
VARCHAR2(12)

PARALLEL
THREAD#
ARCHIVER
LOG_SWITCH_WAIT
LOGINS
SHUTDOWN_PENDING
DATABASE_STATUS
INSTANCE_ROLE
ACTIVE_STATE
BLOCKED

VARCHAR2(3)
NUMBER
VARCHAR2(7)
VARCHAR2(15)
VARCHAR2(10)
VARCHAR2(3)
VARCHAR2(17)
VARCHAR2(18)
VARCHAR2(9)
VARCHAR2(3)

SQL> SELECT HOST_NAME,INSTANCE_NAME,VERSION FROM V$INSTANCE;


HOST_NAME
INSTANCE_NAME
VERSION
---------------------------------------------------------------- -------------------------------TEST-PC
harry
10.2.0.3.0
SQL> DESC V$CONTROLFILE;
Name
Null?
----------------------------------------------------- ------------------------------------------STATUS
NAME
IS_RECOVERY_DEST_FILE
BLOCK_SIZE
FILE_SIZE_BLKS
SQL> DESC V$database
Name
Null?
----------------------------------------------------- ------------------------------------------DBID
NAME
CREATED
RESETLOGS_CHANGE#
RESETLOGS_TIME
PRIOR_RESETLOGS_CHANGE#
PRIOR_RESETLOGS_TIME
LOG_MODE
CHECKPOINT_CHANGE#
ARCHIVE_CHANGE#
CONTROLFILE_TYPE
CONTROLFILE_CREATED
CONTROLFILE_SEQUENCE#
CONTROLFILE_CHANGE#

Type

VARCHAR2(7)
VARCHAR2(513)
VARCHAR2(3)
NUMBER
NUMBER

Type

NUMBER
VARCHAR2(9)
DATE
NUMBER
DATE
NUMBER
DATE
VARCHAR2(12)
NUMBER
NUMBER
VARCHAR2(7)
DATE
NUMBER
NUMBER

CONTROLFILE_TIME
OPEN_RESETLOGS
VERSION_TIME
OPEN_MODE
PROTECTION_MODE
PROTECTION_LEVEL
REMOTE_ARCHIVE
ACTIVATION#
SWITCHOVER#
DATABASE_ROLE
ARCHIVELOG_CHANGE#
ARCHIVELOG_COMPRESSION
SWITCHOVER_STATUS
DATAGUARD_BROKER
GUARD_STATUS
SUPPLEMENTAL_LOG_DATA_MIN
SUPPLEMENTAL_LOG_DATA_PK
SUPPLEMENTAL_LOG_DATA_UI
FORCE_LOGGING
PLATFORM_ID
PLATFORM_NAME
RECOVERY_TARGET_INCARNATION#
LAST_OPEN_INCARNATION#
CURRENT_SCN
FLASHBACK_ON
SUPPLEMENTAL_LOG_DATA_FK
SUPPLEMENTAL_LOG_DATA_ALL
DB_UNIQUE_NAME
STANDBY_BECAME_PRIMARY_SCN
FS_FAILOVER_STATUS
FS_FAILOVER_CURRENT_TARGET
FS_FAILOVER_THRESHOLD
FS_FAILOVER_OBSERVER_PRESENT
FS_FAILOVER_OBSERVER_HOST

DATE
VARCHAR2(11)
DATE
VARCHAR2(10)
VARCHAR2(20)
VARCHAR2(20)
VARCHAR2(8)
NUMBER
NUMBER
VARCHAR2(16)
NUMBER
VARCHAR2(8)
VARCHAR2(20)
VARCHAR2(8)
VARCHAR2(7)
VARCHAR2(8)
VARCHAR2(3)
VARCHAR2(3)
VARCHAR2(3)
NUMBER
VARCHAR2(101)
NUMBER
NUMBER
NUMBER
VARCHAR2(18)
VARCHAR2(3)
VARCHAR2(3)
VARCHAR2(30)
NUMBER
VARCHAR2(21)
VARCHAR2(30)
NUMBER
VARCHAR2(7)
VARCHAR2(512)

SQL> SELECT * FROM V$CONTROLFILE;


no rows selected
SQL> SELECT * FROM V$DATABASE;
SELECT * FROM V$DATABASE
*
ERROR at line 1:
ORA-01507: database not mounted
So,
the
the
will

now in nomount mode, the database SGA and Background process have been initialized only. Only
Instance is created, however, the database can not be queried as it is not initialized, as well as,
CONTROL FILES HAVE YET NOT BEEN READ, although they are present in the INIT.ORA file. They
be read in the Next Mode.

SQL> ALTER DATABASE MOUNT;


Database altered.
SQL> SELECT NAME, OPEN_MODE, LOG_MODE FROM V$DATABASE;
NAME
OPEN_MODE LOG_MODE
-------------------- ---------- -----------HARRY
MOUNTED
ARCHIVELOG
SQL> SELECT * FROM V$CONTROLFILE;
STATUS NAME
IS_ BLOCK_SIZE FILE_SIZE_BLKS
------- -------------------- --- ---------- -------------C:\HARRY\HARRY\CONTR NO
16384
430
OL01.CTL
C:\HARRY\HARRY\CONTR NO
OL02.CTL

16384

430

C:\HARRY\HARRY\CONTR NO
OL03.CTL

16384

430

Now that the Database is MOUNTED, Oracle can read the Control files and knows where all the
datafiles are present.
Control file has pointers that provide connection b/w Datafiles, Redo Logs, Archived Logs, Memory and
Last Updated SCN.
SQL> select * from v$log;
GROUP#
THREAD# SEQUENCE#
BYTES
MEMBERS ARC STATUS
FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- ---------------------------- --------1
1
23
52428800
1 YES INACTIVE
959048 23-JUN-11
3
1
25
52428800
1 NO CURRENT
1033570 25-JUN-11
2
1
24
52428800
1 YES INACTIVE
996350 24-JUN-11
SQL> select * from v$logfile;
GROUP# STATUS
---------- ------3
2 STALE
1

TYPE
------ONLINE
ONLINE
ONLINE

MEMBER
------------------------C:\HARRY\HARRY\REDO03.LOG
C:\HARRY\HARRY\REDO02.LOG
C:\HARRY\HARRY\REDO01.LOG

IS_RECOVERY_DEST_FILE
--------------------NO
NO
NO

SQL> archive log list


Database log mode
Automatic archival
Archive destination
Oldest online log sequence
Next log sequence to archive
Current log sequence

Archive Mode
Enabled
USE_DB_RECOVERY_FILE_DEST
23
25
25

So from here, we can see that the Database in Mount Mode has all the required
parameters initialized,
however the database itself is still not open to users.
MOUNT MODE IS WHERE MAINTENANCE WORK IS DONE.
SQL> ALTER DATABASE OPEN;
Database altered.
SQL> select instance_name, status from v$instance;
INSTANCE_NAME
STATUS
---------------- -----------harry
OPEN
SQL> SELECT NAME, OPEN_MODE FROM V$DATABASE;
NAME
OPEN_MODE
-------------------- ---------HARRY
READ WRITE
Now the database is open for use.
IN A NUTSHELL:
SQL> startup nomount
ORACLE instance started.
Total System Global Area
Fixed Size
Variable Size
Database Buffers
Redo Buffers

591396864
1291916
289409396
293601280
7094272

bytes
bytes
bytes
bytes
bytes

SQL> select instance_name, status from v$instance;


INSTANCE_NAME
STATUS
---------------- -----------harry
STARTED
SQL> alter database mount
2 ;

Database altered.
SQL> select instance_name, status from v$instance;
INSTANCE_NAME
STATUS
---------------- -----------harry
MOUNTED
SQL> alter database open;
Database altered.
SQL> select instance_name, status from v$instance;
INSTANCE_NAME
STATUS
---------------- -----------harry
OPEN

You might also like