You are on page 1of 21

The Oracle Startup Command

You start the Oracle database with the startup command. You must first be logged into an account that has sysdba or Sysoper privileges such as the SYS account Here then is an example of a DBA connecting to his database and starting the instance: C:\Documents and Settings>set oracle_sid=db_name C:\Documents and Settings>sqlplus "sys as sysdba" SQL*Plus: Release 10.1.0.2.0 - Production on Mon Feb 21 12:35:48 Enter password: xxxx Connected to an idle instance. SQL> startup ORACLE instance started. Total System Global Area 251658240 bytes Fixed Size 788368 bytes Variable Size 145750128 bytes Database Buffers 104857600 bytes Redo Buffers 262144 bytes Database mounted. Database opened. 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

1) 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 if you issue the startup command, then Oracle will automatically move onto the next stage of the startup, the mount stage.

4) Mounting the Database: Some forms of recovery require that the database be opened in mount stage. The control file is a binary file that tracks important database information. you might change it from the nomount to mount startup stage using the alter database command: SQL> alter database mount. . it opens and reads the control file. But does not yet open them. Oracle determines the location of the data files. such as the location of the database data files. When this is the case. use the startup mount command as seen here: SQL> startup mount If you have already started the database instance with the startup nomount command. Once the data file locations have been identified. In the mount stage.2) Starting the Oracle Instance (Nomount Stage) There are some types of Oracle recovery operations that require the database to be in nomount stage. the database is ready to be opened. To put the database in mount stage. you need to issue a special startup command: startup nomount. as seen in this example: SQL> startup nomount 3) The Mount Stage When the startup command enters the mount stage.

. 7) Opening the Database in Restricted Mode You can also start the database in restricted mode. SQL> alter system enable restricted session. We use the startup restrict command to open the database in restricted mode as seen in this example. When Oracle opens the database.Put the database in restricted session mode. even though the database is technically open. it accesses all of the datafiles associated with 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.5) The Open Oracle startup Stage The last startup step for an Oracle database is the open stage. Oracle makes sure that all of the database Data files are consistent. Restricted mode will only allow users with special privileges To access the database (typically DBA’s). Once it has accessed the database data files. SQL> startup restrict You can take the database in and out of restricted mode with the alter database command as seen in this example: -. 6) Opening the Oracle Database To open the database.

they must be manually disconnected from the database by exiting gracefully or by the DBA with the “alter system kill session” command.Take the database out of restricted session mode. disk failure or some other catastrophic event from which the database cannot recover. 8) Problems during Oracle Startup The most typical reason for a database not starting up is a prior database crash. SQL> alter system disable restricted session. you have to go into database recovery mode to start your instance. In these cases. Note: Any users connected to the Oracle instance when going into restricted mode will remain connected. . a data corruption.-.

they have to be created and this is generally the job of the DBA. you can use the SQL*Plus desc command to see its structure as seen in this example: SQL>desc books . Creating tables is done with the create table command. author_name VARCHAR2 (40). The create table command does the following: * Defines the table name * Defines the columns in the table and the data types of those columns * Defines what tablespace the table resides in (optional) * Defines other characteristics of the table (optional) Let’s look at the create table command in action: Connect scott/tiger CREATE TABLE books (book_id NUMBER PRIMARY KEY.---------------------Creating Tables---------------------------Before tables can be used. Once you create a table. book_name VARCHAR2 (30). book_isbn VARCHAR2 (20) ) TABLESPACE users.

-----------BOOK_ID NOT NULL NUMBER BOOK_ID_SEQ NOT NULL NUMBER BOOK_NAME VARCHAR2 (30) AUTHOR_NAME VARCHAR2 (40) BOOK_ISBN VARCHAR2 (20) TABLESPACE users. Some things you might find you need to do with the alter table command include: * Moving a table to another tablespace * Adding a column to the table * Dropping a column from the table * Changing a column name * Modify existing constraints or add new constraints For example.Name Null? Type ----------------------------------------. we might want to move the BOOKS table to another tablespace.-------. . ------------------------------Altering Tables-------------------------Having created tables. This is done with the alter table command. The alter table command allows us to do this easily: SQL>ALTER TABLE books MOVE TABLESPACE new_users. you will find there are times that you will want to alter them in some respect.

We demonstrate renaming and dropping a column in the following example. In this case. drop and re-create the table which can have a horrible impact if it’s a big table in a production environment. You can add multiple columns too as seen in this example where we add a column called BOOK_PUB_NO and * BOOK_ALT_TITLE to the BOOKS table: SQL>ALTER TABLE books ADD ( book_pub_no NUMBER. you can rename or drop columns from a table with the alter table command. we are adding a column called BOOK_PRICE to the BOOKS table. It used to be in Oracle that renaming or removing a column from a table was a big deal. This column is a number data type: SQL>ALTER TABLE books ADD book_price NUMBER. We discussed primary key constraints earlier in this section. You actually had to save the data. Now.You can add a column to a table with the alter table command. book_alt_title VARCHAR2 (50) ). In the second example we drop the BOOK_PUB_NO column: SQL>ALTER TABLE books RENAME COLUMN book_isbn TO isbn_number. . First we rename the BOOK_ISBN column to ISBN_NUMBER. SQL>ALTER TABLE books DROP COLUMN book_pub_no.

we should take a moment to see how you can rename a constraint with the alter table command: SQL>ALTER TABLE books RENAME CONSTRAINT pk_books TO pk_book. -----------------------------Dropping Tables---------------------------The drop table command allows you to drop tables from your Oracle database. SQL>DROP TABLE books. Dropped a table by accident????? In Oracle Database 10g the flashback table command will recover the table and many of the objects associated with the table.Oracle actually has a number of different constraint types that we will cover in more detail later in this section. You can recover a table that you have dropped from the recycle bin using the flashback table command as seen here: SQL> DROP TABLE books. SQL> FLASHBACK TABLE books TO BEFORE DROP. . Oracle 10g has a recycle bin. kind of an old tables retirement home. Some things are not recovered like bitmap join indexes and foreign key constraints. However.

---------------------------See the indexes for a table-----------------It is not unusual to wonder what indexes a specific table might have. Owned by two different users (Scott and Poll). It draws on the information in the dba_ind_columns data dictionary view: SQL> column table_owner format a15 SQL> column table_name format a20 SQL> column index_name format a20 SQL> column column_name format a20 . and what columns in the table are assigned to those indexes. table_name. A good exercise for you might be to try to join this query with a view like DBA_EXTENTS and figure out just how big these tables are allocated. we use the dba_tables view to find the owner and tablespace name of the EMP table. we have two tables called EMP. The following query will provide this information to you.--------------------Table and tablespace location--------------------Finding out who owns a table and what tablespace it is in is a pretty common need of the DBA. tablespace_name 2 from dba_tables 3 where table_name='EMP'. Both tables are contained in the USERS tablespace. OWNER -------------SCOTT POLL TABLE_NAME -------------------EMP EMP TABLESPACE_NAME -------------------------USERS USERS As we can see from this query. SQL> select owner. In this query.

index_name.SQL> Select owner. We will then look at how you can use roles to make user administration much easier. which you use to grant system privileges. followed by object privileges. This might include such things as being able to actually connect to the system. First we will look at system privileges.-------------------. table_name. In the next sections we will discuss the grant command. we probably want that user to be able to do something in our database. * Granting Oracle System Level Privileges: The grant command is used to grant system level privileges. or it might include the ability to do things like create objects in schemas other than your own schema. table_name.-------------SCOTT EMP PK_EMP ---------------EMPNO --------------------------Grant user privileges------------------------Once we have created a user. they can not even connect to the database. Also the revoke command is used to revoke privileges from users. A created user has no privileges. column_position 4 Where owner=’SCOTT’ 5 AND table_name=’EMP’. TABLE_OWNER TABLE_NAME INDEX_NAME COLUMN_NAME --------------. . * Oracle System Privileges: System privileges allow the user to perform system level activities. In this section we will address this problem by learning how to give users the privileges they need to actually get some work done. column_name 2 FROM dba_ind_columns 3 Order by owner.

The grant command is pretty simple to use. it will not be able to do anything until you have granted it a basic set of privileges. Typically you would always grant the create session privilege so that the user can connect to the database. create index) * Perform DBA activities. you just need to know what privilege you want to grant and who you want to grant that privilege to. . like backup the database (SYSDBA. SYSOPER) * Alter session related parameters (alter session) Basically. For example you grant system level privileges to a user so that they can: * Connect to the database (create session) * Create objects (create table. even if you create a user account.System level privileges are those privileges that you need to actually do something on the system.

the shutdown command comes in many forms. This is because the normal shutdown waits for everyone to complete their work and then logoff in an orderly fashion. and many Oracle DBA's ensure a swift clean shutdown this way.------------------Oracle shutdown command Concepts------------You might take the database down to make configuration changes. aborting the sessions. de-allocates the SGA and terminates the background processes. As you might guess. and a shutdown immediate to close cleanly: SQL> shutdown abort SQL> startup SQL> shutdown immediate Oracle Normal Shutdown: A normal shutdown of an Oracle database is actually rarely used. Oracle has three shutdown modes: * Normal (default) .terminates all sessions and does a rollback on all uncommitted transactions * Abort .waits for in-flight work to complete * Immediate .aborts all sessions. When a normal shutdown occurs. we use the shutdown command. The "normal" and "immediate" modes can take a long time in you have in-flight transactions. restarting to allow warm start rollback of the aborted transactions. When it’s time to bring your database down. the database is closed in a normal  . leaving current DML in need of rollback. for a backup or to upgrade Oracle software.

Here is an example of the use of the normal shutdown command. then rollback any uncommitted transactions. Oracle Shutdown Immediate: Perhaps the best way to initially shutdown the database is the shutdown immediate command. In these cases. It will simply wait forever until you manually kill those sessions. and all changes made in the database are flushed to the database data files. This command will prevent any new logins. Because of this. A clean shutdown is one that is prepared to come back up without delay. or there are times that Oracle processes become “zombied” (this is where Oracle thinks someone is connected to the database but they really are not). you must perform a recovery by taking the actions required to stand again.  . In the process of bringing down the database. instead. If. you have landed in a way that prepares you to make another jump. which we will discuss in the next sections. This is known as a “clean shutdown”. Most of the time this is not practical… there always seems to be someone who has left for vacation and who forgot to log out.manner. it can not come back up without first recovering itself. we often recommend the shutdown immediate or shutdown abort commands. SQL> shutdown When you execute a shutdown. A dirty shutdown is one that lands on its back. Oracle will flush all the changes in memory out to the database data files. you are in no position to make another jump. Think of it this way: if you jump into the air and land on your feet. instead. This makes database startup quicker because the database is in a consistent state. the database will never come down. you jump and land on your back. and then bring down the database.

and during your DBA years you will find more than a few occasions to use the shutdown abort command.  A shutdown abort should not be your first shutdown method of choice. but there are times when it can hang and fail to shutdown the database. and this can result in a longer time to start the database back up. This makes database startup quicker. Here is an example using the shutdown abort command: SQL> shutdown abort ----------------------Oracle Database Files Concepts---------------The final components of the Oracle architecture are the physical files where our information resided on disk. Oracle Shutdown Abort Command: The shutdown abort command is pretty much a guaranteed way to get your database to shutdown. Still. there may be times when you must force the database down. Here is an example of shutting down a database with the shutdown immediate command: SQL> shutdown immediate The shutdown immediate command will work most of the time. just like a regular shutdown does. Oracle has several types for data files.Oracle will flush all the changes in memory out to the database data files too. In these cases. each for a different purpose: . It’s a “hard crash” of the database. you can’t really hurt the database using the shutdown abort command. the shutdown abort command is called for.

Database data files are only written to by the DBWR processes that we introduced you to earlier (There is an exception or two to this statement.* Database data files * Control files * Online redo logs * Parameter files * Other database related files *****************Database data file******************* Database data files are physical files stored on disk. These database data files are associated with Oracle “tablespaces”. but for now. These files are used to store data on disk. which are “logical” containers for tables and indexes. . assume that this point this true).

We will cover the topic of online . data about the database log files. The control file contains the database name. Because the control file is so important. Later in this book. we will demonstrate how to do this.*******************Control files******************** The Control File of the database is a binary file that contains a great deal of database information. you have lost a lot of data. ***************Online redo logs concepts************** Think of the online redo logs like a tape recorder that records every change in the Oracle database. As changes occur. If this backup tape was several days ago. Many times. they are regularly recorded in the online redo logs. just like you might record a movie on your VCR. and re-apply lost transactions back into the database. Oracle can “replay” the saved transactions in the online redo logs. When you have more than one control file. In the event that a disk crashes. It is a good practice to put these multiple copies on different disks to protect the control file. this means that Oracle can recover from a crash without the DBA having to do anything other than just telling the database to startup. Oracle cannot function without valid control files. then you are said to be multiplexing your control files. you may have to replace the disk and restore the disk data from a backup tape. Oracle allows you to maintain duplicate copies of the control file. Fortunately.

it’s a good idea to have multiplexed copies of the Online redo logs. Each copy is called a member. Oracle allows you to define multiple copies of these files. The reason we call them groups is that there can be mirrored copies of the online redo log files in each group. Each of these individual online redo logs is known as an online redo log group. Oracle allows you to have a manual parameter file (Called a PFILE) or a server-side parameter file (called a SPFILE). Like control files. where to write trace files. . where to find the control files. In most cases the database will not start without a parameter file. The parameter file you configure how much RAM the database is going to use.ora) contains configuration information for the database to use at startup time. At a minimum. Oracle will write redo to the first log. Oracle requires that you have two online redo logs assigned to the database. and when the first log is full. Each redo log group can have one or more members.redo log files and how they relate to database recovery in later chapters of this book. and a whole host of other information. *************Oracle Parameter file Concepts************ The parameter file (sometimes called init. Oracle will switch to the second log and write the same redo.

or based on specific user operational commands. * Oracle Trace Files .The Oracle Database software includes the basic programs that allow the database to function. The following table is a list of the most common files and their general purpose. . Networking configuration files . These can be created as a result of a database crash.ora.ora and listener. * Oracle Database Software Binaries .This is the general log file for each Oracle database. These include files such as tnsnames.***********Other Database Related Files************* When working with the Oracle database you will be introduced to a number of different kinds of files. an unexpected but non-fatal database failure.These files are used to configure the different network components of the Oracle database. * Alert log . a session failure.Created by Oracle in a number of different situations.

. * PMON . The possible multiple DBWR processes in RAC must be coordinated through the locking and global cache processes to ensure efficient processing is accomplished. or when the cache is full and space has to be made for more blocks. PMON monitors and restarts any failed dispatcher or server processes. In RAC. PMON’s role as service registration agent is particularly important.System Monitor process recovers after instance failure and monitors temporary segments and extents. If MTS (also called Shared Server Architecture) is being utilized. * DBWR .*********Oracle Database Required Processes********** Here are some of the most important Oracle background processes: * SMON . SMON in a non-failed instance can also perform failed instance recovery for other failed RAC instance. each RAC instance has its own LGWR process that maintains that instance’s thread of redo logs. * LGWR . Generally.Database Writer or Dirty Buffer Writer process is responsible for writing dirty buffers from the database block cache to the database data files.In RAC.Log Writer process is responsible for writing the log buffers out to the redo logs.Process Monitor process recovers failed process resources. DBWR only writes blocks back to the data files on commit.

the various ARCH processes can be utilized to ensure that copies of the archived redo logs for each instance are available to the other instances in the RAC setup should they be needed for recovery. In RAC.* ARCH – The optional Archive process writes filled redo logs to the archive log location(s). .