You are on page 1of 58

DBA Exercises

Q: What are the Oracle Architectural components?


Q: What are the Oracle Memory Components?
Q: What is the Server Parameter File?
Q: What is the Parameter File?
Q: How do you use the init.ora file?
Q: What is the System Global Area (SGA)?
Q: What is the Shared Pool in SGA?
Q: What is the Buffer Cache in SGA?
Q: What does the Buffer Cache hold in SGA?
Q: What are the differences between the Library Cache and Dictionary Cache?
Q: What is the Redo Log Buffer in SGA?
Q: Describe the Large Pool component in SGA?
Q: Describe the Multi-threaded Server process?
Q: What are PGA and UGA?
Q: Describe the log writer background process (LGWR)?
Q: How often LGWR writes user’s entries to the Online Redo Log Buffer files?
Q: Describe the Checkpoint process?
Q: How do you automatically force the Oracle to perform a checkpoint?
Q: What is the Recovery Process?
Q: What is the Lock Background Process?
Q: How does the Archive Process work?
Q: How do you configure your database to do an automatic archiving?
Q: What is the System Monitor Process?
Q: Describe the Program Monitor Process Job?
Q: What are the differences between the SPFILE and PFILE startup?
Q: What is the controlfile?
Q: How do you backup your database controlfiles?
Q: What does a controlfile contain?
Q: Describe the password file?
Q: How do you create a password file?
Q: Describe the Online Redo Log file?

Create a data dictionary


You can create or recreate a data dictionary, by running the catalog.sql script from within
SQL*Plus while connected to SYS or any users as the administrative privilege SYSDBA. This script
is located at %ORACLE_HOME%. Within the catalog.sql script, the following scripts are called.
CATAUDIT.SQL that creates the sys.aud$ dictionary table,
CATLDR.SQL that creates views for the SQL*Loader tool,
CATEXP.SQL that creates views for the IMPORT/EXPORT utilities,
CATPART.SQL that creates views for partitioning Oracle option,
CATADT.SQL that creates views that support user-defined types and object components.

STANDARD.SQL that creates the STANDARD package, which stores all Oracle datatype such as
VARCHAR2, BLOB and built-in SQL functions such as SUM, DECODE, etc.
SQL> @catalog.sql
DICTIONARY view
The objects of a database will be stored in a place call repository or dictionary. All the database
objects, access security to an object, objects’ relationships, etc can be viewed from repository.
Now, let's to get the list of all dictionary tables that you created from the catalog.sql.
SQL> SELECT table_name FROM dictionary ORDER BY 1;

ALL_, DBA_, and USER_ dictionary views


You use the ALL_ dictionary views such as ALL_TABLES, etc to query all user tables plus all the
granted tables. You use the DBA_ dictionary views such as DBA_TABLES to display the entire
database tables and USER_ dictionary view such as USER_TABLES to list only tables that created
by current user.
Query the count for the number of views that you have in the dictionary for the ALL_, DBA_,
and USER_ dictionary views.

SQL> SELECT SUBSTR(table_name,1,4) , count(1)


FROM dictionary
GROUP BY substr(table_name,1,4)
HAVING substr(table_name,1,4) in ('DBA_','ALL_','USER');
DBA_VIEWS view
You use the DBA_VIEWS view to query all sql script, status, etc. The status column shows that if
a view is INVALID or VALID. If the view is invalid you can compile the view or correct the error.
Set the LONG size to 9999 and the pagesize to 100 and then query the DBA_VIEWS dictionary
view where the VIEW_NAME value is DBA_TABLES.
SQL> SET LONG 9999
SQL> SET PAGESIZE 100
SQL> SELECT text FROM dba_views WHERE view_name = 'DBA_TABLES';
This is an example the DBA_TABLES view source code. Notice that the view can be quite
complex.
V$PWFILE_USERS view
The LOGON_REMOTE_PASSWORD parameter set to the EXCLUSIVE or SHARED value enforces
the user enter a password. A DBA can logon to the database as SYSDBA or SYSOPER privilege if
he knows the password.
Use the V$PWFILE_USERS view to query the users that are in the database password file.
SQL> SELECT * FROM V$PWFILE_USERS;
Notice that any object that is created by anyone logging in as SYSDBA or SYSOPER will be owned
by the SYS user.

V$PARAMETER view
The V$PARAMETER view shows all the parameters value in the database.
Query the V$PARAMETER or V$SYSTEM_PARAMETER view to list information about the
modified parameters that contain the word SHARE.
SQL> SELECT * FROM V$PARAMETER WHERE NAME LIKE '%share%';
Also, you can use the SHOW PARAMETER command. For example:
SQL> SHO PARAMETER share;

V$SGA view
Query the V$SGA view to list information about the SGA parameters.
SQL> SELECT * FROM V$SGA;
SHOW PARAMETER
If you don’t want to use the V$PARAMETER view, then use the SHOW PARAMETER command
(SHO …). It is easier and less typing.
Also, you can use the SHOW PARAMETER command to list the sga information.
SQL> SHOW PARAMETER sga

V$OPTION view
The V$OPTION view shows the installation options Use this view to make sure that you are not
violating any option license agreement.
Query the V$OPTION view to check if the partition option was selected or not.
SQL> SELECT * FROM V$OPTION WHERE parameter like 'Partition%';
V$PROCESS view
The V$PROCESS view contains the database background processes and server processes.
Use the V$PROCESS view to list information about all the database processes.
SQL> SELECT * FROM V$PROCESS;
V$SESSION view
The V$SESSION view shows all the sessions that are inactive or active. A DBA may use this view
to list the username, sid, and serial# of a user to kill it’s session.
Use the V$SESSION view to list information about all of the database inactive and active
sessions.
SQL> SELECT * FROM V$SESSION;

V$VERSION view
Oracle contains so many different components. The V$VERSION view is an excellent view to
display all of its component releases.
Use the V$VERSION view to list all of Oracle's component releases.
SQL> SELECT * FROM V$VERSION;
V$INSTANCE view
Most of the time, you may have multiple instances in your server or machine. Using the
V$INSTANCE view, ensure that if you are in the right instance before performing a database
structure changes.
Use the V$INSTANCE view to list the instance information such as number of instances, instance
name, database version, archive mode, database status, etc.
SQL> SELECT thread#, instance_name, version, archiver, database_status
FROM v$instance;
V$THREAD view
If you have RAC configured, the V$THREAD view tells you that what instance you are in.
Query the V$THREAD view to list the status of your parallel servers.
SQL> SELECT * FROM V$THREAD;
V$PARAMETER view
Query the V$PARAMETER view to list information about the database controlfiles.
SQL> SELECT value FROM V$PARAMETER WHERE name = 'control_files';
V$CONTROLFILE view
The V$CONTROLFILE view shows the location of the controlfiles and the status of it.
Query the V$CONTROLFILE view to list information about the database controlfiles.
SQL> SELECT * FROM V$CONTROLFILE;
Notice that if the controlfile name cannot be determined then the STATUS value is INVALID;
otherwise, it will be NULL.
V$DATABASE view
If you have multiple database on your server, the V$DATABASE view show what database you
are login plus lots of information about the database such as controlfile information.
Query the V$DATABASE view to list information about the database.
SQL> SELECT * FROM V$DATABASE;
Query the V$DATABASE view to list information about the control files of the database, such as
CONTROLFILE TYPE, CONTROLFILE CREATED, CONTROLFILE SEQUENCE NUMBER, and
CONTROLFILE CHANGE NUMBER.
SQL> SELECT controlfile_type as type, controlfile_created as created,
controlfile_sequence#, controlfile_change#
FROM v$database;
Notice that this view gives information that is also stored within the control file.
V$DATAFILE view
The V$DATAFILE view show information about when a datafile was created, what is its status,
when was the last SCN, what is its block size, etc.
Query the V$DATAFILE view to list information about the datafile names.
SQL> SELECT name FROM V$DATAFILE;

Query the V$DATAFILE view to list information about the datafiles' creation, status, checkpoint,
number of blocks, and block size.
SQL> SELECT creation_time created, status,
checkpoint_change#, blocks, block_size
FROM v$datafile;
V$LOGFILE view
Query the V$LOGFILE view to list information about the log files.
SQL> SELECT * from V$LOGFILE;

Shutdown and startup a database


Shutdown the database with the IMMEDIATE option and then start the instance with the
NOMOUNT option.
IMMEDIATE option
The IMMEDIATE option means not to wait for a user to log off and roll back uncommitted
transactions, then shut down the instance and close the database.
NOMOUNT option
The NOMOUNT option starts the instance without mounting the database. It means that all of
the memory structure and background processes are in place, but no database is attached to
the instance.
SQL> SHUTDOWN IMMEDIATE
SQL> -- to start…
SQL> CONNECT / AS SYSDBA
SQL> STARTUP NOMOUNT PFILE=initORCL.ora
Mount a database
The MOUNT option tells the instance the database’s name and its components such as its
datafiles location, online redo log files, maximum number of datafiles, maximum number of
instances, etc. Now, mount the database and then open it.
Don't forget to check your alert file. The alert log file stores information that is extremely useful
in order to know the health of the database. It records the starting and stopping of the
databases, creation of new redo log files, datafiles, tablespaces, and most importantly, the
Oracle system error messages. It is located in the BACKGROUND_DUMP_DEST parameter.
SQL> ALTER DATABASE MOUNT;
When the database is mounted, it does mean that it is open. You should open the database in
order to access to its objects (tables, procedures, functions, views, etc). A DBA will start a
database with the MOUNT option to perform maintenance on it. You will be able to perform the
ALTER DATABASE sql statement such as ALTER DATABASE NOARCHIVELOG.
SQL> ALTER DATABASE OPEN;
Now, shutdown the database with the NORMAL option and then start the instance with the
MOUNT option. The following shows how this works.
NORMAL option
The NORMAL option will wait for users to log out and then, it will close the database and
shutdown the instance.
MOUNT option
The MOUNT option, starts the instance, reads the control file, and attaches the database, but
does not open it.

