Wednesday, October 30, 2013

Starting and Stopping the Database

When an Oracle database is started, it goes through four different and distinct stages:

Shutdown: When the database and instance are shut down, they are at rest. There are no processes present, no memory allocated, nothing is going on. It is important to note that even though the database/instance may be shut down and closed, other Oracle processes (like the listener or OEM agents) maybe still running.

Nomount: When the database is in nomount mode, the instance has been started. Thus, processes have been started and memory allocated.

Mount: When the database is in mount mode (or mounted), the instance is started and the database has opened the control file. The control file is read, but is contents are not validated.

Open: When the database is opened, the control-file contents have been validated against the physical database. The datafiles are all confirmed to be present, and they are opened. Oracle will then analyze the datafiles to determine if the database is in a consistent state.If the database is not in a consistent state, some form of recovery will be required.Typically, the form of recovery required, crash or instance recovery, does not require any DBA involvement. If instance recovery is not possible, then media recovery is required.Media recovery requires the application of backups and recovery operations to bring the database current to the point of failure (if this is possible). The principal determining factors for media recovery is the presence of the needed datafiles and the availability in the online redo logs of the redo needed to bring those files current. If either of these conditions does not exist, then media recovery is required.

Database shutdowns occur in much the same way as startups, except in reverse. There are two different kinds of shutdowns, however: consistent and inconsistent.

Consistent shutdown: If your database shutdown is a consistent shutdown, then the database datafiles and the database control file will be synchronized upon shutdown. The dirty buffers in the database buffer cache will be flushed out to the database datafiles, making them consistent. A consistent shutdown is a nice, tidy shutdown.

Inconsistent shutdown: An inconsistent shutdown is another term for a mess. When our database is shut down in an inconsistent manner, it is in a indeterminate state and will require some form of recovery (typically instance recovery, which requires no DBA intervention) when it is restarted. Inconsistent shutdowns, however bad they might sound, often are the only way to shut down a database in a timely manner.


Starting and Stopping the Database

During backup and recovery operations, you will need to know how to start up and shut down your database correctly. To start up the database in any of the modes described in the previous section, you will use the startup command or the alter database command,as required. To stop the database, you will use the shutdown command. Typically, database startup operations are performed from SQL*Plus or Oracle Enterprise Manager.
The startup command This command is used to start the instance and/or database when the database is in a shutdown state only. The startup command can be used to completely open the database, as shown in this code snippet:

SQL> startup

The startup command also has options that you can use to indicate that you want Oracle to start the startup operation at a certain point. For example, you can indicate that you want the instance to be started only by using the startup nomount command:

SQL> startup nomount

Or perhaps you want to start the instance and mount the database. In this case, the command would be as follows:

SQL> startup mount

Sometimes you want to shut down the database and start it up in one command. You can use the startup force command to perform this action. Note that the startup force command will shut down your database in an inconsistent manner , and some operations (such as putting the database in ARCHIVELOG mode) will not complete successfully if the database was shut down in an inconsistent manner. Here is an example of the startup force command:

SQL> startup force

The shutdown command The shutdown command does what it says; it shuts down the database.
As with the startup command, it comes with a few options. First there is the plain-Jane shutdown command, which will shut down the database if absolutely nothing is going on and if absolutely no one is logged in. You can guess how often those conditions happen in reality! Until its conditions are met, the shutdown command will just sit there, waiting for its opportunity to shut down the database.
Here is an example of the shutdown command:

SQL> shutdown
If waiting is not your forte, then you may want to try the shutdown immediate command. The shutdown immediate command will prevent new logons, roll back any uncommitted transactions, and then bring the database down. It’s a consistent-shutdown, no-waiting approach to stopping the database and lots of DBAs like it. Here is an example:

SQL> shutdown immediate

The cousin of shutdown immediate is shutdown transactional (we are not sure if it’s a first cousin or second cousin; Oracle has not defined this within the body of the Oracle documentation yet). The main difference here is that the shutdown transactional command will wait for active transactions to complete (commit) before shutting down those sessions. As a result, the shutdown transactional command can take a while longer to complete its task, but on the positive side, users might be a little bit happier (if they are actually able to be happy anytime the database comes down). Here is an example of the shutdown transactional command:

SQL> shutdown transactional

The bad boy of database shutdowns is the shutdown abort command. If you want your database
to come down without debate, this is the way to do it. This is like pulling the power cord on your database; it is a crash of the database, shutting it down in an inconsistent manner.
Here is an example of the shutdown abort command:

SQL>shutdown abort

The alter database command The alter database command is used to move the instance/database from one state to another. For example, if the instance was started with the startup nomount command, you may want to mount the database. To do so, you would use the alter database mount command, as shown here:

SQL>alter database mount;

Understanding the Oracle Database as It Relates to Backup and Recovery. If the database is already mounted and you want to open it, then the alter database mount command would be appropriate, as shown in this example:

SQL>alter database open;

No comments: