Professional Documents
Culture Documents
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;
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;
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
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")
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.
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
*/
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
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.
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
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
/
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:'
/
In this exercise you will learn how to maintain tablespaces and datafiles in the database with
and without using Oracle-Managed Files (OMF).
In this exercise you will learn how to maintain a temporary tablespace with or without using
Oracle-Managed Files (OMF) and more.
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.
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
/
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.
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
SELECT t.NAME "Tablespace", f.NAME "Datafile" FROM V$TABLESPACE t, V$DATAFILE f WHERE t.TS# = f.TS# ORDER BY
t.NAME;
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.
Database closed.
Database dismounted.
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.
./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
SQL> startup;
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.
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:
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
Tablespace altered.
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:
------------------------------ -------------------------------------------------------------------------------------------------
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.
Tablespace altered.
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.
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
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
WHERE d.TS#=t.TS#
AND b.FILE#=d.FILE#
AND b.STATUS='ACTIVE';
TB_NAME DF# DF_NAME STATUS
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
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.
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 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
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;
or
Database altered.
or
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.
Database altered.
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26
total 35720
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.
TABLESPACE_NAME STATUS
------------------------------ ---------
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:
/u02/app/oracle/oradata/orcl
[oracle@server1 orcl]$ rm *
-----------------------------------------------------------------------------------
/u02/app/oracle/oradata/orcl
Connected to:
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> exit
Database mounted.
SQL> alter database recover automatic using backup controlfile until cancel;
ERROR at line 1:
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_28/o1_mf_1_12_%u_.ar
'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_28/o1_mf_1_12_%u_.a
'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_28/o1_mf_1_12_%u_.a
rc'
Additional information: 3
ERROR at line 1:
Database altered.
CURRENT_SCN
-----------
931871
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.
Database altered.
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26/o1_mf_1_10_96r11z
px_.arc
<press enter>
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26/o1_mf_1_11_96r4h2
qc_.arc
<press enter>
Log applied.
Database altered.
SQL>
Recovery:
SQL> shutdown abort;
Database mounted.
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_10_26/o1_mf_1_11_96r4h2
qc_.arc
<press enter>
Log applied.
Database altered.
SQL>
Point In Time Recovery (PITR) UNTIL TIME
Insert user data to simulate recovery scenario:
Connected to:
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Table created.
1 row created.
1 row created.
1 row created.
SQL> commit;
Commit complete.
ID NAME
---------- ------------------------------
1 PAVAN
2 RAKESH
3 ROHIT
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)
System altered.
System altered.
< Perform user managed hot backup here as described in procedure UB4>
[oracle@server1 whole_backup]$ sqlplus scott/tiger
Connected to:
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ID NAME
---------- ------------------------------
1 PAVAN
2 RAKESH
3 ROHIT
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;
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.
1 row created.
SQL> commit;
Commit complete.
System altered.
Table dropped.
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
/u02/app/oracle/oradata/orcl
Remove all the files and restore datafiles and control file from backup.
Database mounted.
SQL> recover database until time '2013-nov-04 06:47:50' using backup controlfile;
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_3_97h4p6n
9_.arc
<press enter>
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_4_97h5chq
q_.arc
'/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>
ORA-00289: suggestion :
/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_5_97h5vpq
t_.arc
'/u02/app/oracle/flash_recovery_area/ORCL/archivelog/2013_11_04/o1_mf_1_4_97h5ch
<press enter>
Log applied.
Database altered.
ID NAME
---------- ------------------------------
4 KRISHNA
5 VIJAY
The recovery clauses ‘UNTIL CHANGE’ follows the same procedures but the SCN is used, time
instead.
RMAN
BACKUP DATABASE;
The following example backs up the database, switches the online redo logs, and
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnndf_TA
G20131111T180456_982w59ls_.bkp tag=TAG20131111T180456 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_ncsnf_TAG
20131111T180456_982w6pbg_.bkp tag=TAG20131111T180456 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314wfr_.bkp tag=TAG20131111T193004 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314xjb_.bkp tag=TAG20131111T193004 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314ylc_.bkp tag=TAG20131111T193004 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_98314znw_.bkp tag=TAG20131111T193004 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193004_983150qh_.bkp tag=TAG20131111T193004 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnndf_TA
G20131111T193015_983157wj_.bkp tag=TAG20131111T193015 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_ncsnf_TAG
20131111T193015_98316d0g_.bkp tag=TAG20131111T193015 comment=NONE
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_annnn_TA
G20131111T193053_98316f53_.bkp tag=TAG20131111T193053 comment=NONE
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.
piece
handle=/u02/app/oracle/flash_recovery_area/ORCL/backupset/2013_11_11/o1_mf_nnndf_TA
G20131111T193617_9831jkm8_.bkp tag=TAG20131111T193617 comment=NONE
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
automatically backs up the control file and server parameter file after every backup
and after database structural changes. The control file autobackup contains metadata
If the autobackup feature is not set, then you must manually back up the control file in
Include a backup of the control file within any backup by using the INCLUDE CURRENT
CONTROLFILE option of the BACKUP command.
Back up data file 1, because RMAN automatically includes the control file and server parameter
file in backups of data file 1.
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:
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:
The following example uses a configured disk or SBT channel to back up one copy
You can also specify a range of archived redo logs by time, SCN, or log sequence
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_system_982w8wjr_.dbf
tag=TAG20131111T180652 RECID=7 STAMP=831233235
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_sysaux_982w9ono_.dbf
tag=TAG20131111T180652 RECID=8 STAMP=831233260
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_example_982wbgpt_.dbf
tag=TAG20131111T180652 RECID=9 STAMP=831233265
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_users_982wbot6_.dbf
tag=TAG20131111T180652 RECID=10 STAMP=831233272
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_undotbs1_982wbrx2_.dbf
tag=TAG20131111T180652 RECID=11 STAMP=831233274
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/controlfile/o1_mf_TAG20131111T180652_9
82wbw0t_.ctl tag=TAG20131111T180652 RECID=12 STAMP=831233276
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_users_982wbx2y_.dbf
tag=TAG20131111T180652 RECID=13 STAMP=831233277
output file
name=/u02/app/oracle/flash_recovery_area/ORCL/datafile/o1_mf_users_982wby58_.dbf
tag=TAG20131111T180652 RECID=14 STAMP=831233278
RMAN> exit