SQL> SHUTDOWN NORMAL


SQL> -- start
SQL> CONNECT / AS SYSDBA
SQL> STARTUP MOUNT PFILE=initORCL.ora
Open a database
Now, open the database. We must open the database since in the STARTUP command, we used
the MOUNT option.

Notice that the MOUNT option starts the instance, reads the control file, and attaches the
database, but does not open it.
SQL> ALTER DATABASE OPEN;

Shutdown the database with the TRANSACTIONAL option and then start the instance and open
the database. The following shows how this works.
TRANSACTIONAL option
The TRANSACTIONAL option tells oracle not to wait for a user to log off, but wait for the client to
end the transaction that is in progress, then shut down the instance and close the database.
OPEN option
The OPEN option starts the instance, reads the control file, attaches the database, and then
opens it. Notice that the OPEN option is a default option. You do not need to use the OPEN
option, since it is the default option.
SQL> -- Shutdown
SQL> SHUTDOWN TRANSACTIONAL
SQL> -- start the database…
SQL> CONNECT / AS SYSDBA
SQL> STARTUP OPEN PFILE=initORCL.ora
FORCE option
Use the FORCE option to shutdown and then startup the database. This should be your last
resort when you cannot shutdown your database. The following shows how this works.

Make sure that you have already patiently waited for the database to be shutdown.
SQL> -- Shutdown and Startup
SQL> STARTUP FORCE PFILE=initORCL.ora
READ ONLY mode
You can also open your database on the READ ONLY mode. In the READ ONLY mode, you cannot
insert, update, or delete any records. Nor are you allowed to create, alter, or drop any tables.
Also, you can't change the structure of the database by adding tablespaces or datafiles.
SQL> SHUTDOWN IMMEDIATE
SQL> -- start database…
SQL> CONNECT / AS SYSDBA
SQL> STARTUP OPEN READ ONLY

Now, let's connect to SQL*Plus as the scott user.


SQL> CONNECT scott/tiger

Query the department table.


SQL> SELECT * FROM dept;

Insert a record into the department table.


SQL> INSERT INTO dept VALUES (50, 'EDUCATION','VIRGINIA');
Notice that you are not able to insert any record.

ABORT option
Shutdown the database with the ABORT option. The ABORT option tells Oracle not to wait for a
user and do not roll back for any transaction and shutdown the instance. The following shows
how this works.
SQL> CONNECT system/manager AS sysdba
SQL> -- Shutdown the database
SQL> SHUTDOWN ABORT

Multiplexing controlfiles

In this exercise you will learn how to multiplex control files, backup controlfiles, components of
controlfile and more. You multiplex the controlfiles to protect the database in a case if there
was a lost of its controlfiles. You should make sure that keep multiple copy of each controlfile at
different hard disk. Note that if you lose your controlfile, you will not able to open it unless you
create it. It is not easy to create a control file if you don’t know the database’s structure. Make
sure that you always have a copy of your controlfile with a trace option. The following is an
example of how you can keep a backup of your controlfile with the TRACE option.
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
Connect to a database
First, let's connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
List all the controlfiles
Query the V$CONTROLFILE view to list all of the controlfiles in the database.
SQL> SELECT *
FROM v$controlfile
/
Let us add one more controlfile to the list.
Shutdown a database
Shutdown the database.
SQL> SHUTDOWN IMMEDIATE
Copy a controlfile
Copy a controlfile and name it CONTROL04.CTL. Make sure that in real practice, you copy the
controlfile into a different hard disk. So, in the case if one hard disk failure due to a media failure
the other controlfile be secure.
SQL> HOST COPY \par C:.CTL \par C:.CTL
Edit parameter file
Open the INIT.ORA file located in the PFILE directory.
(%ORACLE_BASE%.ora)

Edit the file and add the CONTROL04.CTL file to the control_files list.
Change from:
control_files=("C:.ctl",
"C:.ctl",
"C:.ctl")
To:
control_files=("C:.ctl",
"C:.ctl",
"C:.ctl",
"C:.ctl")

Then, save and close the file.


Connect back to database
Connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
Start a database
Startup the database with the parameter file (INIT.ORA) that you just edited.
SQL> STARTUP OPEN
PFILE=%ORACLE_BASE%.ora

List all the controlfiles


Query the V$CONTROLFILE view to list all of the controlfiles in the database.
SQL> SELECT *
FROM v$controlfile
/
The controlfile was added. That was how you can multiplex your controlfiles.
Backup a controlfile
Now, let us see how we can backup the controlfile. You don’t need to backup all your
controlfiles since there are exactly identical.

Before making backup, let's first create a directory named c:and then backup the controlfile into
it.
SQL> HOST MKDIR c:
SQL> ALTER DATABASE BACKUP CONTROLFILE
TO 'c:_ddmmyyyy.ctl'
/
Notice that the ddmmyyyy is the current date ex: 25052003, it is there to let you know the date
you backed-up the controlfile.
Backup database structure
It is advisable to backup the CONTROLFILE anytime we change the structure of our database
such as adding or dropping tablespace, datafile, etc.
SQL> ALTER DATABASE BACKUP CONTROLFILE TO TRACE
/
What is in a controlfile?
Now, check to see how a controlfile is divided into several sections.
SQL> SELECT * FROM v$controlfile_record_section
/
Notice that each section stores different information about the database with different record
sizes. From the above query, you see how many records were used in each section.

Reading the ALERT file


In this exercise, you will learn how to read the ALERT file. We will also look at the trace file when
we use the ALTER DATABASE BACKUP CONTROLFILE command with the TRACE option.
View Alert file
Open an alert file. It is located at
$ORACLE_BASE/admin/<database name>/bdump.
Top Part of Alert file
The following is a example of top part of the ALERT file. Pay careful attention to the following
example of top part of the ALERT file. It shows the location of the ALERT file, the date and time
the database started, Oracle version, and some information about the Operating System.
/*
Dump file c:i.LOG
Fri Mar 29 11:50:55 2002
ORACLE V9.0.1.1.1 - Production vsnsta=0
vsnsql=10 vsnxtr=3
Windows 2000 Version 5.0 Service Pack 2, CPU type 586
Starting up ORACLE RDBMS Version: 9.0.1.1.1
*/
Check for any of the system parameters
We can use the ALERT file, to check for any of the system parameters. Remember, the default
parameter values are not included in the ALERT file. The following is an example of the system
parameters included in the ALERT file. You can see the number of processes, the shared pool
size, along with the location of control files, and the block size, etc.
/*
System parameters with non-default values:
processes = 150
shared_pool_size = 46137344
large_pool_size = 1048576
java_pool_size = 33554432
control_files = c:i.CTL,
c:i.CTL,
c:i.CTL
db_block_size = 4096
db_cache_size = 33554432
compatible = 9.0.0
remote_login_passwordfile= EXCLUSIVE
instance_name = school
dispatchers = (PROTOCOL=TCP)(SER=MODOSE),
(PROTOCOL=TCP)(PRE=oracle.aurora.server.GiopServer),
(PROTOCOL=TCP)(PRE=oracle.aurora.server.SGiopServer)
background_dump_dest = c:i
user_dump_dest = c:i
core_dump_dest = c:i
sort_area_size = 524288
db_name = school
open_cursors = 300
*/
Check for Background Process
We can also use the ALERT file, to check the process ID that was assigned to a background
process, such as the DB writer process (DBWn), the LOG writer process(LGWR), etc. This
generated list indicates that the background processes running in the database are successfully
loaded with their associated Process ID (PID) number.
/*
PMON started with pid=2
DBW0 started with pid=3
LGWR started with pid=4
CKPT started with pid=5
SMON started with pid=6
RECO started with pid=7
*/
Archived information
In using the ALERT file, we can also find the date and time that a Redo Log file was successfully
archived or was not able to be archived. The following example shows the Online redo log group
#1 was successfully archived. We will learn about the Online Redo Log file and archiving in the
next few Hands-On exercises.
/*
Thu Jul 18 13:05:32 2002
ARC0: Beginning to archive log 1 thread 1 sequence 200
*/
Check the Frequency of the checkpoint process
The ALERT file, can also be used to check the frequency of the checkpoint process. The
following example shows that the checkpoint process has problems when attempting to
complete it's task. We will learn about the checkpoint process in the next few Hands-On
exercises.
/*
Thu Jul 18 13:05:28 2002
Thread 1 cannot allocate new log, sequence 201
Checkpoint not complete
Current log# 1 seq# 200 mem# 0: C:_1_YMCCM600.LOG
*/

System Error Messages


In using the ALERT file, we can locate system error messages and more. The following sample
indicates that there is a problem with the DB Writer, and it will tell us that we can find out more
about the problem in the schoolDBW0.TRC trace file.
/*
Fri Jun 21 13:27:56 2002
Errors in file c:i.TRC:
ORA-01157: cannot identify/lock data file 11 - see DBWR trace file
ORA-01110: data file 11: 'C:DEPT30TS_01.DBF'
ORA-27041: unable to open file
OSD-04002: unable to open file
O/S-Error: (OS 3) The system cannot find the path specified.
*/

Now, let's look at the backup controlfile which was created with the TRACE option. The reason
we may want to backup the controlfile with the TRACE option is if we lost all of the
controlfile(s), we can use the trace file to rebuild it. It is a good idea to always have a backup of
the controlfile with the TRACE option when you change the database structure. The following is
an example of the backup of a controlfile using the TRACE option.
/*
STARTUP NOMOUNT
CREATE CONTROLFILE REUSE DATABASE "SCHOOL" NORESETLOGS ARCHIVELOG
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 452
LOGFILE
GROUP 4 'C:I_01.LOG' SIZE 500K,
GROUP 5 'C:I_02.LOG' SIZE 500K
DATAFILE
'C:I.DBF',
'C:I.DBF',
'C:I.DBF',
CHARACTER SET WE8MSWIN1252
*/

Changing the database mode


In this exercise you will learn how to change the database mode, such as SUSPEND, RESUME,
RESTRICTED SESSION, and QUIESCE RESTRICTED.
Connect to a database
Connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
SUSPEND mode
First, change the database to the SUSPEND mode.
SQL> ALTER SYSTEM SUSPEND
/
Now, the system is completely in the halted mode. No sessions can do any tasks on it.

To check that, open another session and connect as the ISELF user and check how that affects
the ISELF session.
SQL> CONNECT iself/schooling@school <mailto:iself/schooling@school>
Notice that the user is not able to do anything on his/her session.
Resume a database
To resume the database to the system mode, go back to the system/manager session and
resume the database.
SQL > ALTER SYSTEM RESUME
/

Restricted Session
Open the database while simultaneously preventing all users but DBA from accessing the
database objects. As a system/manager user, do the following command.
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION
/
Notice that this time no user can login to SQL*PLUS to access to the database objects.

Quiescing state
Now, let us to change the database mode to a quiescing state where only DBA transactions,
queries, or PL/SQL statements are allowed to be executed.
SQL > ALTER SYSTEM QUIESCE RESTRICTED
/
Notice that the Oracle Resource Manager must have remained active in all opened instances in
order to do this ALTER SYSTEM command.
To check the Oracle Resource Manager active options, query the RESOURCE_MANAGER_PLAN
parameter.
SQL> SHOW PARAMETER resource_manager_plan
Notice that the RESOURCE_MANAGER_PLAN has a NULL value.
Turn on Resource Manager Plan
To set the parameter RESOURCE_MANAGER_PLAN to a non-null value, open the init.ora
parameter file and Add the following line to it.
RESOURCE_MANAGER_PLAN = 'SYSTEM_PLAN'
And then shutdown and startup the database. Then, execute the ALTER command.

After you changed the INIT<sid>.ORA parameter file, do the shutdown command.
SQL> SHUTDOWN IMMEDIATE
SQL> -- start the database.
SQL> CONNECT system/manager@school AS SYSDBA
SQL> STARTUP PFILE=%ORACLE_HOME%.ora

Query the RESOURCE_MANAGER_PLAN parameter.


SQL> SHOW PARAMETER resource_manager_plan

Change the database mode to a quiescing state where only DBA transactions, queries, or PL/SQL
statements are allowed to execute.
SQL> ALTER SYSTEM QUIESCE RESTRICTED
/
Note that this time, this ALTER SYSTEM command was successful. Remember that the Oracle
Resource Manager must have remained active in all opened instances.

Server Parameter File-SPFILE


In this exercise you will learn how to create and use the Server Parameter File (SPFILE).
Connect to a database
Connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
Set Oracle Parameter Dynamically
Let us try to change an Oracle parameter dynamically and set the RESOURCE_MANAGER_PLAN
parameter to SYSTEM_PLAN dynamically into the Server Parameter File (SPFILE).
SQL> ALTER SYSTEM SET resource_manager_plan='SYSTEM_PLAN'
SCOPE=SPFILE
/
Notice that at this time, you are not able to change any parameter dynamically. You need to
open your database using the Server Parameter File in order to do that.

Server Parameter File


The Server Parameter File (SPFILE) enables you to relieve yourself of the burden of constantly
updating your parameter file (init<sid>.ora). You create the SPFILE to make it possible to change
almost every initialization parameter you desire dynamically while the database is online and
available for users. Remember that when you startup the database, Oracle first looks for the
SPFILE. If it was not found, then it will check for the PFILE file.
Create a SPFILE
Let's create a SPFILE from the database parameter file (PFILE).
SQL> CREATE SPFILE
FROM
PFILE='%ORACLE_HOME%.ora'
/
Notice that the default location of SPFILE is %ORACLE_HOME%. You can save the SPFILE in an
specific location.

Create a SPFILE in the c:directory using the default Parameter file (PFILE). Make a directory first,
if you don’t have that directory
SQL> HOST MKDIR c: -- Make a directory
SQL> CREATE SPFILE='c:.ora' FROM PFILE
/
Start a database with SPFILE
Shutdown and startup the database with the Server Parameter File. Remember that the default
file is the Server Parameter File (SPFILE). Once you created the SPFILE, you don’t need to specify
it in your startup command. You have to shutdown and startup to activate the use of the SPFILE.
To startup with the SPFILE option, it makes it possible to change almost every initialization
parameter you want dynamically while the database is online and available for users.
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP

Now, let us to change the RESOURCE_MANAGER_PLAN parameter to SYSTEM_PLAN


dynamically into the Server Parameter FILE (SPFILE).
SQL> ALTER SYSTEM SET resource_manager_plan='SYSTEM_PLAN'
SCOPE=SPFILE
/
This time you should be able to change the parameter.
SCOPE options
The scope can be MEMORY, SPFILE, or BOTH. Use the MEMORY option if you don't want to keep
the changes. Use the SPFILE option if you want to be active when you reboot the next time. Use
the BOTH option if you want to change it immediately and keep the changes. Notice that the
default option is always BOTH.
Alter system parameters dynamically
Practice to change some of the Oracle parameters dynamically.

Change the SHARED_POOL_SIZE to 20 megabytes dynamically in the memory.


SQL> ALTER SYSTEM SET shared_pool_size = 20000000
SCOPE=MEMORY
/
Query the SHARED_POOL_SIZE parameter information.
SQL > SHOW PARAMETER shared_pool_size
Notice that the SHARED_POOL_SIZE parameter was changed.

Configure the database to the archive mode


In this exercise you will learn how to Archive the database while the database is in the
NOARCHIVELOG MODE and also learn how to maintain the online Redo Log files and
checkpoints.
Connect to a database
Let's first, connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
Check archive mode
Check to see, if you are in the archive mode or not.
SQL> ARCHIVE LOG LIST

Change a database to archive mode


First you should change the following parameters in the parameter file.
log_archive_dest = /u01/app/oracle/admin/<database_name>/arch
log_archive_start = true
log_archive_format = log%s.arc
Shutdown the database and then start the instance and mount but do not open the database.
To change the database mode to the NOARCHIVELOG or the ARCHIVELOG modes, you must
shutdown and then startup the database with the MOUNT option. When you change the
database mode, make sure to take a complete offline backup of the database. You will learn
more about how to take a complete OFFLINE backup during the backup and recovery Hands-On
exercises.
SQL> SHUTDOWN IMMEDIATE
SQL> STARTUP MOUNT
PFILE=%ORACLE_HOME%.ora
/

Now, change the archiving status of the database.


SQL> ALTER DATABASE ARCHIVELOG
/
Notice that this command will modify the contents of the control files. You can change it back
by using the ALTER DATABASE NOARCHIVELOG statement.
Open a database
Open the SCHOOL database.
SQL> ALTER DATABASE OPEN
/
Check a database is open
Just query the DBA_USERS view to verify that the database is open.
SQL> SELECT count(1)
FROM dba_users
/
Check an archive log mode
Check the archive log list again.
SQL> ARCHIVE LOG LIST
Notice that the database mode was changed. It is very important that after changing the
database mode, to shutdown the database and then, take a complete OFFLINE backup.
Check Log file status
Query the V$LOG dictionary view and take notes on the STATUS column where the online redo
log file is CURRENT.
SQL> SELECT * FROM v$log
/
Switch an Online Redo Log
To change the Online Redo Log file, use the ALTER SYSTEM SWITCH command. Now, switch the
Online Redo Log file to the next Online Redo Log file.
SQL> ALTER SYSTEM SWITCH LOGFILE
/

Check log status


Query the V$LOG directory view again and take notes on the STATUS column.
SQL> SELECT * FROM v$log
/
Notice that the CURRENT value, is on a different group number. Remember that anytime the
Online Redo Log file switches the CHECKPOINT PROCESS it tells the DB Writer to write all of the
dirty blocks in the database.
View checkpoint parameters
Show all the checkpoint parameters.
SQL> SHOW PARAMETER checkpoint
Notice that the LOG_CHECKPOINT_INTERVAL is zero. That means, you have a checkpoint
whenever the Online Redo Log file switches. The default LOG_CHECKPOINT_TIMEOUT is 1800,
and it means that if the Redo Log file did not fill up within 30 minutes, the checkpoint will tell
the DB Writer to write all of the dirty blocks in the database. If the
LOG_CHECKPOINTS_TO_ALERT value is true, then any occurrence of checkpoint will be written
in the database alert file.
Checkpoint Manually
Now, let's try to force a checkpoint to happen manually.
SQL> ALTER SYSTEM CHECKPOINT
/
Checkpoint every … hours
Set the checkpoint timeout to a 2-hour time interval.
SQL> ALTER SYSTEM SET log_checkpoint_timeout = 7200

Maintaining and Relocating the Redo Log files


In this exercise you will learn how to maintain and relocate the Redo Log files.
Connect to a database
Let's first, connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
View Log information
Query the V$LOG directory view to display the Online Redo Log information..
SQL> SELECT * FROM v$log
/
View log files location
Query the V$LOGFILE directory view to display the Online Redo Log files location.
SQL> SELECT * FROM v$logfile
/
Notice that the database has only three Online Redo log groups.

Add a log file group


Add a group number 4's Online Redo Log file to the database.
SQL> ALTER DATABASE ADD LOGFILE GROUP 4
'c:.log' size 500k
/
Query the V$LOG dictionary view to display the Online Redo Log information again.
SQL> SELECT * FROM v$log
/
Relocate a log file
Relocate or rename the Online Redo Log file from redo04.log to redo04a.log.

First, shutdown the database.


SQL> SHUTDOWN IMMEDIATE

Then, copy the Online Redo Log file to a new location and delete the previous old Online Redo
Log file.
SQL> HOST COPY -
C:.LOG -C:a.log
SQL> HOST ERASE C:.LOG

Connect to the database as the SYSDBA and start the database with the MOUNT option. The
MOUNT option starts the instance, reads the control file, and attaches the database, but does
not open it.
SQL> CONNECT system/manager@school AS SYSDBA
SQL> STARTUP MOUNT

Alter the database to rename the original Online Redo log file to the new location of the online
redo log file. This alter command will change the structure of the database by updating the
controlfiles. Then open the database. The database needs to be opened since the database was
started with the MOUNT option.
SQL> ALTER DATABASE RENAME FILE
'C:.LOG' TO
'C:a.log'
/
SQL> ALTER DATABASE OPEN
/

Query the V$LOGFILE dictionary view again.


SQL> SELECT * FROM v$logfile
/
Notice that your Online Redo Log file was relocated.
Drop a log file group
Drop group number 4's Online Redo Log file.
SQL> ALTER DATABASE DROP LOGFILE GROUP 4
/

Query the V$LOGFILE directory view again.


SQL> SELECT * FROM v$logfile
/
Notice that your Online Redo Log file was deleted.

Delete the Online Redo Log file's physical file. Notice that when we drop the Online Redo Log
file, we should delete the file using the Operating System command.
SQL> HOST ERASE c:a.log
Multiplexing and Maintaining the Online Redo Log files

In this exercise you will learn how to maintain and multiplex the online redo log files using
Oracle-Managed Files (OMF).
Connect to a database
First, connect to SQL*Plus as the system/manager user.
SQL> CONNECT system/manager@school AS SYSDBA
Oracle-Managed Files
Check to see that the database is using Oracle-Managed Files.
SQL> SHOW PARAMETER db_create_online_log_dest
If the value of all of the DB_CREATE_ONLINE_LOG_DEST column were null, it means that you
cannot take advantage of Oracle-Managed Files.
Create a directory
Create a directory called c:.
SQL> HOST MKDIR c:
Now, the folder was created.
Define Oracle Managed folder
Alter the system so that the database will manage the Online Redo Log files in the Online Redo
Log destination 4.
SQL> ALTER SYSTEM SET db_create_online_log_dest_4='c:'
/

Display the DB_CREATE_ONLINE_LOG_DEST parameter again.


SQL> SHOW PARAMETER db_create_online_log_dest
Notice that there is a value for the log destination 4.
Add a group file using Oracle-Managed file
Alter the database to add one more group to the online redo log files.
SQL> ALTER DATABASE ADD LOGFILE GROUP 4
/

Query the V$LOGFILE view.


SQL> SELECT * FROM v$logfile
/
Notice the Oracle naming convention. The 4 indicates the group number.
Add a log file member
Add a member to the Online Redo Log files group number 4, using Oracle-Managed Files (OMF).
SQL> ALTER DATABASE
ADD LOGFILE MEMBER 'redo04b.log' TO GROUP 4
/

Query the V$LOGFILE view.


SQL> SELECT * FROM v$logfile
/
Notice the new member status is set to invalid. That's okay. Once we start using it, the status
will change.
Clear a log file group
Clear Online Redo Log file group number 1.
SQL> ALTER DATABASE CLEAR LOGFILE GROUP 1
/
You should never execute this command unless you have to. By executing this command you
may loose some important information. Do this command only if your group file has a corrupted
member.
Drop a log file group
Drop the group number 4 of the Online Redo Log file.
SQL> ALTER DATABASE DROP LOGFILE GROUP 4
/
Notice that when you use Oracle-Managed Files, you do not need to delete the physical datafile
from the system using the Operating System command. Oracle does it for you.
Maintaining Tablespace and Datafiles

In this exercise you will learn how to maintain tablespaces and datafiles in the database with
and without using Oracle-Managed Files (OMF).

Now, connect to SQL*Plus as the system/manager user.


SQL> CONNECT system/manager@school AS SYSDBA
Create a tablespace using user defined file
Create a permanent tablespace with the AUTOEXTEND ON option, and a default storage option
with an initial size of 100k, a next size of 100k, a minimum extent of 10, and a maximum extent
of 200.
SQL> CREATE TABLESPACE myfirst_tablespace
DATAFILE 'c:_tablespace_01.dbf'
SIZE 10M
AUTOEXTEND ON
DEFAULT STORAGE (INITIAL 100K NEXT 100K
MINEXTENTS 10 MAXEXTENTS 200)
PERMANENT ONLINE
/
From now on, any object that will be created in this tablespace will have their default storage
the same as the tablespace default storage unless they have been specified by user.
View tablespace information
Query the DBA_TABLESPACES view to display the tablespace name and their extent
management columns.
SQL> SELECT tablespace_name, extent_management
FROM dba_tablespaces
/
Notice the EXTENT_MANAGEMENT column. The default for managing the tablespace is LOCAL.
For performance reason, use locally managed tablespace.
Add a datafile to a tablespace
Add more datafile to MYFIRST_TABLESPACE.
SQL> ALTER TABLESPACE myfirst_tablespace
ADD
DATAFILE 'c:_tablespace_02.dbf'
SIZE 10M
/
View datafile information
Query the DBA_DATA_FILES view to display all information.
SQL> SELECT *
FROM dba_data_files
WHERE tablespace_name = 'MYFIRST_TABLESPACE'
/
Notice that MYFIRST_TABLESPCE has two datafiles.
Change tablespace status
Set the tablespace status to OFFLINE, and then query the DBA_TABLESPACES view to display the
tablespace name and status columns.
SQL> ALTER TABLESPACE myfirst_tablespace OFFLINE
/
SQL> SELECT tablespace_name, status
FROM dba_tablespaces
/

Check the STATUS column. Notice that it is OFFLINE.

Now, set the tablespace status to ONLINE.


SQL> ALTER TABLESPACE myfirst_tablespace ONLINE
/
Drop a tablespace
Drop the tablespace, including all of the objects in it plus the constraints.
SQL> DROP TABLESPACE myfirst_tablespace
INCLUDING CONTENTS CASCADE CONSTRAINTS
/
SQL> HOST ERASE c:_tablespace_01.dbf
SQL> HOST ERASE c:_tablespace_02.dbf
Notice that since we did not use Oracle-Managed Files, we should delete the datafiles from the
system.
Create a tablespace using Oracle-Managed file
Create a tablespace using Oracle-Managed Files (OMF). First, you should alter the system to set
the DB_CREATE_FILE_DEST parameter to a valid sub-directory. Then create a table with a no
datafile option. The database will then create and maintain the datafiles in the defined Oracle
file destination, for example c:directory.
SQL> ALTER SYSTEM SET db_create_file_dest='c:'
/
SQL> CREATE TABLESPACE my2nd_tablespace
/

Query the DBA_DATA_FILES directory view to display all of the information.


SQL> SELECT *
FROM dba_data_files
WHERE tablespace_name = 'MY2ND_TABLESPACE'
/
Check the Oracle database naming convention. Notice that the first eight characters of the
tablespace name is part of the datafile name.
Drop an OMF tablespace
Drop the tablespace including all of the objects in it including the constraints.
SQL> DROP TABLESPACE my2nd_tablespace
INCLUDING CONTENTS CASCADE CONSTRAINTS
/
Notice that since we use Oracle-Managed Files we do not need to delete the datafile from the
system. Oracle automatically deletes it from the system.

Maintaining a TEMPORARY tablespace

In this exercise you will learn how to maintain a temporary tablespace with or without using
Oracle-Managed Files (OMF) and more.

First, connect to SQL*Plus as the system/manager user.


SQL> CONNECT system/manager@school AS SYSDBA
Define a create file destination
Let's first make sure that the DB_CREATE_FILE_DEST value is set to a valid sub-directory.
SQL> ALTER SYSTEM SET db_create_file_dest='c:'
/

Create a temporary tablespace (OMF)


Now, create a temporary tablespace with Oracle-Managed Files (OMF). Users create temporary
segments in a tablespace when a disk sort is required to support their use of select statements
containing the GROUP BY, ORDER BY, DISTINCT, or UNION, or the CREATE INDEX statements.
SQL> CREATE TEMPORARY TABLESPACE mytemp
/

Query the DBA_TABLESPACES view to display the tablespace name, initial extent, max extents,
contents, logging, and tablespace status.
SQL> SELECT tablespace_name, initial_extent, max_extents,
contents, logging, status
FROM dba_tablespaces
/
Notice that the CONTENTS column is set to TEMPORARY. The default init size is 1 Megabytes and
the maximum extend is unlimited.

Query the DBA_DATA_FILES directory view.


SQL> SELECT file_id, file_name, tablespace_name, status
FROM dba_data_files
/
Notice that the temporary tablespace is not there.

Query the DBA_TEMP_FILE directory view.


SQL> SELECT * FROM dba_temp_files
/
Note the naming convention.
Open a new session and connect to SQLPlus as the ISELF user and then do the following
statements.
SQL> CONNECT iself/schooling
SQL> SET SQLPROMP 'iself > '
SQL> SELECT e1.ename
FROM emp e1, emp e2, emp e3, emp e4
ORDER BY 1
/

While the other session is running, come back and query the following statement.
SQL> SET SQLPROMPT 'dba > '
SQL> SELECT s.username, tablespace, contents, extents, blocks
FROM v$session s, v$sort_usage
WHERE s.saddr = session_addr
/

Or you can query the V$SORT_SEGMENT table.


SQL> SELECT tablespace_name, extent_size,
total_extents, max_sort_blocks
FROM v$sort_segment
/
The sort segment high-water mark information is exist for duration of the instance. Starting the
instance will clean this table. This a good way to find out how big the users sort segments has
become.
Drop a temporary tablespace
Drop the mytemp tablespace and create it again with the old method.
SQL> DROP TABLESPACE mytemp
/
Notice that your datafile will be deleted.
Create a temporary tablespace using User-Managed file
SQL> CREATE TABLESPACE mytemp
DATAFILE 'c:_01.tmp' SIZE 20M
TEMPORARY
/
Drop a temporary tablespace (UMF)
Drop the mytemp tablespace and delete the datafile from the system. Note that we need to
delete the datafile since we did not create the temporary tablespace using Oracle-Managed
Files (OMF).
SQL> DROP TABLESPACE mytemp
/
SQL> HOST ERASE c:_01.tmp
TEMPIFLE and UNIFORM options
Now, create a temporary tablespace using the TEMPFILE and UNIFORM options. Make sure to
use Oracle-Managed Files.
SQL> CREATE TEMPORARY TABLESPACE mytemp
TEMPFILE 'mytemp_01.tmp' SIZE 20M
EXTENT MANAGEMENT LOCAL
UNIFORM SIZE 10M
/
The uniform extent sizing is used to simplify how extents are allocated to objects.

Query the DBA_TEMP_FILES view.


SQL> SELECT * FROM dba_temp_files
/
Here, you see the MYTEMP tablespace. Notice that the tablespace is located in
%ORACLE_HOME%sub-directory. Remember that all tablespaces in the database will use the
standard block size defined for the database.
BACKUP AND RECOVERY

USER MANAGED BACKUPS:

Procedure UB1: Making offline backup of whole database (No archive log/
Archive log)

1. Use the V$DATAFILE and V$CONTROLFILE views to identify the data files and control files for
your database.

SQL> select name from v$datafile;

NAME

--------------------------------------------------------------------------------

/u02/app/oracle/oradata/orcl/system01.dbf

/u02/app/oracle/oradata/orcl/sysaux01.dbf

/u02/app/oracle/oradata/orcl/undotbs01.dbf

/u02/app/oracle/oradata/orcl/users01.dbf

/u02/app/oracle/oradata/orcl/example01.dbf

/u02/app/oracle/oradata/orcl/users03.dbf
/u02/app/oracle/oradata/orcl/users04.dbf

Below query to get datafiles and corresponding tablespace details.

SELECT t.NAME "Tablespace", f.NAME "Datafile" FROM V$TABLESPACE t, V$DATAFILE f WHERE t.TS# = f.TS# ORDER BY
t.NAME;

SQL> select name from v$controlfile;

NAME

--------------------------------------------------------------------------------

/u02/app/oracle/oradata/orcl/control01.ctl
/u02/app/oracle/flash_recovery_area/orcl/control02.ctl
2. If the database is open, then use SQL*Plus to shut down the database with the IMMEDIATE
option.

SQL> shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

3. Use an operating system utility to make backups of all data files and all control files specified
by the CONTROL_FILES parameter of the initialization parameter file. Also, back up the
initialization parameter file and other Oracle product initialization files.

[oracle@server1 oracle]$ cp /u02/app/oracle/oradata/orcl/*dbf


/u02/app/oracle/offline_backups/whole_backup

[oracle@server1 oracle]$ cp /u02/app/oracle/oradata/orcl/control01.ctl


/u02/app/oracle/offline_backups/whole_backup

[oracle@server1 dbhome_1]$ find . -name *.ora

./rdbms/admin/externaljob.ora

./rdbms/install/filemap.ora

./srvm/admin/init.ora

./mgw/admin/sample_mgw.ora

./hs/admin/extproc.ora

./hs/admin/initdg4odbc.ora

./network/admin/tnsnames.ora

./network/admin/samples/listener.ora

./network/admin/samples/tnsnames.ora

./network/admin/samples/sqlnet.ora

./network/admin/sqlnet.ora

./server1.sony.com_orcl/sysman/config/server/repoconn.ora

./server1.sony.com_orcl/sysman/config/emkey.ora

./dbs/spfileorcl.ora
./dbs/init.ora

./dbs/initorcl.ora

[oracle@server1 dbhome_1]$ find . -name *.ora -exec cp {}


/u02/app/oracle/offline_backups/whole_backup \;

4. Restart the database with the STARTUP command in SQL*Plus.

[oracle@server1 backup]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Oct 25 19:21:04 2013

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

Connected to an idle instance.

SQL> startup;

ORACLE instance started.

Total System Global Area 1607008256 bytes

Fixed Size 1336820 bytes

Variable Size 419432972 bytes

Database Buffers 1174405120 bytes

Redo Buffers 11833344 bytes

Database mounted.

Database opened.

Procedure UB2: Making offline backups of tablespaces and datafiles (No archive
log)

 You cannot take offline the SYSTEM tablespace or a tablespace with active undo
segments. The following technique cannot be used for such tablespaces.

 Assume that a table is in tablespace Primary and its index is in tablespace


Index.Taking tablespace Index offline while leaving tablespace Primary online can
cause errors when data manipulation language (DML) is issued against theindexed
tables located in Primary. The problem appears only when the access method chosen
by the optimizer must access the indexes in the Index tablespace.

1. Identify the tablespace's data files by querying the DBA_DATA_FILES view. For example,
assume that you want to back up the USERS tablespace. Enter the following statement in
SQL*Plus:

SQL> col file_name for a100;

SQL> select tablespace_name,file_name from dba_data_files where tablespace_name='USERS';

TABLESPACE_NAME FILE_NAME

------------------------------ ----------------------------------------------------------------------------------------------------

USERS /u02/app/oracle/oradata/orcl/users01.dbf

USERS /u02/app/oracle/oradata/orcl/users03.dbf

USERS /u02/app/oracle/oradata/orcl/users04.dbf

2. Take the tablespace offline.

SQL> alter tablespace USERS offline;

Tablespace altered.

3. Back up the offline data files.

[oracle@server1 partial_backup]$ cp /u02/app/oracle/oradata/orcl/users*dbf


/u02/app/oracle/offline_backups/partial_backup

4. Bring the tablespace online.

SQL> alter tablespace USERS online;

Tablespace altered.

Procedure UB3: Making offline backups tablespaces and datafiles (Archive log)
1. Identify the tablespace's data files by querying the DBA_DATA_FILES view. For example,
assume that you want to back up the USERS tablespace. Enter the following statement in
SQL*Plus:

SQL> col file_name for a100;

SQL> select tablespace_name,file_name from dba_data_files where tablespace_name='USERS';


TABLESPACE_NAME FILE_NAME

------------------------------ -------------------------------------------------------------------------------------------------

USERS /u02/app/oracle/oradata/orcl/users01.dbf

USERS /u02/app/oracle/oradata/orcl/users03.dbf

USERS /u02/app/oracle/oradata/orcl/users04.dbf

2. Take the tablespace offline using normal priority if possible, because it guarantees that you
can subsequently bring the tablespace online without having to recover it, else with offline
temporary or offline immediate.

OFFLINE NORMAL
Specify NORMAL to flush all blocks in all datafiles in the tablespace out of the system global area
(SGA). You need not perform media recovery on this tablespace before bringing it back online.
This is the default.

OFFLINE TEMPORARY
If you specify TEMPORARY, then Oracle Database performs a checkpoint for all online datafiles in
the tablespace but does not ensure that all files can be written. Files that are offline when you
issue this statement may require media recovery before you bring the tablespace back online.

OFFLINE IMMEDIATE
If you specify IMMEDIATE, then Oracle Database does not ensure that tablespace files are
available and does not perform a checkpoint. You must perform media recovery on the
tablespace before bringing it back online.

SQL> alter tablespace USERS offline;

Tablespace altered.

3. Back up the offline data files.

[oracle@server1 partial_backup]$ cp /u02/app/oracle/oradata/orcl/users*dbf


/u02/app/oracle/offline_backups/partial_backup

4. Bring the tablespace online.

SQL> alter tablespace USERS online;

5. Archive the unarchived redo logs so that the redo required to recover the tablespace backup
is archived.
SQL> alter system archive log current;

System altered.
Procedure UB5: Making online backups of read/write tablespaces and
datafiles(Archive log)
 You must put a read/write tablespace in backup mode to make user-managed data
file backups when the tablespace is online and the database is open.

 You should not back up temporary tablespaces.

 In backup mode, the database copies whole changed data blocks into the redo
stream.

 After you take the tablespace out of backup mode the database advances the data
file checkpoint SCN to the current database checkpoint SCN.

 When restoring a data file backed up in this way, the database asks for the
appropriate set of redo log files to apply if recovery is needed. The redo logs contain
all changes required to recover the data files and make them consistent.

 To check whether a data file is part of a current online tablespace backup, query the
V$BACKUP view.

 The V$BACKUP view is most useful when the database is open. It is also useful
immediately after an instance failure because it shows the backup status of the files
at the time of the failure. Use this information to determine whether you have left
any tablespaces in backup mode.

 V$BACKUP is not useful if the control file currently in use is a restored backup or a
new control file created after the media failure occurred. A restored or re-created
control file does not contain the information that the database needs to populate
V$BACKUP accurately.

 If you fail to take the tablespace out of backup mode, then Oracle Database
continues to write copies of data blocks in this tablespace to the online redo logs,
causing performance problems. Also, you receive an ORA-01149 error if you try to
shut down the database with the tablespaces still in backup mode.

 You can take online tablespaces backup parallel or serially. In case of parallel all the
tablespaces are kept in backup mode, the related datafiles are copied to backup
location and the backup mode is ended. Where as in case of serial the tablespace are
kept in backup mode and ended one after the other. Note, that parallel online
tablespace backups generates more amount of redo.
1. Before beginning a backup of a tablespace, use the DBA_DATA_FILES data dictionary view to
identify all of the data files in the tablespace. For example,assume that you want to back up
the users tablespace. Enter the following:
SQL> SELECT TABLESPACE_NAME, FILE_NAME FROM SYS.DBA_DATA_FILES WHERE TABLESPACE_NAME =
'USERS';

TABLESPACE_NAME FILE_NAME

------------------------------ --------------------------------------------------------------------------------

USERS /u02/app/oracle/oradata/orcl/users01.dbf

USERS /u02/app/oracle/oradata/orcl/users03.dbf

USERS /u02/app/oracle/oradata/orcl/users04.dbf

2. Check the status of the datafiles of USERS tablespace before starting the backup mode.
SQL> SELECT t.name AS "TB_NAME", d.file# as "DF#", d.name AS "DF_NAME", b.status

FROM V$DATAFILE d, V$TABLESPACE t, V$BACKUP b

WHERE d.TS#=t.TS#

AND b.FILE#=d.FILE#

AND b.STATUS='ACTIVE';

no rows selected

3. Mark the beginning of the online tablespace backup. For example, the following statement
marks the start of an online backup for the tablespace users:
SQL> alter tablespace USERS begin backup;

Tablespace altered.

4. Now check the status of the datafiles of USERS tablespace after placing the tablespace in
backup mode. In the STATUS column, NOT ACTIVE indicates that the file is not currently in
backup mode, whereas ACTIVE indicates that the file is currently in backup mode.
SQL> SELECT t.name AS "TB_NAME", d.file# as "DF#", d.name AS "DF_NAME", b.status

FROM V$DATAFILE d, V$TABLESPACE t, V$BACKUP b

WHERE d.TS#=t.TS#

AND b.FILE#=d.FILE#

AND b.STATUS='ACTIVE';
TB_NAME DF# DF_NAME STATUS

---------- ---------- -------------------------------------------------- ------------------

USERS 4 /u02/app/oracle/oradata/orcl/users01.dbf ACTIVE

USERS 6 /u02/app/oracle/oradata/orcl/users03.dbf ACTIVE

USERS 7 /u02/app/oracle/oradata/orcl/users04.dbf ACTIVE

5. Back up the online data files of the online tablespace with operating system commands. For
example, Linux and UNIX users might enter:
[oracle@server1 orcl]$ pwd

/u02/app/oracle/oradata/orcl

[oracle@server1 orcl]$ cp user*dbf /u02/app/oracle/online_backups/partial_backup

6. After coping the datafiles end the backup mode.


SQL> alter tablespace USERS end backup;

Tablespace altered.

7. Archive the unarchived redo logs so that the redo required to recover the tablespace backup
is archived. For example, enter:
SQL> alter system archive log current;

System altered.

8. Copy archive logs to the backup location.


SQL> archive log list;

Database log mode Archive Mode

Automatic archival Enabled

Archive destination USE_DB_RECOVERY_FILE_DEST

Oldest online log sequence 9

Next log sequence to archive 11

Current log sequence 11

SQL> show parameter db_recovery;


NAME TYPE VALUE

------------------------------------ ----------- ------------------------------

db_recovery_file_dest string /u02/app/oracle/flash_recovery_area

db_recovery_file_dest_size big integer 3852M

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

[oracle@server1 ~]$ cd /u02/app/oracle/flash_recovery_area/ORCL/archivelog

[oracle@server1 archivelog]$ ls

2013_10_26

[oracle@server1 archivelog]$ cd *

[oracle@server1 2013_10_26]$ ls

o1_mf_1_10_96r11zpx_.arc o1_mf_1_9_96qp8453_.arc

[oracle@server1 2013_10_26]$ cp * /u02/app/oracle/online_backups/partial_backup/

Procedure UB4: Making online backups of whole database (Archive log)


 User managed online database backup is similar to the online backup of tablespace
or datafiles, but in this case the complete database(all the tablespaces i.e., except
temp and read only ) is kept in to backup mode.

1. Prepare the online tablespaces for backup by issuing all necessary ALTER TABLESPACE
statements at once. For example, put tablespaces users, tools, and index in backup mode as
follows:
SQL> ALTER TABLESPACE users BEGIN BACKUP;

SQL> ALTER TABLESPACE tools BEGIN BACKUP;

SQL> ALTER TABLESPACE indx BEGIN BACKUP;

or

SQL> ALTER DATABASE BEGIN BACKUP;

Database altered.

2. Back up all files of the online tablespaces.


[oracle@server1 orcl]$ cp *.dbf /u02/app/oracle/online_backups/whole_backup
3. Take the tablespaces out of backup mode.
SQL> ALTER TABLESPACE users END BACKUP;

SQL> ALTER TABLESPACE tools END BACKUP;

SQL> ALTER TABLESPACE indx END BACKUP;

or

SQL> ALTER DATABASE END BACKUP;

Database altered.

4. Archive the online redo logs so that the redo required to recover the tablespace backups is
available for later media recovery. For example, enter:
SQL> alter system archive log current;

System altered.

5. Back up the database's control file, specifying a file name for the output binary file. The
following example backs up a control file to
/u02/app/oracle/online_backups/whole_backup/cf.bak. REUSE to make the new control file
overwrite one that currently exists.

Note- Don’t use the operating system’s copy command to do this


SQL> alter database backup controlfile to '/u02/app/oracle/online_backups/whole_backup/cf.bak'
REUSE;

Database altered.

6. Copy the archive logs to the backup location.


[oracle@server1 2013_10_26]$ pwd

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26

[oracle@server1 2013_10_26]$ ls -lrt

total 35720

-rw-r----- 1 oracle dba 296960 Oct 26 10:00 o1_mf_1_9_96qp8453_.arc

-rw-r----- 1 oracle dba 8732160 Oct 26 13:04 o1_mf_1_10_96r11zpx_.arc

-rw-r----- 1 oracle dba 27488768 Oct 26 14:02 o1_mf_1_11_96r4h2qc_.arc

[oracle@server1 2013_10_26]$ cp * /u02/app/oracle/online_backups/whole_backup/


Procedure UB6: Making online backups of read only tablespaces /datafiles
(Archive log)
 When backing up an online read-only tablespace, you can simply back up the online
data files. You do not have to place the tablespace in backup mode because the
database is not permitting changes to the data files.

 If a media error or a user error occurs (such as accidentally dropping a table in the
read-only tablespace), you can transport the tablespace back into the database.

1. Query the DBA_TABLESPACES view to determine which tablespaces are read-only.


SQL> SELECT TABLESPACE_NAME, STATUS FROM DBA_TABLESPACES WHERE STATUS = 'READ ONLY';

TABLESPACE_NAME STATUS

------------------------------ ---------

EXAMPLE READ ONLY

2. Before beginning a backup of a read-only tablespace, identify all of the tablespace's


(EXAMPLE) data files by querying the DBA_DATA_FILES data dictionary view.
SQL> SELECT TABLESPACE_NAME, FILE_NAME FROM DBA_DATA_FILES WHERE TABLESPACE_NAME LIKE
'EXAMPLE';

TABLESPACE_NAME FILE_NAME

------------------------------ --------------------------------------------------

EXAMPLE /u02/app/oracle/oradata/orcl/example01.dbf

3. Back up the online data files of the read-only tablespace with operating system commands.
You do not have to take the tablespace offline or put the tablespace in backup mode
because users are automatically prevented from making changes to the read-only
tablespace.
[oracle@server1 readonly]$ cp /u02/app/oracle/oradata/orcl/example01.dbf
/u02/app/oracle/online_backups/readonly
USER MANAGED RECOVERY:

Loss of Controlfile & Datafiles


In order to create a scenario, letsl manually delete all controlfiles, redologs and datafiles when the database is up
and running.

[oracle@server1 orcl]$ pwd

/u02/app/oracle/oradata/orcl

[oracle@server1 orcl]$ rm *

[oracle@server1 orcl]$ rm /u02/app/oracle/flash_recovery_area/orcl/control02.ctl

-----------------------------------------------------------------------------------

[oracle@server1 orcl]$ pwd

/u02/app/oracle/oradata/orcl

[oracle@server1 orcl]$ cp /u02/app/oracle/online_backups/whole_backup/* /u02/app/oracle/oradata/orcl/

[oracle@server1 orcl]$ mv cf.bak control01.ctl

[oracle@server1 orcl]$ cp control01.ctl /u02/app/oracle/flash_recovery_area/orcl/control02.ctl

[oracle@server1 orcl]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 28 20:42:29 2013

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate;

ORA-03113: end-of-file on communication channel

SQL> exit

[oracle@server1 orcl]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 28 20:42:48 2013

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

Connected to an idle instance.

SQL> startup mount;


ORACLE instance started.

Total System Global Area 1607008256 bytes

Fixed Size 1336820 bytes

Variable Size 419432972 bytes

Database Buffers 1174405120 bytes

Redo Buffers 11833344 bytes

Database mounted.

SQL> alter database recover automatic using backup controlfile until cancel;

alter database recover automatic using backup controlfile until cancel

ERROR at line 1:

ORA-00279: change 931298 generated at 10/26/2013 14:02:58 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_28/o1_mf_1_12_%u_.ar

ORA-00280: change 931298 for thread 1 is in sequence #12

ORA-00278: log file

'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_28/o1_mf_1_12_%u_.a

rc' no longer needed for this recovery

ORA-00308: cannot open archived log

'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_28/o1_mf_1_12_%u_.a

rc'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

SQL> recover cancel;

Media recovery complete.

SQL> alter database open;

alter database open


*

ERROR at line 1:

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open resetlogs;

Database altered.

SQL> select current_scn from v$database;

CURRENT_SCN

-----------

931871

Loss of a Non-System datafile


Deleting users01.dbf to simulate loss of non-system datafile.
[oracle@server1 orcl]$ rm -f /u02/app/oracle/oradata/orcl/users01.dbf

Recovery:
SQL> select file_id,file_name from dba_data_files;

FILE_ID FILE_NAME

---------- --------------------------------------------------------------------------------

4 /u02/app/oracle/oradata/orcl/users01.dbf

3 /u02/app/oracle/oradata/orcl/undotbs01.dbf

2 /u02/app/oracle/oradata/orcl/sysaux01.dbf

1 /u02/app/oracle/oradata/orcl/system01.dbf

5 /u02/app/oracle/oradata/orcl/example01.dbf

6 /u02/app/oracle/oradata/orcl/users03.dbf

7 /u02/app/oracle/oradata/orcl/users04.dbf

7 rows selected.

SQL> alter database datafile 4 offline;

Database altered.

[oracle@server1 orcl]$ cp /u02/app/oracle/online_backups/partial_backup/users01.dbf


/u02/app/oracle/oradata/orcl/
SQL> recover datafile 4;

ORA-00279: change 923719 generated at 10/26/2013 12:02:26 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26/o1_mf_1_10_96r11z

px_.arc

ORA-00280: change 923719 for thread 1 is in sequence #10

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

<press enter>

ORA-00279: change 926093 generated at 10/26/2013 13:04:47 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26/o1_mf_1_11_96r4h2

qc_.arc

ORA-00280: change 926093 for thread 1 is in sequence #11

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

<press enter>

Log applied.

Media recovery complete.

SQL> alter database datafile 4 online;

Database altered.

SQL>

Loss of System datafile


In order to create a scenario, let's delete the datafile belonging to system
tablespace.
[oracle@server1 orcl]$ rm /u02/app/oracle/oradata/orcl/system01.dbf

Recovery:
SQL> shutdown abort;

ORACLE instance shut down.

[oracle@server1 orcl]$ cp /u02/app/oracle/online_backups/whole_backup/system01.dbf


/u02/app/oracle/oradata/orcl
[oracle@server1 orcl]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 28 21:31:37 2013

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

Connected to an idle instance.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 1607008256 bytes

Fixed Size 1336820 bytes

Variable Size 419432972 bytes

Database Buffers 1174405120 bytes

Redo Buffers 11833344 bytes

Database mounted.

SQL> recover database;

ORA-00279: change 927927 generated at 10/26/2013 13:53:12 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26/o1_mf_1_11_96r4h2

qc_.arc

ORA-00280: change 927927 for thread 1 is in sequence #11

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

<press enter>

Log applied.

Media recovery complete.

SQL> alter database open;

Database altered.

SQL>
Point In Time Recovery (PITR) UNTIL TIME
Insert user data to simulate recovery scenario:

[oracle@server1 orcl]$ sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on Mon Oct 28 21:43:34 2013

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create table students (id number, name varchar2(30));

Table created.

SQL> insert into students values (1,'PAVAN');

1 row created.

SQL> insert into students values (2,'RAKESH');

1 row created.

SQL> insert into students values (3,'ROHIT');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from students;

ID NAME

---------- ------------------------------

1 PAVAN

2 RAKESH

3 ROHIT

SQL> select thread#,sequence#,status,first_change#,to_char(first_time, 'DD-MON-YY HH24:MI:SS') from v$log;

THREAD# SEQUENCE# STATUS FIRST_CHANGE# TO_CHAR(FIRST_TIME

---------- ---------- ---------------- ------------- ------------------

1 1 CURRENT 975216 04-NOV-13 05:35:41

1 0 UNUSED 0
1 0 UNUSED 0

The create table and inserted 3 records redo entries are in seq#1 (time 04-NOV-13 05:35:41)

Perform couple of log switches.


SQL> alter system switch logfile;

System altered.

SQL> alter system switch logfile;

System altered.

SQL> select thread#,sequence#,status,first_change#,to_char(first_time, 'DD-MON-YY HH24:MI:SS') from v$log;

THREAD# SEQUENCE# STATUS FIRST_CHANGE# TO_CHAR(FIRST_TIME

---------- ---------- ---------------- ------------- ------------------

1 1 ACTIVE 975216 04-NOV-13 05:35:41

1 2 ACTIVE 975733 04-NOV-13 05:46:11

1 3 CURRENT 975737 04-NOV-13 05:46:16

< Perform user managed hot backup here as described in procedure UB4>
[oracle@server1 whole_backup]$ sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on Tue Oct 29 08:48:13 2013

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

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select * from students;

ID NAME

---------- ------------------------------

1 PAVAN

2 RAKESH

3 ROHIT

SQL> delete from students;

3 rows deleted.
SQL> commit;

Commit complete.

SQL> select thread#, sequence#, status, first_change#,to_char(first_time, 'DD-MON-YY HH24:MI:SS') from v$log;

THREAD# SEQUENCE# STATUS FIRST_CHANGE# TO_CHAR(FIRST_TIME

---------- ---------- ---------------- ------------- ------------------

1 4 ACTIVE 978172 04-NOV-13 06:27:50

1 5 CURRENT 978571 04-NOV-13 06:39:11

1 3 INACTIVE 975737 04-NOV-13 05:46:16

The delete records statement entry is recorded in seq#4 (04-NOV-13 06:27:50), now let’s insert
some records in students table.
SQL> insert into students values (4,'KRISHNA');

1 row created.

SQL> insert into students values (3,'VIJAY');

1 row created.

SQL> commit;

Commit complete.

SQL> alter system archive log current;

System altered.

SQL> select thread#,sequence#,status,first_change#,to_char(first_time, 'DD-MON-YY HH24:MI:SS') from v$log;

THREAD# SEQUENCE# STATUS FIRST_CHANGE# TO_CHAR(FIRST_TIME

---------- ---------- ---------------- ------------- ------------------

1 4 INACTIVE 978172 04-NOV-13 06:27:50

1 5 ACTIVE 978571 04-NOV-13 06:39:11

1 6 CURRENT 978911 04-NOV-13 06:47:50

Log sequence#5 contains the vectors of newly added two records.

Now let’s drop the table students


SQL> drop table students;

Table dropped.

SQL> alter system archive log current;


System altered.

SQL> select thread#,sequence#,status,first_change#,to_char(first_time, 'DD-MON-YY HH24:MI:SS') from v$log;

THREAD# SEQUENCE# STATUS FIRST_CHANGE# TO_CHAR(FIRST_TIME

---------- ---------- ---------------- ------------- ------------------

1 7 CURRENT 979036 04-NOV-13 06:51:41

1 5 ACTIVE 978571 04-NOV-13 06:39:11

1 6 ACTIVE 978911 04-NOV-13 06:47:50

The drop table statement is recorded in seq#6.

Recovery starts:

Let's prepare for recovery to ensure that we recover the two records (Krishna, Vijay) inserted
ago (recover UNTIL TIME '04-NOV-13 06:47:50') just before dropping the table.

Ensure that you have all the archives for the log sequences from #1 to #6.
-rw-r----- 1 oracle dba 265728 Nov 4 05:46 o1_mf_1_1_97h283cl_.arc

-rw-r----- 1 oracle dba 1024 Nov 4 05:46 o1_mf_1_2_97h288cr_.arc

-rw-r----- 1 oracle dba 2900480 Nov 4 06:27 o1_mf_1_3_97h4p6n9_.arc

-rw-r----- 1 oracle dba 208896 Nov 4 06:39 o1_mf_1_4_97h5chqq_.arc

-rw-r----- 1 oracle dba 208896 Nov 4 06:47 o1_mf_1_5_97h5vpqt_.arc

-rw-r----- 1 oracle dba 31232 Nov 4 06:51 o1_mf_1_6_97h62x7g_.arc

SQL> shutdown abort;

ORACLE instance shut down.

[oracle@server1 orcl]$ pwd

/u02/app/oracle/oradata/orcl

Remove all the files and restore datafiles and control file from backup.

[oracle@server1 orcl]$ rm -rf *dbf

[oracle@server1 orcl]$ rm -rf *ctl

[oracle@server1 orcl]$ rm -rf *log

[oracle@server1 orcl]$ cp /u02/app/oracle/online_backups/whole_backup_nov4/*dbf .

[oracle@server1 orcl]$ cp /u02/app/oracle/online_backups/whole_backup_nov4/controlfile_bkp .

[oracle@server1 orcl]$ mv controlfile_bkp control01.ctl


[oracle@server1 orcl]$ cp control01.ctl /u02/app/oracle/flash_recovery_area/orcl/control02.ctl

Start the database in mount stage.


[oracle@server1 orcl]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Mon Nov 4 07:11:25 2013

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

Connected to an idle instance.

SQL> startup mount;

ORACLE instance started.

Total System Global Area 1607008256 bytes

Fixed Size 1336820 bytes

Variable Size 419432972 bytes

Database Buffers 1174405120 bytes

Redo Buffers 11833344 bytes

Database mounted.

SQL> recover database until time '2013-nov-04 06:47:50' using backup controlfile;

ORA-00279: change 977965 generated at 11/04/2013 06:22:27 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_3_97h4p6n

9_.arc

ORA-00280: change 977965 for thread 1 is in sequence #3

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

<press enter>

ORA-00279: change 978172 generated at 11/04/2013 06:27:50 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_4_97h5chq

q_.arc

ORA-00280: change 978172 for thread 1 is in sequence #4

ORA-00278: log file

'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_3_97h4p6
n9_.arc' no longer needed for this recovery

<press enter>

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

ORA-00279: change 978571 generated at 11/04/2013 06:39:11 needed for thread 1

ORA-00289: suggestion :

/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_5_97h5vpq

t_.arc

ORA-00280: change 978571 for thread 1 is in sequence #5

ORA-00278: log file

'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_4_97h5ch

qq_.arc' no longer needed for this recovery

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

<press enter>

Log applied.

Media recovery complete.

SQL> alter database open resetlogs;

Database altered.

SQL> select * from scott.students;

ID NAME

---------- ------------------------------

4 KRISHNA

5 VIJAY

The recovery clauses ‘UNTIL CHANGE’ follows the same procedures but the SCN is used, time
instead.
RMAN

Backing Up a Whole Database with RMAN


The simplest form of the command requires no options or parameters:

BACKUP DATABASE;

The following example backs up the database, switches the online redo logs, and

includes archived logs in the backup:

BACKUP DATABASE PLUS ARCHIVELOG;

[oracle@server1 ~]$ rman target /

Recovery Manager: Release 11.2.0.1.0 - Production on Mon Nov 11 18:04:50 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

connected to target database: ORCL (DBID=1357359438)

RMAN> backup database;

Starting backup at 11-NOV-13

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=34 device type=DISK

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u02/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u02/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/u02/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00006 name=/u02/app/oracle/oradata/orcl/users03.dbf


input datafile file number=00003 name=/u02/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00004 name=/u02/app/oracle/oradata/orcl/users01.dbf

input datafile file number=00007 name=/u02/app/oracle/oradata/orcl/users04.dbf

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnndf_TA
G20131111T180456_982w59ls_.bkp tag=TAG20131111T180456 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:45

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_ncsnf_TAG
20131111T180456_982w6pbg_.bkp tag=TAG20131111T180456 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-NOV-13

RMAN> backup database plus archivelog;

Starting backup at 11-NOV-13

current log archived

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=1 device type=DISK

channel ORA_DISK_1: starting archived log backup set


channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=9 RECID=1 STAMP=829821620

input archived log thread=1 sequence=10 RECID=2 STAMP=829832688

input archived log thread=1 sequence=11 RECID=3 STAMP=829836180

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314wfr_.bkp tag=TAG20131111T193004 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=4 STAMP=830035934

input archived log thread=1 sequence=2 RECID=5 STAMP=830036754

input archived log thread=1 sequence=3 RECID=13 STAMP=830577268

input archived log thread=1 sequence=4 RECID=11 STAMP=830577267

input archived log thread=1 sequence=5 RECID=12 STAMP=830577267

input archived log thread=1 sequence=6 RECID=10 STAMP=830577034

input archived log thread=1 sequence=7 RECID=9 STAMP=830577034

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314xjb_.bkp tag=TAG20131111T193004 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=14 STAMP=830577290


input archived log thread=1 sequence=2 RECID=15 STAMP=830577296

input archived log thread=1 sequence=3 RECID=22 STAMP=830583341

input archived log thread=1 sequence=4 RECID=20 STAMP=830583341

input archived log thread=1 sequence=5 RECID=21 STAMP=830583341

input archived log thread=1 sequence=6 RECID=19 STAMP=830583297

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314ylc_.bkp tag=TAG20131111T193004 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=23 STAMP=830583971

input archived log thread=1 sequence=2 RECID=24 STAMP=830583976

input archived log thread=1 sequence=3 RECID=25 STAMP=830586470

input archived log thread=1 sequence=4 RECID=26 STAMP=830589255

input archived log thread=1 sequence=5 RECID=28 STAMP=830589255

input archived log thread=1 sequence=6 RECID=27 STAMP=830589255

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314znw_.bkp tag=TAG20131111T193004 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=1 RECID=29 STAMP=831011905


input archived log thread=1 sequence=2 RECID=30 STAMP=831031641

input archived log thread=1 sequence=3 RECID=31 STAMP=831060452

input archived log thread=1 sequence=4 RECID=32 STAMP=831144840

input archived log thread=1 sequence=5 RECID=33 STAMP=831238203

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_983150qh_.bkp tag=TAG20131111T193004 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07

Finished backup at 11-NOV-13

Starting backup at 11-NOV-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u02/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u02/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/u02/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00006 name=/u02/app/oracle/oradata/orcl/users03.dbf

input datafile file number=00003 name=/u02/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00004 name=/u02/app/oracle/oradata/orcl/users01.dbf

input datafile file number=00007 name=/u02/app/oracle/oradata/orcl/users04.dbf

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnndf_TA
G20131111T193015_983157wj_.bkp tag=TAG20131111T193015 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:35


channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current control file in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_ncsnf_TAG
20131111T193015_98316d0g_.bkp tag=TAG20131111T193015 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-NOV-13

Starting backup at 11-NOV-13

current log archived

using channel ORA_DISK_1

channel ORA_DISK_1: starting archived log backup set

channel ORA_DISK_1: specifying archived log(s) in backup set

input archived log thread=1 sequence=6 RECID=34 STAMP=831238253

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193053_98316f53_.bkp tag=TAG20131111T193053 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-NOV-13

Backing Up Tablespaces and Datafiles with RMAN


You can back up one or more tablespaces with the BACKUP TABLESPACE command or one or
more datafiles with the BACKUP DATAFILE command. When you specify tablespaces, RMAN
translates the tablespace name internally into a list of datafiles.

The database can be mounted or open. Tablespaces can be read/write or read-only

RMAN automatically backs up the control file and the server parameter file (if the instance was
started with a server parameter file) when data file 1 is included in the backup. If control file
autobackup is enabled, then RMAN writes the current control file and server parameter file to a
separate autobackup piece. Otherwise, RMAN includes these files in the backup set that
contains data file 1.

RMAN> backup tablespace users;

Starting backup at 11-NOV-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00006 name=/u02/app/oracle/oradata/orcl/users03.dbf

input datafile file number=00004 name=/u02/app/oracle/oradata/orcl/users01.dbf

input datafile file number=00007 name=/u02/app/oracle/oradata/orcl/users04.dbf

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13

piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnndf_TA
G20131111T193617_9831jkm8_.bkp tag=TAG20131111T193617 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-NOV-13

Backing Up Control Files with RMAN

You can back up the control file when the database is mounted or open. RMAN uses a
snapshot control file to ensure a read-consistent version. If the CONFIGURE

CONTROLFILE AUTOBACKUP command is set to ON (by default it is OFF), then RMAN

automatically backs up the control file and server parameter file after every backup

and after database structural changes. The control file autobackup contains metadata

about the previous backup, which is crucial for disaster recovery.

If the autobackup feature is not set, then you must manually back up the control file in

one of the following ways:

Run BACKUP CURRENT CONTROLFILE .

BACKUP AS COPY CURRENT CONTROLFILE FORMAT '/tmp/control01.ctl';

Include a backup of the control file within any backup by using the INCLUDE CURRENT
CONTROLFILE option of the BACKUP command.

BACKUP DEVICE TYPE sbt TABLESPACE users INCLUDE CURRENT CONTROLFILE;

Back up data file 1, because RMAN automatically includes the control file and server parameter
file in backups of data file 1.

BACKUP DATAFILE 1,2,3,4 DATAFILECOPY '/tmp/system01.dbf';

Backing Up Server Parameter Files with RMAN


RMAN automatically backs up the current server parameter file in certain cases. The BACKUP
SPFILE command backs up the parameter file explicitly. The server parameter file that is backed
up is the one currently in use by the instance.

Backing Up Archived Redo Logs with RMAN


Archived Redo Log Failover

The archived redo log failover feature enables RMAN to complete a backup even when some
archiving destinations are missing logs or contain logs with corrupt blocks. If at least one log
corresponding to a given log sequence and thread is available in the fast recovery area or any of
the archiving destinations, then RMAN tries to back it up. If RMAN finds a corrupt block in a log
file during backup, it searches other destinations for a copy of that log without corrupt blocks.
However, unknown to RMAN, a user deletes logs 122 and 124 from the /arch1 directory.
Afterward, you run the following backup:

BACKUP ARCHIVELOG FROM SEQUENCE 121 UNTIL SEQUENCE 125;

With failover, RMAN completes the backup, using logs 122 and 124 in /arch2.

The following example backs up the database and all archived redo logs:

BACKUP DATABASE PLUS ARCHIVELOG;

The following example uses a configured disk or SBT channel to back up one copy

of each log sequence number for all archived redo logs:

BACKUP ARCHIVELOG ALL;

You can also specify a range of archived redo logs by time, SCN, or log sequence

number, as in the following example:

BACKUP ARCHIVELOG FROM TIME 'SYSDATE-30' UNTIL TIME 'SYSDATE-7';

Deleting Archived Redo Logs After Backups


The BACKUP ARCHIVELOG ... DELETE INPUT command deletes archived log files after they are
backed up. This command eliminates the separate step of manually deleting archived redo logs.

BACKUP ARCHIVELOG ALL DELETE ALL INPUT;


RMAN>

RMAN> backup as copy database;

Starting backup at 11-NOV-13

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile copy

input datafile file number=00001 name=/u02/app/oracle/oradata/orcl/system01.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_system_982w8wjr_.dbf
tag=TAG20131111T180652 RECID=7 STAMP=831233235

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile copy

input datafile file number=00002 name=/u02/app/oracle/oradata/orcl/sysaux01.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_sysaux_982w9ono_.dbf
tag=TAG20131111T180652 RECID=8 STAMP=831233260

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25

channel ORA_DISK_1: starting datafile copy

input datafile file number=00005 name=/u02/app/oracle/oradata/orcl/example01.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_example_982wbgpt_.dbf
tag=TAG20131111T180652 RECID=9 STAMP=831233265

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07

channel ORA_DISK_1: starting datafile copy

input datafile file number=00006 name=/u02/app/oracle/oradata/orcl/users03.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_users_982wbot6_.dbf
tag=TAG20131111T180652 RECID=10 STAMP=831233272

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03


channel ORA_DISK_1: starting datafile copy

input datafile file number=00003 name=/u02/app/oracle/oradata/orcl/undotbs01.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_undotbs1_982wbrx2_.dbf
tag=TAG20131111T180652 RECID=11 STAMP=831233274

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03

channel ORA_DISK_1: starting datafile copy

copying current control file

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_TAG20131111T180652_9
82wbw0t_.ctl tag=TAG20131111T180652 RECID=12 STAMP=831233276

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting datafile copy

input datafile file number=00004 name=/u02/app/oracle/oradata/orcl/users01.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_users_982wbx2y_.dbf
tag=TAG20131111T180652 RECID=13 STAMP=831233277

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting datafile copy

input datafile file number=00007 name=/u02/app/oracle/oradata/orcl/users04.dbf

output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_users_982wby58_.dbf
tag=TAG20131111T180652 RECID=14 STAMP=831233278

channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01

channel ORA_DISK_1: starting full datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

including current SPFILE in backup set

channel ORA_DISK_1: starting piece 1 at 11-NOV-13

channel ORA_DISK_1: finished piece 1 at 11-NOV-13


piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnsnf_TAG
20131111T180652_982wbz8j_.bkp tag=TAG20131111T180652 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01

Finished backup at 11-NOV-13

RMAN> exit

Recovery Manager complete.

You might also like