http://appsjagan.blogspot.in/search?

updated-min=2010-01-01T00:00:00%2B05:30&updatedmax=2011-01-01T00:00:00%2B05:30&max-results=50 http://oraclemamukutti.blogspot.in/2011/03/performance-tuning-part-1.html http://www.dba-oracle.com/oracle_tips_fix_corrupt_undo_segments.htm http://allthingsoracle.com/convert-single-instance-to-rac-part-2-manually-convert-to-rac/ http://oracledbascratchpad.blogspot.in/2009/10/tuning-scripts.html http://kumarmohitlal.blogspot.in/2012/01/oracle-real-time-interview-questions.html http://gavinsoorma.com/category/oracle-11g/ http://dbaadnanrafi.blogspot.in/2011_01_01_archive.html http://www.siue.edu/~dbock/cmis565/ http://oraclemamukutti.blogspot.in/2011/03/performance-tuning-part-1.html http://oraclemamukutti.blogspot.in/2011/03/performance-tuning-part-2.html http://satya-dba.blogspot.in/2010/04/rman-commands.html#catalog (IMP) http://docs.oracle.com/cd/E11882_01/server.112/e25494/dba006.htm#ADMIN11052 Primary database scn is 22 and standby SCN is 24 how you will resolve this issue In case of a dedicated server, a server process is associated with a single user process and serves it dedicatedly. In case of a shared server, a single server process can serve multiple user processes. This is achieved with the help of a dispatcher process, which places each user process in a single request queue. Server process picks up the user process whenever it is free. After that, the server process puts the result in the individual response queue associated with different dispatcher processes. How to increase SGA_MAX_SIZE
SQL> SHOW parameter spfile NAME TYPE VALUE ------------------------------------ ----------- -----------------------------spfile string /u01/app/oracle/product/10.2.0 /dbs/spfileDB1.ora SQL> CREATE pfile FROM spfile; File created. SQL> ALTER system SET sga_max_size=600M scope=spfile; System altered. SQL> shutdown immediate; DATABASE closed. DATABASE dismounted. ORACLE instance shut down. SQL> startup

Data Files: moving renaming deleting
SQL> SELECT name FROM v$datafile; NAME --------------------------------------------------------/u01/app/oracle/product/10.2.0/oradata/DBSID/SYSTEM01.DBF

/u01/app/oracle/product/10.2.0/oradata/DBSID/UNDOTBS01.DBF /u01/app/oracle/product/10.2.0/oradata/DBSID/SYSAUX01.DBF /u01/app/oracle/product/10.2.0/oradata/DBSID/USERS01.DBF /u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE01.DBF

Shutdown the database first:
SQL> SHUTDOWN IMMEDIATE;

Rename a datafile:

SQL> host mv -v /u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE01.DBF \ /u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE02.DBF

Move a datafile to the new location:
SQL> HOST mv -v /u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE01.DBF \ /u01/app/oracle/oradata/DBSID/EXAMPLE01.DBF

Move and rename a datafile to the new location:

SQL> HOST mv -v /u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE01.DBF \ /u01/app/oracle/oradata/DBSID/EXAMPLE02.DBF SQL> STARTUP MOUNT

Move and rename a datafile variant:
SQL> ALTER DATABASE RENAME FILE '/u01/app/oracle/product/10.2.0/oradata/DBSID/EXAMPLE01.DBF' TO '/u01/app/oracle/oradata/DBSID/EXAMPLE02.DBF'; SQL> ALTER DATABASE OPEN; SQL> SELECT name FROM v$datafile; NAME ---------------------------------------------------------------/u01/app/oracle/product/10.2.0/oradata/DBSID/SYSTEM01.DBF /u01/app/oracle/product/10.2.0/oradata/DBSID/UNDOTBS01.DBF /u01/app/oracle/product/10.2.0/oradata/DBSID/SYSAUX01.DBF /u01/app/oracle/product/10.2.0/oradata/DBSID/USERS01.DBF /u01/app/oracle/oradata/DBSID/EXAMPLE02.DBF

Database altered

Deleting dropping a datafile:

If a datafile you wish to drop is only datafile, present in the tablespace in which it resides, you can simply drop a tablespace:
SQL> SELECT file_name, tablespace_name FROM dba_data_files; FILE_NAME TABLESPACE_NAME ------------------------------------------------------------------- -----------------------------/u01/app/oracle/oradata/DBSID/EXAMPLE02.DBF EXAMPLE02 SQL>ALTER DATABASE DATAFILE /u01/app/oracle/oradata/DBSID/EXAMPLE02.DBF OFFLINE DROP

SQL>DROP TABLESPACE EXAMPLE02 INCLUDING CONTENTS; SQL> host rm -f /u01/app/oracle/oradata/DBSID/EXAMPLE02.DBF

OR

SQL>DROP TABLESPACE EXAMPLE02 INCLUDING CONTENTS AND DATAFILES;

Redo Online Logs: add clear move delete After default database 10g installation usually we‘ve got 2-3 redo log files in 2-3 groups:
SQL>select GROUP#, member from v$logfile; GROUP# MEMBER ---------------------------------------------1 /u01/app/oracle/oradata/DBSID/redo01.log 2 /u01/app/oracle/oradata/DBSID/redo02.log 3 /u01/app/oracle/oradata/DBSID/redo03.log

Let’s make some changes and create 3 additional members on a different mount point...

Adding new redo log members to an existing group:

NOTE: The database is up and running. First, create physical directories:
as a root user: #mkdir -p /u02/app ; chmod -R 775 /u02; chown -R root:oinstall /u02

And next:
as an oracle user: $ mkdir -p /u02/app/ oracle/oradata/DBSID/ SQL> ALTER DATABASE ADD LOGFILE MEMBER '/u02/app/oracle/oradata/DBSID/redo1b.log' TO GROUP 1, '/u02/app/oracle/oradata/DBSID/redo2b.log' TO GROUP 2, '/u02/app/oracle/oradata/DBSID/redo3b.log' TO GROUP 3; SQL>select GROUP# , member from v$logfile order by group#; GROUP# MEMBER ---------------------------------------------1 /u01/app/oracle/oradata/DBSID/redo01.log 1 /u01/app/oracle/oradata/DBSID/redo1b.log 2 /u01/app/oracle/oradata/DBSID/redo02.log 2 /u01/app/oracle/oradata/DBSID/redo2b.log 3 /u01/app/oracle/oradata/DBSID/redo03.log 3 /u01/app/oracle/oradata/DBSID/redo3b.log

Renaming, moving the redo log files

First shutdown the database:
SQL>shutdown immediate

Move, rename physical files on the OS
$mv –v /u01/app/oracle/oradata/DBSID/redo01.log \ /u01/app/oracle/oradata/DBSID/redo1a.log $mv –v /u01/app/oracle/oradata/DBSID/redo02.log \ /u01/app/oracle/oradata/DBSID/redo2a.log $mv –v /u01/app/oracle/oradata/DBSID/redo03.log \ /u01/app/oracle/oradata/DBSID/redo3a.log

Go back to SQLplus and startup database in mount mode:
SQL>STARTUP MOUNT SQL>ALTER DATABASE RENAME FILE '/u01/app/oracle/oradata/DBSID/redo01.log' TO '/u01/app/oracle/oradata/DBSID/redo1a.log'; SQL>ALTER DATABASE RENAME FILE '/u01/app/oracle/oradata/DBSID/redo02.log' TO '/u01/app/oracle/oradata/DBSID/redo2a.log'; SQL>ALTER DATABASE RENAME FILE '/u01/app/oracle/oradata/DBSID/redo03.log' TO '/u01/app/oracle/oradata/DBSID/redo3a.log'; SQL> ALTER DATABASE OPEN; SQL>select GROUP# , member from v$logfile order by group#; GROUP# MEMBER ---------------------------------------------1 /u01/app/oracle/oradata/DBSID/redo1a.log 1 /u02/app/oracle/oradata/DBSID/redo1b.log 2 /u01/app/oracle/oradata/DBSID/redo2a.log 2 /u02/app/oracle/oradata/DBSID/redo2b.log 3 /u01/app/oracle/oradata/DBSID/redo3a.log 3 /u02/app/oracle/oradata/DBSID/redo3b.log

Creating a new redo log file:

1 SQL>ALTER DATABASE ADD LOGFILE 2 '/u01/app/oracle/oradata/DBSID/redo4a.log' SIZE 10M

A new group is created automatically.
SQL>select GROUP# , member from v$logfile order by group#; GROUP# MEMBER ---------------------------------------------1 /u01/app/oracle/oradata/DBSID/redo1a.log 1 /u02/app/oracle/oradata/DBSID/redo1b.log 2 /u01/app/oracle/oradata/DBSID/redo2a.log 2 /u02/app/oracle/oradata/DBSID/redo2b.log 3 /u01/app/oracle/oradata/DBSID/redo3a.log 3 /u02/app/oracle/oradata/DBSID/redo3b.log 4 /u02/app/oracle/oradata/DBSID/redo4a.log

Managing Tablespaces and Datafiles Using multiple tablespaces provides several Advantages  Separate user data from data dictionary data to reduce contention among dictionary objects and schema objects for the same datafiles.log'. '/u02/app/oracle/oradata/DBSID/redo3b. .Creating new multiple log files: 1 2 3 4 5 SQL>ALTER DATABASE ADD LOGFILE ('/u02/app/oracle/oradata/DBSID/redo3b.  Dropping redo log group and redo log member: NOTE: There are some restrictions when dropping redo log groups or redo log files: . Switching redo log files group and force to create an archive log file arc.log' . you need to force clear 1 SQL>ALTER DATABASE CLEAR UNARCHIVED LOGFILE 2 '/u02/app/oracle/oradata/DBSID/redo3a.log '. When archive log mode is YES. .log'. To drop a group member: 1 SQL>ALTER DATABASE DROP LOGFILE MEMBER 2 '/u02/app/oracle/oradata/DBSID/redo4A.There must be at least two redo log groups and each redo log group must have at least one log member left.log '.log') SIZE 10M. SQL>ALTER SYSTEM SWITCH LOGFILE. To drop a group: SQL>ALTER DATABASE DROP LOGFILE GROUP 4. Clearing Log Files and Group 1 SQL>ALTER DATABASE CLEAR LOGFILE 2 '/u02/app/oracle/oradata/DBSID/redo3a. '/u02/app/oracle/oradata/DBSID/redo3b. SQL>ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 2.Only inactive group can be dropped.

If you omit SIZE. Store different the datafiles of different tablespaces on different disk drives to reduce I/O contention. resulting in the following benefits:   Concurrency and speed of space operations is improved. In prior versions of Oracle only Dictionary managed Tablespaces were available but from Oracle ver. The alternative to AUTOALLOCATE is UNIFORM. The advantages of locally managed tablespaces are Locally managed tablespaces track all extent information in the tablespace itself by using bitmaps. You can specify that size in the SIZE clause of UNIFORM. The following example creates a Locally managed tablespace with uniform extent size of 256K SQL> CREATE TABLESPACE ica_lmt DATAFILE '/u02/oracle/ica/ica01. providing better overall availability. To Create Dictionary Managed Tablespace . which specifies that the tablespace is managed with extents of uniform size. then the default size is 1M. because recursive operations that are sometimes required during dictionary-managed space allocation are eliminated To create a locally managed tablespace give the following command SQL> CREATE TABLESPACE ica_lmts DATAFILE '/u02/oracle/ica/ica01. Creating New Tablespaces You can create Locally Managed or Dictionary Managed Tablespaces.   Separate data of one application from the data of another to prevent multiple applications from being affected if a tablespace must be taken offline.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K. because space allocations and deallocations modify locally managed resources (bitmaps stored in header files) rather than requiring centrally managed resources such as enqueues Performance is improved. 8i you can also create Locally managed tablespaces. AUTOALLOCATE causes the tablespace to be system managed with a minimum extent size of 64K.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL AUTOALLOCATE. Take individual tablespaces offline while others remain online.

dbf' SIZE 50M EXTENT MANAGEMENT DICTIONARY. in contrast. Option 3 You can also use auto extend feature of datafile. To add a new datafile to an existing tablespace give the following command. but very large (up to 4G blocks) datafile. To create a bigfile tablespace give the following command SQL> CREATE BIGFILE TABLESPACE ica_bigtbs DATAFILE '/u02/oracle/ica/bigtbs01. SQL> alter tablespace add datafile ‘/u02/oracle/ica/icatbs02. This will increase the size from 50M to 100M Option 2 You can also extend the size of a tablespace by adding a new datafile to a tablespace. can contain multiple datafiles. Bigfile Tablespaces (Introduced in Oracle Ver. To Extend the Size of a tablespace Option 1 You can extend the size of a tablespace by increasing the size of an existing datafile by typing the following command SQL> alter database ica datafile ‘/u01/oracle/data/icatbs01. .SQL> CREATE TABLESPACE ica_lmt DATAFILE '/u02/oracle/ica/ica01. Oracle will automatically increase the size of a datafile whenever space is required.dbf’ size 50M. Traditional smallfile tablespaces.dbf' SIZE 50G. Bigfile tablespaces can reduce the number of datafiles needed for a database. You can specify by how much size the file should increase and Maximum size to which it should extend. This is useful if the size of existing datafile is reached o/s file size limit or the drive where the file is existing does not have free space.dbf’ resize 100M. In this. 10g) A bigfile tablespace is a tablespace with a single. but the files cannot be as large.

dbf’ auto extend ON next 5M maxsize 500M. In some cases. You can also make a datafile auto extendable while creating a new tablespace itself by giving the following command.. To decrease the size of a tablespace You can decrease the size of tablespace by decreasing the datafile associated with it. the database uses the free extent closest in size to the required extent. SQL> create tablespace ica datafile ‘/u01/oracle/ica/icatbs01. When allocating new extents to a tablespace segment. when segments are dropped. You decrease a datafile only up to size of empty space in it.dbf’ size 50M auto extend ON next 5M maxsize 500M. The result is fragmentation that makes allocation of larger extents more difficult. To Coalesce a tablespace give the following command SQL> alter tablespace ica coalesce.To make a existing datafile auto extendable give the following command SQL> alter database datafile ‘/u01/oracle/ica/icatbs01. You should often use the ALTER TABLESPACE .. To decrease the size of a datafile give the following command SQL> alter database datafile ‘/u01/oracle/ica/icatbs01. but adjacent free extents are not immediately recombined into larger free extents. Coalescing Tablespaces A free extent in a dictionary-managed tablespace is made up of a collection of contiguous free blocks. their extents are deallocated and marked as free. . COALESCE statement to manually coalesce any adjacent free extents.dbf’ resize 30M.

Making a tablespace read-only prevents write operations on the datafiles in the tablespace. If the datafile has become corrupt or missing when the database is running in NOARCHIVELOG mode then you can only drop it by giving the following command SQL>alter database datafile ‘/u01/oracle/ica/ica_tbs01. Conversely. You must have the ALTER TABLESPACE or MANAGE TABLESPACE system privilege. Making a Tablespace Read only. The rest of the database remains open and available for users to access data.dbf’ offline for drop. The primary purpose of read-only tablespaces is to eliminate the need to perform backup and recovery of large. static portions of a database. Making a tablespace read-only prevents updates on all tables in the tablespace. To Take a Tablespace Offline give the following command SQL>alter tablespace ica offline. .dbf’ online. To alter the availability of a tablespace.dbf’ offline. SQL>alter tablespace ica online. Note: You can‘t take individual datafiles offline it the database is running in NOARCHIVELOG mode.Taking tablespaces Offline or Online You can take an online tablespace offline so that it is temporarily unavailable for general use. To take individual datafile offline type the following command SQL>alter database datafile ‘/u01/oracle/ica/ica_tbs01. To again bring it back online give the following command. Again to bring it back online give the following command SQL> alter database datafile ‘/u01/oracle/ica/ica_tbs01. you can bring an offline tablespace online to make the schema objects within the tablespace available to database users. use the ALTER TABLESPACE statement. The database must be open to alter the availability of a tablespace. regardless of a user's update privilege level. Read-only tablespaces also provide a way to protecting historical data so that users cannot modify it.

This will drop the tablespace even if it is not empty. For example. You must have the DROP TABLESPACE system privilege to drop a tablespace. Therefore. If the tablespace being renamed is the SYSTEM tablespace or the SYSAUX tablespace. But the datafiles will not be deleted you have to use operating system command to delete the files. or if the tablespace is offline. then the tablespace is not renamed and an error is raised. the following statement renames the users tablespace: ALTER TABLESPACE users RENAME TO usersts. then it will not be renamed and an error is raised. back up the database completely To drop a tablespace give the following command. Also. make sure that all data contained in a tablespace to be dropped will not be required in the future. Caution: Once a tablespace has been dropped.To make a tablespace read only SQL>alter tablespace ica read only Again to make it read write SQL>alter tablespace ica read write. immediately before and after dropping a tablespace from a database. SQL> drop tablespace ica. you can rename a permanent or temporary tablespace. Dropping Tablespaces You can drop a tablespace and its contents (the segments contained in the tablespace) from the database if the tablespace and its contents are no longer required. Renaming Tablespaces Using the RENAME TO clause of the ALTER TABLESPACE. If it is not empty and if you want to drop it anyhow then add the following keyword SQL>drop tablespace ica including contents. . If any datafile in the tablespace is offline. the data in the tablespace is not recoverable. The following affect the operation of this statement:    The COMPATIBLE parameter must be set to 10. This will drop the tablespace only if it is empty.0 or higher.

To create temporary tablespace give the following command. Increasing or Decreasing the size of a Temporary Tablespace You can use the resize clause to increase or decrease the size of a temporary tablespace. so its name cannot be the same as any tablespace. SQL>create temporary tablespace temp tempfile ‘/u01/oracle/data/ica_temp.But If you include datafiles keyword then. the associated datafiles will also be deleted from the disk. A tablespace group has the following characteristics:    It contains at least one tablespace. SQL>drop tablespace ica including contents and datafiles. The following statement drops a temporary file and deletes the operating system file: SQL> ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02.dbf’ size 100M extent management local uniform size 5M. You can specify a tablespace group name wherever a tablespace name would appear when you assign a default temporary tablespace for the database or a temporary tablespace for a user. The AUTOALLOCATE clause is not allowed for temporary tablespaces.dbf' RESIZE 18M. Tablespace Groups A tablespace group enables a user to consume temporary space from multiple tablespaces. The following statement resizes a temporary file: SQL>ALTER DATABASE TEMPFILE '/u02/oracle/data/lmtemp02. Temporary Tablespace Temporary tablespace is used for sorting large tables. Every database should have one temporary tablespace. There is no explicit limit on the maximum number of tablespaces that are contained in a group. The extent management clause is optional for temporary tablespaces because all temporary tablespaces are created with locally managed extents of a uniform size. It shares the namespace of tablespaces. .dbf' DROP INCLUDING DATAFILES.

ALTER TABLESPACE ica_temp2 TABLESPACE GROUP group2. if neither group1 nor group2 exists. The view DBA_TABLESPACE_GROUPS lists tablespace groups and their member tablespaces. For example.You do not explicitly create a tablespace group. then the following statements create those groups. particularly on a table that has many partitions. Diagnosing and Repairing Locally Managed Tablespace Problems To diagnose and repair corruptions in Locally Managed Tablespaces Oracle has supplied a package called DBMS_SPACE_ADMIN. rather than a single temporary tablespace. A tablespace group enables parallel execution servers in a single parallel operation to use multiple temporary tablespaces... it is created implicitly when you assign the first temporary tablespace to the group. For example: ALTER DATABASE sample DEFAULT TEMPORARY TABLESPACE group2. Using a tablespace group.DEFAULT TEMPORARY TABLESPACE statement to assign a tablespace group as the default temporary tablespace for the database.dbf' SIZE 50M TABLESPACE GROUP group1. Assigning a Tablespace Group as the Default Temporary Tablespace Use the ALTER DATABASE . This package has many procedures described below: Procedure Description . Rather. The group is deleted when the last temporary tablespace it contains is removed from it. Creating a Temporary Tablespace Group You create a tablespace group implicitly when you include the TABLESPACE GROUP clause in the CREATE TEMPORARY TABLESPACE or ALTER TABLESPACE statement and the specified tablespace group does not currently exist. each of which has only the specified tablespace as a member: CREATE TEMPORARY TABLESPACE ica_temp2 TEMPFILE '/u02/oracle/ica/ica_temp. can alleviate problems caused where one tablespace is inadequate to hold the results of a sort.

Marks the segment corrupt or valid so that appropriate error recovery can be done. Migrates a tablespace from dictionary-managed format to locally managed format. Verifies that the bitmaps and extent maps for the segments in the tablespace are in sync. Rebuilds the appropriate bitmap. Migrates a locally managed tablespace to dictionarymanaged tablespace. Cannot be used for a locally managed SYSTEM tablespace. Drops a segment currently marked corrupt (without reclaiming space). Cannot be used for a locally managed system tablespace. Cannot be used for a locally managed SYSTEM tablespace.Procedure SEGMENT_VERIFY SEGMENT_CORRUPT Description Verifies the consistency of the extent map of the segment. Marks the appropriate data block address range (extent) as free or used in bitmap. Fixes the state of the segments in a tablespace in which SEGMENT_DROP_CORRUPT SEGMENT_DUMP TABLESPACE_VERIFY TABLESPACE_REBUILD_BITMAPS TABLESPACE_FIX_BITMAPS TABLESPACE_REBUILD_QUOTAS TABLESPACE_MIGRATE_FROM_LOCAL TABLESPACE_MIGRATE_TO_LOCAL TABLESPACE_RELOCATE_BITMAPS TABLESPACE_FIX_SEGMENT_STATES . Cannot be used for a locally managed SYSTEM tablespace. Cannot be used to migrate a locally managed SYSTEM tablespace to a dictionary-managed SYSTEM tablespace. Cannot be used for a locally managed SYSTEM tablespace. Dumps the segment header and extent map of a given segment. Relocates the bitmaps to the destination specified. Rebuilds quotas for given tablespace.

Call TABLESPACE_REBUILD_QUOTAS to fix up quotas. For each range. Call the SEGMENT_DUMP procedure to dump the ranges that the administrator allocated to the segment. In this scenario. Call the SEGMENT_DUMP procedure to dump the DBA ranges allocated to the segment. Call TABLESPACE_REBUILD_QUOTAS to fix up quotas. The system has automatically marked the segment corrupted. Contact Oracle Support before using these procedures. Call the SEGMENT_VERIFY procedure with the SEGMENT_VERIFY_EXTENTS_GLOBAL option. For each range. In this scenario. then proceed with steps 2 through 5.Procedure Description migration was aborted. perform the following tasks: 1. Following are some of the Scenarios where you can use the above procedures Scenario 1: Fixing Bitmap When Allocated Blocks are Marked Free (No Overlap) The TABLESPACE_VERIFY procedure discovers that a segment has allocated blocks that are marked free in the bitmap. 3. call the TABLESPACE_FIX_BITMAPS procedure with the TABLESPACE_EXTENT_MAKE_USED option to mark the space as used. 5. 2. Scenario 3: Fixing Bitmap Where Overlap is Reported . 3. call TABLESPACE_FIX_BITMAPS with the TABLESPACE_EXTENT_MAKE_FREE option to mark the space as free. 2. 4. Be careful using the above procedures if not used properly you will corrupt your database. If no overlaps are reported. Scenario 2: Dropping a Corrupted Segment You cannot drop a segment because the bitmap has segment blocks marked "free". perform the following tasks: 1. Call SEGMENT_DROP_CORRUPT to drop the SEG$ entry. but no overlap between segments is reported.

If necessary. In this scenario. You use the TABLESPACE_MIGRATE_TO_LOCAL procedure. For example if you want to migrate a dictionary managed tablespace ICA2 to Locally managed then give the following command. Some of the real data must be sacrificed based on previous internal errors. essentially moving tablespaces between the databases.The TABLESPACE_VERIFY procedure reports some overlapping. The tablespaces being transported can be either dictionary managed or locally managed. Call the SEGMENT_VERIFY procedure on all objects that t1 overlapped. . Starting with Oracle9i. in this case say. 2. Drop table t1. Scenario 4: Correcting Media Corruption of Bitmap Blocks A set of bitmap blocks has media corruption. 3.TABLESPACE_MIGRATE_TO_LOCAL ('ica2'). Call the TABLESPACE_REBUILD_QUOTAS procedure to rebuild quotas. follow up by calling the SEGMENT_DROP_CORRUPT procedure. Call the TABLESPACE_VERIFY procedure to verify that the bitmaps are consistent. table t1. Transporting Tablespaces You can use the transportable tablespaces feature to move a subset of an Oracle Database and "plug" it in to another Oracle Database. If necessary. the transported tablespaces are not required to be of the same block size as the target database standard block size. perform the following tasks: 1. 2. Call the TABLESPACE_REBUILD_BITMAPS procedure. EXEC DBMS_SPACE_ADMIN. Rerun the TABLESPACE_VERIFY procedure to verify the problem is resolved. perform the following tasks: 1. 3. Make a list of all objects that t1 overlaps. either on all bitmap blocks. or on a single block if only one is corrupt. Scenario 5: Migrating from a Dictionary-Managed to a Locally Managed Tablespace To migrate a dictionary-managed tablespace to a locally managed tablespace. After choosing the object to be sacrificed. call the TABLESPACE_FIX_BITMAPS procedure to mark appropriate bitmap blocks as used. 4.

This is because the datafiles containing all of the actual data are simply copied to the destination location. then no conversion is necessary and tablespaces can be transported as if they were on the same platform. the datafile header must identify the platform to which it belongs. then an additional step must be done on either the source or target platform to convert the tablespace being transported to the target format. Important: Before a tablespace can be transported to a different platform. SQL> COLUMN PLATFORM_NAME FORMAT A30 SQL> SELECT * FROM V$TRANSPORTABLE_PLATFORM. .-----------------------------.Moving data using transportable tablespaces is much faster than performing either an export/import or unload/load of the same data. Big Big Little Little Big Big Little Big Little Little If the source platform and the target platform are of different endianness.-------------1 Solaris[tm] OE (32-bit) 2 Solaris[tm] OE (64-bit) 7 Microsoft Windows NT 10 Linux IA (32-bit) 6 AIX-Based Systems (64-bit) 3 HP-UX (64-bit) 5 HP Tru64 UNIX 4 HP-UX IA (64-bit) 11 Linux IA (64-bit) 15 HP Open VMS 10 rows selected. In an Oracle Database with compatibility set to 10. However not all platforms are supported. and you use an import utility to transfer only the metadata of the tablespace objects to the new database. you can transport tablespaces across platforms. If they are of the same endianness. PLATFORM_ID PLATFORM_NAME ENDIAN_FORMAT ----------.0. To see which platforms are supported give the following query. Starting with Oracle Database 10g. This functionality can be used to Allow a database to be migrated from one platform to another.0 or higher. you can accomplish this by making the datafile read/write at least once.

no conversion is necessary. If both platforms have the same endianness. If you are transporting the tablespace set to a platform with different endianness from the source platform. you should perform a target-side conversion now. 2. Transport the tablespace set. the DBMS_FILE_COPY package. and you have not performed a source-side conversion to the endianness of the target platform. then determine if the source and target platforms are supported and their endianness. 1.SQL> alter tablespace ica read only. . If you have transported the tablespace set to a platform with different endianness from the source platform. Copy the datafiles and the export file to the target database. you must convert the tablespace set to the endianness of the target platform. Plug in the tablespace. If you are transporting the tablespace set to a platform different from the source platform. or publishing on CDs). Pick a self-contained set of tablespaces. Generate a transportable tablespace set. or you can perform a target-side conversion as part of step 4. Then. For cross-platform transport. You can perform a source-side conversion at this step in the procedure. SQL> alter tablespace ica read write. 5. Procedure for transporting tablespaces To move or copy a set of tablespaces. 3. Ignore this step if you are transporting your tablespace set to the same platform. Otherwise you must do a conversion of the tablespace set either at the source or target database. A transportable tablespace set consists of datafiles for the set of tablespaces being transported and an export file containing structural information for the set of tablespaces. an operating system copy utility. You can do this using any facility for copying flat files (for example. perform the following steps. check the endian format of both platforms by querying the V$TRANSPORTABLE_PLATFORM view. 4. ftp.

-------------Microsoft Windows NT Little You can see that the endian formats are different and thus a conversion is necessary for transporting the tablespace set. where it is assumed the following datafiles and tablespaces exist: Tablespace ica_sales_1 ica_sales_2 Datafile: /u01/oracle/oradata/ica_salesdb/ica_sales_101.-------------Solaris[tm] OE (32-bit) Big The following is the result from the target platform: PLATFORM_NAME ENDIAN_FORMAT ------------------------. V$DATABASE d WHERE tp.PLATFORM_NAME = d. That is it should not have tables with foreign keys referring to primary key of tables which are in other .dbf /u01/oracle/oradata/ica_salesdb/ica_sales_201.dbf Step 1: Determine if Platforms are Supported and Endianness This step is only necessary if you are transporting the tablespace set to a platform different from the source platform.PLATFORM_NAME. You can only transport a set of tablespaces that is self-contained. ENDIAN_FORMAT FROM V$TRANSPORTABLE_PLATFORM tp. The following is the query result from the source platform: PLATFORM_NAME ENDIAN_FORMAT ------------------------. Step 2: Pick a Self-Contained Set of Tablespaces There may be logical or physical dependencies between objects in the transportable set and those outside of the set.PLATFORM_NAME. If ica_sales_1 and ica_sales_2 were being transported to a different platform. you can execute the following query on both platforms to determine if the platforms are supported and their endian formats: SELECT d. Transporting Tablespace Example These steps are illustrated more fully in the example that follows.Invoke the Export utility to plug the set of tablespaces into the target database.

and the endianness of the platforms is different.ica_sales_2 If ica_sales_1 and ica_sales_2 are being transported to a different platform. To find out whether the tablespace is self contained do the following EXECUTE DBMS_TTS. Tablespace altered.SALES is partially contained in the transportable set These violations must be resolved before ica_sales_1 and ica_sales_2 are transportable Step 3: Generate a Transportable Tablespace Set After ensuring you have a self-contained set of tablespaces that you want to transport.TRANSPORT_SET_CHECK('ica_sales_1. TRUE). and if you want to convert before transporting the . VIOLATIONS --------------------------------------------------------------------------Constraint DEPT_FK between table SAMI. It should not have tables with some partitions in other tablespaces.dmp TRANSPORT_TABLESPACES = ica_sales_1. Invoke the Export utility on the host system and specify which tablespaces are in the transportable set.tablespaces.EMP in tablespace ICA_SALES_1 and table SAMI. Tablespace altered. SQL> ALTER TABLESPACE ica_sales_1 READ ONLY. SQL> ALTER TABLESPACE ica_sales_2 READ ONLY. generate a transportable tablespace set by performing the following actions: Make all tablespaces in the set you are copying read-only. SQL> HOST $ exp system/password FILE=/u01/oracle/expdat.DEPT in tablespace OTHER Partitioned table SAMI. After executing the above give the following query to see whether any violations are there.ica_sales_2'. SQL> SELECT * FROM TRANSPORT_SET_VIOLATIONS.

You can use any facility for copying flat files (for example.dbf converted datafile=/temp/data_D-10_I-3295731590_TS-ADMIN_TBS_FNO5_05ek24v5 channel ORA_DISK_1: datafile conversion complete. directory /temp. an operating system copy utility. . ftp. has already been created.0.1. elapsed time: 00:00:45 Finished backup at 08-APR-07 Step 4: Transport the Tablespace Set Transport both the datafiles and the export file of the tablespaces to a place accessible to the target database. RMAN> CONVERT TABLESPACE ica_sales_1. the DBMS_FILE_TRANSFER package.0. Starting backup at 08-APR-03 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: sid=11 devtype=DISK channel ORA_DISK_1: starting datafile conversion input datafile fno=00005 name=/u01/oracle/oradata/ica_salesdb/ica_sales_101. The converted datafiles are assigned names by the system.tablespace set. Oracle Corporation.0 Copyright (c) 1995. connected to target database: ica_salesdb (DBID=3295731590) Convert the datafiles into a temporary location on the source platform. All rights reserved. then convert the datafiles composing the ica_sales_1 and ica_sales_2 tablespaces. You have to use RMAN utility to convert datafiles $ RMAN TARGET / Recovery Manager: Release 10.dbf converted datafile=/temp/data_D-10_I-3295731590_TS-EXAMPLE_FNO4_06ek24vl channel ORA_DISK_1: datafile conversion complete. 2003. assume that the temporary location. elapsed time: 00:00:15 channel ORA_DISK_1: starting datafile conversion input datafile fno=00004 name=/u01/oracle/oradata/ica_salesdb/ica_sales_101.ica_sales_2 TO PLATFORM 'Microsoft Windows NT' FORMAT '/temp/%U'. or publishing on CDs). In this example.

dbf REMAP_SCHEMA=(smith:sami) REMAP_SCHEMA=(williams:john) The REMAP_SCHEMA parameter changes the ownership of database objects. To view information about Datafiles SQL>select * from dba_data_files. ALTER TABLESPACE ica_sales_2 READ WRITE. To view information about Tempfiles . If you do not specify REMAP_SCHEMA. imp: IMP system/password FILE=expdat. In this case. SQL>select * from v$datafile. objects in the tablespace set owned by smith in the source database will be owned by sami in the target database after the tablespace set is plugged in. Check the import logs to ensure that no error has occurred. put the tablespaces into read/write mode as follows: ALTER TABLESPACE ica_sales_1 READ WRITE./ica_salesdb/ica_sales_201. but must have users sami and john.dmp DATAFILES=/ica_salesdb/ica_sales_101. and those users must already exist in the target database. Some of them are: To view information about Tablespaces in a database give the following query SQL>select * from dba_tablespaces SQL>select * from v$tablespace. the target database is not required to have users smith and williams. If they do not exist.dbf. then the import utility returns an error. Similarly. Viewing Information about Tablespaces and Datafiles Oracle has provided many Data dictionaries to view information about tablespaces and datafiles. Now.Step 5: Plug In the Tablespace Set Plug in the tablespaces and integrate the structural information using the Import utility. all database objects (such as tables and indexes) are created in the same user schema as in the source database. objects owned by williams in the source database will be owned by john in the target database. In this example. all tablespaces in the set being copied remain in readonly mode. After this statement executes successfully.

dbf’ Now you want to relocate /u01/oracle/ica/usr01. 1. Copy the file to new location using o/s command.dbf /u02/oracle/ica/usr01.dbf’ and want to rename ‘/u01/oracle/ica/usr02. Relocating or Renaming Datafiles You can rename datafiles to either change their names or relocate them. For Example suppose you have a tablespace users with the following datafiles /u01/oracle/ica/usr01. Take the tablespace offline Rename or Relocate the datafiles using operating system command Give the ALTER TABLESPACE with RENAME DATAFILE option to change the filenames within the Database.dbf’ .dbf’ then follow the given the steps 1. 2. Bring the tablespace Online 4. 3.dbf’ to ‘/u01/oracle/ica/users02. To view information about free space in datafiles SQL>select * from dba_free_space.dbf’ /u01/oracle/ica/usr02. SQL>select * from v$tempfile. Bring the tablespace offline SQL> alter tablespace users offline.SQL>select * from dba_temp_files. To view information about free space in tempfiles SQL>select * from V$TEMP_SPACE_HEADER. Renaming or Relocating Datafiles belonging to a Single Tablespace To rename or relocate datafiles belonging to a Single Tablespace do the following. 2. $cp /u01/oracle/ica/usr01.dbf’ to ‘/u02/oracle/ica/usr01.

dbf’ to ‘/u01/oracle/ica/users02. In particular.Rename the file ‘/u01/oracle/ica/usr02. specify the old datafile names exactly as they appear in the DBA_DATA_FILES view. You must have the ALTER DATABASE system privilege To rename datafiles in multiple tablespaces. 1.dbf’ to ‘/u02/oracle/ica/usr01. $mv 3. Copy the datafiles to be renamed to their new locations and new names. Use ALTER DATABASE to rename the file pointers in the database control file. Always provide complete filenames (including their paths) to properly identify the old and new datafiles.dbf’..dbf /u01/oracle/ica/users02.dbf and /u02/oracle/rbdb1/user3. using the operating system. For example.dbf'. the following statement renames the datafiles/u02/oracle/rbdb1/sort01.dbf’. follow these steps.dbf. '/u02/oracle/rbdb1/users03.’/u01/oracle/ica/users02. ‘/u01/oracle/ica/usr02. '/u02/oracle/rbdb1/user3.dbf to /u02/oracle/rbdb1/temp01.dbf. respectively: ALTER DATABASE RENAME FILE '/u02/oracle/rbdb1/sort01. /u01/oracle/ica/usr02.dbf’ using o/s command.dbf and /u02/oracle/rbdb1/users03. Now bring the tablespace Online SQL> alter tablespace users online.dbf’.dbf' TO '/u02/oracle/rbdb1/temp01. 4. 2.dbf'. Ensure that the database is mounted but closed. . Procedure for Renaming and Relocating Datafiles in Multiple Tablespaces You can rename and relocate datafiles in one or more tablespaces using the ALTER DATABASE RENAME FILE statement. 3. This method is the only choice if you want to rename or relocate datafiles of several tablespaces in one operation.dbf Now start SQLPLUS and type the following command to rename and relocate these files SQL> alter tablespace users rename file ‘/u01/oracle/ica/usr01.

one member in one disk and another in second disk. have at least two log members.e. it does write changes to disk per statement instead it performs write in batches. That‘s why Oracle writes the statement in redo logfile so that in case of power failure or system crash oracle can re-execute the statements next time when you open the database. Back up the database. Oracle will change the row in db_buffer_cache and records the statement in the logfile and give the message to the user that row is updated. 5. Oracle writes all statements except. Note: You can add members to a group up to the MAXLOGMEMBERS setting you have specified at the time of creating the database.ora’ size 10M. If you want to change MAXLOGMEMBERS setting you have create a new controlfile Important: Is it strongly recommended that you multiplex logfiles i.ora’ to group 1.e. in a database. So in this case if a user updates a row. This is known as deferred batch writes. After making any structural changes to a database. Adding Members to an existing group To add new member to an existing group give the following command SQL>alter database add logfile member ‘/u01/oracle/ica/log11. After 3 seconds the row is actually written to the datafile. always perform an immediate and complete backup. This is done because Oracle performs deferred batch writes i. Adding a New Redo Logfile Group To add a new Redo Logfile group to the database give the following command SQL>alter database add logfile group 3 ‘/u01/oracle/ica/log3. Note: You can add groups to a database up to the MAXLOGFILES setting you have specified at the time of creating the database. .4. SELECT statement. Start the Database Managing REDO LOGFILES Every Oracle database must have at least 2 redo logfile groups. to the logfiles. Actually the row is not yet written back to the datafile but still it give the message to the user that row is updated. Since Oracle defers writing to the datafile there is chance of power failure or system crash before the row is written to the disk. If you want to change MAXLOGFILE setting you have to create a new controlfile.

If you want to drop members from the current group.ora’. If you want to resize a logfile create a new logfile group with the new size and subsequently drop the old logfile group. then do the following Steps 1. Note: When you drop logfiles the files are not deleted from the disk. Note: When you drop logfiles the files are not deleted from the disk.Dropping Members from a group You can drop member from a log group only if the group is having more than one member and if it is not the current group. Dropping Logfile Group Similarly. Resizing Logfiles You cannot resize logfiles. SQL>alter database drop logfile group 3. You have to use O/S command to delete the files from disk. To force a log switch give the following command SQL>alter system switch logfile. Shutdown the database . The following command can be used to drop a logfile member SQL>alter database drop logfile member ‘/u01/oracle/ica/log11. You have to use O/S command to delete the files from disk. force a log switch or wait so that log switch occurs and another group becomes current.ora’. suppose you want to move a logfile from ‘/u01/oracle/ica/log1.ora’ to ‘/u02/oracle/ica/log1. you can also drop logfile group only if the database is having more than two groups and if it is not the current group. Renaming or Relocating Logfiles To Rename or Relocate Logfiles perform the following steps For Example.

The following statement clears the log files in redo log group number 3: ALTER DATABASE CLEAR LOGFILE GROUP 3.ora Clearing REDO LOGFILES A redo log file might become corrupted while the database is open. The database writes a message in the alert log describing the backups from which you cannot recover .SQL>shutdown immediate. Start and mount the database SQL>startup mount 4. Now give the following command to change the location in controlfile SQL>alter database rename file ‘/u01/oracle/ica/log1.ora 3. The cleared redo logs are available for use even though they were not archived.ora’ to ‘/u02/oracle/ica/log2. and ultimately stop database activity because archiving cannot continue. use the UNARCHIVED keyword in the statement. 2. 5. This statement overcomes two situations where dropping redo logs is not possible:   If there are only two log groups The corrupt redo log file belongs to the current group If the corrupt redo log file has not been archived. In this situation the ALTER DATABASE CLEAR LOGFILE statement can be used reinitialize the file without shutting down the database.ora’. Move the logfile from Old location to new location using operating system command $mv /u01/oracle/ica/log1. /u02/oracle/ica/log1. Open the database SQL>alter database open. If you clear a log file that is needed for recovery of a backup. ALTER DATABASE CLEAR UNARCHIVED LOGFILE GROUP 3. then you can no longer recover from that backup. This statement clears the corrupted redo logs and avoids archiving them.

You can multiplex control file at the time of creating a database and later on also.------1 1 20605 1048576 2 1 20606 1048576 3 1 20603 1048576 4 1 20604 1048576 MEMBERS ------1 1 1 1 ARC --YES NO YES YES STATUS --------ACTIVE CURRENT INACTIVE INACTIVE FIRST_CHANGE# ------------61515628 41517595 31511666 21513647 FIRST_TIM --------21-JUN-07 21-JUN-07 21-JUN-07 21-JUN-07 To See how many members are there and where they are located give the following query SQL>SELECT * FROM V$LOGFILE.----.e. GROUP# -----1 2 STATUS ------MEMBER ---------------------------------/U01/ORACLE/ICA/LOG1. The control file includes:      The database name Names and locations of associated datafiles and redo log files The timestamp of the database creation The current log sequence number Checkpoint information It is strongly recommended that you multiplex control files i. which is a small binary file that records the physical structure of the database.Viewing Information About Logfiles To See how many logfile groups are there and their status type the following query.ORA /U01/ORACLE/ICA/LOG2.------.ORA Managing Control Files Every Oracle Database has a control file. . In this way if control file becomes corrupt in one disk the another copy will be available and you don‘t have to do recovery of control file. SQL>SELECT * FROM V$LOG. in a database. GROUP# THREAD# SEQ BYTES -----. Have at least two control files one in one hard disk and another one located in another disk. If you have not multiplexed control file at the time of creating a database you can do it now by following given procedure.

Now open the parameter file and specify the new location like this CONTROL_FILES=/u01/oracle/ica/control.Multiplexing Control File Steps: 1. . MAXLOGFILES. Shutdown the Database.ora /u02/oracle/ica/control. Changing the Name of a Database If you ever want to change the name of database or want to change the setting of MAXDATAFILES. Creating a New Control File Follow the given steps to create a new controlfile Steps 1.ora 4./u02/oracle/ica/contro l. 2. SQl>SHUTDOWN IMMEDIATE.ora.ora Change it to CONTROL_FILES=/u01/oracle/ica/control. First generate the create controlfile statement SQL>alter database backup controlfile to trace. if one control file is lost you can copy it from another location. For example. $cp /u01/oracle/ica/control.ora 3. MAXLOGMEMBERS then you have to create a new control file. Start the Database Now Oracle will start updating both the control files and. Copy the control file from old location to new location using operating system command.

dbs' SIZE 5M. This file will contain the CREATE CONTROLFILE statement. Let it be c. GROUP 2 ('/u01/oracle/ica/redo02_01. Start and do not mount the database.dbf' SIZE 3M. Now execute c.dbs' SIZE 5M.TRC and it is created in USER_DUMP_DEST directory.log'). '/u01/oracle/ica/redo02_02.dbs' SIZE 5M MAXLOGFILES 50 MAXLOGMEMBERS 3 MAXLOGHISTORY 400 MAXDATAFILES 200 MAXINSTANCES 6 ARCHIVELOG. Go to the USER_DUMP_DEST directory and open the latest trace file in text editor. Now open the database with RESETLOGS SQL>ALTER DATABASE OPEN RESETLOGS. Since we are changing the name of the Database we have to use RESETLOGS option of CREATE CONTROLFILE statement. '/u01/oracle/ica/redo01_02.log'.log'.sql 6.log') RESETLOGS DATAFILE '/u01/oracle/ica/system01. Cloning an Oracle Database.sql file in text editor and set the database name from ica to prod shown in an example below CREATE CONTROLFILE SET DATABASE prod LOGFILE GROUP 1 ('/u01/oracle/ica/redo01_01.log'). The company management wants to develop some new modules and they have hired some programmers to do that. SQL>STARTUP NOMOUNT.sql script SQL> @/u01/oracle/c. '/u01/oracle/ica/temp01. 2. '/u01/oracle/ica/rbs01.sql 3. Now copy and paste the statement in a file.log'. Now these . Now open the c. You have a Production database running in one server. It will have two sets of statement one with RESETLOGS and another without RESETLOGS. The trace file will be randomly named something like ORA23212. '/u01/oracle/ica/users01. '/u01/oracle/ica/redo03_02. 4.After giving this statement oracle will write the CREATE CONTROLFILE statement in a trace file. 5. GROUP 3 ('/u01/oracle/ica/redo03_01.

In SERVER 2 you have /d01 filesystem. Copy the CREATE CONTROLFILE statement and paste in a file.ora /u01/oracle/ica/log2. Steps :1. This file will contain steps and as well as CREATE CONTROLFILE statement.ora BACKGROUND_DUMP_DEST=/u01/oracle/ica/bdump USER_DUMP_DEST=/u01/oracle/ica/udump CORE_DUMP_DEST=/u01/oracle/ica/cdump LOG_ARCHIVE_DEST_1=”location=/u01/oracle/ica/arc1” DATAFILES = /u01/oracle/ica/sys. Let the filename be cr.dbf /u01/oracle/ica/usr. 2.sql The CREATE CONTROLFILE Statement will look like this. Let us see an example of cloning a database We have a database running the production server with the following files PARAMETER FILE located in /u01/oracle/ica/initica.ora' .dbf /u01/oracle/ica/tmp.ora CONTROL FILES=/u01/oracle/ica/control. In SERVER 1 generate CREATE CONTROLFILE statement by typing the following command SQL>alter database backup controlfile to trace. CREATE CONTROLFILE SET DATABASE prod LOGFILE GROUP 1 ('/u01/oracle/ica/log1.programmers require access to the Production database and they want to make changes to it.dbf LOGFILE= /u01/oracle/ica/log1.ora Now you want to copy this database to SERVER 2 and in SERVER 2 you don‘t have /u01 filesystem. In SERVER 2 install the same version of o/s and same version Oracle as in SERVER 1.dbf /u01/oracle/ica/sysaux.dbf /u01/oracle/ica/rbs. You as a DBA can‘t give direct access to Production database so you want to create a copy of this database on another server and wants to give developers access to it. Now. To Clone this Database on SERVER 2 do the following. go to the USER_DUMP_DEST directory and open the latest trace file.

'/u01/oracle/ica/usr.ora' DATAFILE '//d01/oracle/ica/sys. Now.dbf' SIZE 300M.GROUP 2 ('/u01/oracle/ica/log2.ora' DATAFILE '/u01/oracle/ica/sys.dbf’ size 100M. 3.dbf' SIZE 300M.dbf' SIZE 50M. logfiles and control file to SERVER 2 in /d01/oracle/ica directory. MAXLOGFILES 50 MAXLOGMEMBERS 3 MAXLOGHISTORY 400 MAXDATAFILES 200 MAXINSTANCES 6 ARCHIVELOG. Copy parameter file to SERVER 2 in /d01/oracle/dbs directory and copy all archive log files to SERVER 2 in /d01/oracle/ica/arc1 directory. ‘/u01/oracle/ica/sysaux. . '/u01/oracle/ica/tmp. '//d01/oracle/ica/rbs.ora' GROUP 2 ('//d01/oracle/ica/log2.dbf' SIZE 50M.sql script file to /d01/oracle/ica directory. 4. In SERVER 2 create the following directories $cd /d01/oracle $mkdir ica $mkdir arc1 $cd ica $mkdir bdump udump cdump Shutdown the database on SERVER 1 and transfer all datafiles. Copy the cr.ora BACKGROUND_DUMP_DEST=//d01/oracle/ica/bdump USER_DUMP_DEST=//d01/oracle/ica/udump CORE_DUMP_DEST=//d01/oracle/ica/cdump LOG_ARCHIVE_DEST_1=”location=//d01/oracle/ica/arc1” 5.sql file in text editor and change the locations like this CREATE CONTROLFILE SET DATABASE prod LOGFILE GROUP 1 ('//d01/oracle/ica/log1. Open the parameter file SERVER 2 and change the following parameters CONTROL FILES=//d01/oracle/ica/control. '/u01/oracle/ica/rbs.dbf' SIZE 50M.dbf' SIZE 50M. open the cr.

Managing the UNDO TABLESPACE Every Oracle Database must have a method of maintaining information that is used to roll back.sql script to create the controlfile SQL>@/d01/oracle/ica/cr. 6. MAXLOGFILES 50 MAXLOGMEMBERS 3 MAXLOGHISTORY 400 MAXDATAFILES 200 MAXINSTANCES 6 ARCHIVELOG.dbf' SIZE 50M.sql 7. '//d01/oracle/ica/tmp. which simplifies undo space management by eliminating the complexities associated with rollback segment management. These records are collectively referred to as undo.dbf' SIZE 50M. Undo records are used to:      Roll back transactions when a ROLLBACK statement is issued Recover the database Provide read consistency Analyze data as of an earlier point in time by using Flashback Query Recover from logical corruptions using Flashback features Earlier releases of Oracle Database used rollback segments to store undo.dbf’ size 100M. changes to the database. Open the database SQL>alter database open. Such information consists of records of the actions of transactions. ‘//d01/oracle/ica/sysaux. In SERVER 2 export ORACLE_SID environment variable and start the instance $export ORACLE_SID=ica $sqlplus Enter User:/ as sysdba SQL> startup nomount.'//d01/oracle/ica/usr. primarily before they are committed. Run cr. Oracle9i introduced automatic undo management. or undo. Oracle strongly recommends that .

When the system is first running in the production environment. and so forth) As an example. In this case. bitmaps. Now Oracle Database will use Automatic Undo Space Management. UPS is undo blocks for each second overhead is the small overhead for metadata (transaction tables.you use undo tablespace to manage undo rather than rollback segments. if UNDO_RETENTION is set to 3 hours. Calculating the Space Requirements For Undo Retention You can calculate space requirements manually using the following formula: UndoSpace = UR * UPS + overhead where:     UndoSpace is the number of undo blocks UR is UNDO_RETENTION in seconds. with a 8K block size. and the transaction rate (UPS) is 100 undo blocks for each second. Switching to Automatic Management of Undo Space To go for automatic management of undo space set the following parameter. the required undo space is computed as follows: . you may be unsure of the space requirements of the undo tablespace. Start the Database. Steps:1. Shutdown the Database and set the following parameters in parameter file. This value should take into consideration longrunning queries and any flashback requirements. create an undo tablespace by typing the following command SQL>create undo tablespace myundo datafile ‘/u01/oracle/ica/undo_tbs. If you have not created an undo tablespace at the time of creating a database then.dbf’ size 500M autoextend ON next 5M . UNDO_MANAGEMENT=AUTO UNDO_TABLESPACE=myundo 3. you can enable automatic extension for datafiles of the undo tablespace so that they automatically increase in size when more space is needed 2.

Assuming myundo is the current undo tablespace. the instance uses myundo2 in place of myundo as its undo tablespace. you can resize existing datafiles or add new datafiles to it The following example extends an existing datafile SQL> alter database datafile ‘/u01/oracle/ica/undo_tbs. Because the UNDO_TABLESPACE initialization parameter is a dynamic parameter. Dropping an Undo Tablespace Use the DROP TABLESPACE statement to drop an undo tablespace. The following statement switches to a new undo tablespace: ALTER SYSTEM SET UNDO_TABLESPACE = myundo2. the DROP TABLESPACE statement fails. Overhead query the V$UNDOSTAT view. the ALTER SYSTEM SET statement can be used to assign a new undo tablespace. The following example drops the undo tablespace undotbs_01: SQL> DROP TABLESPACE myundo. By giving the following statement SQL> Select * from V$UNDOSTAT.dbf’ resize 700M The following example adds a new datafile to undo tablespace SQL> ALTER TABLESPACE myundo ADD DATAFILE '/u01/oracle/ica/undo02. after this command successfully executes. Viewing Information about Undo Tablespace . a transaction died but has not yet been recovered).(3 * 3600 * 100 * 8K) = 8. Switching Undo Tablespaces You can switch from using one undo tablespace to another.24GBs To get the values for UPS. If the undo tablespace contains any outstanding transactions (for example. An undo tablespace can only be dropped if it is not currently used by any instance.dbf' SIZE 200M AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED. Altering UNDO Tablespace If the Undo tablespace is full.

and Import tool to load data into the target database. triggers are imported. Export and Import These tools are used to transfer data from one oracle database to another oracle database. integrity constraints are enabled on the new tables. function-based. You Export tool to export data from source database. 5. At the target database the Import tool will copy the data from dump file to the target database. views. 6. This sequence also prevents redundant triggers from firing twice on the same data Invoking Export and Import . and domain indexes When you import the tables the import tool will perform the actions in the following order. When you export tables from source database export tool will extracts the tables and puts it into the dump file. The export dump file contains objects in the following order: 1. From Ver. procedures. new tables are created.To view statistics for tuning undo tablespace query the following dictionary SQL>select * from v$undostat. and any bitmap. 10g Oracle is recommending to use Data Pump Export and Import tools. function-based. and/or domain indexes are built. 4. This dump file is transferred to the target database. which are enhanced versions of original Export and Import tools. and triggers Bitmap. data is imported and indexes are built. 2. 3. This sequence prevents data from being rejected due to the order in which tables are imported. To see how many active Transactions are there and to see undo segment information give the following command SQL>select * from v$transaction. To see the sizes of extents in the undo tablespace give the following query SQL>select * from DBA_UNDO_EXTENTS. Type definitions Table definitions Table data Table indexes Integrity constraints.

If you supply command line arguments when calling exp or imp then it will run in command line mode Command Line Parameters of Export tool You can control how Export runs by entering the EXP command followed by various arguments..valueN) Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP. these tools will prompt you for all the necessary input..You can run Export and Import tool in two modes Command Line Mode Interactive Mode When you just type exp or imp at o/s prompt it will run in interactive mode i.DMP) import into one extent (Y) export grants (Y) export indexes (Y) direct path (N) log file of screen output export data rows (Y) cross-table consistency(N) export entire file (N) ..DEPT.e. you use keywords: Format: EXP KEYWORD=value or KEYWORD=(value1. if T1 is partitioned table Keyword Description (Default) -------------------------------------------------------------USERID BUFFER FILE COMPRESS GRANTS INDEXES DIRECT LOG ROWS CONSISTENT FULL username/password size of data buffer output files (EXPDAT. To specify parameters..MGR) or TABLES=(T1:P1.T1:P2).value2.

export (Y) export triggers (Y) analyze objects (ESTIMATE) parameter filename export constraints (Y) transaction set to read only during object export (N) CONSTRAINTS OBJECT_CONSISTENT FEEDBACK FILESIZE FLASHBACK_SCN FLASHBACK_TIME QUERY RESUMABLE RESUMABLE_NAME display progress every x rows (0) maximum size of each dump file SCN used to set session snapshot back to time used to get the SCN closest to the specified time select clause used to export a subset of a table suspend when a space related error is encountered(N) text string used to identify resumable statement RESUMABLE_TIMEOUT wait time for RESUMABLE TTS_FULL_CHECK TABLESPACES perform full or partial dependency check for TTS list of tablespaces to export export transportable tablespace metadata (N) TRANSPORT_TABLESPACE TEMPLATE template name which invokes iAS mode export The Export and Import tools support four modes of operation .OWNER TABLES list of owner usernames list of table names RECORDLENGTH length of IO record INCTYPE RECORD TRIGGERS STATISTICS PARFILE incremental export type track incr.

Using Import Utility Objects exported by export utility can only be imported by Import utility.sales) FILE=exp_tab.e. Exporting Individual Tables To export individual tables give the following command $exp USERID=scott/tiger TABLES=(scott.dmp The above command will export all the objects stored in SCOTT and ALI‘s schema. USERID option specifies the user account to connect to the database. Example of Exporting Full Database The following example shows how to export full database $exp USERID=scott/tiger FULL=y FILE=myfull.scott. . Note. Import utility can run in Interactive mode or command line mode.dmp This will export scott‘s emp and sales tables.ALI) FILE=exp_own. to perform full export the user should have DBA or EXP_FULL_DATABASE privilege. FILE option specifies the name of the dump file.emp. Export utility will export a consistent image of the table i. Exporting Consistent Image of the tables If you include CONSISTENT=Y option in export command argument then. Example of Exporting Schemas To export Objects stored in a particular schemas you can run export utility with the following arguments $exp USERID=scott/tiger OWNER=(SCOTT. FULL option specifies that you want to export the full database.dmp In the above command. the changes which are done to the table during export operation will not be exported.FULL :Exports all the objects in all schemas OWNER :Exports objects only belonging to the given OWNER TABLES :Exports Individual Tables TABLESPACE :Export all objects located in a given TABLESPACE.

To specify parameters.. you can control how Import runs by entering the IMP command followed by various arguments..valueN) Example: IMP SCOTT/TIGER IGNORE=Y TABLES=(EMP.value2..You can let Import prompt you for parameters by entering the IMP command followed by your username/password: Example: IMP SCOTT/TIGER Or.DMP) just list file contents (N) ignore create errors (N) import grants (Y) import indexes (Y) import data rows (Y) log file of screen output import entire file (N) list of owner usernames list of usernames list of table names length of IO record incremental import type commit array insert (N) parameter filename import constraints (Y) overwrite tablespace data file (N) write table/index info to specified file skip maintenance of unusable indexes (N) display progress every x rows(0) skip validation of specified type ids maximum size of each dump file import precomputed statistics (always) . Keyword USERID BUFFER FILE SHOW IGNORE GRANTS INDEXES ROWS LOG FULL FROMUSER TOUSER TABLES RECORDLENGTH INCTYPE COMMIT PARFILE CONSTRAINTS DESTROY INDEXFILE SKIP_UNUSABLE_INDEXES FEEDBACK TOID_NOVALIDATE FILESIZE STATISTICS Description (Default) username/password size of data buffer input files (EXPDAT.. if T1 is partitioned table USERID must be the first parameter on the command line. you use keywords: Format: IMP KEYWORD=value or KEYWORD=(value1.T1:P2).DEPT) FULL=N or TABLES=(T1:P1.

suppose Ali has exported tables into a dump file mytables. importing table "DEPT" "EMP" 4 rows imported 14 rows imported Import terminated successfully without warnings. . use ―%‖ wild character in TABLES option. Now Scott wants to import these tables.00. the following command will import all tables whose names starts with alphabet ―e‖ and those tables whose name contains alphabet ―d‖ $imp scott/tiger FILE=myfullexp.RESUMABLE RESUMABLE_NAME RESUMABLE_TIMEOUT COMPILE STREAMS_CONFIGURATION STREAMS_INSTANITATION suspend when a space related error is encountered(N) text string used to identify resumable statement wait time for RESUMABLE compile procedures.dept) This command will import only emp. Importing Tables of One User account into another User account For example. To achieve this Scott will give the following import command $imp scott/tiger FILE=mytables. Example. dept tables into Scott user and you will get a output similar to as shown below Export file created by EXPORT:V10. .00 via conventional path import done in WE8DEC character set and AL16UTF16 NCHAR character set . To do so.dmp FROMUSER=scott TABLES=(emp. importing SCOTT's objects into SCOTT . For example. Example Importing Tables Using Pattern Matching Suppose you want to import all tables from a dump file whose name matches a particular pattern. and functions (Y) import streams general metadata (Y) import streams instantiation metadata (N) Example Importing Individual Tables To import individual tables from a full database export dump file give the following command $imp scott/tiger FILE=myfullexp.dmp. packages.dmp FROMUSER=ali TOUSER=scott Then import utility will give a warning that tables in the dump file was exported by user Ali and not you and then proceed.dmp FROMUSER=scott . importing table .

Otherwise. issue the following SQL query to get the exact name of all tablespaces. 2. The following steps present a general overview of how to move a database between platforms.%d%) Migrating a Database across platforms. You will need this information later in the process. As a DBA user. perform a full import with the IGNORE parameter enabled: > imp system/manager FULL=y IGNORE=y FILE=myfullexp. As a DBA user. the import will create the corresponding datafiles in the same file structure as at the source database.TABLES=(a%. Before importing the dump file. Perform a full backup of your new database .dmp Using IGNORE=y instructs Oracle to ignore any creation errors during the import and permit the import to complete. As a DBA user. you must first create your tablespaces. which may not be compatible with the file structure on the target system. 5. for example: > exp system/manager FULL=y FILE=myfullexp. be sure to copy it in binary format (by entering binary at the FTP prompt) to avoid file corruption. 6. 7. This includes moving between UNIX and NT systems and also moving between two NT systems running on different platforms.dmp 3. using the information obtained in Step 1. SQL> SELECT tablespace_name FROM dba_tablespaces. perform a full export from the source database. If you use FTP. Create a database on the target server. 4. The Export and Import utilities are the only method that Oracle supports for moving an existing Oracle database from one hardware platform to another. Move the dump file to the target database server. 1.

e. This allows DBAs and other operations personnel to monitor jobs from multiple locations. Data Pump is similar to EXPORT and IMPORT utility but it has many advantages. The ability to estimate how much space an export job would consume. The ability to detach from and reattach to long-running jobs without affecting the job itself. without actually performing the export Support for an interactive-command mode that allows monitoring of and interaction with ongoing jobs     Using Data Pump Export Utility To Use Data Pump. The following example creates a directory in the filesystem and creates a directory object in the database and grants privileges on the Directory Object to the SCOTT user. DBA has to create a directory in Server Machine and create a Directory Object in the database mapping to the directory created in the file system. This results in increased performance because data is not transferred through network. Oracle has introduced an enhanced version of EXPORT and IMPORT utility known as DATA PUMP. Some of the advantages are:  Most Data Pump export and import operations occur on the Oracle database server.DATA PUMP Utility Starting with Oracle 10g. This is particularly useful if you have started an export or import job and after some time you want to do some other urgent work. all the dump files are created in the server even if you run the Data Pump utility from client machine. .write on directory data_pump_dir to scott. $mkdir my_dump_dir $sqlplus Enter User:/ as sysdba SQL>create directory data_pump_dir as ‘/u01/oracle/my_dump_dir’. You can Stop and Re-Start export and import jobs. i. Now grant access on this directory object to SCOTT user SQL> grant read.

dmp SCHEMAS=SCOTT You can omit SCHEMAS since the default mode of Data Pump export is SCHEMAS only.Example of Exporting a Full Database To Export Full Database. If you want to export objects of multiple schemas you can specify the following command $expdp scott/tiger DIRECTORY=data_pump_dir DUMPFILE=scott_schema. full03. In this situation you can create multiple dump files by typing the following command $expdp scott/tiger FULL=y DIRECTORY=data_pump_dir DUMPFILE=full%U. Example of Exporting a Schema To export all the objects of SCOTT‘S schema you can run the following export data pump command.dmp SCHEMAS=SCOTT. The FILESIZE parameter specifies how much larger the dump file should be.dmp FILESIZE=5G LOGFILE=myfullexp.HR.dmp. The following example shows the syntax to export tables $expdp hr/hr DIRECTORY=dpump_dir1 DUMPFILE=tables.dmp in the directory on the server /u01/oracle/my_dump_dir In some cases where the Database is in Terabytes the above command will not feasible since the dump file size will be larger than the operating system limit. and hence export will fail. give the following command $expdp scott/tiger FULL=y DIRECTORY=data_pump_dir DUMPFILE=full. $expdp scott/tiger DIRECTORY=data_pump_dir DUMPFILE=scott_schema. full02.dmp and so on.dmp .ALI Exporting Individual Tables using Data Pump Export You can use Data Pump Export utility to export individual tables.log JOB_NAME=myfullJob This will create multiple dump files named full01.log JOB_NAME=myfullJob The above command will export the full database and it will create the dump file full.dmp LOGFILE=myfullexp.dmp.

GRANTS. SCHEMA Using Query to Filter Rows during Export You can use QUERY option to export only required rows.tbs_5.tbs_6 Excluding and Including Objects during Export You can exclude objects while performing a export by using EXCLUDE option of Data Pump utility.dmp . Similarly you can also INCLUDE option to only export certain objects like this $expdp scott/tiger DIRECTORY=data_pump_dir DUMPFILE=scott_schema. USER.dmp TABLESPACES=tbs_4.dmp SCHEMAS=SCOTT EXCLUDE=TABLE:”like ‘A%’” Then all tables in Scott‘s Schema whose name starts with ―A ― will not be exported. it will export only those tables of Scott‘s schema whose name starts with ―A‖ Similarly you can also exclude INDEXES.TABLES=employees. the following will export only those rows of employees tables whose salary is above 10000 and whose dept id is 10. For example you are exporting a schema and don‘t want to export tables whose name starts with ―A‖ then you can type the following command $expdp scott/tiger DIRECTORY=data_pump_dir DUMPFILE=scott_schema. CONSTRAINTS.jobs. For Example.dmp SCHEMAS=SCOTT INCLUDE=TABLE:”like ‘A%’” This is opposite of EXCLUDE option i. tbs_6 The above will export all the objects located in tbs_4. tbs_5.e. expdp hr/hr QUERY=emp:'"WHERE dept_id > 10 AND sal > 10000"' NOLOGFILE=y DIRECTORY=dpump_dir1 DUMPFILE=exp1.departments Exporting Tables located in a Tablespace If you want to export tables located in a particular tablespace you can type the following command $expdp hr/hr DIRECTORY=dpump_dir1 DUMPFILE=tbs.

Then he presses CTRL+C to enter into interactive mode. You can start a job in one client machine and then. you can suspend it. suppose a DBA starts a full database export by typing the following command at one client machine CLNT1 by typing the following command $expdp scott/tiger@mydb FULL=y DIRECTORY=data_pump_dir DUMPFILE=full. After finishing his other work. the user has locked his/her cabin.log JOB_NAME=myfullJob After some time. So now the DBA will go to another client machine and he reattach to the job by typing the following command $expdp hr/hr@mydb ATTACH=myfulljob After the job status is displayed. Afterwards when your work has been finished you can continue the job from the same client. . the DBA wants to resume the export job and the client machine from where he actually started the job is locked because.dmp LOGFILE=myfullexp. if he doesn‘t want to continue with the export job. the DBA wants to stop this job temporarily. where you stopped the job. and processing status is output to the client. Note: After reattaching to the Job a DBA can also kill the job by typing KILL_JOB.Suspending and Resuming Export Jobs (Attaching and Re-Attaching to the Jobs) You can suspend running export jobs and later on resume these jobs or kill these jobs using Data Pump Export. Export> CONTINUE_CLIENT A message is displayed that the job has been reopened. or you can restart the job from another client machine. Then he will get the Export> prompt where he can type interactive commands Now he wants to stop this export job so he will type the following command Export> STOP_JOB=IMMEDIATE Are you sure you wish to stop this job ([y]/n): y The job is placed in a stopped state and exits the client. he can issue the CONTINUE_CLIENT command to resume logging mode and restart the myfulljob job. For Example. if because of some work.

Now he can give a flashback AS. D for Delete :Starting System Change Number when the row version was :Starting System Change Time when the row version was created :SCN when the row version expired. After 1 hour he realizes that delete statement is mistakenly performed. suppose a user accidently deletes rows from a table and commits it also then. It is useful to recover from accidental statement failures. using flash back query he can get back the rows. A new row version is created whenever a COMMIT statement is executed. 9i Oracle has introduced Flashback Query feature. Or SQL> SELECT * FROM emp AS OF TIMESTAMP TO_TIMESTAMP('2007-06-07 10:00:00'. OF query to get back the deleted rows like this.Flash Back Features From Oracle Ver. 'YYYY-MM-DD HH:MI:SS') To insert the accidently deleted rows again in the table he can type SQL> insert into emp (select * from emp as of timestamp sysdate1/24) Using Flashback Version Query You use a Flashback Version Query to retrieve the different versions of specific rows that existed during a given time interval. I for Insert. Users can recover from their mistakes made since last 2 hours only. U for Update. The Flashback Version Query returns a table with a row for each version of the row that existed at any time during the time interval you specify.. If you have set the UNDO_RETENTION parameter to 2 hours then. Flashback Query SQL>select * from emp as of timestamp sysdate-1/24. Flashback feature depends upon on how much undo retention time you have specified. Oracle will not overwrite the data in undo tablespace even after committing until 2 Hours have passed. :Timestamp when the row version expired . suppose John gives a delete statement at 10 AM and commits it. The pseudocolumns available are VERSIONS_XID VERSIONS_OPERATION VERSIONS_STARTSCN created VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIME :Identifier of the transaction that created the row version :Operation Performed. For example. For example. Each row in the table includes pseudocolumns of metadata about the row version.

To understand let‘s see the following example Before Starting this example let‘s us collect the Timestamp SQL> select to_char(SYSTIMESTAMP. SQL>commit.name varchar2(20). At this time emp table has one version of one row.versions_endtime. SQL> select versions_xid.’Sami’. Now a user sitting at another machine erroneously changes the Salary from 5000 to 2000 using Update statement SQL> update emp set sal=sal-3000 where empno=101.5000).name. SQL> commit.sal from emp versions between timestamp to_timestamp(‘2007-06-19 20:30:00’. SQL> commit.’YYYYY --------------------------2007-06-19 20:30:43 Suppose a user creates a emp table and inserts a row into it and commits the row.’yyyy-mm-dd hh:mi:ss’) . the DBA detects the application error and needs to diagnose the problem.’YYYY-MM-DD HH:MI:SS’) from dual. SQL> insert into emp values (101. At this point. The query uses Flashback Version Query pseudocolumns SQL> SQL> SQL> SQL> Connect / as sysdba column versions_starttime format a16 column versions_endtime format a16 set linesize 120. TO_CHAR(SYSTIMESTAMP. The DBA issues the following query to retrieve versions of the rows in the emp table that correspond to empno 101.sal number(10.empno. a new transaction updates the name of the employee from Sami to Smith. versions_operation.versions_starttime.2)). SQL> Create table emp (empno number(5). SQL>update emp set name=’Smith’ where empno=101. Subsequently.

Therefore. You can only flash back tables up to the retention time you specified. OPERATION LOGON_USER UNDO_SQL --------. UNDO_RETENTION parameter is significant in Flashing Back Tables to a past state. Oracle Flashback Table provides the DBA the ability to recover a table or set of tables to a specified point in time in the past very quickly. and without taking any part of the database offline. Flashback Table eliminates the need to perform more complicated point-in-time recovery operations. Flashback Table uses information in the undo tablespace to restore the table.logon_user. easily.and to_timestamp(‘2007-06-19 21:00:00’.--------------------------------------U SCOTT update emp set sal=5000 where ROWID = 'AAAKD2AABAAAJ29AAA' Now DBA can execute the command to undo the changes made by the user SQL> update emp set sal=5000 where ROWID ='AAAKD2AABAAAJ29AAA' 1 row updated Using Flashback Table to return Table to Past States.’yyyy-mm-dd hh:mi:ss’). In many cases. . The DBA identifies the transaction 02001003C02 as erroneous and issues the following query to get the SQL command to undo the change SQL> select operation. from the output we can see that an Insert has taken place and then erroneous update has taken place and then again update has taken place to change the name. VERSION_XID ----------0200100020D 02001003C02 0002302C03A V U U I STARTSCN -------11323 11345 12320 ENDSCN -----EMPNO ----101 101 101 NAME SAL -------.---------.---SMITH 2000 SAMI 2000 SAMI 5000 The Output should be read from bottom to top.undo_sql from flashback_transaction_query where xid=HEXTORAW(’02001003C02’).

You have to give ENABLE TRIGGERS option otherwise.Row movement must be enabled on the table for which you are issuing the FLASHBACK TABLE statement. This feature is not dependent on UNDO TABLESPACE so UNDO_RETENTION parameter has no impact on this feature. The following example performs a FLASHBACK TABLE operation the table emp FLASHBACK TABLE emp TO TIMESTAMP TO_TIMESTAMP('2007-06-19 09:30:00'. by default all database triggers on the table will be disabled. the table is renamed and placed in Recycle Bin. the last time she ran a report. The FLASHBACK TABLE…BEFORE DROP command will restore the table. Example:At 17:00 an HR administrator discovers that an employee "JOHN" is missing from the EMPLOYEE table. She uses Flashback Table to return the table to its state at 14:00. Recovering Drop Tables (Undo Drop Table) In Oracle Ver. Someone accidentally deleted the record for "JOHN" between 14:00 and the present time. Instead. This employee was present at 14:00. For Example. suppose a user accidently drops emp table SQL>drop table emp. as shown in this example: FLASHBACK TABLE EMPLOYEES TO TIMESTAMP TO_TIMESTAMP('2007-06-21 14:00:00'. Table Dropped . You can enable row movement with the following SQL statement: ALTER TABLE table ENABLE ROW MOVEMENT. whatever tables you drop the database does not immediately remove the space used by table. The emp table is restored to its state when the database was at the time specified by the timestamp.e. 10g Oracle introduced the concept of Recycle Bin i. `YYYY-MM-DD HH24:MI:SS').'YYYY-MM-DD HH:MI:SS') ENABLE TRIGGERS.

You can also restore the dropped table by giving it a different name like this SQL> Flashback table emp to before drop rename to emp2. If you want to purge objects of logon user give the following command SQL> purge recycle bin. To view the contents of Recycle Bin give the following command SQL> show recycle bin. Purging Objects from Recycle Bin If you want to recover the space used by a dropped table give the following command SQL> purge table emp. If you have the SYSDBA privilege. To recover this dropped table a user can type the command SQL> Flashback table emp to before drop.Now for user it appears that table is dropped but it is actually renamed and placed in Recycle Bin. then you can purge all objects from the recycle bin. If you want to recover space for dropped object of a particular tablespace give the command SQL> purge tablespace hr. You can also purge only objects from a tablespace belonging to a specific user. using the following form of the command: SQL>PURGE TABLESPACE hr USER scott. This will drop the table permanently and it cannot be restored. . using this command: SQL>PURGE DBA_RECYCLEBIN. regardless of which user owns the objects. Permanently Dropping Tables If you want to permanently drop tables without putting it into Recycle Bin drop tables with purge command like this SQL> drop table emp purge.

. when you perform Flashback Drop. The following example shows the retrieval from the recycle bin of all three dropped EMP tables from the previous example. whenever tablespace becomes full and transaction requires new extents then. For example. A table and all of its dependent objects (indexes. . FLASHBACK TABLE EMP TO BEFORE DROP RENAME TO EMP_VER_1. Likewise. as shown in this example: FLASHBACK TABLE EMP TO BEFORE DROP. triggers. and they will all be stored in the recycle bin. CREATE TABLE EMP ( . constraints and so on) go into the recycle bin together.columns ). and no guarantee as to how long dropped objects remain in the recycle bin. You can retrieve it and assign it a new name using a RENAME TO clause. # EMP version 2 DROP TABLE EMP.. Important Points: 1.. FLASHBACK TABLE EMP TO BEFORE DROP RENAME TO EMP_VER_2.columns ). a dropped object may remain in the recycle bin for seconds. Oracle might empty recycle bin whenever Space Pressure occurs i. LOB segments.. In such a case. oracle will delete objects from recycle bin 2. with its original name. 3. Depending upon system activity. each table EMP is assigned a unique name in the recycle bin when it is dropped. # EMP version 1 DROP TABLE EMP. # EMP version 3 DROP TABLE EMP.e.columns ). The most recently dropped table with that original name is retrieved from the recycle bin. consider these SQL statements: CREATE TABLE EMP ( . There is no guarantee that objects will remain in Recycle Bin. nested tables. You can use a FLASHBACK TABLE. with each assigned a new name: FLASHBACK TABLE EMP TO BEFORE DROP RENAME TO EMP_VER_3. when you drop the table.Flashback Drop of Multiple Objects With the Same Original Name You can create. There is no fixed amount of space allocated to the recycle bin. or for months. the objects are generally all retrieved together. TO BEFORE DROP statement with the original name of the table.. CREATE TABLE EMP ( . several objects with the same original name.... and then drop.

Step 3. To determine the earliest SCN and earliest Time you can Flashback your database. After you have enabled the Flashback Database feature and allowed the database to generate some flashback logs. To how much size we should set the flash recovery area. Shutdown the database if it is already running and set the following parameters DB_RECOVERY_FILE_DEST=/d01/ica/flasharea DB_RECOVERY_FILE_DEST_SIZE=10G DB_FLASHBACK_RETENTION_TARGET=4320 (Note: the db_flashback_retention_target is specified in minutes here we have specified 3 days i. Once you set these parameters. lets you quickly recover the entire database from logical data corruptions or user errors. you set up a flash recovery area. From that time on. Now enable the flashback database by giving the following command SQL>alter database flashback on. To enable Flashback Database. give the following query: .e. at regular intervals. How far you can flashback database. 3x24x60=4320) Step 2. Enabling Flash Back Database Step 1. and set a flashback retention target.Flashback Database: Alternative to Point-In-Time Recovery Oracle Flashback Database. This will show how much size the recovery area should be set to. run the following query: SQL> SELECT ESTIMATED_FLASHBACK_SIZE FROM V$FLASHBACK_DATABASE_LOG. to specify how far back into the past you want to be able to restore your database with Flashback Database. the database copies images of each altered block in every datafile into flashback logs stored in the flash recovery area. Now Oracle start writing Flashback logs to recovery area. These Flashback logs are use to flashback database to a point in time. Start the instance and mount the Database. SQL>startup mount.

RMAN> FLASHBACK DATABASE TO TIME (SYSDATE-8/24). OLDEST_FLASHBACK_TIME FROM V$FLASHBACK_DATABASE_LOG. you can flashback the database to 9:50AM by following the given procedure 1. Start RMAN $rman target / 2. Now since you have configured the flashback area and set up the flashback retention time to 3 Days. a user erroneously drops a schema at 10:00AM. or. you can also type this command. RMAN> SQL 'ALTER DATABASE OPEN READ ONLY'. or perform FLASHBACK DATABASE again with an SCN further in the past. You can completely undo the effects of your flashback operation by performing complete recovery of the database: RMAN> RECOVER DATABASE. You as a DBA came to know of this at 5PM. you can evaluate the results by opening the database read-only and run some queries to check whether your Flashback Database has returned the database to the desired state. At this time. When the Flashback Database operation completes. you have several options Option 1:If you are content with your result you can open the database by performing ALTER DATABASE OPEN RESETLOGS SQL>ALTER DATABASE OPEN RESETLOGS. Option 2:If you discover that you have chosen the wrong target time for your Flashback Database operation. Run the FLASHBACK DATABASE command to return the database to 9:59AM by typing the following command RMAN> FLASHBACK DATABASE TO TIME timestamp('2007-06-21 09:59:00'). 3. you can use RECOVER DATABASE UNTIL to bring the database forward. .SELECT OLDEST_FLASHBACK_SCN. Example: Flashing Back Database to a point in time Suppose.

Without a dictionary. LogMiner uses the dictionary to translate internal object identifiers and datatypes to object names and external data formats. you can query the contents of online redo log files and archived log files.dmp Log Miner Using Log Miner utility. you can open the database read-only. as well as a tool for sophisticated data analysis.Option 3:If you only want to retrieve some lost data from the past time. . then perform a logical export of the data using an Oracle export utility. Now.dmp owner=SCOTT 5. when it presents the redo log data that you request. and the redo log files containing the data of interest:   The source database is the database that produces all the redo log files that you want LogMiner to analyze. then run RECOVER DATABASE to return the database to the present time and re-import the data using the Oracle import utility 4. 6. and comprehensive relational interface to redo log files. LogMiner Configuration There are three basic objects in a LogMiner configuration that you should be familiar with: the source database. Now Start RMAN and recover database to the present time $rman target / RMAN> RECOVER DATABASE. Because LogMiner provides a well-defined. After database is recovered shutdown and restart the database in normal mode and import the schema by running IMPORT utility $imp userid=system/manager file=scott. LogMiner returns internal object IDs and presents data as binary data. the LogMiner dictionary. third option is relevant for us. Since in our example only a schema is dropped and the rest of database is good. The LogMiner dictionary allows LogMiner to provide table and column names. come out of RMAN and run EXPORT utility to export the whole schema $exp userid=system/manager file=scott. it can be used as a powerful data audit tool. easy-to-use. instead of internal object IDs.

 The redo log files contain the changes made to the database or database dictionary. specify the online catalog as your dictionary source when you start LogMiner. 11000). LogMiner gives you three options for supplying the dictionary:  Using the Online Catalog Oracle recommends that you use this option when you will have access to the source database from which the redo log files were created and when no changes to the column definitions in the tables of interest are anticipated. LogMiner Dictionary Options LogMiner requires a dictionary to translate object IDs into object names when it returns redo data to you.JOBS(JOB_ID. or if you anticipate that changes will be made to the column definitions in the tables of interest.'Technical Writer'.HEXTORAW('546563686e6963616c20577269746572')."COL 4") values (HEXTORAW('45465f4748'). JOB_TITLE. LogMiner will display: insert into "UNKNOWN". Using the Online Catalog To direct LogMiner to use the dictionary currently in use for the database."COL 3". as follows: SQL> EXECUTE DBMS_LOGMNR. consider the following the SQL statement: INSERT INTO HR. This is the most efficient and easy-to-use option."COL 2".  Extracting the LogMiner Dictionary to a Flat File This option is maintained for backward compatibility with previous releases. Without the dictionary.  Extracting a LogMiner Dictionary to the Redo Log Files Oracle recommends that you use this option when you do not expect to have access to the source database from which the redo log files were created."OBJ# 45522"("COL 1". This option does not guarantee transactional consistency. MIN_SALARY. HEXTORAW('c229'). MAX_SALARY) VALUES('IT_WT'. 4000. Oracle recommends that you use either the online catalog or extract the dictionary from redo log files instead.HEXTORAW('c3020b')).For example.START_LOGMNR(- .

Set the initialization parameter. Oracle recommends that you regularly back up the dictionary extract to ensure correct analysis of older redo log files. For example. This procedure creates the dictionary file.OPTIONS => DBMS_LOGMNR.BUILD procedure with the STORE_IN_REDO_LOGS option.ora'. use the DBMS_LOGMNR_D. Specify a filename for the dictionary and a directory path name for the file.STORE_IN_FLAT_FILE). Therefore. Redo Log File Options To mine data in the redo log files. enter the following in the initialization parameter file: UTL_FILE_DIR = /oracle/database 2. Do not specify a filename or location. For example. Extracting a LogMiner Dictionary to the Redo Log Files To extract a LogMiner dictionary to the redo log files. While the dictionary is being extracted to the redo log stream.'/oracle/database/'. DBMS_LOGMNR_D. To extract dictionary information to the redo log files. UTL_FILE_DIR. Extracting the LogMiner Dictionary to a Flat File When the LogMiner dictionary is in a flat file.BUILD. no DDL statements can be executed. LogMiner needs information about which redo log files to mine.BUILD(OPTIONS=> DBMS_LOGMNR_D. Execute the PL/SQL procedure DBMS_LOGMNR_D. in the initialization parameter file. 1.ora in /oracle/database: SQL> EXECUTE DBMS_LOGMNR_D. Start the Database SQL> startup 3.STORE_IN_REDO_LOGS).BUILD('dictionary. SQL> EXECUTE DBMS_LOGMNR_D.DICT_FROM_ONLINE_CATALOG). the database must be open and in ARCHIVELOG mode and archiving must be enabled. . the dictionary extracted to the redo log files is guaranteed to be consistent (whereas the dictionary extracted to a flat file is not). enter the following to create the file dictionary. fewer system resources are used than when it is contained in the redo log files. to set UTL_FILE_DIR to use /oracle/database as the directory where the dictionary file is placed.

Step 2 Start LogMiner.ADD_LOGFILE( LOGFILENAME => '/usr/oracle/ica/log1.You can direct LogMiner to automatically and dynamically create a list of redo log files to analyze. This example shows how to do the simplest analysis using LogMiner. Use the CONTINUOUS_MINE option when you start LogMiner. When using this method. Specify the redo log files which you want to analyze.NEW). After the first redo log file has been added to the list. SQL> EXECUTE DBMS_LOGMNR. then you can direct LogMiner to find and create a list of redo log files for analysis automatically. Manually Use the DBMS_LOGMNR. OPTIONS => DBMS_LOGMNR. or you can explicitly specify a list of redo log files for LogMiner to analyze.ora'. as follows: Automatically If LogMiner is being used on the source database. each subsequently added redo log file must be from the same database and associated with the same database RESETLOGS SCN. OPTIONS => DBMS_LOGMNR.ora'.ADDFILE).ADD_LOGFILE procedure to manually create a list of redo log files before you start LogMiner. Start LogMiner and specify the dictionary to use.ADD_LOGFILE( LOGFILENAME => '/u01/oracle/ica/log2. SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR( . Example: Finding All Modifications in the Current Redo Log File The easiest way to examine the modification history of a database is to mine at the source database and use the online catalog to translate the redo log files. SQL> EXECUTE DBMS_LOGMNR. LogMiner need not be connected to the source database. Step 1 Specify the list of redo log files to be analyzed.

"DEPARTMENT_ID") values ('307'."MANAGER_ID". "COMMISSION_PCT"."EMPLOYEES" where "EMPLOYEE_ID" = '306' and "FIRST_NAME" = 'Mohammed' and "LAST_NAME" = 'Sami' and "EMAIL" = 'MDSAMI' and "PHONE_NUMBER" = '1234567890' and "HIRE_DATE" = TO_DATE('10-JAN-2003 13:34:43'.'Sami'. '. 'OE').1. "PHONE_NUMBER".1. OE 1.11."FIRST_NAME". The output shows the DML statements in the order in which they were executed. USR ---HR HR XID --------1.11.1484 OE 1."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00') where "PRODUCT_ID" = '1801' and "WARRANTY_PERIOD" = TO_YMINTERVAL('+01-00') and ROWID = 'AAAHTKAABAAAY9mAAC'. 'dd-mon-yyyy hh24:mi:ss') and "JOB_ID" ='105' and "DEPARTMENT_ID" = '50' and ROWID = 'AAAHSkAABAAAY6rAAP'. SQL_UNDO FROM V$LOGMNR_CONTENTS WHERE username IN ('HR'. '105'. "DEPARTMENT_ID") values ('306'. delete from "HR"."EMPLOYEES"( "EMPLOYEE_ID".'110000'. "PHONE_NUMBER". OE OE 1."SALARY"."HIRE_DATE". update "OE"."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+01-00') where "PRODUCT_ID" = '1801' and "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00') and ROWID ='AAAHTKAABAAAY9mAAC'. 'SH_CLERK'."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00') where "PRODUCT_ID" = '1799' and "WARRANTY_PERIOD" = TO_YMINTERVAL('+01-00') and ROWID = 'AAAHTKAABAAAY9mAAB'. update "OE"."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+01-00') where "PRODUCT_ID" = '1799' and "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00') and ROWID = 'AAAHTKAABAAAY9mAAB'.'10').'50').DICT_FROM_ONLINE_CATALOG).1484 commit. insert into "HR".' || XIDSLT || '. 'HR_REP'."EMAIL"."EMPLOYEES"( "EMPLOYEE_ID".11. TO_DATE('10-jan-2003 13:34:43'. 'dd-mon-yyyy hh24:mi:ss') and "JOB_ID" = 'HR_REP' and "SALARY" = '120000' and "COMMISSION_PCT" = '. "COMMISSION_PCT"."EMPLOYEES" "EMPLOYEE_ID" = '307' and "FIRST_NAME" = 'John' and "LAST_NAME" = 'Silver' and "EMAIL" = 'JSILVER' and "PHONE_NUMBER" = '5551112222' and "HIRE_DATE" = TO_DATE('10-jan2003 13:41:03'.' || XIDSQN) AS XID. Step 3 Query the V$LOGMNR_CONTENTS view.'Mohammed'. 'JSILVER'.'Silver'. '.1. 'MDSAMI'.1484 HR 1.SQL_REDO. Note that there are four transactions (two of them were committed within the redo log file being analyzed. update "OE". SQL> SELECT username AS USR."SALARY". 'dd-mon-yyyy hh24:mi:ss').1.1476 1.OPTIONS => DBMS_LOGMNR.05' and "DEPARTMENT_ID" = '10' and ROWID = 'AAAHSkAABAAAY6rAAO'."FIRST_NAME".'John'. delete from "HR". '105'. 'dd-mon-yyyy hh24:mi:ss'). set transaction read write.1476 SQL_REDO SQL_UNDO ---------------------------------------------------set transaction read write. insert into "HR". "LAST_NAME". "JOB_ID". "LAST_NAME".05'. (XIDUSN || '. '1234567890'. TO_DATE('10-jan-2003 13:41:03'.1484 1. and two were not)."MANAGER_ID". update "OE". '5551112222'.'120000'. "JOB_ID".1476 ."HIRE_DATE". thus transactions interleave among themselves."EMAIL".05'.

update "OE".'Shelley'.START_LOGMNR procedure.15."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+20-00') where "PRODUCT_ID" = '2350' and "WARRANTY_PERIOD" = TO_YMINTERVAL('+20-00') and ROWID ='AAAHTKAABAAAY9tAAD'.HR HR 1."EMPLOYEES" where "EMPLOYEE_ID" = '205' and "FIRST_NAME" = 'Shelley' and "LAST_NAME" = 'Higgins' and "EMAIL" = 'SHIGGINS' and "PHONE_NUMBER" = '515."EMAIL". and specify either a time range or an SCN range of interest. and 'SHIGGINS'. "COMMISSION_PCT". "LAST_NAME".'110')."EMPLOYEES"( "EMPLOYEE_ID".'515. 'AC_MGR'. OE OE 1. use the DBMS_LOGMNR."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+12-06') where "PRODUCT_ID" = '2350' and "WARRANTY_PERIOD" = TO_YMINTERVAL('+20-00') and ROWID = 'AAAHTKAABAAAY9tAAD'. commit.'12000'.'101'. TO_DATE('07-jun-1994 10:05:01'.NULL.11. Example : Mining Redo Log Files in a Given Time Range This example assumes that you want to use the data dictionary extracted to the redo log files.123.1481 set transaction read write. SQL> SELECT NAME. Example of Mining Without Specifying the List of Redo Log Files Explicitly The previous example explicitly specified the redo log file or files to be mined. delete from "HR"."PHONE_NUMBER".8.15.123."FIRST_NAME"."MANAGER_ID".1484 1. 'dd-mon-yyyy hh24:mi:ss').8. However. 'dd-mon-yyyy hh24:mi:ss') and "JOB_ID" = 'AC_MGR' and "SALARY"= '12000' and "COMMISSION_PCT" IS NULL and "MANAGER_ID" = '101' and "DEPARTMENT_ID" = '110' and ROWID = 'AAAHSkAABAAAY6rAAM'. if you are mining in the same database that generated the redo log files. "HIRE_DATE". SQL> EXECUTE DBMS_LOGMNR. set transaction read write. FIRST_TIME FROM V$ARCHIVED_LOG WHERE SEQUENCE# = (SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG .END_LOGMNR(). To mine a set of redo log files without explicitly specifying them.1476 Step 4 End the LogMiner session.1481 1.1484 HR 1.8080'."SALARY". "DEPARTMENT_ID") values ('205'. "JOB_ID". Step 1 Determine the timestamp of the redo log file that contains the start of the data dictionary.8080' and "HIRE_DATE" = TO_DATE( '07-jun-1994 10:05:01'.CONTINUOUS_MINE option to the DBMS_LOGMNR.'Higgins'. then you can mine the appropriate list of redo log files by just specifying the time (or SCN) range of interest. update "OE". insert into "HR".

This step is not required. and CONTINUOUS_MINE options.dbf FIRST_TIME -------------------10-jan-2003 12:01:34 Step 2 Display all the redo log files that have been generated so far. but is included to demonstrate that the CONTINUOUS_MINE option works as expected. OPTIONS => DBMS_LOGMNR. SQL> SELECT FILENAME name FROM V$LOGMNR_LOGS WHERE LOW_TIME > '10-jan-2003 12:01:34' NAME ---------------------------------------------/usr/oracle/data/db1arch_1_207_482701534.dbf /usr/oracle/data/db1arch_1_208_482701534.COMMITTED_DATA_ONLY + DBMS_LOGMNR. SQL> EXECUTE DBMS_LOGMNR.PRINT_PRETTY_SQL + DBMS_LOGMNR.WHERE DICTIONARY_BEGIN = 'YES').dbf Step 3 Start LogMiner. PRINT_PRETTY_SQL. as will be shown in Step 4. Start LogMiner by specifying the dictionary to use and the COMMITTED_DATA_ONLY. .CONTINUOUS_MINE).START_LOGMNR(STARTTIME => '10-jan-2003 12:01:34'.dbf /usr/oracle/data/db1arch_1_209_482701534. NAME -------------------------------------------/usr/oracle/data/db1arch_1_207_482701534. ENDTIME => SYSDATE.DICT_FROM_REDO_LOGS + DBMS_LOGMNR.dbf /usr/oracle/data/db1arch_1_210_482701534.

START_LOGMNR procedure with the CONTINUOUS_MINE option includes all of the redo log files that have been generated so far.) SQL> SELECT FILENAME name FROM V$LOGMNR_LOGS. . as expected.dbf /usr/oracle/data/db1arch_1_209_482701534. NAME -----------------------------------------------------/usr/oracle/data/db1arch_1_207_482701534. exclude all DML statements done in the sys or system schema.(XIDUSN || '. modified_time date.dbf /usr/oracle/data/db1arch_1_210_482701534.) Note that all reconstructed SQL statements returned by the query are correctly translated. old_list_price number(8.' || XIDSQN) as XID. (Compare the output in this step to the output in Step 2. To reduce the number of rows returned by the query.' || XIDSLT || '. USR ----------SYS SYS XID -------1.2).dbf Step 5 Query the V$LOGMNR_CONTENTS view. SQL> SELECT USERNAME AS usr. create table oe. This step shows that the DBMS_LOGMNR. old_warranty_period interval year(2) to month).1594 SQL_REDO ----------------------------------set transaction read write. 'SYSTEM') AND TIMESTAMP > '10-jan-2003 15:59:53'.product_tracking (product_id number not null.Step 4 Query the V$LOGMNR_LOGS view. (This query specifies a timestamp to exclude transactions that were involved in the dictionary extraction.2.dbf /usr/oracle/data/db1arch_1_208_482701534.2.1594 1. SQL_REDO FROM V$LOGMNR_CONTENTS WHERE SEG_OWNER IS NULL OR SEG_OWNER NOT IN ('SYS'.

:old. sysdate.1602 1.1602 commit.product_information for each row when (new.1594 1. .9.2.1598 commit. create or replace trigger oe. SYS OE 1. OE 1. "MODIFIED_TIME" = TO_DATE('13-jan-2003 16:07:03'.list_price.18. "LIST_PRICE" = 100 where "PRODUCT_ID" = 1729 and "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00') and "LIST_PRICE" = 80 and ROWID = 'AAAHTKAABAAAY9yAAA'.list_price <> old.SYS SYS SYS 1. :old."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+08-00').warranty_period) declare begin insert into oe.18.product_tracking values (:old. update "OE".list_price or new.18.warranty_period <> old.product_id."PRODUCT_TRACKING" values "PRODUCT_ID" = 1729.product_tracking_trigger before update on oe.9. end.warranty_period).1598 insert into "OE".1602 1. set transaction read write. 'dd-mon-yyyy hh24:mi:ss').

"OLD_LIST_PRICE" = 72. 'dd-mon-yyyy hh24:mi:ss'). "OLD_WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00').9. OE 1.1598 update "OE"."PRODUCT_TRACKING" values "PRODUCT_ID" = 2340. OE 1."PRODUCT_INFORMATION" set "WARRANTY_PERIOD" = TO_YMINTERVAL('+08-00').9.9.END_LOGMNR(). "MODIFIED_TIME" = TO_DATE('13-jan-2003 16:07:07'."OLD_LIST_PRICE" = 80.1598 insert into "OE". OE 1. "LIST_PRICE" = 92 where "PRODUCT_ID" = 2340 and "WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00') and "LIST_PRICE" = 72 and ROWID = 'AAAHTKAABAAAY9zAAA'. SQL> EXECUTE DBMS_LOGMNR. "OLD_WARRANTY_PERIOD" = TO_YMINTERVAL('+05-00').1598 commit. Step 6 End the LogMiner session. .

BACKUP AND RECOVERY Opening or Bringing the database in Archivelog mode. Follow these steps: STEP 1: Shutdown the database if it is running. STEP 3: Set the following parameters in parameter file. To again bring back the database in NOARCHIVELOG mode.%r. .arc LOG_ARCHIVE_DEST_1=”location=/u02/ica/arc1” If you want you can specify second destination also LOG_ARCHIVE_DEST_2=”location=/u02/ica/arc1” Step 3: Start and mount the database. Step 7: It is recommended that you take a full backup after you brought the database in archive log mode.%t. STEP 6: Now open the database SQL>alter database open. STEP 2: Take a full offline backup. STEP 2: Comment the following parameters in parameter file by putting " # " . SQL> STARTUP MOUNT STEP 4: Give the following command SQL> ALTER DATABASE ARCHIVELOG. To open the database in Archive log mode. Follow these steps: STEP 1: Shutdown the database if it is running. SQL> ARCHIVE LOG LIST. STEP 5: Then type the following to confirm. LOG_ARCHIVE_FORMAT=ica%s.

Logfiles query the data dictionary tables V$DATAFILE and V$LOGFILE before shutting down. $sqlplus SQL> connect / as sysdba SQL> Shutdown immediate SQL> Exit After Shutting down the database. Copy all the datafiles. parameter file and password file to your backup destination. $cd /u01/ica $cp * /u02/backup/ Be sure to remember the destination of each file. This will be useful when restoring from this backup. Now you can open the database. logfiles. Lets suppose all the files are in "/u01/ica" directory. controlfiles. .%r. STEP 4: Give the following Commands SQL> ALTER DATABASE NOARCHIVELOG.# LOG_ARCHIVE_DEST_1=”location=/u02/ica/arc1” # LOG_ARCHIVE_DEST_2=”location=/u02/ica/arc2” # LOG_ARCHIVE_FORMAT=ica%s. TAKING OFFLINE BACKUPS. Then start SQL Plus and connect as SYSDBA. Then the following command copies all the files to the backup destination /u02/backup. STEP 5: Shutdown the database and take full offline backup.%t.arc STEP 3: Startup and mount the database. TIP: To identify the datafiles. You can create text file and put the destinations of each file for future use. SQL> STARTUP MOUNT. ( UNIX ) Shutdown the database if it is running.

Let us suppose we want to take online backup of "USERS" tablespace. The following are the steps to drop a damaged datafile and open the database. SQL> exit. After connecting give the command "archive log list" this will show you the status of archiving. Lets suppose the file is "/u01/ica/usr1. You will loose all information contained in the damaged datafile. Option 1: When you don’t have a backup. you can drop the damaged datafile and open the database. You can query the V$DATAFILE view to find out the name of datafiles associated with this tablespace.TAKING ONLINE (HOT) BACKUPS. $sqlplus Enter User:/ as sysdba SQL> alter tablespace users begin backup. Give the following series of commands to take online backup of USERS tablespace. To check whether the database is running in Archivelog mode or Noarchivelog mode.dbf ".(UNIX) . If you have lost one datafile and if you don't have any backup and if the datafile does not contain important objects then.(UNIX) To take online backups the database should be running in Archivelog mode.dbf /u02/backup SQL> alter tablespace users end backup. SQL> host cp /u01/ica/usr1. $sqlplus Enter User:/ as sysdba SQL> ARCHIVE LOG LIST If the database is running in archive log mode then you can take online backups. Start sqlplus and then connect as SYSDBA. RECOVERING THE DATABASE IF IT IS RUNNING IN NOARCHIVELOG MODE.

STEP 1: Take a full backup of current database. STEP 2: Start the sqlplus and give the following commands. You will loose all the changes made to the database since last full backup. To restore from full database backup. If the database is running in Noarchivelog mode and if you have a full backup. Or you can restore from full backup. copy all the files from backup to their original locations(UNIX) Suppose the backup is in "/u2/oracle/backup" directory. If you have lost the control file and if it is mirrored. Either you can drop the damaged datafile. '/u01/ica/usr1. Then there are two options for you.STEP 1: First take full backup of database for safety. $sqlplus Enter User:/ as sysdba SQL> STARTUP MOUNT SQL> ALTER DATABASE DATAFILE SQL>alter database open. $cp /u02/backup/* /u01/ica This will copy all the files from backup directory to original destination. Then simply copy the control file from mirrored location to the damaged location and open the database . if it does not contain important information which you can afford to loose.e. To drop the damaged datafile follow the steps shown previously. RECOVERING FROM LOST OF CONTROL FILE. ii .dbf' offline drop. Then do the following. Also remember to copy the control files to all the mirrored locations. Option 2:When you have the Backup. STEP 2: Restore from full database backup i. Do the following. i .

Then follow the steps shown below. If you have already taken the backup of control file creation statement by giving this command. Refer to "Managing Control File" topic for the CREATE CONTROL FILE statement. STEP 2. If you have lost one datafile. Recovering from the lost of Damaged Datafile. SQL> STARTUP NOMOUNT STEP 4: Run the "CR. You will lose any datafiles which you do not include. .SQL" Then just do the following. STEP 5: Mount and Open the database. " ALTER DATABASE BACKUP CONTROLFILE TO TRACE. Restore the datafile from most recent backup.SQL" script file. SQL>alter database mount. Then you have to alter the script and include the filename and size of the file in script file. SQL>alter database open. If your script file containing the control file creation statement is "CR. " and if you have not added any tablespace since then. Recovering Database when the database is running in ARCHIVELOG Mode. Shutdown the Database if it is running. STEP 1. If you do not have a backup of Control file creation statement. Then you have to manually give the CREATE CONTROL FILE statement. just create the controlfile by executing the statement Buf If you have added any new tablespace after generating create controlfile statement. Then you can recreate a control file. STEP 1: Start sqlplus STEP 2: connect / as sysdba STEP 3: Start and do not mount a database like this.If you have lost all the mirrored control files and all the datafiles and logfiles are intact. You have to write the file names and sizes of all the datafiles.

SQL>alter database recover. SQL>Set autorecovery on. Some user accidently drop the table on Thursday 16-Aug-2007 and nobody notice this until Saturday. Restore all the datafiles. STEP 4. $sqlplus Enter User:/ as sysdba SQL>Startup mount. Shutdown the database and take a full offline backup. Now to recover the table follow these steps.STEP 3. Go on to next step. If all archive log files are available then recovery should go on smoothly. SQL> recover database until time '2007:08:16:13:55:00' . Then give the following command to recover database until specified time. You have taken a full backup of the database on Monday 13-Aug-2007 and the table was created on Tuesday 14-Aug-2007 and thousands of rows were inserted into it. Time Based Recovery (INCOMPLETE RECOVERY). logfiles and control file from the full offline backup which was taken on Monday. Now open the database SQL>alter database open. After you get the "Media Recovery Completely" statement. Suppose a user has a dropped a crucial table accidentally and you have to recover the dropped table. STEP 1. STEP 4. Then Start sqlplus and connect as SYSDBA. Recovering from the Lost Archived Files: If you have lost the archived files. Then Immediately shutdown the database and take a full offline backup. STEP 2. Start SQLPLUS and start and mount the database. STEP 3.

Tunning: indexes and execution plans .Check iostat Weekly . After database is open.Check CPU contention . For further information please refer to Flashback Features Topic in this book Daily .Top SQL .Check network load .Cleaning of alert logs .Analyze the data increment trend . Restore from the full database backup which you have taken on Saturday.Environments consistence . Because you have performed a Incomplete Recovery.Review of ressource policy . Export the table to a dump file using Export Utility.Verify instance status . STEP 7. Open the database and reset the logs.Review of RMAN Monthly .Check alerts .Check memory usage .Check storage .Check waiting times .Recovery tests .Check configured metrics . like this SQL> alter database open resetlogs.Invalid objects .Tunning . Note: In Oracle 10g you can easily recover drop tables by using Flashback feature.Fragmentation .Check RMAN backups .using backup controlfile. STEP 8.Trends and peaks .Review I/O . STEP 6. Open the database and Import the table. STEP 5.

sum(bytes)/1024/1024 from dba_free_space group by tablespace_name.The DBA role will be assigned to this account.role Contains all database system privileges. Tablespace administration sql statements Finding out the historical tablespace usage select name .Row chaining . tablespace_maxsize*8192/(1024*1024*1024) . and no one should create any tables in the schema of user SYS. select tablespace_name.Schedule monthly downtime SYS: automatically created when Oracle database is installed automatically granted the DBA role has a default password: CHANGE_ON_INSTALL (make sure you change it) owns the base tables and views for the database data dictionary the default schema when you connect as SYSDBA Tables in the SYS schema are manipulated only by the database. tablespace_usedsize*8192/(1024*1024*1024) . v$tablespace b where tablespace_id = 175 and a..It has all the system privileges for the database and additional tables and views that display administrative information and internal tables and views used by oracle tools are created using this username.tablespace_id = b. tablespace_size*8192/(1024*1024*1024) .Scalability . SYSTEM: automatically created when Oracle database is installed automatically granted the DBA role has a default password: MANAGER (make sure you change it) used to create additional tables and views that display administrative information used to create internal tables and views used by various Oracle database options and tools Never use the SYSTEM schema to store tables of interest to non-administrative users. Database users should not connect to the Oracle database using the SYS account. All of the base tables and views for the database's dictionary are store in this schema and are manipulated only by ORACLE.High Availability Analysis . find out free space on the mentioned tablespace. They should never be modified by any user or database administrator. . rtime from DBA_HIST_TBSPC_SPACE_USAGE a . SYSTEM user account . DBA . SYS user account .TS# order by rtime desc.

tablespace_name = d. bytes from dba_data_files d. select file_name.tablespace_name and bytes/1024/1024 > 3000 . find out existing size of the tablespaces by using the following command select file_name.tablespace_name find out the tablespaces whose size is greater than 3 GB select file_name. dba_tablespaces t where t.tablespace_name = d. d. sum(bytes)/1024/1024 from dba_free_space where tablespace_name = ‗TS_RBS‘ group by tablespace_name.tablespace_name creating a temporary tablespace CREATE TEMPORARY TABLESPACE TS_TEMP TEMPFILE ‗/global/reuterdb1/oracle/reutertp/data1/reutertp_temp01. select d.tablespace_name tablespace. bytes/1024/1024 .tablespace_name tablespace.status. . sum(bytes/1024/1024) from dba_data_files d. alter database rename file ‗/global/reuterdb1/oracle/reutertp/data6/reutertp_GFD_data11. select t.dbf‘ .dbf‘ SIZE 20000M REUSE EXTENT MANAGEMENT LOCAL UNIFORM SIZE 16M.tablespace_name and d. select file_name.tablespace_name = d.increment_by.select tablespace_name.dbf‘ to ‗/global/reuterdb1/oracle/reutertp/data3/reutertp_GFD_data11.tablespace_name = d. d.tablespace_name tablespace. bytes from dba_data_files d. d.tablespace_name tablespace.tablespace_name group by d.tablespace_name = d.tablespace_name = d.tablespace_name and d. dba_tablespaces t where t.maxbytes from dba_data_files d. Command to rename a datafile name.autoextensible autoextend . dba_tablespaces t where t. t. dba_tablespaces t where t. sum(bytes/1024/1024) from dba_data_files d. sum(bytes/1024/1024)/count(*) from dba_data_files d. bytes/1024/1024 from dba_data_files d. dba_tablespaces t where t.tablespace_name group by t. t.tablespace_name = d.tablespace_name and t.status.tablespace_name = ‗TS_GFD_DATA‘ group by t.tablespace_name like ‗UN%‘ . dba_tablespaces t where t.This is normally used when you previously copied the datafile from one location to another location and you want to now update the control file .tablespace_name = ‗TS_TRAINENGINE_FACT_DATA‘ select t.tablespace_name and bytes/1024/1024 > 3000 .Be careful that you have to move the datafiles only when the database is completely shutdown. dba_tablespaces t where t.

changing a users quota on a tablespace to unlimited alter user ims quota unlimited on ts_data_1. to change the maxbytes of a datafile do the below command ALTER DATABASE DATAFILE ‗ /global/riskeb/oracle/redb/data2/redb_TRAINENGINE_interm_data01. select file_name.dbf‘ resize 1000M. Resize the data file with the following command alter database datafile ‗/u10/oradata/RSOD/RSODundo_02_02. DBA_USERS Describes all users of the database ALL_USERS Lists users visible to the current user.if problem with tablespace size then increase the tablespace size. resizing a datafile alter database datafile ‗ /global/mrt-db/oracle/mrt/data1/ppmrtint_tools01.tablespace_name tablespace. t.tablespace_name from dba_data_files. bytes from dba_data_files d.tablespace_name = d. dba_tablespaces t where t.dbf‘ SIZE 2048M AUTOEXTEND ON NEXT 1024M MAXSIZE 32000M. but does not describe . Adding datafile to a tablespace alter tablespace ts_GFD_indx add datafile ‗/global/reuterdb1/oracle/reutertp/data6/reutertp_GFD_indx25.dbf ‗ resize 680M adding datafile to a tablespace alter tablespace INDEX_MED_OPG ADD DATAFILE ‗/var/opt/oracle/DSS1/data04/INMED_OPGDSS105. find out datafile path and name for the specified tablespace select file_name.tablespace_name like ‗BRAINLOBZIP‘.tablespace_name and d.dbf‘ size 1000M.dbf‘ AUTOEXTEND ON NEXT 10M MAXSIZE 2000M.

Defining user quotas on tablespaces Alter user listmgmt quota 1024M on ts_data01 quota 1024M on ts_index01 Finding out tablespace quotas for an user.them USER_USERS Describes only the current user DBA_TS_QUOTAS Describes tablespace quotas for all users USER_TS_QUOTAS Describes tablespace quotas for current user USER_PASSWORD_LIMITS Describes the password profile parameters that are assigned to the user USER_RESOURCE_LIMITS Displays the resource limits for the current user DBA_PROFILES Displays all profiles and their limits RESOURCE_COST Lists the cost for each resource Syntax for creating a user ALTER USER avyrros IDENTIFIED by ‗password‘ DEFAULT TABLESPACE data_ts TEMPORARY TABLESPACE temp_ts QUOTA 100M ON data_ts QUOTA 0 ON test_ts PROFILE clerk. TABLESPACE_NAME USERNAME BYTES —————————— —————————— ———- . SQL> select * from dba_ts_quotas where username like ‗%LISTMGMT%‘.

Unlimited quotas are indicated by -1 Users having both zero quota and zero bytes used in a tablespace are not listed in the report.— TS_DATA01 1048576000 TS_INDEX01 1048576000 128000 80768 LISTMGMT 128000 NO LISTMGMT 128000 NO 1048576000 661651456 SQL> Alter user listmgmt quota 1024M on ts_data01 quota 1024M on ts_index01. Note that this number is always a multiple of the database block size. TABLESPACE USERNAME BYTES MAX_BYTES BLOCKS MAX_BLOCKS ———. TFSTSUSR reports on DBA_TS_QUOTAS.———USERS JFEE 0 512000 0 250 USERS DCRANNEY 0 -1 0 -1 When specific quotas are assigned.——. includes user name V$SESSTAT Lists user session statistics .MAX_BYTES BLOCKS MAX_BLOCKS DRO ———. A user can have an overriding database resource privilege that can be seen by querying DBA_USERS.———. so if you specify a tablespace quota that is not a multiple of the database block size.———. which holds resource privilege information only at the tablespace level. the exact number is indicated in the MAX_BYTES column.——— ——– ———. The following query lists all tablespace quotas specifically assigned to each user: SELECT * FROM DBA_TS_QUOTAS. then it is rounded up accordingly. User altered. V$SESSION Lists session information for each current session.

oracle error no of sessions exceeded reason is the processes are created from asp.ora file and increase the default max no. One day we got the above error on our development server. If you are using web-application. So. So asked the app team to check their front end code. a change in the processes parameter from 75 to 150 will not have much of an impact on the system‘s oracle-dedicated memory (the SGA). of processes form 50 to 200 or 300. it is not using any resources to maintain a ―place‖ for that process. There is also some SGA space for all processes (active or not – but it is small). The processes that are active take up some of the system memory in what is called the PGA. Edit the init<sid>. or they might have a loop and then opening the connection. which is not part of the shared memory parameters.V$STATNAME Displays decoded statistic names for the statistics shown in the V$SESSTAT view PROXY_USERS Describes users who can assume the identity of other users See Also: Oracle Database SQL Reference for complete descriptions of the preceding data dictionary and dynamic performance views 2)WHEN MAX ERRORS REACHED OCCURS the error ORA-00020: maximum number of processes (%s) exceeded is because of the following reasons. and we know that we dont have 100 users at the moment on dev.net or whatever and then not closed. Generally. On our development server the processes parameter is set to 100. . Be careful to take memory availabily into account.ora file. if a process is not active. so the only reason could be that somebody has opened a connection in front end and then not closing it. 1)when the number of processes accessing oracle database exceeds specified limit. Restart the application on the MMS – console. This will give you a temporary solution only.oracle has a limit on no of processes specified in the init.

it can‘t be used for tablespaces that contain active rollback segments or temporary segments.OBJECT_ID and a. Take the tablespace offline. sometimes we need to move the datafiles to another filesystem temporarily so the filesstem can be extended by the unix team. select username. 1.‘||b. 1.owner||‘. substr( SID||‘.OBJECT_ID = b.select value. substr( lower(USERNAME). but it only works with non-SYSTEM tablespaces. 1. name from v$parameter where name=‘processes‘. select TERMINAL. instr( PROGRAM . COUNT(*) from v$session where schemaname = ‗KEYSTONE‘ GROUP BY TERMINAL select TERMINAL. This method has the advantage that it doesn‘t require shutting down the instance.SID. ‗\‘. -1)+ 1) ―PROGRAM‖ from V$LOCKED_OBJECT a. 30) ―TABLE‖ . substr( PROGRAM . 1.object_name. all_objects b. COUNT(*) from v$session GROUP BY TERMINAL.non system datafiles can be moved by the following way. v$session c where a. 10) ―SESSION_ID‖ . select substr( b. Rename and/or move the datafile using operating . lower(TERMINAL) ―TERMINAL‖ . COUNT(*) from v$session GROUP BY TERMINAL select * from v$session where schemaname = ‗KEYSTONE‘ and terminal = ‗SPL1W082‘ GROUP BY TERMINAL when filesystem is 100% full.‘||SERIAL#.username. Further. 10) ―USERNAME‖ .TERMINAL. lower(OSUSER) ―OSUSER‖ . 2.SESSION_ID = c.

4. 3. How to find pending transactions in the database? set lines 250 column start_time format a20 column sid format 999 column serial# format 999999 column username format a10 column status format a10 column schemaname format a10 column osuser format a10 column process format a10 column machine format a15 . Use the alter tablespace command to rename the file in the database.system commands.dbf ‗ TO ‗/u02/oracle/U1/data04.dbf ‗ . sql> alter tablespace app_date rename datafile ‗/u01/oracle/U1/data01. sql> connect sys/oracle as sysdba sql> alter tablespace app_data offline. Bring the tablespace back online. sql> alter tablespace app_data online. The tablespace will be back online using the new name and/or location of the datafile.

machine.s. you can shutdown the database.s.s. v$session s where s. s. How to find if spfile is used? this is the correct way: select distinct isspecified from v$spparameter if you see ‗TRUE‘ there. select value from v$parameter where name = ‗spfile‘.sid. spfile is used otherwise pfile.schemaname.osuser. what about if i just want to use pfile.serial#.status.ora‘ then you can delete the spfile .to_char(s.s.ses_addr order by start_time.‘DD/MON/YY HH24:MI:SS‘) logon_time from v$transaction t.username.start_time.s.saddr = t. should i just delete the spfile? you will need to shutdown and startup open pfile=‘/path/to/initSID.process. if this comes back with a value other than null. you are using an spfile. and startup open spfile=‘/path/to/spfile‘. if you are using a pfile.terminal.s.program.logon_time.s.module.s.s.s.column terminal format a10 column program format a25 column module format a10 column logon format a20 prompt #################################################### prompt # current transactions: prompt #################################################### select t..

dba_tablespaces t where t.s suppose there is an user by name user1 and you want to log into his schema. t.tablespace_name Find free space in tablespace select tablespace_name. . 4. tables etc .tablespace_name = d. here are the steps (It will work only if you have DBA privilege ie. Find last analyzed time for the schema. bytes from dba_data_files d. now you can connect as user1 by using the new password. last_analyzed FROM user_tables ORDERBY last_analyzed DESC select table_name.tablespace_name tablespace.—This is to update statistics. access to dba_users and other dba_ views) 1. save the value in the password column for this user retrieved from query in step 1 (say the encrypted value is abcdefgh1234) change the password of the user alter user user1 indetified by temppass. then restore the original password (either connected as user1 or through your own user). 10)9i how to delete and compute statistics Analyze table test compute statistics. 5. alter user user1 identified by values ‗abcdefgh1234‘. password from dba_users. sum(bytes)/1024/1024 from dba_free_space group by tablespace_name. How to find users passwords in the database? yeah you can connect to the user schema without knowing the user‘s actual password.Find size of table space select file_name. SELECT table_name. — this will analyze the indexes as well. select username.last_analyzed from dba_tables where owner like ‗SUP%‘ and rownum < 4.

find all indexes on a table select index_name from all_indexes where owner = ‗SCOTT‘ and table_name = ‗TEST‘. schemaname. column_position from all_ind_cols where owner = ‗SCOTT‘ and table_name = ‗TEST‘. program FROM v$session ORDER BY schemaname. osuser. osuser. — compute new stats The above commands are 9i . get sql info for a session SELECT sql_text . Use dbms_stats. terminal. — this is to help you find any columns being not added in the multi column index get all session info Detailed sessions informations are returned by : SELECT sid. column_name. — delete the existing stats first and then analyze table test compute statistics.gather_table_stats procedure.or analyze table test delete statistics. If you are using 10g then don‘t use compute statistics. terminal. — this is to find the indexes for a particular table find all indexed columns select index_name. program.

this drops the whole tablespace. Then v$session would show this information for the session running the SQL in question in the CLIENT_IDENTIFIER field. drop tablespaces incuding objects.datafiles . Be very careful. drop tablespace data_med_lcp including contents and datafiles cascade constraints describe the different user privileges views here granting privileges to users -> some examples grant CREATE SYNONYM to price_dev grant CREATE SESSION to price_dev select grantor. Other ways will take more work. select ‗grant ‗ || privilege || ‗ to keystone ‗ from dba_sys_privs where grantee=‘KEYSTONE‘ . ―Daily Reports‖.FROM v$sqltext WHERE concat(hash_value. ―Invoicing‖. address)=(SELECT concat(sql_hash_value. That would be the easiest way. ‗SYSTEM‘) You can query the user_tab_privs_recd and the user_sys_privs: Select grantee. sql_address) FROM v$session WHERE sid=?????) ORDER BY piece.privilege from dba_tab_privs where owner in (‗SYS‘.constraints. select * from dba_sys_privs where grantee=‘KEYSTONE‘. privilege from dba_tab_privs where owner = ‗SIEBEL‘ and table_name= ‘S_SRC‘ select * from user_sys_privs where username=user. etc. 15) setting identifiers for different application modules There is a way for programs to ―identify themselves‖. they could use this to set the identifier differently for different application modules ―New Client Entry‖. DBMS_SESSION.SET_IDENTIFIER (client_id VARCHAR2) If you are working with Application Developers.

Did you know that it has UNLIMITED TABLESPACE system privilege. allows the grantee to issue sql_trace = TRUE in their session.? (A) select * from dba_role_privs where GRANTEE=‘RKSREPGEN‘ (2) How can I see all the ‘grants’ that have been assigned to a role…. If possible. . not anything else. Create your own roles. however. You would want to restrict the tablespaces to specific users only. this is not what you want.? (A) select * from dba_sys_privs where grantee = ‗RKSREPGEN‘ Oracle provides several roles that are built into the database. select * from dba_role_privs where grantee = [user]. This is generally given to schema owners. has the CREATE TABLE/SEQUENCE/SYNONYM and a few more options. put them in the appropriate roles which you have created. This can have far reaching consequences. Let‘s examine RESOURCE. select ‗grant ‗ || granted_role || ‗ to keystone ‗ from dba_role_privs where grantee = ‗KEYSTONE‘. RESOURCE. select * from user_tab_privs_recd where owner in (‗SYS‘.? (A) select * from dba_sys_privs where GRANTEE=<ROLE_NAME> (3) How can I see all the ‘grants’ that have been assigned to a user…. identify the privileges users will need. Similarly the role CONNECT. ‗SYSTEM‘). Most DBAs use them to make their tasks easier and simpler. try not to use the Oracle built-in roles like RESOURCE and CONNECT. The name CONNECT somehow conveys the impression of the ability to connect only. select * from role_role_privs. and CONNECT. and use them to control authorization. Another privilege. select * from user_tab_privs_recd . Rather.select * from dba_role_privs where grantee=‘SUPPDB‘. the ability is much more than that. making it able to create any table anywhere in the database – including the SYSTEM tablespace? Obviously. Some of them are DBA. it is not prudent to use built-in roles. As you can see. role_sys_privs role_tab_privs (1) How can I select the role(s) that a user has been assigned…. by default. ALTER SESSION system privilege. Therefore. but each of them is a security nightmare.

oracle. CREATE SESSION.920/a96540/statements_912a.htm#2063440 In Oracle 10gR2 things are fairly sane: CONNECT role has only CREATE SESSION RESOURCE has CREATE CLUSTER. . CREATE SEQUENCE.htm#2063331 For object privileges http://downloadwest. CREATE CLUSTER.oracle. CREATE TABLE and CREATE VIEW. CREATE TABLE.dbf‘ resize 2000M Kill session The SQL*Plus Approach Sessions can be killed from within oracle using the ALTER SYSTEM KILL SESSION syntax. CREATE SEQUENCE.oracle. Rather a scary lot for a role called ‗connect‘ RESOURCE has CREATE CLUSTER.com/docs/cd/B10501_01/server. CREATE PROCEDURE. CREATE DATABASE LINK. CREATE SYNONYM.com/docs/cd/B10501_01/server. CREATE TRIGGER and CREATE TYPE In Oracle 9iR2 things get a little scary: CONNECT has ALTER SESSION. CREATE SEQUENCE. CREATE INDEXTYPE.com/docs/cd/B10501_01/server. CREATE OPERATOR. CREATE OPERATOR.920/a96540/statements_912a. CREATE INDEXTYPE.Try these For system privileges http://downloadwest.htm#2073689 For role privileges http://downloadwest. CREATE TRIGGER and CREATE TYPE Resize datafiles alter database datafile ‗/var/opt/oracle/DSS1/data04/INDEX_MED_OPGDSS102. CREATE TABLE. CREATE PROCEDURE.920/a96540/statements_912a.

s.EXE ORACLE. Killing OS processes is dangerous and can lead to instance failures.sid.EXE SQLPLUSW. s.serial#. In these cases the session will be ―marked for kill‖.serial#‘. SID SERIAL# OSUSER PROGRAM ———. as explained below.EXE ORACLE.EXE ORACLE.exe is not able to kill the session immediately.First identify the offending session as follows: SELECT s.EXE ORACLE. If the marked session persists for some time you may consider killing the process at the operating system level. Issuing the ALTER SYSTEM KILL SESSION command is the only safe way to kill an Oracle session.—————————— ————— 1 2 3 4 5 6 20 43 33 1 SYSTEM 1 SYSTEM 1 SYSTEM 1 SYSTEM 1 SYSTEM 1 SYSTEM 60 SYSTEM 11215 USER1 5337 USER2 ORACLE.EXE DBSNMP.program FROM v$session s. In some situations the Oracle. s.———.osuser.EXE SQLPLUSW. It will then be killed as soon as possible. so do this at your own peril.EXE The SID and SERIAL# values of the relevant session can then be substituted into the following statement: SQL> ALTER SYSTEM KILL SESSION ‗sid. .EXE ORACLE.

so this also works: alter user SYSTEM identified by SECRET But in 11g passwords are case-sensitive. But if your server and database are set up to allow you to connect as SYS without explicitly entering a password. No.It is possible to force the kill by adding the IMMEDIATE keyword: SQL> ALTER SYSTEM KILL SESSION ‗sid. usernames and passwords in Oracle not case-sensitive. you can then change the password for SYS (and any other user also. . Therefore.so be careful. to change the password for SYSTEM to be ―‖secret‖. more info on orapwd file. This should prevent you ever needing to use the orakill.exe in Windows. So. or the kill command in UNIX/Linux change sys password There is no difference. just enter this: alter user system identified by secret. The syntax is simply: alter user [username] identified by [new_password]. like: SYSTEM) if you want to.serial#‘ IMMEDIATE. privileged users must be authenticated by the operating system. REMOTE_LOGIN_PASSWORDFILE Parameter type = String Syntax REMOTE_LOGIN_PASSWORDFILE= {NONE | SHARED | EXCLUSIVE} Default value NONE REMOTE_LOGIN_PASSWORDFILE specifies whether Oracle checks for a password file and how many databases can use the password file. NONE >> Oracle ignores any password file.

It doesn‘t make any difference what username and password is used. Only user recognized by the password file is SYS. If not already created. Connect to the database as user SYS (or as another user with the administrative privilege). Preparing to Use Password File Authentication To enable authentication of an administrative user using password file authentication you must do the following: Create an operating system account for the user. Using Password File Authentication This section describes how to authenticate an administrative user using password file authentication. Give it a try with a username you know doesn‘t exist: conn fred/flintstone as sysdba. EXCLUSIVE >> The password file can be used by only one database and the password file can contain names other than SYS. If you are. If the user does not already exist in the database. create the user. Grant the SYSDBA or SYSOPER system privilege to the user: GRANT SYSDBA to scott. to get listing of user enabled to connect to the database using ORAPWD file. Create the password file using the ORAPWD utility: ORAPWD FILE=filename PASSWORD=password ENTRIES=max_users Set the REMOTE_LOGIN_PASSWORDFILE initialization parameter to EXCLUSIVE. . This statement adds the user to the password file. thereby enabling connection AS SYSDBA As soon as Oracle sees ‗as sysdba‘ it checks to see if you‘re allowed to connect.SHARED >>More than one database can use a password file. you can query view sql> select * from V$PWFILE_USERS. you are connected as the SYS user.

ora Logging as sysdba to the database sqlplus ‗/as sysdba‘ This will let you login to Oracle as sys using OS authentication (must be login as Oracle user in Unix/Windows).STATUS from v$datafile. you can use lsnrctl status or lsnrctl services to see if your doing shared or dedicated (or just query SERVER from v$session) I ran the select… SQL> set echo on SQL> select server from v$session where sid=(select sid from v$mystat where rownum=1). DEDICATED SQL> spool off that shows a single dedicated server session. the default password of SYS and SYSTEM is ―change_on_install‖ and ―system‖ respectively when you create a new database. when you have conversion errors in toad Change the nls_lang in the registry editor of the client to .Unless you create the password file. Otherwise. find out whether datafiles are online select FILE#.be careful about including the dot before the character set.UTF8 or whichever character set you want. Maximum cursors . select server. find out whether a server is dedicated or shared. the password for sys is sepcified when you create the password file: orapwd file=orapw<sid> password=<sys‘s password> entries=<max # user‘s> with REMOTE_LOGIN_PASSWORDFILE=exclusive in the init<SID>. count(*) from v$session group by server.

CONSTRAINT_NAME = B.value as numopencursors . Dropped the primary key using alter table surveyor.ISO_COUNTRY_CODE.BUSINESS_UNIT. Then I recreated primary key with ALTER TABLE surveyor. B.TABLE_NAME CHILD.R_CONSTRAINT_NAME AND A.machine .sid = s. USER_CONSTRAINTS B WHERE A. observed that the index was not dropped. A.RECEIVING_CENTER_MATRIX ADD CONSTRAINT pk_RECEIVING_CENTER_MATRIX1 PRIMARY KEY (PDA_TYPE_ID.s.RECEIVING_CENTER_ID) USING INDEX TABLESPACE CLM_DATA.CONSTRAINT_NAME. ALTER TABLE TAB_PK DROP PRIMARY KEY CASCADE.sid Modify primary key columns If foreign key constraints are referencing this primary key then find them by using query SELECT A.username FROM V$SESSTAT v.statistic# = 3 and v.To check how many cursors are in use run this sql statement: SELECT v.s.osuser. After spooling above information and after confirmation from application team use below command to drop primary key and cascade all constraints.CONSTRAINT_NAME FROM USER_CONSTRAINTS A. B.RECEIVING_CENTER_MATRIX drop primary key .TABLE_NAME PARENT. CASCADE option drops the foreign key constraints on any table referencing the PK being dropped. So In toad I had to manually drop the index. .CONSTRAINT_NAME = ‗PK_RECEIVING_CENTER_MATRIX‘. V$SESSION s WHERE v.s.

TABLE_NAME. there is a new function under the alter tablecommand called MOVE TABLE clause. PCT_FREE from dba_indexes where owner = ‗SURVEYOR‘ and index_name = ‗PK_RECEIVING_CENTER_MATRIX‘ change initial extent of table or any storage parameters 1) Pre-Oracle 8i – drop an recreate the table and then reload (probably best done with export/import) 2) 8i and beyond – use the new ―alter table …. INCLUDE_COLUMN. INI_TRANS.‘ feature. MAX_TRANS. INITIAL_EXTENT. PCT_INCREASE. MAX_EXTENTS. INDEX_TYPE.find table and index storage parameters select OWNER. MAX_TRANS.. FREELISTS. PCT_INCREASE. MAX_EXTENTS.TABLESPACE_NAME. and optionally modify any of its storage attributes.. I recommend that you take an export for safety)… . storage. FREELISTS. MIN_EXTENTS. TABLE_NAME. INDEX_NAME. optionally in a different tablespace. FREELIST_GROUPS. PCT_THRESHOLD. INI_TRANS. MIN_EXTENTS. INITIAL_EXTENT. TABLESPACE_NAME. move tablespace …. The move_table_clause lets you relocate data of a nonpartitioned table into a new segment. NEXT_EXTENT. PCT_USED. FREELIST_GROUPS from dba_tables where owner = ‗SURVEYOR‘ and table_name = ‗RECEIVING_CENTER_MATRIX‘ select OWNER. NEXT_EXTENT.PCT_FREE. This can be done without taking down the database (however. TABLE_OWNER. TABLE_TYPE.

The syntax is: alter table <TABLE_NAME> move tablespace <NEW_TBSP> storage( <STORAGE_CLAUSE>).MAX_EXTENTS.a. a.MIN_EXTENTS. You rebuild indexes with the following command.segment_name 9* and a. a.table_name =b.owner=‘SCOTT‘ 7 8 and a. a. get table_size 1 select a. dba_segments b 6 where a. One restriction.owner=b.owner. alter index <INDEX_NAME> rebuild tablespace <NEW_TBSP> storage( <STORAGE_CLAUSE>). b.emp 2 move tablespace DATA 3 storage (initial 200K next 200K minextents 1 maxextents 299) 4 / Note: there is one catch—the table cannot contain a column of the long datatype 3) Random advice: Don‘t go crazy about compressing tables into a single extent (or just a few extents). There was .table_name.owner and a.next_extent.NUM_ROWS.TABLESPACE_NAME. 2 3 4 a. you must rebuild all associated indexes after moving a table because the move invalidates them.table_name =‘EMP‘ alter table scott.initial_extent. a. a.extents NUM_EXTENTS 5 from dba_tables a.

In theory I shouldn‘t have to touch them for a long period of time. plus I place objects of the same extent sizes in the same tablespace: Why? This reduces the fragmentation of the extents and makes maximum efficient use of the tablespace‘s space (even with tables that grow and shrink dynamically) while reducing the possibility of creating dead space fragments.orapub. And while extents do grow. So. you must should know you database & data Thus plan in advance—do calculations of the growth and set storage sizes appropriately – while the new tools allow you to do storage management on the fly. I like to set the initial extent size = next extent size. & others (Mike Ault.com . I have tested this in Oracle 8 and have confirmed this. the number of outstanding extents that a table has DOES NOT IMPACT performance until a high number is reached — they have noticed performance slowdowns after 1000 extents—even with Locally managed Tablespaces. Follow the traditional rules. Dave Ensor…). TUSC.According to presentations at IOUG2000 — from Oracle‘s Performance Group. you do not want to be babysitting extent managment all the time—takes away from the really challenging DBA tasks! There are two good papers to read about extent sizing and fragmentation & Storage Management. 1) ―How to Stop Defragmenting and Start Living: The Definitive Word on Fragmentation‖ from Oracle presented at OracleWorld 1999 2) I cannot remember the name—but the is a great paper on www. such as one of mine is to size growth rates for apx 1 extent per month When allocating storage for an Object (table or index).

dbf‘ with explorer 9. You can also manually recompile packages if you prefer. here is the chance to make your first consistent cold backup 7. 6. alter database datafile ‗D:\oracle\oradata\ABCDev\OEM_Repository.segment_type . 4.sum(bytes) from dba_segments group by owner order by owner.sql script to recompile invalid database objects: . shutdown immediate. Recreate your repository find out export size before exporting.dbf‘ offline drop. Here is an example of calling the utlrp. 3.segment_type. startup mount. non system datafile shutdown the database and Copy all the database files into some safe place !! 2. select owner. select owner.handle database recovery when datafile gets corrupted. 5. Copy all files. in 10g you can use expdp and find out the expected size of the export dump without the above sql queres. Delete ‗D:\oracle\oradata\ABCDev\OEM_Repository. startup 8. select owner.segment_type . This script is maintained in the $ORACLE_HOME/rdbms/admin directory on your database server.sum(bytes)/1024/1024 from dba_segments where owner = ‗SURVEYOR‘ group by owner .segment_type.sum(bytes)/1024/1024 from dba_segments where owner = ‗SURVEYOR‘ group by owner.sum(bytes)/1024/1024 from dba_segments where owner = ‗DSADM‘ group by owner. You can recompile invalid packages with the utlrp.sql SQL script that is supplied with Oracle. alter database open. compiling packages in sys schema This script will give you a list of invalid objects.no backup files available. select owner.

status from v$datafile where status not in (‗ONLINE‘.status from dba_tablespaces. Use the following query to find out the status of the datafiles. ‗SYSTEM‘) .DBF‘ online.sql 31)find deprecated parameters in 10g select name from V$PARAMETER where ISDEPRECATED = ‗TRUE‘. ORA-1113 will be encountered: Make sure that the archived log destination has all required archived files because when you execute recover command it will prompt you for exact archived log files that are required. ORA-00376: file 40 cannot be read at this time .status. To recovery the datafile try using the command: SQL> recover datafile ‗<full_path_of_datafile>‘.name. Else.enabled from v$datafile. If the tablespace datafiles exist and are online and checked three times! check the following: Find the status of the tablespaces: SQL> select tablespace_name. eg: SQL> select name.Oracle will automatically suggest the required file names and you just have to type enter if you agree. alter tablespace offline_ts online. alter database datafile ‗C:\ORACLE\ORADATA\OFFLINE. ORA-00376: file %s cannot be read at this time There was a problem accessing the datafile. SQL> select file#. SQL> alter database datafile <full_path_datafile_name> online. If the status says ‗recover‘ then media recovery must be done by bringing the datafile online.@?/rdbms/admin/utlrp. The datafile or tablespace the datafile belongs to is either offline or the datafile is gone. .

Operation Systems. you must create a new console on a different port for each database. they are replaced with Database Control (Java and HTML versions) and Grid Control respectively. Among the both which will be good in terms of functionality. find out oracle version on the server using unix commands sqlplus –version but this command may not tell you the correct version when there are multiple oracle homes. To monitor more than one database. It can be used to manage one database (one target) at a time (standalone). So export ORACLE_HOME=/opt/oracle/product/10.select * from v$recover_file. 10g Grid Control is the Enterprise version in that you can monitor different Target from different operationg systems at the same time. To administer multiple database 10g grid control is better. These include Application Servers. syntax for doing secure copy to different server scp filename oracleuser@servername:path difference between oracle 10g db control and grid control Database Control is the HTTP Management environment and comes installed with the 10g Database. OEM Database Control comes with Oracle Enterprise Edition and does 10g Grid control is a separate software or added with Oracle Enterprise Edition . So. In 10g. It‘s not free whereas DB Console is.‘ALL‘)).0 . Listeners. for someone who was using OEM 9i. Then you have to set more oracle environment variables. Either set the tablespace or datafile back online or – if the datafile is gone – restore the datafile. You will need a license for GC. That‘s correct. You go to OTN to download it or edelivery. there was connection in to Standalone Console (Java) and Oracle Management Server (Java and HTML). You need an additional license from that of the Database Server for Grid Control How to get a formatted explain plan? select plan_table_output from table(dbms_xplan.null. Non Oracle Database Systems using plugins (from 10gR2).display(‗PLAN_TABLE‘.2.

SERIAL#. @?/rdbms/admin/utlrp.And then Export LD_LIBRARY_PATH=/opt/oracle/product/10. it will work.sql 3. you don‘t need to worry.html#A4828 find out long running job processes and the work progress.2.2) ―%_COMPLETE‖ FROM V$SESSION_LONGOPS WHERE OPNAME NOT LIKE ‗%aggregate%‘ AND TOTALWORK != 0 AND SOFAR <> TOTALWORK  invalid objects 1. .oracle. unless you get anything in the view DBA_ERRORS which will contain the compilation errors. and if it‘s ok. SQL> SELECT distinct object_name FROM dba_objects WHERE status=‘INVALID‘ when an object in oracle get‘s invalid. TOTALWORK. CONTEXT. the application running the sql with the invalid object will then get the relevant error message. this is not a problem usually. SOFAR.0/lib:$LD_LIBRARY_PATH Then sqlplus –version gives the right version all faqs about sqlplus errors can be found here http://www. oracle will try to compile it first. ROUND(SOFAR/TOTALWORK*100. SELECT SID. 4.com/technology/support/tech/sql_plus/htdocs/faq101. all the dependent objects get invalid also. Verify that all expected packages and classes are valid: SQL> SELECT count(*) FROM dba_objects WHERE status=‘INVALID‘. because when you try to use an objects that is marked invalid. if the compilation fails.

..... Oracle 10g Database New Features Oracle 10g Database New Features Simplicity vs Flexibility • • • • – • – – – Automatic statistics gathering Advisories Automatic tuning Less than 30 basic (init.. iSQL*Plus started. Type the address for ISQL*PLUS http://PC-NAME:5560/isqlplus/ Syntax http:// host_name:portnumber/isqlplus Check Computer Name à Right click on my computer Then properties Than click computer name to check Port number: oracle_home=where oracle software installed.ini step 3 after opening the iSQL*Plus page on Expolorer. LOGIN SCREEN ENTER username and password Now isqlplus started.ora) parameters Basic. hidden parameters Easier operations alter tablespace rename flashback queries ―undrop‖ table Manageability .. STEP 2 Open Any compatible Internet Browser.. oracle_home\install\portlist.Cmd on command prompt type: isqlplusctl start after issuing the above command following prompt will displayed Starting iSQL*Plus . start..Configure iSQL*PLUS STEP 1 goto dos prompt..Run... advanced.

Large Pool. Can‘t rename SYSTEM or SYSAUX . bitmap_merge_area_size – Contents automatically managed Basic Parameters COMPATIBLE CONTROL_FILES DB_BLOCK_SIZE DB_CREATE_FILE_DEST DB_CREATE_ONLINE_LOG_DEST DB_DOMAIN DB_NAME DB_RECOVERY_FILE_DEST DB_RECOVERY_FILE_DEST_SIZE INSTANCE_NUMBER JOB_QUEUE_PROCESSES LOG_ARCHIVE_DEST_n LOG_ARCHIVE_DEST_STATE_n NLS_LANGUAGE NLS_TERRITORY OPEN_CURSORS PROCESSES REMOTE_LISTENER REMOTE_LOGIN_PASSWORDFILE ROLLBACK_SEGMENTS SESSIONS SHARED_SERVERS STAR_TRANSFORMATION_ENABLED UNDO_MANAGEMENT UNDO_TABLESPACE Rename Tablespace • • – Useful in Transportable Tablespace scenarios ALTER TABLESPACE prod RENAME to arc1. Java Pool Dynamically and automatically adjustable Automatic changes persist in SPFILE PGA_AGGREGATE_TARGET Available since 9i Sets total size target for all server processes sort_area_size.• – – – – • – – – SGA_TARGET Sets total size for all SGA components Buffer Cache. sort_area_retained_size. Shared Pool. hash_area_size.

resumable operations Client can detach and reconnect Can be parallelized using PARALLEL Even loads to/from external text files Parallelization level can be changed on the fly for long running jobs Monitored through DBA_DATAPUMP_JOBS Fine-Grained Object Selection exclude=function exclude=procedure exclude=package:‖like ‗PAYROLL%‘ ‖ include=table content=metadata_only | data_only | both query=―modify_date > sysdate-1‖ DDL Transformations. DDL extract .. ..– – Tablespace and all datafiles must be online Can also rename READ ONLY tablespaces Bigfile Tablespaces • – – – Support for sizes up to 8 Exabytes! 8 000 000 Terabytes Max 65535 files in database SYSTEM & SYSAUX can’t be bigfile tablespaces Crossplatform Transportable TS RMAN> CONVERT TABLESPACE sales_1.sales_2 2> TO PLATFORM ’Microsoft Windows NT’ 3> FORMAT ’/temp/%U’. Transporting Tablespaces Between Databases input datafile fno=00004 name=/u01/oracle/oradata/salesdb/sales_101. elapsed time: 00:00:45 Data Pump • • • • – • • • • • – – • • – – – – – – • A server-managed data transportation tool Direct load/extract capabilities Very high performance/efficient with large data sets Replacement for exp/imp old exp/imp remain supported Commands expdp/impdp Can use files or direct network transfer Dynamic configuration.dbf converted datafile=/temp/data_D-10_I-3295731590_TS-EXAMPLE_FNO-4_06ek24vl channel ORA_DISK_1: datafile conversion complete.

empname. versions_operation OPERATION. operation."SALARY") values ('111'. table_name from dba_transaction_query where xid = ‘000200030000002D‘. Flashback Row History SELECT versions_xid XID. undo_sql. versions_endscn END_SCN. start_scn. ALTER TABLESPACE test1 FLASHBACK OFF."EMPNAME".--------.'655') 000200030000002D 112670 113565 I delete from "SCOTT".--------. ALTER TABLESPACE test1 FLASHBACK ON. commit_scn.'Mike'.--------.--------."DEPT" .------------------------000200030000002D 112670 113565 D insert into "SCOTT".FlashBack Database • – – – Flash Recovery Area must be configured Flashback logs are stored there Consisting of old database block images Fast ―rollback‖ of database. ALTER DATABASE FLASHBACK OFF.employees_demo VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE where empno = 111."EMP" ("EMPNO".------.-----0004000700000058 113855 I Tom 927 000200030000002D 113564 D Mike 555 000200030000002E 112670 113564 I Mike 555 3 rows selected • Useful for auditing Flashback Transaction History select xid. no redologs required FlashBack Database • • • • • • • Configuration parameters: DB_RECOVERY_FILE_DEST DB_RECOVERY_FILE_DEST_SIZE DB_FLASHBACK_RETENTION_TARGET Commands: ALTER DATABASE FLASHBACK ON.------.---------. salary FROM hr. XID START_SCN COMMIT_SCN OPERATION UNDO_SQL --. versions_startscn START_SCN. XID START_SCN END_SCN OPERATION EMPNAME SALARY --.

• PURGE RECYCLEBIN.) Undo Advisor Performance Troubleshooting • – – • – – – – Automatic Workload Repository Runtime execution statistics are gathered in memory MMON background process flushes stats to disk V$SQL_BIND_CAPTURE Samples bind variables for all sessions Faster than sql_trace (10046 trace on level 4) But doesn‘t capture all variable types And doesn‘t capture occurences of bindings .) Segment Advisor (Fragmentation. etc. Table is renamed internally. Systemwide recyclebin DBA_RECYCLEBIN Or show recyclebin command in sqlplus FLASHBACK TABLE RB$$3560$TABLE$1 TO BEFORE DROP RENAME TO scott.emp...where "DEPTNO" = '20' and "DEPTNAME" = 'Finance' 000200030000002D 112670 113565 D update ―SCOTT‖. it‘s available Optimizer able to use run-time statistics exec dbms_stats. etc. Performance Tuning • – – • – – • – – – – RBO is dead. long live the CBO! Even data dictionary. not dropped Indexes & other structures remain Table is purged when out of free space or quota SELECT * FROM RECYCLEBIN. SYS tables using CBO However. RBO is gone nowhere. Shared Pool.‖EMP‖ set ―SALARY‖ = ‗555‘ where ―EMPNO‖ = ‗111‘ and ‖EMPNAME‖ = ‗Mike‘ and ―SALARY‖ = ‗655‘ 3 rows selected Table Recovery using Flashback • – – – • – – • DROP TABLE X.gather_system_statistics(…) OPTIMIZER_DYNAMIC_SAMPLING (default: 2) Multiple Advisors SQL Access & Tuning Advisor Memory Advisors (SGA. • DROP TABLE X PURGE.

sql scripts are executed also on CONNECT Other • – • • – – – • – dbms_scheduler calendar Expressions: Yearly. UPDATE. VB/C# in Microsoft products). 2010 Database Normalization explained. database must be closed mounted exclusively restricted default user tablespace specifies default tablespace for new users. Hourly. Weekly. Understanding and mastering database normalization techniques is essential in order to achieve a high performance database design for your system. you're well off. Monthly. drop database. The Database Normalization eBook shows you . INSERT or DELETE) is difficult. Secondely alter system flush buffer_cache. similar to default temporary tablespace in 9i * NYOUG General Meeting March 2004 Sunday. chances are high that you will find it hard to achieve the performance needed for a successful application. Furthermore. Minutely. Many "experts" will tell you that if you do database normalization up to (and including) the Third Normal Form. without using a lot of procedural coding (PL/SQL in Oracle.• – _cursor_bind_capture_interval defaults to 900 seconds Good for getting samples of database operations SQLPLUS Changes • – • • – • Improvements SPOOL CREATE | REPLACE | APPEND also works for SAVE command SHOW RECYCLE BIN SQLPROMPT runtime variable substitution SET SQLPROMPT "_USER'@'_CONNECT_IDENTIFIER >" glogin. and sometimes actually impossible. December 5. If your design doesn't conform to (at least) the Third Normal Form (3NF). Daily.sql and login. you will find that writing good DML-statements (SELECT.

1. C:\Documents and Settings\orasoft>d: D:\>set oracle_home=d:\oracle\product\10. 2010 Setting Up iSQL*Plus for SYSDBA Access Microsoft Windows XP [Version 5.that this a far too easy approach.2.2. December 2.props -jar %oracle_home%\oc4j\j2ee\home\jazn.0\db_1\oc4j\j2ee\isqlplus\application-deployments\isqlplu s>exit now type following URL or your browser http://pc-name:port_number/isqlplus/dba to get your host name type following query on SQL Prompt .0\db_1 D:\>set java_home=%oracle_home%\jdk D:\>set oracle_home oracle_home=d:\oracle\product\10.security.jar -user "iSQL *Plus DBA/admin" -password welcome -shell JAZN:> adduser "iSQL*Plus DBA" orasoft orasoft JAZN:> grantrole webDba "iSQL*Plus DBA" orasoft JAZN:> exit JAZN:> D:\oracle\product\10.2.2.2600] (C) Copyright 1985-2001 Microsoft Corp. and it is richly documented with graphical Entity Relationship and Server Diagram examples.security.0\db_1\jdk D:\>cd %oracle_home%\oc4j\j2ee\isqlplus\application-deployments\isqlplus D:\oracle\product\10.0\db_1\oc4j\j2ee\isqlplus\application-deployments\isqlplu s> %java_home%\bin\java -Djava.0\db_1 D:\>set java_home java_home=d:\oracle\product\10. for more Detail Click Here! Thursday.2.properties=%oracle_home%\oc4j\j2ee\home\c onfig\jazn.

Managing Database Structure CHAPTER # 5 Managing Database Storage Structures LOGICAL AND PHYSICAL STRUCTURE OF DATABASE .select host_name from v$instance. to get Port number check in file .

A set of extents that are allocated for a certain logical structure form one segment. The DB_BLOCK_SIZE parameter specifies how large a logical block is. The default size is 8 KB. Logically. HOW DATA IS STORED Page # 5-4 When a table is created. A row is ultimately stored in a database block in the form of row piece. a table contains rows of column values. ANATOMY OF A DATABLOCK (CONTENT OF DB) Page # 5-5 . A tablespace contains a collection of segments. This is happens when an inserted row is too large to fit into a single block or when an update causes an existing row to out groom its current space. Each tablespace has many logical oracle data blocks. a segment is created to hold its data. A specific number of contiguous logical blocks form an extent. An oracle data block is the smallest unit of logical I/O. It is called row piece because under some circumstances the entire row may not be place in one place. A logical block can range from 2KB to 32KB in size.STORAGE STRUCTURES Page # 5-3 A database is divided into logical storage unit called tablespaces.

Oracles Data block contain the following: 123Block Header Row Data Free Space BLOCK HEADER: The block header contains The segment type (such as Table. However deletions and updates may fragment the free space in the block. which are used are used when modification are made to row s in the block. Index Partition. Row data space grows upward from the bottom. Initially the free space in a block is contiguous. Row Directory and Transaction slots of size 23 bytes each. Index. TABLESPACES AND DATA FILES Oracle stores data logically in tablespaces and physically in data files. Data Block Address. This enables the (1) Header and the (2) Row Data space to grow when necessary. Cluster etc). The block header grows downward from the top ROW DATA: This is actual data for the rows in the block. FREE SPACE: Free space is the middle of the block. The examples of events that cause header growth are when the row directory needs more row entries or more transaction slots are required. Table Directory. Table partition.  Page # 5-6 TABLESPACES: . Row data takes up free space as new rows are inserted or column of existing rows are updated with larger values.

Each TABLESPACE in an oracle database consists of one or more files called data files. Non-system Tablespaces SYSTEM TABLESPACES:  Created with the database . DATABASE.Are further divided into logical storage of unit  DATA FILES: . System Tablespaces 2. which are physical structures that conform to the operating system in which oracle is running. but they have important differences. TABLESPACES AND DATAFILES Are closely related. which collectively store all of the database‘s data. Another database can have three tablespaces.Are repository (where information is stored) for schema object data. TYPES OF TABLESPACES There are two types of table spaces 1.Can belongs to only one database at a time .    An ORACLE DATABASE consists of one or more logical storage unit called tablespaces.. each consisting of two data files (for a total of six data files) A single database can potentially have as many as 65534 datafiles.Can belongs to only one tablespace and one database .Consist of one or more data files . A database‘s data is collectively stored in the DATA FILES that constitute each tablespace of the database For example The simplest oracle database would have two table spaces (the required SYSTEM ams SYSAUX tablespaces) each with one data file.

  Locally managed tablespaces Dictionary managed tablespaces LOCALLY MANAGED TABLESPACES: The extents are managed within the tablespace via bitmaps. Separate data by backup requirements Separate dynamic and statistics data Control the amount of space allocated to the user‘s objects.    Required in all database Contains the data dictionary. TEMPORARY. & APPLICATION INDEX segments. Tablespace can be created to use one of the following two different methods of keeping track of free and used space. including stored program units. Contains the SYSTEM undo segment Should not contain user data. When an extent is allocated or freed for reuse. although it is allowed NON-SYSTEM TABLESPACES:      Enable more flexibility in database administration Separate UNDO. APPLICATION DATA. the oracle manages the bitmap values to show the new status of the blocks. Locally managed is the default beginning with ORACLE9i In locally managed tablespace Reduce contention on data dictionary tables . SPACE MANGEMENT IN TABLESPACES Tablespaces allocate space in extents. Each bit in the bitmap corresponds to a block or a group of blocks.

This is the backward capability. We can easily view the logical structure of our database through OEM. Detailed information about each structure can be obtained by clicking the links in the Storage Region of the Administration Page. VIEW STORAGE STRUCTURE IN OEM Page # 5-9 Logical data structures are stored in the physical files of the database. By default a tablespace is locally managed. DICTIONARY MANAGED TABLESPACES: The extents are managed by the data dictionary.No undo generated when space allocation or deallocation occurs No coalescing required The local option of the EXTENT MANAGEMENT clause specifies that a tablespace is to be locally managed. The oracle server update data dictionary whenever extent allocated or unallocated. CREATE TABLESPACE ON OEM SESSION Page # 5-10 Go to ORACLE ENTERPRISE MANAGER.g: ABC  auto fixed  auto fixed  auto fixed . it is recommended that we use locally managed tablespaces. Click on Administration Page Click tablespaces on STORAGE TAB Click on create button Enter the name of the table space Extend management LOCALLY Type PERMANENT Status READ WRITE  e.

0\ORADATA\ORCL\AAAA01.DBF' SIZE 50M.Go Datafile Section Click on add datafile Enter the name of datafile  e.g: 100KB Maximum size check unlimited  means file grow to unlimited size  e.0\ORADATA\ORCL2\ CREATE TABLESPACE ON SQL*PLUS SESSION FOR DATABASE 10g RELEASE 1 & 2 (same path) CREATE TABLESPACE AAAA DATAFILE 'E:\ORACLE\PRODUCT\10. To see the information of the tablespace we create above perform the query SELECT TABLESPACE_NAME.g: abc01.2.1.g: 10 MB by default 100 MB size is given Now table space has been created in the location of E:\ORACLE\PRODUCT\10. Tablespace created.  e.dbf Enter the size of datafile Goto Storage Tab Check on AUTOMATICALLY EXTENT And give the size of increment in KB. .

ALLOCATION_TYPE.-----------LOGGING PERMAN LOCAL SYSTEM AUTO In The Above Tablespace We Give Tablespace Name and Path of Datafile with Size We see by default PAREMTER set with the tablespace LOGGING.----------AAAA ONLINE ------------. EXTENT_MANAGEMENT. EXTENT_MANAGEMENT. ALLOCATION TYPE. CONTENTS. LOGGING. TS_NAME STATUS LOGGING CONTENTS EXTENT_MAN ALLOCATIO SEGMEN ------------.------------------. CONTENETS. SEGMENT SPACE MANAGEMENT Logging Default / No Logging Permanent Default / Temporary / Undo Locally Default / Dictionary System Default / Local Uniform Size Automatic Default / Manual There Are Two Modes of Logging 1) Logging 2) No Logging  Logging .STATUS.----------------.--------------. SEGMENT_SPACE_MANAGEMENT FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='AAAA'.

LOGGING IS THE DEFAULT. This is obsolete now. The default size 100 MB There Are Two Type of Segment Space Management for locally managed tablespace. There Are Three Types of Contents 1) Permanent 2) Temporary 3) Undo  Contents There Two Type of Extent Management  1) Local 2) Dictionary Extent_management DICTIONARY MANAGED: Specifies that the tablespace is managed using dictionary tables. 2) UNIFORM For uniform allocation we must give extent management clause and specify uniform size specifies that the TB is managed with uniform extent size.LOGGING: specifies that. NOLOGGING: means do not write all changes to online redo log files. indexes. by default all tables. MINIMUM EXTENT. 1)Automatic 2) Manual . LOCALLY MANAGED: Specifies that the tablespace is managed via bitmap. and partition within the tablespace have all changes written to online redo log files. NOTE: If you specify LOCAL you cannot specify DEFAULT storage_clause. or TEMPORARY STROAGE FOR LOCALLY MANAGED TABLESPACE Page # 5-12 The extents with in the locally managed tablespace can be allocated in one of these two ways: 1) System or autoallocate or automatic 2) Uniform 1) SYSTEM OR AUTOALLOCATE OR AUTOMATIC  Allocatin_type By default allocation types is system or autoallocate or automatic if we do not specify extent management local clause means the size of extent within the tablespace are system managed.

The size of extents are managed locally can be determined automatically by the system. 2) MANUALL: Specifies that we want to use free list for managing free space within segments. Locally managed tablespace do not record free space in the data dictionary tables. 2.2. NOTE: If we are managing a database that has dictionary managed tablespaces and we want to convert them to locally manged tablespace.DBF' SIZE 50M 3 NOLOGGING 4 OFFLINE 5 EXTENT MANAGEMENT LOCAL UNIFORM SIZE 100K .0\ORADATA\BBBB01.1) AUTOMATIC:  Segment_Space_Management Oracle database uses bitmaps to manage the free space within segments. they reduce contention on these tables.TABLESPACE_MIGRATE_TO_LOCAL Create another tablespace other than default parameters 1 CREATE TABLESPACE BBBB 2 DATAFILE 'E:\ORACLE\PRODUCT\10. 4. use the DBMS_SPACE_ADMIN. ADVANTAGES OF LOCALLY MANAGED TABLESPACES: Locally managed tablespaces have the following advantages over dictionary managed tablespaces. 1. 3. Changes to the extent bitmaps do not generate undo information. Local management avoids recursive space management operations.

4 LOGGING.------------------.----------AAAA BBBB ONLINE LOGGING CONTENTS EXTENT_MAN ALLOCATIO SEGMEN ------------.6 SEGMENT SPACE MANAGEMENT MANUAL. Tablespace created. 3 STATUS.----------------. 'BBBB'). Now perform the above query to see the parameters of the tablespace AAAA and BBBB SQL> SELECT 2 TABLESPACE_NAME.--------------. 5 CONTENTS. 8 SEGMENT_SPACE_MANAGEMENT 9 FROM DBA_TABLESPACES 10 WHERE TABLESPACE_NAME IN ('AAAA' . TS_NAME STATUS ------------.-----------LOGGING PERMAN LOCAL SYSTEM AUTO OFFLINE NOLOGGING PERMANENT LOCAL UNIFORM MANUAL TABLESPACE IN THE PRECONFIGUED DATABASE: There are six tablespace that are automatically created with the database creation. 6 EXTENT_MANAGEMENT. 7 ALLOCATION_TYPE. 12SYSTEM SYSAUX Page # 5-14 .

In the preconfigured database. UNDOTBS1 This is the undo tablespace used by the database server to store undo information. In OEM we can see a pie chart of the contents of this tablespace. EXAMPLE This tablespace contains the sample schemas that can be installed when we create the database. SYSAUX This is an auxiliary tablespace to the system tablespace. the user tablespace is the default tablespace for all objects created by NONSYSTEM users. This means that if no temporary tablespace is specified when the user is created. USERS This tablespace is used to store permanent user objects and data. These all contained in SYS schema and can be access by the SYS and system users or other administrative users.3456- TEMP UNDOTBS1 USERS EXAMPLE SYSTEM The system tablespace is used by the oracle server to manage the database. This tablespace is created at database creation time. Some components and product that are earlier used by SYSTEM tablespace now use the SYSAUX tablespace. The tamp tablespace is defined as the default tablespace for sorting data. the oracle database assigns this tablespace to the user. It contains the data dictionary and tables that contain administrative information about the database. Create TEMPORARY tablespace . TEMP Temporary tablespace is used when we execute a SQL statement that require sorting.

Tablespace created.0\ORADATA\ORCL\UNDOO01. Database altered.DBF' SIZE 100M. We can set default temporary tablespace for all users ALTER DATABASE DEFAULT TEMPORARY TABLESPACE KHAN. ALTER A TABLESPACE We can alter any tablespace in several ways as the need of your system change. FOR DATABASE 9i RELEASE 2 SQL > CREATE TABLESPACE ABCD DATAFILE 'D:\ORACLE\ORADATA\ORCL\ABCD01. Create UNDO tablespace CREATE UNDO TABLESPACE UNDOO1 DATAFILE 'E:\ORACLE\PRODUCT\10.CREATE TEMPORARY TABLESPACE KHAN TEMPFILE 'E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\KHAN01. Tablespace created.DBF' SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 128K.DBF' SIZE 10M. Restore default temporary tablespace ALTER DATABASE DEFAULT TEMPORARY TABLESPACE TEMP. Database altered.2. Page # 5-16 .

B  At the time of tablespace creation.We can resize of any tablespace by adding a new datafile b.2 Automatically using AUTOEXTEND A  At the time of database creation. C  After the tablespace creation.1.1  By manually using alter database command B.RESIZING A TABLESPACE: a- We can resize of any tablespace by adding a new datafile SQL> ALTER TABLESPACE AAAA ADD DATAFILE 'E:\ORACLE\PRODUCT\10. RESIZING A TABLESPACE a. 1.Read only 3. b- By changing the size of datafile We can enlarge a tablespace by .2.By changing the size of datafile B.Read write 2. 2 BY CHANGING THE STATUS OF TABLESPACE A Tablespace can be in one of the three different status or states.0\ORADATA\ORCL\AAAA03. Tablespace altered.DBF' SIZE 5M.Offline 1.

Tablespace altered. CREATE TABLESPACE AAAA . 1. 2.DBF' RESIZE 10M.By manually using ALTER DATABASE 2. At the time of tablespace creation. We can also decrease the size of data file NOTE: If there are database objects stored above the specified size.2. At the time of database creation. After the tablespace creation.0\ORADATA\ORCL\AAAA02.1.At the time of tablespace creation. then the datafile is decrease only to the last block of the last object in the datafile 2Automatically using AUTOEXTEND We can use AUTOEXTEND clause in three ways.Automatically using AUTOEXTEND 1By manually using ALTER DATABASE SQL> ALTER DATABASE DATAFILE 'E:\ORACLE\PRODUCT\10. 1. 3.At the time of database creation. When we create database at that time use AUTOEXTEND ON with the datafile 2.

SQL> DESC DBA_DATA_FILES Name Null? Type ----------------------------------------. 3. Determining wether AUTOEXTEND is ENABLED or DISABLED We use DBA_DATA_FILES view.DBF' SIZE 10M AUTOEXTEND ON.DBF' AUTOEXTEND ON. Database altered.-------.After the tablespace creation.DATAFILE 'E:\ORACLE\PRODUCT\10. ALTER DATABASE DATAFILE 'E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\AAAA01.2. Tablespace created.0\ORADATA\ORCL\AAAA01.---------------------------FILE_NAME FILE_ID TABLESPACE_NAME BYTES BLOCKS STATUS RELATIVE_FNO VARCHAR2(513) NUMBER VARCHAR2(30) NUMBER NUMBER VARCHAR2(9) NUMBER .

2.0\ORADATA\BBBB01.2.DBF E:\ORACLE\PRODUCT\10.------------------------------------------------------USERS SYSAUX UNDOTBS1 SYSTEM EXAMPLE ABC ABCD ABC1 XYZ BBBB UNDOO1 AAAA E:\ORACLE\PRODUCT\10.DBF E:\ORACLE\PRODUCT\10.0\ORADATA\ORCL\ABCD01.DBF E:\ORACLE\PRODUCT\10.2.2.2.DBF E:\ORACLE\PRODUCT\10.0\ORADATA\ORCL\EXAMPLE01.2.AUTOEXTENSIBLE MAXBYTES MAXBLOCKS INCREMENT_BY USER_BYTES USER_BLOCKS ONLINE_STATUS VARCHAR2(3) NUMBER NUMBER NUMBER NUMBER NUMBER VARCHAR2(7) SQL> SELECT TABLESPACE_NAME.0\ORADATA\ORCL\SYSAUX01.0\ORADATA\ORCL\UNDOTBS01.DBF E:\ORACLE\PRODUCT\10.0\ORADATA\ORCL\ABC01.2.DBF E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\SYSTEM01.0\ORADATA\ORCL\AAAA01. AUTOEXTENSIBLE FROM DBA_DATA_FILES. FILE_NAME.2.0\ORADATA\ORCL\XYZ01. TABLESPACE_NAME FILE_NAME AUTOEXTENSIB --------------------YES YES YES YES YES NO NO YES NO NO NO YES -----------------------------.DBF E:\ORACLE\PRODUCT\10.0\ORADATA\ORCL\ABC101.0\ORADATA\ORCL\USERS01.DBF E:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\UNDOO01.DBF E:\ORACLE\PRODUCT\10.DBF E:\ORACLE\PRODUCT\10.2.2.DBF .DBF E:\ORACLE\PRODUCT\10.

We cannot offline temporary tablespace until new default is not available. When the tablespace in read only mode. . 1.Read write 2. Tablespace altered.2. No further write operation can occur in the tablespace except existing transaction can be completed (committed or rollback) Tablespace is online while in read-only state. Object can be dropped from read only status of tablespace. For Example if tablespace type is permanent. SQL> ALTER TABLESPACE AAAA READ ONLY.Offline By default the status of the tablespace is Read Write. For Example if tablespace type is default temporary.Read only 3. READ ONLY MODE: We can set permanent tablespace to read only mode by using alter tablespace command. We cannot alter a temporary tablespace to permanent. We cannot offline SYSTEM and SYSAUX tablespace. Because these command affect only the data dictionary. Any of the following states may not be available because their availability depends on the type of tablespace.BY CHANGING THE STATUS OF TABLESPACE A Tablespace can be in one of the three different status or states.

but we use the temporary clause. performing check pointing on them as it does so.OFFLINE MODE: We can take an online tablespace offline so that this portion of the database is not available for general use. the tablespace require recovery before you can bring it back online. The oracle database take the data files (which are not already offline) offline. a) NORMAL b) TEMPORARY c) IMMEDIATE d) FOR RECOVER a) OFFLINE NORMAL A tablespace can be taken offline normally if no error conditions exist for any of data files of the tablespace. For normal offline there is no need to write NORMAL SQL> ALTER TABLESPACE AAAA OFFLINE. ALTER TABLESPACE AAAA OFFLINE TEMPORARY. media recovery is not required to bring the tablespace back online. Tablespace altered. and we take the tablespace offline temporarily. The oracle database ensures that all data is written to disk by taking a checkpoint for all the data files of the tablespace as it take them offline. b) OFFLINE TEMPORARY A tablespace can be taken offline temporarily if there are errors conditions exist for one or more data files of the tablespace. if one or more files of the tablespace are offline because of write error. When we take tablespace offline. . If no files are offline. Tablespace altered. The rest of the database is open and available for users to access data. we can use the following options. However.

Tablespace dropped. the objects and data in it will no longer be available. SQL> ALTER TABLESPACE AAAA OFFLINE IMMEDIATE. Tablespace altered. Oracle recommends a backup before and after dropping a tablespace. media recovery for the tablespace is required before the tablespace can be brought online.c) OFFLINE IMMEDIATE A tablespace can be taken offline immediately without the oracle database taking a checkpoint on any of the data files. The syntax is supported for backward compatibility. DROP TABLESPACE BBBB. d) OFFLINE FOR RECOVER The for recover setting has been depreciated. INCLUDING CONTENTS: Drops all segments in the tablespace . Use Contents and data file option DROP TABLESPACE BBBB INCLUDING CONTENTS AND DATAFILE. To recover them can be a time consuming process. NOTE: We cannot take a tablespace offline immediate if the database is running in NOARCHIVELOG mode. When we specify immediate. Tablespace dropped. DROPPING TABLESPACE Page # 5-21 Once a tablespace has been dropped.

Page # 5-22 TO VIEWING TABLESPACE INFORMATION ON SQL*PLUS SQL> desc v$tablespace Name Null? Type ----------------------------------------------------------------------------------. name from v$tablespace. When we drop any tablespace the operating system file cannot delete at the same time we can delete the tablespace than we can delete data file manually from the operating system. Some restriction when we drop any tablespace     We cannot drop system and sysaux tablespace We cannot drop temporary tablespace until new default is not available We cannot drop a tablespace that contains any active undo segments.-----------------------------0 SYSTEM 1 UNDOTBS1 2 SYSAUX NUMBER VARCHAR2(30) VARCHAR2(3) VARCHAR2(3) VARCHAR2(3) .-------.AND DATA FILE: Delete the related operating system file CASCADE CONSTRAINTS: Drop referential integrity constraints from table outside the tablespace.-----TS# NAME INCLUDED_IN_DATABASE_BACKUP BIGFILE FLASHBACK_ON SQL> select ts#. TS# NAME ---------.

-------.4 USERS 3 TEMP 6 EXAMPLE 7 ABC 8 SCOTT1 8 rows selected. SQL> desc dba_tablespaces Name Null? Type ----------------------------------------------------------------------------------.-----TABLESPACE_NAME BLOCK_SIZE INITIAL_EXTENT NEXT_EXTENT MIN_EXTENTS MAX_EXTENTS PCT_INCREASE MIN_EXTLEN STATUS CONTENTS LOGGING FORCE_LOGGING EXTENT_MANAGEMENT ALLOCATION_TYPE NOT NULL VARCHAR2(30) NOT NULL NUMBER NUMBER NUMBER NOT NULL NUMBER NUMBER NUMBER NUMBER VARCHAR2(9) VARCHAR2(9) VARCHAR2(9) VARCHAR2(3) VARCHAR2(10) VARCHAR2(9) .

VARCHAR2(3) VARCHAR2(6) VARCHAR2(8) VARCHAR2(11) VARCHAR2(3) TO VIEWING DATAFILE INFORMATION ON SQL*PLUS Page # 5-22 SQL> DESC V$DATAFILE Name Null? Type ----------------------------------------. LOGGING. EXTENT_MANAGEMENT. CONTENTS.---------------------------FILE# CREATION_CHANGE# CREATION_TIME NUMBER NUMBER DATE . ALLOCATION_TYPE. STATUS. SEGMENT_SPACE_MANAGEMENT FROM DBA_TABLESPACES .PLUGGED_IN SEGMENT_SPACE_MANAGEMENT DEF_TAB_COMPRESSION RETENTION BIGFILE Query to view thee information of tablespace perform the query SELECT TABLESPACE_NAME.-------.

Create new database users Alter database users Drop database users Monitoring information about existing users Obtain user information Page # 6-3 DATABASE USER ACCOUNTS: . 3.TS# RFILE# STATUS ENABLED CHECKPOINT_CHANGE# CHECKPOINT_TIME UNRECOVERABLE_CHANGE# UNRECOVERABLE_TIME LAST_CHANGE# LAST_TIME OFFLINE_CHANGE# ONLINE_CHANGE# ONLINE_TIME BYTES BLOCKS CREATE_BYTES NUMBER NUMBER VARCHAR2(7) VARCHAR2(10) NUMBER DATE NUMBER DATE NUMBER DATE NUMBER NUMBER DATE NUMBER NUMBER NUMBER CHAPTER # 6 Administering User Security Managing Users 1. 5. 2. 4.

Each user account has A security domain defines the settings that apply to the users. TABLESPACE QUOTA . a user must specify a valid database user account and successfully authenticate as required by that user account. The database administrator defines the names of the users who are allowed to access the database.To access the database. Security domain include 1) A unique user name 2) Authentication mechanism 3) Tablespace quota 4) Default tablespace 5) Temporary tablespace 6) Account locking 7) Resource limit 8) Direct privilege 9) Role privilege AUTHENTICATION MECHANISM A user can access the database can be authenticated by on of the following A) Data dictionary (PASSWORD) B) Operating system (EXTERNALLY) C) Network (GLOBAL) Means of authentication can be defined at the time of user creation or Can be defined later by ALTER command In this lesson we study Data dictionary & Operating System Authentication.

DEFAULT TABLESPACE Default tablespace are the location where segments that are created by user are stored. This can be done automatically or the DBA can lock / unlock the a/c manually. of session a user open. This can be cover next part of this lesson. procedures and packages) that is associated with the particular user. TEMPORARY TABLESPACE Temporary tablespace are the location where extent are allocated by the oracle server if the user performs the operation like sorting the data. Therefore user and schema are often used interchangeably. ACCOUNT LOCKING User account can be lock to prevent the user when user logging on the database. If user does not explicitly define the tablespace at the time of segments are created. When a database user is created a corresponding schema with the same name is created for that user. RESOURCE LIMIT Limits can be places on the user of resources such as CPU time / Logical I/O / No. clusters. A user can be associated with one schema only. DATABASE SCHEMA A database schema is a named collection of object such as (tables. DIRECT PRIVILEGE Privilege are used to control the action that a user can perform in a database ROLE PRIVILEGE A user can be granted privileges indirectly through the use of roles. When we create any user we must consider the following point that called checklist for creating user. . views.Tablespace quota controls the amount of physical storage that is allowed to the user in the tablespace in the database.

NOTE: When this users creates objects by default objects are kept on example tablespace. 3.Objects are reorganized and places on different tablespaces. 2. If the user wants to kept object on another tablespace than must give tablespace name at the end of object.Table owned by user grow continuously 2. Quota : Maximum space allowed to the user for objects in any tablespace.Assign a default tablespace and temporary tablespace 4.Identify the tablespace where user stores objects. CREATING A USER IN SQL*Plus BY PASSWORD Page # 6-6 Create user abc1 Identified by abc1 Default tablespace example Temporary tablespace temp Quota 15m on example Quota unlimited on users Password expire.1.Grant privileges and assign role to the user.An application is enhanced and requires more table or indexes.Decide tablespace quota for each tablespace 3. . Quota can be define integer byte/ kilo bytes (KB) and megabytes (MB) Unlimited: This keyword use for user can use as much as space available in any tablespace. CHANGING USER QUOTA ON TABLESAPACES We can modify user table quotas in following situations 1.

CREATING A USER IN SQL*Plus BY EXTERNALLY Step#1 SQL> CREATE USER RAHEEL IDENTIFIED EXTERNALLY. RESOURCE TO RAHEEL.Than we use ALTER USER command to solve this problem SQL> ALTER USER ABC1 2 QUOTA 10M ON USERS. Important note: after 0 qouta assign to user then no new extent can be allocated for the objects of user. System altered. Grant succeeded. Step#2 SQL> GRANT CONNECT. . Step#4 SQL> ALTER SYSTEM SET REMOTE_OS_AUTHENT = TRUE SCOPE = SPFILE. User created. User altered. OR Alter user abc1 Quota 0 on users. Step#3 Page # 6-6 SQL> ALTER SYSTEM SET OS_AUTHENT_PREFIX =" " SCOPE = SPFILE. System altered.

ora And change the parameter #SQLNET.2.AUTHENTICATION_SERVICES= (NTS)  hash sign of previous SQLNET.ora file on notepad from the path C:\oracle\product\10. Step#6 Now create a new user Click Start  Setting  Control Panel  User Account  Create a New Account  Enter User name same as we create on SQL*Plus (RAHEEL)  Check on Limited  click NEXT  Select the account we create  Click Create Password  Enter Password  Than click Create Password Step#7 Click Start  Setting  Control Panel  Administrator Tools  Computer Management  Click on Local User & Groups  Double Click on Users  Right Click (The User Which We Create in Operating System ‗RAHEEL‘) Select Properties  Select Member Of Tab  Click on Add  Click on Advance  Than click on Find Now  Select Ora_dba  Than Click Ok 3 Times Step#8 Restart All Oracle services from services.AUTHENTICATION_SERVICES= (NONE)  type new Save and close the file.Step#5 Open sqlnet.msc Step#9 Log of current User Step#10 Log on the user we create RAHEEL Step#11 .0\db_1\NETWORK\ADMIN\sqlnet.

User Altered DROPING A USER A user can be drop by using the following command DROP USER ABC1. UNLOCKING A USER ACCOUNT AND RESETTING THE PASSWORD THROUG OEM AND SQL*PLUS Page # 6-10 ALTER USER SCOTT IDENTIFIED BY TIGER ACCOUNT UNLOCK.--------------username user_id password account_status not null not null not null varchar2(30) number varchar2(30) varchar2(32) .Open SQL*PLUS and enter / on password window Now we connect to the ORCL database. TO GET INFORMATION ABOUT THE USERS OF ORACLE USE THIS QUERY SQL> DESC DBA_USERS name null? Type -----------------------------------------.---------. If we want to remove the user and its associated objects then we use cascade option DROP USER ABC1 CASCADE.

Connect to database .-------.lock_date expiry_date default_tablespace temporary_tablespace created profile initial_rsrc_consumer_group external_name not null not null not null not null date date varchar2(30) varchar2(30) date varchar2(30) varchar2(30) varchar2(4000) IF WE GET THE INFORMATION ABOUT TABLESPACE QUOTA OF USERS THEN DESC DBA_TS_QUOTAS.-----tablespace_name username bytes max_bytes blocks max_blocks not null varchar2(30) not null varchar2(30) number number not null number number Managing Privileges WHAT IS PRIVILEGE ? A privilege is a right to execute a particular type of SQL statement or to access another user's object. name null? Type ----------------------------------------------------------------. The oracle database enables you control what user can or cannot do within the database These include the right to 1.

Many system privileges contain the ANY clause. by the administrator.Granting privileges to all users (public) . procedure.Providing a user the right to perform a type of operation 2. sequences.Execute another user stored procedure There are two types of oracle user privileges 1. 2.OBJECT PRIVILEGES: Each object privilege allows a user to perform particular action on a specific object For example a table.Select rows from another user table 4. user can access only their own objects. A DBA's control of privileges include 1.Object privileges: 1. Without specific permission.Create a table 3. factions or package.Grant privileges directly to the users or to roles 4. System privileges can be granted by the administrator or by someone who explicitly give permission to administrator the privilege. view.SYSTEM PRIVILEGES: Each system privilege allows a user to perform a particular database action or class of database operations. or by someone who has been explicitly given permission to grant privileges on the object. Object privileges can be granted by the owner of an abject.2.System privileges: 2. For example the privilege of create tablespace is the system privilege. There are more then a hundred distinct system privileges.Grant and revoke access to perform system functions 3.

Privileges that enable system-wide operation Example: Create Session. REVOKE COMMAND Delete the privileges. Privileges can be classified as 1. Create Tablespace 2. MOST COMMON SYSTEM PRIVILEGES ARE Index : Create any index Alter any index Drop any index Table : Create table Create any table Alter any table . Revoke and Grand are the DDL commands. Privileges that enable management of objects in a user’s own schema Example: Create Table 3.SYSTEM PRIVILEGES: There are more than 100 system privileges. Privileges that enable management of objects in any schema Example Create Any Table ANY KEYWORD Signifies that user have the privilege in any schema GRANT COMMAND Signifies add a privilege to a user or a group of users.

the Create Table Privilege allows you to create a table but only within your own schema. NOTE: Granting a privilege with ANY clause means that the privilege crosses schema lines. . For example.There is no create index privilege because .User must have quota on tablespace or must have Grant unlimited tablespace. .Privilege such as create table.Unlimited tablespace cannot be granted to role .The drop any table privilege is necessary to truncate a table in another schema. . create procedure.Drop any table Select any table Update any table Delete any table Session : Create session Alter session Restricted session Tablespace: Create tablespace Alter tablespace Drop tablespace Unlimited tablespaces IMPORTANT NOTE: . But Create Any Table Privilege allows you to create table your own schema as well as .Create table include the create index and the analyze commands. create cluster include dropping this objects.

It includes the following system privileges. some system privileges are usually granted only to administrator. Carefully consider security requirements before granting system permissions.other user‘s schemas.Alter tablespace begin/end backup SYSOPER 1. Selecting With Admin Option check box enables you to administrator the privilege and Grants the system privilege to other users.Having SYSOPER privileges with admin option 2. startup.Startup / shutdown 2.Create database 3. but without the ability to look at the user data. Differentiates SYSDBA And SYSOPER Privileges SYSDBA 1. and perform recovery and other administrative tasks in the database.Alter database backup control file to recover database .Alter database open | mount 3. 1) Restricted Session 2) SYSDBA and SYSOPER 3) Drop Any Object 4) Create Any Directory 5) Grant Any Object Privilege 6) Alter Database and Alter System  Restricted Session: This privilege allows you to log in even if the database has been opened in restricted mode. SYSOPER allow a user to perform basic operational tasks.  SYSDBA and SYSOPER: These privileges allow you to shutdown.

the opening system directory where the code resides must be linked to a virtual oracle directory object.  Alter Database and Alter System: These very powerful privileges allow you to modify the database and the oracle instance.  Grant Any Object Privilege: This privilege allows you to grant object permissions on objects that you do not own. HOW TO GRANT SYSTEM PRIVILEGES ON SQL*PLUS . Manage.Recover database until ( MEANS: past recovery ) 6. Drop and Alter Tablespace: These privileges allow for tablespace administration including creating. such as renaming a data file or flushing the buffer cache.Restricted session 5.Alter database Recover (Complete Recover  Drop Any Object The Drop Any privilege allows you to delete objects that other users own.  Create.Restricted session 6. you can potentially call insecure code objects.4.Deletion of Database 4. dropping and changing their attributes.  Create Any Directory: The oracle database allows developers to call external code (for example.Alter database archive log 5. With the create any directory privilege. As a security measure. a C library) from within PL/SQL.

RESTRICTIONS ON SYSTEM PRIVILEGES SQL > Show parameter o7_dictionary_accessibility name -----------------------------------o7_dictionary_accessibility type value ----------. Now default is false means Do not allow access to sys schema. .----boolean false This parameter control restrictions on system privileges If set to true Allow access to objects in sys schema For example: Select Any Table System privileges allow the user to accessing the objects of any schema as well as sys/ dictionary schema.SQL > Grant create session to emi. This was oracle 7 behavior. Note: WITH ADMIN OPTION privilege is usually reserved for security administrator and is rarely granted to other users. For example: Select Any Table System privileges allow the user to accessing the objects of any schema but do not allow to access the object in sys/ dictionary schema. If Grantee Want To Further Grant The System Privilege Then We Use With Admin Option SQL > Grant create session to emi with admin option.

Create Table privilege to OWAIS OWAIS create table in his schema NOW DBA revoke create session. REVOKING SYSTEM PRIVILEGES WITH ADMIN OPTION There are no cascading effects when a system privilege is revoked. regardless of whether it was given with admin option SCENARIO If DBA grant Create Session. create table privilege from UMAR RESULT: UMAR table still exist but no new table can be create OWAIS table still exist and have to create further new table as OWAIS want Therefore no effect on OWAIS because system privileges are independent NOTE : DBA having the ability to revoke system privilege from any user .HOW TO REVOKE SYSTEM PRIVILEGES ON SQL*PLUS Use REOVKE command to remove a system privilege from a user Only privileges granted with a GRAND command can be revoked Revoke create table from emi. IMPORTANT NOTE: The revoke command can only revoke privileges that have been granted directly with a grant option. Create Table Privilege With Admin Option to UMAR UMAR create table in his schema And UMAR give Create Session.

User created. STEP # 1 Connect to sys and Create 2 users with default tablespace and quota SQL> CONN SYS/ORACLE AS SYSDBAS Connected SQL> CREATE USER SSS IDENTIFIED BY RRR DEFAULT TABLESPACE ABC QUOTA 5M ON ABC. User created. STEP # 2 Now DBA grant system privileges to user 1 (RRR) SQL> GRANT CONNECT TO RRR WITH ADMIN OPTION. SQL> CREATE USER SSS IDENTIFIED BY SSS DEFAULT TABLESPACE ABC QUOTA 5M ON ABC. .If DBA grant create session with admin option to UMAR And UMAR give create session to OWAIS However DBA having the ability to revoke directly OWAIS privilege.

. STEP # 4 User 1 (RRR) grant system privileges to user 2 (SSS) SQL> GRANT CONNECT TO SSS WITH ADMIN OPTION . Table created. SQL> INSERT INTO AAA 2 VALUES 3 ('RAHEEL'). Grant succeeded.Grant succeeded. SQL> GRANT CREATE TABLE TO RRR WITH ADMIN OPTION. Grant succeeded. 1 row created. SQL> CREATE TABLE AAA ( 2 NAME VARCHAR2(20)). SQL> GRANT CREATE TABLE TO SSS WITH ADMIN OPTION. STEP # 3 Now connect to user 1 (RRR) and create objects and insert the values SQL> CONN RRR/RRR Connected.

Connected. STEP # 5 Connect to user 2 (SSS) create objects and insert values SQL> CONN SSS/SSS Connected. STEP # 6 Connect to sys and REVOKE system privileges from user 1 (RRR) SQL> CONN SYS/ORACLE AS SYSDBA. Table created. SQL> INSERT INTO BBB VALUES ('SOVSTM'). Revoke succeeded. 1 row created. SQL> REVOKE CREATE TABLE FROM RRR.Grant succeeded. . SQL> CREATE TABLE BBB ( NAME VARCHAR2(20)).

SQL> CONN SSS/SSS Connected. Because SYSTEM PRIVILEGES are independent. . SQL> CREATE TABLE EMP ( EMPNO NUMBER(4)). SQL> CREATE TABLE EMP ( 2 EMONO NUMBER(4)). CREATE TABLE EMP ( * ERROR at line 1: ORA-01031: insufficient privileges STEP # 8 Connect user 2 (SSS) and create abject now user one successfully create object.STEP # 7 Connect user 1 (RRR) and create abject now user one receive an error of insufficient privileges SQL> CONN RRR/RRR Connected. Table created.

SQL> INSERT INTO EMPNO VALUES (1111). HOW TO GRANT OBJECT PRIVILEGES ON SQL*PLUS SQL > GRANT UPDATE ON SCOTT. sequences. Each object has a particular set of grantable privileges. procedure. 1 row created. USE WITH ADMIN OPTION Means user has able to transfer this grant to other GRANT UPDATE ON SCOTT.EMP TO AAA WITH GRANT OPTION. view.EMP TO AAA. OBJECT PRIVILEGES: Object Privileges ALTER DELETE EXECUTE INDEX INSERT REFERENCES SELECT UPDATE Table Y Y Y Y Y Y Y View Y Y Y Y Y Y Y Sequence Y Y Procedure An object privilege is a privilege or right to perform a particular action of user on a specific table. . This slide does not provide complete object privileges but commonly used objects. or package. function.

User revoking the privileges must be the original granter of the object privilege being revoked REVOKE SELECT ON SCOTT. Connected SQL> Create User UMAR Identified By UMAR.EMP FROM AAA. SQL> CONN TO SYS/ORACLE AS SYSDBA. .REVOKING OBJECT PRIVILEGES Use the revoke command to revoke object privileges. SCENARIO If user AAA grant SELECT object privilege on EMP WITH GRANT OPTION to BBB And BBB grant the SELECT privilege on EMP to CCC Later user AAA revoke SELECT privilege from BBB Result: This revoke also apply on CCC means (CCC do not has the right of select EMP) Therefore effect on CCC because object privileges are dependent STEP # 1 Connect to sys and Create two users and grants connect resource to both users. User created.

CHAPTER # 4

Managing The Oracle Instance

MANAGEMENT FRAME WORK

There are three components of the oracle database 10g management framework:

  

A Database instance that is being managed A Listener that allows connections to the database The Management Interface. This may be either a Management Agent running on the database server (which connects it to oracle enterprise manager grid control) OR The stand-alone Oracle Enterprise Manager Database Control also called DATABSE CONSOLE

NOTE : Each of these components must be explicitly started before we can use the service of the component and must be shutdown cleanly when shutting down the Oracle Database.

STARTING AND STOPPING DATABASE CONTROL

Page # 4-4

When we install Oracle database, Oracle universal installer also installs Oracle enterprise Manager (OEM). Its web-based Database Control serves as the primary tool for managing our oracle database

STEP # 1 Open dos prompt Set oracle_sid=orcl2  database name may change C:>Emctl start dbconsole C:>Lsnrctl

STEP # 2

Open Internet Explorer On Address bar type  http://computer name:port number/em

Check Computer Name  right click on my computer Then properties Than click computer name For Port number  when we start emctl dbconsole we see port number of our database. Normally 1158 is the port number

STEP # 3 LOGIN SCREEN ENTER username and password

STEP # 4 Enterprise manager 10g windows open Click on administration Then work start We can do all things that we can perform on sql plus.

ISQL PLUS PRACTICAL

Page # 4-9

STEP # 1 Start dos prompt Write  isqlplusctl start STEP # 2

Open Internet Explorer Type the address for ISQL*PLUS http://PC-01:5560/isqlplus/ Syntax http:// host_name:portnumber/isqlplus Check Computer Name  Right click on my computer Then properties Than click computer name For Port number Or manually E:\oracle\product\10.1.0\Db_1\install\portlist STEP # 3 LOGIN SCREEN ENTER username and password Now isqlplus started. We can do all things that we can perform on sqlplus.  for isqlplus usually 5560.

LOGIN ISQLPLUS AS SYSDBA PRACTICAL

Page # 4-10

STEP # 1 Open CMD SET JAVA_HOME=D:\ORACLE\PRODUCT\10.2.0\DB_1\JDK SET ORACLE_HOME=D:\ORACLE\PRODUCT\10.2.0\DB_1 SET ORACLE_SID=ORCL

CD D:\ORACLE\PRODUCT\10.2.0\DB_1\OC4J\J2EE\ISQLPLUS\APPLICATIONDEPLOYMENTS\ISQLPLUS

Type D:  enter drive name where oracle install

s> d:\oracle\product\10.2.0\db_3\jdk\bin\java Djava.security.properties=%ORACLE_HOME%\oc4j\j2ee\home\config\jazn.security.props -jar %oracle_home%\oc4j\j2ee\home\jazn.jar -user "iSQL*Plus DBA/admin" -password welcome shell Now you enter JAZN:>  Prompt write the following steps on JAZN JAZ:> adduser "iSQL*Plus DBA" xyz xyz JAZN:>listusers JAZN:>grantrole WebDba "iSQL*Plus DBA" xyz JAZN:> exit

STEP # 2 Open Internet Explorer Type the path http:\\localhost:5560/isqlplus/dba security window open type username and password xyz/xyz now isqlplus started enter username sys password oracle as SYSDBA Now start work

Select * from emp. Write following sql statement on notepad file Select * from emp . Update emp . Select * from cat. Select sum(sal). Select * from emp Where sal > (select sal from emp where ename=‘SMITH‘). min(sal). max(sal) from emp. Select * from emp where job=‘SALESMAN‘. dept.USING THE SQL PLUS Page # 4-12 For BLACK screen RUN  sqlplus Than enter username and password For WHITE screen Program  oracle 10g home 1  application development  sqlplus CALLING SCRIPT ON SQLPLUS Page # 4-14 STEP # 1 Create a script file on note pad.

Set job=‘SALESMAN‘; Select * from emp; Rollback; Select * from emp; Where ename like ‗&\_%‘ escape ‗\‘; Select * from emp Where job in ( select job from emp where empno=7788); Insert into emp Values (9999,‘RAHEEL‘,‘SALESMAN‘,‘‘,‘‘,‘‘,‘‘,‘‘);

Now save the notepad file with sql extension  script file.sql

STEP # 2 On sqlplus or isqlplus

@path of the file  destination of the file you create above like @ E:\PRACTICE\Raheel\Raheel\final\10G\script.sql

INITIALIZATION PARAMETER FILE

Page # 4-15

In order to start an instance and open the database, we must connect sysdba and enter the startup command. The oracle server will then read the initialization parameter file and prepare the instance according to the initialization parameters contained within. For this we must have sysdba privileges There are two types of parameter files.

Static parameter file, PFILE, commonly referred as initsid.ora Dynamic persistent server parameter file SPFILE, commonly referred as spfilesid.ora.

CONTENTS OF PARAMETER FILE       A list of instance parameters The name of the database the instance is associated with Allocation for memory structures of the SGA What to do with filled online redo log files. ---------------------------The names and locations of control files. Information about undo tablespace.

Text initialization parameter file: PFILE  init<sid>.ora - Text File - Modified with an operating system editor - Mod made manually

(sid) means database name

- Whenever we need to change the value of the parameter file we must shutdown the database. - The pfile is read only during instance startup. (Changes take effect on next startup)

For oracle 9i

 default location C:\oracle\admin\orcl\pfile\initsid.ora

For oracle 10g (R2)  default location E:\oracle\product\10.2.0\Db_1\database\initorcl.ora Server parameter file: SPFILE :  spfile<sid>.ora  (sid) means database name - Binary File - Maintained by the oracle server

- Always resides on the server side having read and write by database server - Ability to make changes persistent across SHUTDOWN and STARTUP - Can self-tune parameter values - Can have RMAN support for backup the initialization parameter

For oracle 9i  default location C:\oracle\ora92\database\spfileorcl.ora For oracle 10g (R2)  default location E:\oracle\product\10.2.0\Db_1\dbs\spfileorcl.ora PRACITCAL -----------------------------------------------------------------------------------------------------------To see which parameter file is running with the current instance. SQL> show parameter spfile; NAME TYPE VALUE or show parameter pfile;

------------ ----------- -----------------------------spfile string C:\ORACLE\PRODUCT\10.2.0\DB_1\DBS\SPFILEORCL.ORA

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

VIEWING AND MODIFYING INITILIZATION PARAMETERS

Page # 4-18

We can use enterprise manager to view and modify initialization parameters by clicking On Administration Tab  database configuration  All Initialization Parameters OR ALTER SYSTEM command is used to change the value of instance parameter. DESC V$SPPARAMETER SELECT * FROM V$SPPARAMETER

Startup command behavior
ORDER OF PRECEDENCE : When the command startup is used, the spfileSID.ora on the server side is used to start up the instance. If the spfileSID.ora is not found the default Spfile.ora on the server side is used to start up the instance. If the default spfile.ora is not found, the initSID.ora on the server side will be used to start up the instance. A specified PFILE can override the use of the default SPFILE to start the instance. CREATE SPFILE FROM PFILE FOR ORACLE 9i Create SPFILE = 'd:\oracle\ora92\database\spfileorcl.ora' from pfile = 'd:\oracle\admn\orcl\pfile\initorcl.ora'; This work also be done without defining address and shutdown stage Create spfile from pfile ; FOR ORACLE 10g CREATE SPFILE = 'C:\oracle\product\10.2.0\Db_1\dbs\SPFILEORCL1.ORA' FROM PFILE = 'C:\oracle\product\10.2.0\Db_1\database\INITorcl.ORA' File created. This work also be done without defining address and shutdown stage Create spfile from pfile ;

STARTING UP THE DATABASE :
There are 4 stages to startup and shutdown the database When startup database

Page # 4-21

ora .Shutdown  Nomount  mount  open AT NOMOUNT STAGE: An instance is typically started only in NOMOUNT mode During Database creation.To perform special maintenance operations . During Re-creation of control files.Reading the control file to obtain the name.ora specifying the PFILE parameter with STARTUP overrides the default behavior.Reading initialization parameter file .if not found then. Or During certain backup and recovery scenarios.Locating and opening the control file specified in the parameter file. . status and destination of DATA FILES AND ONLINE REDO LOG FILES .log files and trace files AT MOUNT STAGE: Mounting a database includes the following tasks: .Allocating SGA . spfile.Associating a database with instance start at nomount stage. At this stage following tasks are performed .First spfileSID.opening the alertSID.ora .Starting the background Process .If not found then. . . initsid.

Renaming data files (data files for an offline tablespace can be renamed when the database is open) .Performing full Database Recovery AT OPEN STAGE: Opening a database includes the following tasks: . then the oracle server returns an error. STARTUP COMMAND  use to start database STARTUP NOMOUNT. Alter database open. . to move the database form NOMOUNT TO MOUNT or from NOMOUNT TO OPEN use ALTER DATABASE COMMAND Alter database mount. Total System Global Area 171966464 bytes Fixed Size Variable Size 787988 bytes 145750508 bytes . SQL> startup nomount ORACLE instance started.Open online data files .Enabling and disabling online redo log file archiving options.Open online redo log files NOTE : If any of the data files or online redo log files are not present when you attempt to open the database..

This can be done in two ways 1.Before startup the database SQL> STARTUP RESTRICT ORACLE instance started. Database altered. 1250452 bytes 281021292 bytes 327155712 bytes 2940928 bytes .Database Buffers Redo Buffers SQL> SQL> 25165824 bytes 262144 bytes SQL> alter database mount. OPENING A DATABASE IN RESTRICTRED MODE : Page # 4-23 Last A restricted session is useful when you perform structure maintenance or a database import and export. Total System Global Area 612368384 bytes Fixed Size Variable Size Database Buffers Redo Buffers Database mounted. Database opened. Database altered. SQL> alter database open. Then database can be started in restricted mode so that it is available only to users having restricted session / administrative privileges.

.After database open use alter system command SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION. This can be done by the following SQL> ALTER SYSTEM KILL SESSION 'integer1. you may want to kill all current users before performing administrative tasks.integer2' where integer1: value of the SID column in the V$SESSION view integer2: value of the SERIAL# column in the V$SESSION view Effects of terminating session : Alter system kill session command causes the background process PMON to perform the following steps 1. OR After database open SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION .Free all resources currently reserved by the user SQL> STARTUP RESTRICT. SYSTEM ALTERED. SYSTEM ALTERED After placing an instance in restricted mode.Release all currently held table or row lock 3.or 2.Rollback the user current transactions 2.

SQL> CONN ABC/ABC.TERMINATE SESSION STEP # 1 SQL> CREATE USER ABC IDENTIFIED BY ABC . RESOURCE TO XYZ IDENTIFIED BY XYZ. Grant succeeded. SQL> CREATE USER XYZ IDENTIFIED BY XYZ. SQL> CONN SYS/ORACLE AS SYSDBA. RESOURCE TO ABC IDENTIFIED BY ABC. SQL> GRANT CONNECT. SQL> GRANT CONNECT . Grant succeeded. Connected. logon denied Warning: You are no longer connected to ORACLE. When we connect database an error occurred because this user has no right to connect with database. User created. User created. STEP # 2 Open another SQL session abc/abc xyz/xyz  session 2  session 3 scott/tiger  session 4 . ERROR: ORA-01045: user ABC lacks CREATE SESSION privilege.

STEP # 3 Query on scott/tiger session  4 SQL> SELECT * FROM EMP . 14 rows selected. serial# from v$session view SQL> select USERNAME. Step # 6 Now Come to SYS session session  1 Find username .EMP. STEP # 4 Now scott grant select right to abc and xyz SQL> GRANT SELECT ON SCOTT. SID. Query on xyz session  3 SELECT * FROM SCOTT. SQL> UPDATE EMP SET SAL=1000.EMP.EMP TO XYZ. Grant succeeded. STEP # 5 Query on abc/abc session  2 SELECT * FROM SCOTT. SID. SERIAL# from V$SESSION . Grant succeeded. SQL> SELECT * FROM EMP.EMP TO ABC. SQL> GRANT SELECT ON SCOTT. 14 rows updated. 14 rows selected.

OPENING A DATABASE IN READ ONLY MODE To prevent data from being modified by user transactions database can be open at read only mode. SELECT * FROM EMP * ERROR at line 1: ORA-00028: your session has been killed --------------------------------------------------------------ERROR: ORA-01012: not logged on This means the session of this user has been killed he is not able to work with the database. Where Integer 1 = SID Integer 2 = serial # SQL> AFTER SYSTEM KILL THE SESSION ‘123. SYSTEM ALTERED STEP # 7 Query on abc  SESSION Select * from scott. SQL> ALTER DATABASE OPEN READ ONLY.emp.23’. .Then Alter system kill session ‗integer1. An error occurred -------------------------------------------------------------SQL> SELECT * FROM EMP. integer2‘.

SHUTDOWN TRANSACTIONAL : .database and redo buffer written to the disk .take datafiles offline and online.When all transaction finished shutdown occur immediately .Background process terminated and SGA remove from memory .Oracle closes and dismount database before shutdown .Oracle server waits all users to disconnect .No new connection can be made .In this mode of database no DDL.Execute disk sort using locally manage tablespaces .Next startup does not require recovery 2.SHUTDOWN NORMAL : .No new connection can be made .Next startup does not require recovery Page # 4-24 3. DML operation perform READ ONLY session can be used : .SHUTDOWM IMMEDIATE : .Execute query .Current SQL statement being processed is not completed .User automatically disconnect after completing the transaction in progress . SHUTDOWN THE DATABASE : There are 4 ways to shutdown database 1. but not tablespaces .perform recovery of offline datafiles and tablespaces.

the log sequence number LGWR is writing to .Oracle closes and dismount database before shutdown. such as the SQL statements CREATE.Oracle does not wait for user currently connected to the database . . MONITORING AN INSTANCE USING ALERT LOG FILES : Each oracle instance has an alert<sid>.Oracle server does not wait for the user who are currently connected to the database . The alert file keeps a record of the following information . and RECOVER .Next startup does not require recovery 4.when the database was STARTED and SHUTDOWN .the startup backgroud process . DROP .a list of non default initialization parameters . log file.the thread used by the instance .The database is not close or dismounts .information regarding to log switch .Administrative operations. The file must manage by DBA It continuous grow while the database continuous to work Alert log file should be the first place you look when diagnostic day-to-day operations or errors. ALTER. The file is on the server with the database and is stored in the directory specified with the background_dump_dest initialization parameter..Database and redo buffers are not written to the disks .Next startup requires instance recovery.The instance terminated without closing the files .SHUTDOWN ABORT : .When the database ARCHIVELOG.

DYNAMIC PERFORMANCE VIEWS: Page # 4-32 The oracle database also maintains a more dynamic set of data about the operation and performance of database instance. but no database is mounted we can query V$BGPROCESS to see the list of background process that are running . DESTINATION: for ORACLE 10g E:\oracle\product\10. These views are often referred as ―V DOLLOR‖ V$ views. These views are based on virtual tables that are built from memory structure inside the database server. And re-create every time instance started. SQL>SELECT * FROM V$FIXED_TABLE .log location is defined by the BACKGROUND_DUMP_DEST initialization parameter. For example: If an instance has been started. These views are owned by the sys user.Block corruption errors (ORA-1578). However DBA grant privileges on them. That is they are not true tables. and TABLESPACE creation of tablespace and undo segments . Some dynamic performance views contain that is not applicable to all states of an instance or database.1. Read consistency is not granted on these views because the data is dynamic.information regarding error messages such as ORA-600 and extent errors.DATABASE. These views provide access to information about changing states and condition in the database. This data stored in dynamic performance views. . We can query V$ FIXED_TABLE to see all view names.0\admin\ORCL\bdump NOTE : This file can grow to an unmanageable size. That is why some of them can show you data before a database is mounted or open. and deadlock errors (ORA-60) The alertSID. Any other user cannot access these views. If alert log file delete during database open it must be re-created automatically.

But we cannot query V$DATAFILE to see the status of data files. Dynamic Performance Views include information about:          Session File States Progress of Jobs and Tasks Locks Backup States Memory Usage and Allocation System and Session Parameter SQL execution Statistics and Metrics LIST OF COMMON DYNAMIC VIEWS V$CONTROLFILE List the name of control files V$DATAFILE Contain datafile information from the control file V$DATABASE Contains database information from the control file V$INSTANCE Display the state of current instance V$PARAMETER List parameter and values currently in effect fro the session V$SESSION List session information for each current session . Because database is not mounted.SQL>SELECT * FROM V$BGPROCESS.

SQL> --. . Commit complete. You can perform queries on the database as of a certain wall clock time or user-specified system commit number (SCN) Example --SQL> --.At 11 : 34 SQL> DELETE FROM EMP WHERE JOB='SALESMAN'.At 12 : 19 Delete Case .V$SGA Contain summary information on the system global area (SGA) V$SPPARAMETER List the contents of SPFILE V$TABLESPACE Display the tablespace information from the control file V$THREAD Contain thread information from the control file V$VERSION Version numbers of core library components in the oracle server. 4 rows deleted. . use the SELECT . Flashback query Query all data as it existed at a specific point in time. Next. AS OF query to retrieve Flashback data from the past. Flashback query lets you view and repair historical data. SQL> COMMIT.

as shown here: SQL>INSERT INTO EMP SELECT * FROM EMP AS OF TIMESTAMP SYSDATE-1/24 WHERE JOB='SALESMAN' 4 rows created. Or SQL> SELECT * FROM emp AS OF TIMESTAMP TO_TIMESTAMP ( '2010-03-05 11:33:30' . Commit complete. 7900 JAMES CLERK 7698 03-DEC-81 3000 30 SQL> --. SQL> COMMIT. Commit complete. SQL> SELECT * FROM EMP UPDATE CASE SQL> --. 7900 JAMES CLERK 7698 03-DEC-81 950 30 SQL> UPDATE EMP SET SAL=3000 WHERE EMPNO=7900.AT 12 : 40 SQL> SELECT * FROM EMP AS OF TIMESTAMP . Once we confirm the validity of the accidentally deleted data. SQL> SELECT * FROM EMP WHERE EMPNO=7900. 'YYYY-MM-DD HH24:MI:SS'). it’s easy to reinsert the data by using the previous query as part of an INSERT statement.AT 12 : 22 SQL> SELECT * EMP WHERE EMPNO=7900. 1 rows updated. SQL> COMMIT .SQL> SELECT * FROM EMP AS OF TIMESTAMP SYSDATE-1/24.

AT 12 : 22 SQL> SELECT * EMP WHERE JOB=’SALESMAN’. 7499 ALLEN 7521 WARD 7654 MARTIN 7844 TURNER SALESMAN SALESMAN SALESMAN SALESMAN 7698 20-FEB-81 7698 22-FEB-81 7698 28-SEP-81 7698 08-SEP-81 10000 10000 10000 10000 300 500 1400 0 30 30 30 30 . 1 row updated. 7900 JAMES CLERK 7698 03-DEC-81 950 30 UPDATE CASE 2 SQL> --. SQL> COMMIT.TO_TIMESTAMP ('2010-03-08 12:20:00' . SQL> SELECT * FROM EMP WHERE EMPNO=7900. 4 rows updated. Commit complete. SQL> SELECT * FROM EMP WHERE JOB=’SALESMAN’. 'YYYY-MM-DD HH24:MI:SS') WHERE EMPNO=7900) WHERE EMPNO=7900. 'YYYY-MM-DD HH24:MI:SS') WHERE EMPNO=7900 7900 JAMES CLERK 7698 03-DEC-81 950 30 SQL> UPDATE EMP SET SAL=(SELECT SAL FROM EMP AS OF TIMESTAMP TO_TIMESTAMP ('2010-03-08 12:20:00' . 7499 ALLEN 7521 WARD 7654 MARTIN 7844 TURNER SALESMAN SALESMAN SALESMAN SALESMAN 7698 20-FEB-81 7698 22-FEB-81 7698 28-SEP-81 7698 08-SEP-81 1600 1250 1250 1500 300 500 1400 0 30 30 30 30 SQL> UPDATE EMP SET SAL=10000 WHERE JOB=’SALESMAN’.

EMPNO=EMPNO AND JOB='SALESMAN') WHERE JOB='SALESMAN'. 'YYYY-MM-DD HH24:MI:SS') WHERE JOB=’SALESMAN’ 7499 ALLEN 7521 WARD 7654 MARTIN 7844 TURNER SALESMAN SALESMAN SALESMAN SALESMAN 7698 20-FEB-81 7698 22-FEB-81 7698 28-SEP-81 7698 08-SEP-81 1600 1250 1250 1500 300 500 1400 0 30 30 30 30 SQL> UPDATE EMP E SET SAL=( SELECT SAL FROM EMP AS OF TIMESTAMP TO_TIMESTAMP('2010-03-08 15:25:04'. how to execute it.SQL> --. Parsing means what Oracle understands about the statement and based on that. 7499 ALLEN 7521 WARD 7654 MARTIN 7844 TURNER SALESMAN SALESMAN SALESMAN SALESMAN 7698 20-FEB-81 7698 22-FEB-81 7698 28-SEP-81 7698 08-SEP-81 1600 1250 1250 1500 300 500 1400 0 30 30 30 30 The previous examples use a time stamp to pinpoint the exact time the data was accidentally dropped. DDL/DML. use the time-stamp method to specify the time. Query Parsing What is Query Parsing ? In oracle.AT 12 : 40 SQL> SELECT * FROM EMP AS OF TIMESTAMP TO_TIMESTAMP ('2010-03-08 12:20:00' . SQL> SELECT * FROM EMP WHERE JOB=’SALESMAN’. optimize its execution. statement. . gets parsed. 4 row updated. If you need to be very specific regarding the time point. We could use the SCN for the transaction instead of time stamps. This process is also known as Optimization of the query.'RRRR-MM-DD HH24:MI:SS') WHERE E. or anything else. The idea is how best Oracle can process the query or in other words.

Parsing is of two types, Hard parse and Soft parse. If the said query is found in Oracle's cache, the query optimization is not needed.Oracle can pick up the optimized query and can execute it. If the query is run for the first time or the query's cached version is obsolete or flushed out from oracle's cache, query needs to be optimized and the process is c called Hard parse of the query. Hard parse , in general , is unavoidable as for the very first time, each query needs to be parsed , atleast for once. But in the subsequent executions, query should be simply soft parsed and executed. The mechanism which works in the backend for doing all this is called Optimizer. There are two versions of it, Rule Based and Cost Based. The Rule Based optimizer(RBO) is made deprecated from Oracle version release 10g. This was not very much efficient as it was "statement driven". The Cost Based is now the only and supported mode of optimizer which is, as the name suggests, cost based and takes into the account the resource consumption of the query.

Queries
============================================ Display time waited for each wait class. ============================================

SELECT a.wait_class, sum(b.time_waited)/1000000 time_waited FROM v$event_name a JOIN v$system_event b ON a.name = b.event GROUP BY a.wait_class;

=============================================== Display session wait information by wait class. ===============================================

SELECT * FROM v$session_wait_class WHERE sid = &enter_sid;

=============================================== Statistics (delete lock unlock) ===============================================

BEGIN DBMS_STATS.delete_table_stats('MY_SCHEMA','LOAD_TABLE'); DBMS_STATS.lock_table_stats('MY_SCHEMA','LOAD_TABLE'); DBMS_STATS.unlock_table_stats('MY_SCHEMA','LOAD_TABLE');

END;

============================================= Retrieve SAMPLE Date (%) ============================================ SELECT e.empno, e.ename, d.dname FROM emp SAMPLE (10) e JOIN dept d ON e.deptno = d.deptno;

=============================================== past 30 minutes waits =============================================== select ash.event, sum(ash.wait_time +ash.time_waited) ttl_wait_time from v$active_session_history ash where ash.sample_time between sysdate - 30/1440 and sysdate group by ash.event order by 2 /

================================================= What user is waiting the most(last_hour) ? =================================================

select sesion.sid, sesion.username, sum(active_session_history.wait_time + active_session_history.time_waited) ttl_wait_time from v$active_session_history active_session_history, v$session sesion where active_session_history.sample_time between sysdate - 1/24 and sysdate and active_session_history.session_id = sesion.sid group by sesion.sid, sesion.username order by 3

============================================== What SQL is currently using the most resources? (lasthour) ============================================== select active_session_history.user_id, dba_users.username, sqlarea.sql_text, sum(active_session_history.wait_time + active_session_history.time_waited) ttl_wait_time from v$active_session_history active_session_history, v$sqlarea sqlarea, dba_users where active_session_history.sample_time between sysdate - 1/24 and sysdate and active_session_history.sql_id = sqlarea.sql_id and active_session_history.user_id = dba_users.user_id group by active_session_history.user_id,sqlarea.sql_text, dba_users.username order by 4 /

============================================== What object is currently causing the highest resource waits? (lasthour) ==============================================

select dba_objects.object_name, dba_objects.object_type, active_session_history.event, sum(active_session_history.wait_time + active_session_history.time_waited) ttl_wait_time from v$active_session_history active_session_history, dba_objects where active_session_history.sample_time between sysdate - 1/24 and sysdate and active_session_history.current_obj# = dba_objects.object_id group by dba_objects.object_name, dba_objects.object_type, active_session_history.event order by 4

=========================================== script to gather database statistics

========================================== begin DBMS_STATS.GATHER_DATABASE_STATS ( estimate_percent =>100, block_sample=>FALSE, method_opt=>'for all columns size auto', degree=>null, cascade=>true, no_invalidate=>false, options=>'GATHER STALE', gather_sys=>FALSE); DBMS_STATS.GATHER_DATABASE_STATS ( estimate_percent =>100, block_sample=>FALSE, method_opt=>'for all columns size auto', degree=>null, cascade=>true, no_invalidate=>false, options=>'GATHER EMPTY', gather_sys=>FALSE); end;

========================================= script to gather dictionary statistics ========================================

begin DBMS_STATS.GATHER_DICTIONARY_STATS ( estimate_percent =>100, block_sample=>FALSE, method_opt=>'for all columns size auto', degree=>null, cascade=>true, no_invalidate=>false, options=>'GATHER STALE' ); DBMS_STATS.GATHER_DICTIONARY_STATS ( estimate_percent =>100, block_sample=>FALSE, method_opt=>'for all columns size auto',

degree=>null, cascade=>true, no_invalidate=>false, options=>'GATHER EMPTY' ); end;

======================================== schedule a job (statistics) =======================================

begin sys.dbms_scheduler.create_job(job_name => '"SYS"."ESTIMATE100_GATHERAUTO"', job_type => 'PLSQL_BLOCK', job_action => 'begin DBMS_STATS.GATHER_DATABASE_STATS ( estimate_percent =>100, block_sample=>FALSE, method_opt=>''for all columns size auto'', degree=>null, cascade=>true, no_invalidate=>false, options=>''GATHER STALE'', gather_sys=>FALSE); DBMS_STATS.GATHER_DATABASE_STATS ( estimate_percent =>100, block_sample=>FALSE, method_opt=>''for all columns size auto'', degree=>null, cascade=>true, no_invalidate=>false, options=>''GATHER EMPTY'', gather_sys=>FALSE); end;', repeat_interval => 'FREQ=DAILY;BYHOUR=2;BYMINUTE=0;BYSECOND=0', start_date => trunc(sysdate+1) + 2/24, job_class => 'DEFAULT_JOB_CLASS', comments => 'Gather auto stats on every table with 100% sampling', auto_drop => FALSE, enabled => FALSE);

sys.dbms_scheduler.set_attribute(name => '"SYS"."ESTIMATE100_GATHERAUTO"', attribute => 'job_priority', value => 4); sys.dbms_scheduler.enable('"SYS"."ESTIMATE100_GATHERAUTO"'); end;

Oracle Datapump parameter REMAP_SCHEMA
Loads all objects from the source schema into a target schema.

Syntax
REMAP_SCHEMA=source_schema:target_schema

Suppose that you execute the following Export and Import commands to remap the hr schema into the scott schema:
> expdp SYSTEM/password SCHEMAS=hr DIRECTORY=dpump_dir1 DUMPFILE=hr.dmp

> impdp SYSTEM/password DIRECTORY=dpump_dir1 DUMPFILE=hr.dmp REMAP_SCHEMA=hr:scott

In this example, if user scott already exists before the import, then the Import REMAP_SCHEMA command will add objects from the hr schema into the existing scott schema. You can connect to the scott schema after the import by using the existing password (without resetting it). If user scott does not exist before you execute the import operation, Import automatically creates it with an unusable password. This is possible because the dump file, hr.dmp, was created by SYSTEM, which has the privileges necessary to create a dump file that contains the metadata needed to create a schema. However, you cannot connect to scott on completion of the import, unless you reset the password for scott on the target database after the import completes.

Basic Introduction to SQL*PLUS
The SQL*PLUS (pronounced "sequel plus") program allows you to store and retrieve data in the relational database management system ORACLE. Databases consist of tables which can be manipulated by structured query language (SQL) commands. A table is made up of columns (vertical) and rows (horizontal). A row is made up of fields which contain a data value at the intersection of a row and a column. Be aware that SQL*PLUS is a program and not a standard query language.

Getting Started
It is a prerequisite that users are registered for ORACLE, an ORACLE account is needed. On Unix platforms you must start the script oraenv to set the ORACLE environment. Enter the command . oraenv and press <Return;>. Don't forget to type a blank between the dot and oraenv.

If you are working with a PC using MS Windows, simply use Netinstall to install the product. You can find the software in the database folder. Enter sqlplus on unix systems or run it on Windows from the start menue. Answer the displayed prompts by entering your ORACLE user-name and password. The SQL*PLUS command prompt SQL > indicates that you are ready to work.

Some elementary Commands
alter user user identified by newpassword Help exit, quit ho[st] ho[st] command ho[st] oerr enables user to change the password accesses the SQL*PLUS help system terminates SQL*PLUS leads to the operating system without leaving SQL*PLUS executes a host operating system command accesses the ORACLE error help for unix

Editing and Executing
All entered input is stored as a single SQL*PLUS statement in the command buffer. Pressing the <Return> key while editing will either open a new numbered line or, if the previous line ends with a semicolon or consists of a single slash, will execute the SQL*PLUS command. Opening new numbered lines allows you to structure statements and enables you to refer to particular lines by later using edit functions. l[ist] ln or n ln m a text c/oldstring/newstring i del r[un] / ; lists command buffer (the current line is marked with a star) makes line n the current line and lists it lists lines n through m appends text to current line changes oldstring to newstring in current line inserts a line after current line deletes the current line runs and lists command buffer runs command buffer lists command buffer

If you use substitution variables, like &variable, instead of values or names in your SQL statement, SQL*PLUS will prompt you and substitute the entered value. A substitution variable is a user variable name preceded by an ampersand.

Working with Command Files
You can use command files to save complex commands. After creating a command file you can retrieve, edit, and run it. The default file extension is .sql . If you use other file extensions you must write the full file name like name.extension. ed[it] overwrites a scratch file with the contents of the command buffer edit enables you to edit this file with the defined host operating system editor. The name of the scratch file is afiedt.buf . After leaving the editor the buffer is listed and you can execute it.

sql creates file filename and stores the command buffer into it stores command buffer into file filename Possible options are cre[ate]. Queries and Subqueries Retrieving data from the database is the most common SQL operation.ed[it] filename sav[e] filename sav[e] filename [option] enables you to edit an existing or new file filename. col2*3 from tabname selects col1.col2 from tabname where col1 < col2 and col2 !=0 order by col2 Columns col1. you will be prompted for that value. select col1. from tabname selects specified columns from table tabname select col1.] executes file filename arg1 arg2 . get filename loads the host operating system file filename into the command buffer sta[rt] filename [arg1 arg2 . called clauses: select some data from table. A query is an SQL command (specifically a select) that retrieves information from one or more tables.col2 from tabname where col1 like '_A%' or col1 like '+++' order by col2 desc . col2 are selected from table tabname and all rows where col2 is not equal to zero and col1 is less than col2 are displayed in an ascending order (ordered bycol2). Examples select col1. are arguments you wish to pass to the command file If you run a command file in which a substitution variable like &1 is used. rep[lace]. app[end].. A where clause consists of one or more search conditions which can be connected by logical operators...col2 from table tabname and lists col1. To display the retrieved data in a specific order you need to add an order by clause. col2 multiplied by 3 select 2*3 from dual calculates 2*3 and will display the result Selecting Rows and Ordering To retrieve specific rows from a table you need to add a where clause. A subquery is a select which is nested in another SQL command The Describe Command desc[ribe] name lists the column definition for table or view name Basic Select Commands The basic select command consists of two parts. You can avoid being prompted by passing an argument to the command file. Examples select * from tabname selects all columns and rows from table tabname select distinct col from tabname selects column col from table tabname and returns only one copy of duplicate rows select col1. col2 ..

tabname alias2 where alias1. you list the names of the tables you are querying in the from clause and the names of the linking columns in the where clause.col2 This is the most common type of join. . set operator union union all intersect minus returns all distinct rows selected by either query returns all rows selected by either query.col1 "Header 2" from tabname alias1.tab2.col2 from tab1.tab2 where tab1.col3 from tab1. you can do this by issuing different queries or a single JOIN query.col1 between lowval and highval Since this join doesn't return rows based on a equality condition. The underscore matches exactly one character whereas the percent sign can match zero or more characters. Querying Multiple Tables If you want to retrieve information from different tables. they will be evaluated from left to right. select col1. If a column name is not unique. Self Join select alias1. Using of two different alias names for the same table allows you to refer to it twice. therefore it is also called an equi-join Non-Equi Join select tab1.tab1.col2 are selected from table tabname and all rows where col1 is equal to '+++' or where the second letter in col1 is an 'A' are displayed in a descending order.value2 ) Columns col1. If a statement contains multiple set operators.tab2 where tab1.g.col2 from tabname where col1 not between value1 and value2 Columns col1. select col1.col1. In a JOIN query. Since the names of the resulting columns in this example are the same.col2 from tabname where col1 in ( value1.col2 are selected from table tabname and all rows where col1 is equal to value1 or to value2 are displayed.Columns col1.col2.alias2.col2 are selected from table tabname and all rows where col1 is not in the range between value1 and value2 are displayed.col1. Using Set Operator Set operators combine the results of two queries into a single result. it is called a non-equi join. columns of table1 and table2. Simple Join select col1. including all duplicates returns all distinct rows selected by both queries returns all distinct rows selected by the first query but not the second Example select * from table1 union all select * from table2 This will combine all rows. The omission of the linking where clause causes a cartesian product of both tables. It returns rows from two tables based on an equality condition. In this example two different escape characters are used. the second column gets a new header.col3 In this example the table tabname is joined with itself. tablename. A JOIN combines rows from two or more tables where columns which the tables have in common match.columnname). you must use a prefix to make clear which column from which table you want to select (e.col2=tab2.col2=alias2.

. where cond updates rows in table tabname columns are set to values of expressions if condition cond is true update tabname set (col1.) inserts rows into table tabname insert into tabname subquery inserts rows(selected by a subquery) into &table tabname update tabname set col1=expr1.col1 will be selected...tab2 where tab1.) rename oldname to newname alter user user identified by newpassword. number specifies a floating point number. A subquery is a form of the select command which enables you to select columns from an existing table... insert into tabname (col1.Outer Join select col1. A simple join will select only matching rows whereas the outer join extends the result. If rows match.. Data Definition Language DDL DDL commands allow you to create.col2.. the values from tab2.val 2.. create table tabname as subquery creates table tabname subquery inserts rows into the table upon its creation.type2.col2(+) Suppose you want to retrieve information from two tables where not all rows match but the result should contain all values from one or more columns.g tables. char(size) specifies fixed length (max 255) character data of length size.) alter table tabname modify (col1 type1.) creates table tabname col1 .. if not. varchar.col2. char. type1... These commands do not commit current actions.col1=tab2.. specifies the datatype of a column which can be number. create table tabname (col1 type1.) values (val1. number(p.. In the example the number of rows which are selected is the number of rows in table tab2. All matching rows will be selected and when you append the outer join operator (+) to a column name.col2 type2. date. the outer join works as a simple join. views) and also to grant and revoke privileges.. coln are the column names.col2 type2. those rows which do not match will also be selected.col2 from tab1. grant privilege on object to user revoke privilege on object from user removes table tabname from the database adds columns to table tabname modifies column definitions renames table oldname enables user to change the password to newpassword grants a privilege to user revokes a privilege from user Data Manipulation Language DML DML commands manipulate and query data in existing tables.... varchar2(size) specifies variable length (max 2000) character string having a maximum length of size bytes.col2 and a NULL value for the non existing value of tab1.col2=expr2.)=(subquery) where cond updates rows in table tabname . drop table tabname alter table tabname add (col1 type1.. alter and delete objects (e..s) specifies a fixed point number having precision p (total number of digits) and scale s (number of digits to the right of the decimal point). number(p) specifies a fixed point number.col2 type2.. create view viewname as subquery creates view viewname A view is a logical table based on one or more tables.

CEIL( BLOCKS*&&BLKSIZE/1024/1024) CURRSIZE. Example select * from scott.emp Transaction Control Commands Transaction Control Commands manage changes made by Data Manipulation Language commands.1)*&&BLKSIZE)/1024/1024 )||'M. exit.FILE_ID = B.'.1)*&&BLKSIZE)/1024/1024 ) SAVINGS FROM DBA_DATA_FILES A. If you are not the owner of the object. CEIL( (NVL(HWM. but the owner granted some privileges to you. CEIL( BLOCKS*&&BLKSIZE/1024/1024) CEIL( (NVL(HWM. rollback . A transaction (or logical unit of work) is a sequence of SQL statements that ORACLE treats as a single unit.delete from tabname [where cond] columns are set to selected values if condition cond is true either deletes all rows from table tabname or rows where cond is true Schema When you select data from a table or you insert data into a table then this object has to be in your own schema.tabname. ( SELECT FILE_ID.g="" for="" size="" span="" your=""> SELECT /*+rule*/ 'ALTER DATABASE DATAFILE '''||FILE_NAME||''' RESIZE '||CEIL( (NVL(HWM. you have to specify schema. MAX(BLOCK_ID+BLOCKS-1) HWM FROM DBA_EXTENTS GROUP BY FILE_ID ) B WHERE A. A transaction ends with a commit.1)*&&BLKSIZE)/1024/1024 ) SMALLEST. or any DDL statement which issues an implicit commit. In other words.FILE_ID(+) . In most cases transactions are implicitly controlled. commit rollback rollback to savepoint savep savepoint savep makes all changes since the beginning of a transaction permanent rolls back (undoes) all changes since the beginning of a transaction rolls back to savepoint savep defines savepoint savep Resize Datafile to Optimal Size SQL> Define BLKSIZE=<="" block="" db="" e. you must be the owner.

2. then consider changing RMAN ARCHIVELOG DELETION POLICY. SMALLEST 684 466 89 5 82 CURRSIZE 690 490 90 5 100 SAVINGS 6 24 1 0 18 Oracle OCP test Quiz ORA-19809: limit exceeded for recovery files – db_recovery_file_dest_size and archiver error As we working on development systems normal work around was to free up some space in the db_recovery_file_dest and hope that that the database would continue after the archiver logger error. ALTER DATABASE DATAFILE 'D:\ORACLCE\APP\ADNAN\ORADATA\ORCL\SYSAUX01.DBF' RESIZE 82M. Add disk space and increase db_recovery_file_dest_size parameter to reflect the new space. ************************************************************************ You have following choices to free up space from flash recovery area: 1.DBF' RESIZE 466M. ALTER DATABASE DATAFILE 'D:\ORACLCE\APP\ADNAN\ORADATA\ORCL\USERS01. ALTER DATABASE DATAFILE 'D:\ORACLCE\APP\ADNAN\ORADATA\ORCL\UNDOTBS01. Consider changing RMAN RETENTION POLICY. and has 0 remaining bytes available. 3. .OUTPUT 'ALTERDATABASEDATAFILE'''||FILE_NAME||'''RESIZE'||CEIL((NVL(HWM.DBF' RESIZE 89M. The alert log typically shows an entry as follows :ORA-19815: WARNING: db_recovery_file_dest_size of 42949672960 bytes is 100.1)*8192)/1024/1024)||'M. Back up files to tertiary device such as tape using RMAN BACKUP RECOVERY AREA command.DBF' RESIZE 5M.DBF' RESIZE 684M. If you are using Data Guard. Invariably we needed to restart the database and hope that the problem resolves itself.' ALTER DATABASE DATAFILE 'D:\ORACLCE\APP\ADNAN\ORADATA\ORCL\SYSTEM01.00% used. ALTER DATABASE DATAFILE 'D:\ORACLCE\APP\ADNAN\ORADATA\ORCL\EXAMPLE01.

as set by dest_size then we will fail. then use RMAN CROSSCHECK and DELETE EXPIRED commands.1 has an unpublished note on the subject Cause ~~~~~~~ We register all the information about what we place in the flash recovery area in the rman repository/controlfile. If an operating system command was used to delete files. 1) Increase the parameter db_recovery_file_dest_size 2) Stop using the db_recovery_file_dest by unsetting the parameter. Delete unnecessary files using RMAN DELETE command.trc: ORA-19809: limit exceeded for recovery files ORA-19804: cannot reclaim 1063256064 bytes disk space from 42949672960 limit ARCH: Error 19809 Creating archive log file to ‗+FRA‘ connect from Rman RMAN > CHANGE ARCHIVELOG ALL VALIDATE.p27_show_help:621248. ************************************************************************ Errors in file /u00/app/oracle/diag/rdbms/sid/SID/trace/SID_ora_20214.995.com/metalink/plsql/f?p=200:27:9917209390401703684::::p27_id. Metalink Document https://metalink. 1.4. If we determine that there is not sufficient space in the recovery file destination. RMAN > DELETE EXPIRED ARCHIVELOG ALL.p27_show_header. Fix ~~~~ There are a couple of possible options. ( This assumes you never really wanted to use this option ) 3) Remove the Entries from the rman repository/Controlfile . Just deleting the old backups/archive logs from disk is not sufficient as it‘s the rman repository/controlfile that holds the space used information.oracle.

The removal is desribed in the RMAN documentation but this is a quick and dirty way if you don‘t have an rman repository – but could endanger your ability to recover – so be careful.LOG') SIZE 1M. 'D:\ORACLE\ORADATA\ORCL\REDO04B. ADDING ONLINE REDO LOG FILE GROUPS In some cases you may need to create additional log file group.LOG' TO GROUP 3 . 'D:\ORACLE\ORADATA\ORCL\REDO03B.LOG' . ALTER DATABASE ADD LOGFILE GROUP 4 ('D:\ORACLE\ORADATA\ORCL\REDO04A.LOG' TO GROUP 4 . a) delete unwanted archive log files from disk ( rm /del ) b) connect to rman c) rman crosscheck archivelog all – marks the controlfile that the archives have been deleted d) rman delete expired archivelog all – deletes the log entries identified above MAINTAINING ONLINE REDO LOG FILES Before adding group and members first check how many group already in the database using the view SQL > select * from V$LOG. SQL > select * from V$LOGFILE. To solve availability problem this can be done by SQL command. ADDING ONLINE REDO LOG FILE MEMBER We can add new members to existing online redo log file groups using the following SQL command: ALTER DATABASE ADD LOGFILE MEMBER 'D:\ORACLE\ORADATA\ORCL\REDO04C.

Even group is in INACTIVE MODE DROPPING ONLINE REDO LOG FILE MEMBERS We can drop online redo log file member by using SQL statement ALTER DATABASE DROP LOGFILE MEMBER 'D:\ORACLE\ORADATA\ORCL\REDO02B. the operating system file are nat deleted. 3. An ACTIVE and CURRENT group cannot be dropped. Otherwise the files are created in a default directory of the database server.When adding member use the fully specified name of the log file members. DROPPING ONLINE REDO LOGFILE GROUPS Online redo log file group can be dropped by the SQL command ALTER DATABASE DROP LOGFILE GROUP 4. 2. NOTE: If database is in archive mode group can not be dropped until archival process not completely done. RESTRICTIONS: While deleting online redo log file group we must consider the following restrictions 1.LOG'. RESTRICTIONS: While deleting online redo log file members we must consider the following restrictions . An instance requires at least 2 group of online redo log files. When an online redo log file group is dropped.

Alter database rename file command ALTER DATABASE RENAME FILE COMMAND use following steps: STEP # 1: Shutdown the database SQL > SHUTDOWN. We cannot drop the last valid member of any group 2. If the group is current. STEP # 4: Rename the online redo log file member using the SQL >ALTER DATABASE RENAME FILE . you must force switch log file before you can drop the member. If the database is in archived mode and the log file group to which the member belongs is not archived.1. when a online redo log file member is dropped. REALLOCATING OR RENAMING ONLINE REDO LOG FILES The location of online redo log files can be changed by renaming the online redo log files. STEP # 2: Copy the online redo log file to the new location in operating system STEP # 3: To start database at mount SQL > STARTUP MOUNT. ensure that the new online redo log file can exists. Before renaming the online redo log files. the member can not be dropped 4. Relocate or rename online redo log files in one of the 2 following ways: 1. 3. the operation system file cannot be deleted. Add new members and drop old members 2.

The command can overcome two situations where dropping online redo log file is not possible:   If the are only two log groups The corrupt online redo log file belongs to the current group Use the UNARCHIVED keyword in the command to clear the corrupted online file to avoid archiving. you must test different configurations. Oracle server multiplexed group can contain different no. of members this is called asymmetric configuration (means all members in a group placed on same disk) In this case we get temporary result because of disk failure Oracle recommended try to built symmetric configuration (means member of any group also placed on different location) By doing this if one member is not available the other is available and instance does not shutdown Separate archive log file and online redo log files on different disks to reduce contention b/w the ARCn and LGWR .LOG’. In this situation ALTER DATABASE CLEAR LOGFILE command can be used to reinitialize the online redo log file with out shutdown the database. and ultimately stop database activity because activity cannot continue. CLEARING ONLINE REDO LOG FILES An online redo log file might become corrupt while the database is open .LOG’ TO ‘D:\ORACLE\ORADATA\REDO03B.‘D:\ORACLE\ORADATA\ORCL\REDO03C. ONLINE REDO LOG FILE CONFIGURATION To determine the appropriate number of online redo log files for a database.

INACTIVE: Indicates that the online redo log file group is no longer needed for instance recovery. SQL > Select * from V$logfile. DELETED: . redo log file group. In the V$log views the status column having the values 1. It 4. 3. UNUSED: Indicates that the online redo log file group has never been written to 2. SQL > Select * from V$log. In the V$logfile views the status column having the values 1. INVALID: Indicates that the file is inaccessible 2. STALE: Indicates that the contents of the file are incomplete 3.Data files and online files should be placed on different disk to reduce contention b/w LGWR and DBWn SIZE OF ONLINE REDO LOG FILE The minimum size of online redo log file is 50KB and Maximum size is specifying in the operating system. ACTIVE: Indicates that the online redo log file group is active but is not the current online is needed for crash recovery. CURRENT: Indicates the current online redo log file group. This implies that the online redo log file group is active.

440 minutes): SQL> SHOW PARAMETER RETENTION SQL> ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=1440. Shut down and restart the database in the mount exclusive mode. Set up a flash recovery area. Tuesday. SQL> ALTER DATABASE ARCHIVELOG. 2011 Configuring Flashback Database through SQL In order to configure the Flashback Database feature. Check that our database is in the archive log mode by either querying the $DATABASE view. after first shutting down the database and starting it up initially in the mount mode: SQL> SHUTDOWN IMMEDIATE. we can turn archive logging on with the ALTER DATABASE statement shown in the following code. November 15. SQL> STARTUP MOUNT.Indicates that the file is no longer used 4. 4. as follows: 1. or by simply issuing the following command: SQL> ARCHIVE LOG LIST The preceding output reveals that the database is indeed running in the archive log mode. The following code sets the Flashback target to 1 day (1. If it isn’t. we need to step through a series of operations. If we are using a single instance. BLANK Indicates that the file is in use. a simple MOUNT command can be used: . as we learn in the FLASH RECOVERY AREA CHAPTER 3. Set the DB_FLASHBACK_RETENTION_TARGET initialization parameter to specify how far back you can flashback your database. SQL> ALTER DATABASE OPEN 2.

SQL> SHUTDOWN IMMEDIATE. Using this technique. This technique helps in analysis and auditing of transactions. such as when a batch job runs twice and you want to determine which objects were affected. Oracle Flashback Concept FLASHBACK LEVELS In Oracle Database 10g. 5. retrieve it and undo erroneous changes. you have access to flashback techniques at the row. 6. It can also provide an audit history of changes. Use the ALTER DATABASE OPEN command to open the database and then confirm that the Flashback Database feature is enabled. by querying the V$DATABASE view: SQL> SELECT FLASHBACK_ON FROM V$DATABASE. • Flashback Versions Query: Allows us to view all versions of the same row over a period of time so that you can undo logical errors. as follows: Row level We can use Flashback techniques to undo erroneous changes to individual rows. SQL> ALTER DATABASE OPEN. we can view the older data and. and all of them rely on undo data stored in the undo tablespace: • Flashback Query: Allows us to view old row data based on a point in time or an SCN. Table level There are two main Flashback features available at the table level: . There are three types of row-level Flashback techniques. Enable the Flashback Database feature: SQL> ALTER DATABASE FLASHBACK ON. and database levels. we can undo changes made by an entire transaction during a specified period. SQL> STARTUP MOUNT. effectively allowing us to compare present data against historical data without performing any DML activity. table. • Flashback Transaction Query: Lets us view changes made at the transaction level. if necessary.

For example. Note: If we have a damaged disk drive. No matter how limited the extent of the corruption. thus undoing all changes since that time. we would undertake traditional point-in-time recovery techniques. Oracle’s Flashback technology employs a variety of techniques. we would need to restore entire data files and apply the archived redo logs. Flashback techniques allow us to selectively restore certain objects. This feature uses DML changes to undo the changes in a table. Furthermore. or if there is physical corruption (not logical corruption due to application or user errors) in our database. Or we may just want to query historical data and perform change analysis. For example. When the block is subsequently read again. if we suffered logical database corruption. thus eliminating the possibility of corruption at the physical disk level. it also relies. the only way to recover from human error was to employ traditional backup and restore techniques. on archived redo logs to completely recover a database without restoring data files and performing traditional media recovery. Flashback vs. By setting the DB_BLOCK_CHECKSUM initialization parameter to FULL. to a much smaller extent.Traditional Recovery Techniques Unlike traditional recovery techniques. Note: Oracle can check data block integrity by computing checksums before writing the data blocks to disk. there is likely corruption in the data block.• Flashback Table: Restores a table to a point in time or to a specified SCN without restoring data files. • Flashback Drop: Allows us to reverse the effects of a DROP TABLE statement. we may want to revert the entire database to a previous point in time. As we can see. but to recover from human errors. Database level • Flashback Database: The Flashback Database feature allows us to restore an entire database to a point in time. the checksum for the data block is computed again. without resorting to a point-in-time recovery. The row-level Flashback techniques and Flashback Table use undo data Flashback Drop use new concept of Recycle Bin and Flashback Database rely on the new concept of Flashback log data. and Flashback technology offers us a much more efficient and much faster way to recover from logical errors. With traditional techniques. We will focus on these techniques in this chapter. and if the two checksums differ. however. to undo errors at various levels. we have no choice but to recover the entire database. In some extreme cases. This was often time-consuming and cumbersome. in most cases while the database is still online and available to users. we can make the database perform the check in the database buffer cache itself. The process of restoring the database files and then rolling forward through all the redo logs could often involve significant downtime. we may accidentally change the wrong set of data or drop a table. we must still use the traditional methods of restoring backups and using archived redo logs to perform the recovery. respectively. The DB_BLOCK_CHECKSUM parameter is FALSE by default. The Flashback Drop feature uses the Recycle Bin to restore a dropped table. restoring data file backup copies and then using archived redo logs to advance the database forward. we can restore a dropped schema or an erroneously truncated table. Flashback Database mainly uses flashback logs to retrieve older versions of the data blocks. FLASHBACK DATABASE Before Oracle Database 10g. The Flashback Table feature relies on undo data. . Traditionally. the primary use of Flashback techniques isn’t to recover from a media loss.

We can issue the FLASHBACK DATABASE command from either RMAN or SQL*Plus. The only difference is that RMAN will automatically retrieve the necessary archived redo logs. Once the Flashback Database feature is enabled. whereas in SQL*Plus we may have to supply the archived redo logs. it is the size of the error and not the size of the database that determines the time it takes to recover. This means that we can recover from logical errors in a fraction of the time —perhaps as little as a hundredth of the time. unless we use the SET AUTORECOVERY ON feature in SQL*Plus. the time it takes to recover is directly proportional to the number of changes that we need to undo. to undo changes to a point in time just before a specified target time or SCN. Thus. A Flashback Database operation simply reverts all data files of the database to a specified previous point in time. Note: Flashing back a database is possible only when there is no media failure. Since the specified target time and the actual recovery time may differ slightly. Oracle Shutdown SHUTDOWN THE DATABASE: There are 4 ways to shutdown database . we simply use the FLASHBACK DATABASE command to return the database to its state at a previous time. Tip Since we need the current data files in order to apply changes to them.In Oracle Database 10g. but first let’s look at how to enable (and disable) the Flashback Database feature. We’ll take a look at the whole Flashback Database process in more detail shortly. we can’t use the Flashback Database feature in cases where a data file has been damaged or lost. we then use archived redo logs to recover the database over the short period of time between the target time and the actual recovery time. We can use Flashback Database in the following situations:  To retrieve a dropped schema  When a user error affects the entire database  When we truncate a table in error  When a batch job performs only partial changes The Flashback Database feature uses flashback database logs. you’ll have to recover using a restored data file from backups. or log sequence. depending on the size of the database — that it would take using traditional methods. If you lose a data file or it becomes corrupted. the Flashback Database feature restores data files but without requiring backup data files and using just a fraction of the archived redo log information. which are stored in the new flash recovery area. SCN. With Flashback Database.

SHUTDOWN ABORT:      Oracle does not wait for user currently connected to the database Database and redo buffers are not written to the disks The instance terminated without closing the files The database is not close or dismounts Next startup requires instance recovery. During Re-creation of control files.SHUTDOWM IMMEDIATE:     Current SQL statement being processed is not completed Oracle server does not wait for the user who are currently connected to the database Oracle closes and dismount database before shutdown.SHUTDOWN NORMAL:       No new connection can be made Oracle server waits all users to disconnect database and redo buffer written to the disk Background process terminated and SGA remove from memory Oracle closes and dismount database before shutdown Next startup does not require recovery 2. Oracle 10g startup STARTING UP THE DATABASE: There are 4 stages to startup and shutdown the database When startup database Shutdown  Nomount  Mount  Open At NOMOUNT Stage: An instance is typically started only in NOMOUNT mode During Database creation.1.SHUTDOWN TRANSACTIONAL:     No new connection can be made User automatically disconnect after completing the transaction in progress When all transaction finished shutdown occur immediately Next startup does not require recovery 3. Next startup does not require recovery 4. .

log files and trace files At MOUNT Stage: Mounting a database includes the following tasks:    Associating a database with instance start at nomount stage. Reading the control file to obtain the name.Or During certain backup and recovery scenarios. changing the archive logging mode of the database.    Allocating SGA Starting the background Process opening the alertSID. Prior to this stage. At OPEN Stage: The last stage of the startup process is opening the database. all valid users can connect to the database and perform database operations. the general users can’t connect to the database at all. At this stage following tasks are performed  Reading initialization parameter file First spfileSID. flashback options. When the database is started in the open mode. initsid. You can bring the database into the o pen mode by issuing the ALTER DATABASE command as follows: . spfile.ora specifying the PFILE parameter with STARTUP overrides the default behavior. status and destination of DATA FILES AND ONLINE REDO LOG FILES   To perform special maintenance operations Renaming data files (data files for an offline tablespace can be renamed when the database is open)   Enabling and disabling online redo log file archiving. Locating and opening the control file specified in the parameter file.ora if not found then. or renaming data files. Performing full Database Recovery We usually need to start up a database in mount mode when you’re doing activities such as performing a full database recovery. Note that all three of these operations require Oracle to access the data files but can’t accommodate any user operations in the files.ora If not found then.

Database altered.SQL> ALTER DATABASE OPEN. to move the database from NOMOUNT TO MOUNT or from NOMOUNT TO OPEN use ALTER DATABASE COMMAND ALTER DATABASE MOUNT. we can use a number like 1. the Oracle server first opens all the data files and the online redo log files. ALTER DATABASE OPEN. the default is 0. DB_KEEP_CACHE_SIZE . It can be modified with the ALTER SYSTEM command. IN SHORT Opening a database includes the following tasks:   Open online data files Open online redo log files NOTE If any of the data files or online redo log files are not present when you attempt to open the database. it’s the greater of 48MB or 4MB * number of CPUs * granule size. we simply use the STARTUP command to mount and open our database all at once: SQL> STARTUP To open the database. For example. if the SCNs in the control files don’t match some of the SCNs in the data file headers—the background process will automatically perform an instance recovery before opening the database.024MB. If the database isn’t consistent—for example. STARTUP COMMAND  use to start database STARTUP NOMOUNT. More commonly. Oracle Parameter related to Database Buffer Cache DB_CACHE_SIZE This parameter sets the size of the default buffer pool for those buffers that have the primary block size (this is the block size defined by DB_BLOCK_SIZE). Oracle will signal that a database recovery is called for and won’t open the database until you perform the recovery. and verify that the database is consistent. If we aren't using SGA_TARGET. Parameter type: Dynamic. If media recovery rather than instance recovery is needed. then the oracle server returns an error. Default value: If we're using the SGA_TARGET parameter.

large pool. For example. The parameter is set as follows: DB_RECYCLE_CACHE_SIZE = 200MB Default value: 0.The normal behavior of the buffer pool is to treat all the objects placed in it equally. 4. In contrast. if we know that certain objects don’t really need to be in memory for a long time. we can assi gn them to a recycle pool. That is. Parameter type: Dynamic. which removes the objects right after they’re used. It can be changed by using the ALTER SYSTEM command. DB_nK_CACHE_SIZE If we prefer to use nonstandard-sized buffer caches. Oracle removes objects from this pool as soon as the objects are used. this parameter is not configured. and streams pool). Oracle will show zero values for these when we query the V$PARAMETER view. we need to specify the DB_nK_CACHE_SIZE parameter for each. Default value: 0 Parameter type: Dynamic. When this happens. database buffer cache. Objects are removed (aged out) only when there is no free space. by default. It can be changed by using the ALTER SYSTEM command. the keep pool always retains an object in memory if it’s created with the KEEP option. DB_RECYCLE_CACHE_SIZE The DB_RECYCLE_CACHE_SIZE parameter specifies the size of the recycle pool in the buffer cache. 8. The DB_KEEP_CACHE_SIZE parameter specifies the size of the keep pool. any object will remain in the pool as long as free memory is available in the buffer cache. Parameter type: Dynamic. Java pool. set the SGA_TARGET parameter to a positive value. as in the following two examples: DB_4K_CACHE_SIZE=2048MB DB_8K_CACHE_SIZE=4096MB The values for n that can be used in this parameter are 2. or 32. and it’s set as follows: DB_KEEP_CACHE_SIZE = 500MB Default value: 0. The use of two specialized buffer pools—the keep pool and the recycle pool—allows us to specify at object-creation time how we want the buffer pool to treat certain objects. In order to use automatic shared memory management. Oracle SGA_TARGET Parameter SGA_TARGET The SGA_TARGET parameter determines whether our database will use automatic shared memory management. which shows the values of all our . You can change this parameter’s value with the ALTER SYSTEM command. 16. We don’t have to specify the five automatic shared memory components in our initialization file (shared pool. this parameter is not configured. the oldest unused objects sitting in memory are removed to make space for new objects. by default.

the buffer cache recycle pool.ora file. the nondefault-sized buffer cache pools and nKBsized buffer caches. Oracle Compatible Parameter COMPATIBLE The COMPATIBLE parameter allows us to use the latest Oracle database release. and we have to manually set the values for all the previously mentioned SGA components. Note If we set the SGA_TARGET parameter. If we set the SGA_TARGET parameter to zero. To get a quick idea about how much memory to allocate for the SGA_TARGET parameter under automatic shared memory management. Default value: 0 (no automatic shared memory management) Parameter type: Dynamic. in which case we can explicitly specify them in the file. SHARED_POOL_SIZE. and the fixed SGA allocations) will be deducted from the SGA_TARGET value first. The value for SGA_TARGET must be a minimum of 64MB. we can leave out all the automatic SGA parametersDB_CACHE_SIZE. the buffer cache keep pool. unless we want to ensure a minimum size for some of these. however.initialization parameters. . When we use automatic shared memory management by setting a value for the SGA_TARGET parameter. we disable automatic shared memory management. We may. and the upper limit is dependent on the operating system. LARGE_POOL_SIZE. the memory we allocate for the manually sized components (the log buffer. run the following query: SQL> SELECT ( (SELECT SUM(value) FROM V$SGA) (SELECT CURRENT_SIZE FROM V$SGA_DYNAMIC_FREE_MEMORY) ) "SGA_TARGET" FROM DUAL. You can use the ALTER SYSTEM command to modify the value. and STREAMS_POOL_SIZE—from our init. choose minimum values for any of the five auto-memory parameters. while making sure that the database is compatible with an earlier release. in which case we should specify the values in the initialization file. JAVA_POOL_SIZE.

If. This parameter can’t be changed after the database is created. we could set the COMPATIBLE parameter equal to 9. we can reset the COMPATIBLE initialization parameter to 10.2 features. but we won’t be able to downgrade our database to 9.2 so the untested features of the new Oracle version won’t hurt our application. which is the default value for Oracle Database 10g Release 2 (10. The DB_NAME value should be the same as the value of the ORACLE_SID environment variable. referred as spfileSID. Default value: 10. instead.2. We must understand this irreversible compatibility clearly.Suppose we upgrade to the Oracle Database 10g Release 2 version. we immediately raise the compatible value to 10. we can use all the new 10.0.2. but our application developers haven’t made any changes to their Oracle9i application.0 Parameter type: Static DB_NAME and DB_UNIQUE_NAME DB_NAME The DB_NAME parameter sets the name of the database. This is a mandatory parameter and the value is the same as the database name you used to create the database. Contents Of Parameter File A list of instance parameters The name of the database the instance is associated with . Types of initialization parameter file Oracle uses a parameter file to store the initialization parameters and their settings for an instance.ora A text file that contains a list of all initialization parameters.2 or any other lower versions. Later on. before we set the value for this parameter. PFILE. In this case. Default value: false Parameter type: Static DB_UNIQUE_NAME The DB_UNIQUE_NAME parameter lets us specify a globally unique name for the database. Server parameter file (SPFILE): Dynamic persistent server parameter file SPFILE. commonly 2. after the application has been suitably upgraded.2.ora A binary file that contains the initialization parameters Initialization parameter file (pfile): Static parameter file. commonly referred as initSID.2). You can have a DB_NAME value of up to eight characters. We can use either of the following two types of parameter files: 1.

'B023').Can have RMAN support for backup the initialization parameter Verify Database 32/64 bit creation to check database been created originally in a 32-bit environment and is now on a 64-bit platform select decode(instr(metadata.Maintained by the oracle server .Allocation for memory structures of the SGA What to do with filled online redo log files.ora (sid) means database name Text File Modified with an operating system editor Modification made manually Whenever we need to change the value of the parameter file we must shutdown the database. Text initialization parameter file: PFILE  initsid. The pfile is read only during instance startup.Always resides on the server side having read and write by database server .Can self-tune parameter values . Information about undo tablespace.ora Server parameter file: SPFILE :  spfilesid. '32bit Database') "DB Creation" from kopm$.0\Db_1\database\initorcl.2. 0. 2012 DB Buffer Usage Query .ora  (sid) means database name .Binary File . '64bit Database'. (Changes take effect on next startup) For oracle 10g (R2)  default location E:\oracle\product\10. (Archive Destination) The names and locations of control files. September 8.Ability to make changes persistent across SHUTDOWN and STARTUP . Saturday.

CPU USAGE BY current Users --. 'Not Modified'. 0. decode(lrba_seq. . 'Not Modified'. 'Available'.CPU USAGE BY USER SELECT s. count(*) "count" from sys. k. 1. 2.username.serial#. 2. '[ORACLE PROCESS]') user_name. s. 'Being Modified'). 0. decode(lrba_seq. 'Free'. 3. 'Being Read'.client_info.machine. s. 'Being Read'. 3.-.program.osuser os_user. s. 'Free'. 0. 'Other'). nvl(s. s. s. 'Other') block_status.ksusestv cpu_usage.action. s.x$bh group by decode(state. 1.DB Buffer Usage select decode(state.sid. 0. s.module. 'Available'. 'Being Modified').

'OEM_MONITOR'. 'CTXSYS'. 'IMP_FULL_DATABASE'.logon_time FROM v$session s.s. s sys. 'EXP_FULL_DATABASE'.x$ksusesta k WHERE k.v_$session%ROWTYPE. 'IFSSYS'. 'UNLIMITED TABLESPACE') admin_option = 'YES') grantee not in ('SYS'. 'AQ_ADMINISTRATOR_ROLE'. 'ORDSYS' ) Oracle User info using Process ID set serveroutput on size 50000 set echo off feed off veri off accept 1 prompt 'Enter Unix process id: ' DECLARE v_sid number. 'MDSYS'.type != 'BACKGROUND' ORDER BY k. sys.sid AND k. admin_option from where or or and sys. 'OUTLN'.ksusestv DESC Find Power Privileges given to users To check which Powerful privileges are granted to users perform following query select grantee.indx = s. 'ORDPLUGINS'. 'DBSNMP'. 'DBA'. privilege.dba_sys_privs (privilege like '% ANY %' privilege in ('BECOME USER'. 'SYSTEM'. .ksusestn = 12 AND s.

'||s.spid = s.v_$process%ROWTYPE. end.program).addr (p.put_line(sqlerrm).serial#).v_$process where addr = s.process = '&&1').v_$session s p. dbms_output. sys.put_line('Unable to find process id &&1!!!'). select * into s from sys.put_line('Foreground . return. select * into p from sys. : '|| : '|| 'PID: '||s. dbms_output.'||s. sys. BEGIN begin select sid into v_sid from where and or exception when no_data_found then dbms_output.put_line('======================================== =========='). when others then dbms_output.p sys.paddr.v_$session where sid = v_sid.paddr = &&1 s.process||' .v_$process p.sid||'. return. dbms_output.put_line('SID/Serial s.

v_$sqltext . dbms_output.' || to_char(s. dbms_output. dbms_output. 'NONE')).put_line('Shadow '||p.sql_hash_value order by piece) loop dbms_output.lockwait.username).put_line('Last Call : '|| to_char(sysdate(s. dbms_output.put_line(chr(9)||c1. 'Dy HH24:MI:SS') || ' . : '|| to_char(s.latchspin.machine).program).spid||' : '|| s.terminal).dbms_output. end loop. dbms_output.put_line('Current SQL statement:').last_call_et/60/60/24). '990. dbms_output.put_line('Status Flags: '|| s.latchwait.put_line('Previous SQL statement:').v_$sqltext where HASH_VALUE = s. 'NONE')). for c1 in ( select * from sys.status||' '||s.osuser||' on : '|| s.put_line('Tran Active : '|| nvl(s.sql_text).server||' '||s.put_line('Lock/ Latch : '|| nvl(s. 'NONE')||'/ '||nvl(p.logon_time.put_line('Terminal p. dbms_output. dbms_output. for c1 in ( select * from sys.taddr.type).put_line('Ora User : '|| 'PID: '||p.put_line('Latch Spin 'NONE')). dbms_output. : '|| nvl(p.last_call_et/60.0') || ' min').put_line('OS User '||s. dbms_output. dbms_output.put_line('Login Time 'Dy HH24:MI:SS')).terminal || '/ ' || : '|| s.

'CF'. end loop. end loop. -end loop.put_line('Connect Info:'). -- dbms_output. 'TRANSAC .put_line(chr(9)||': '||c1.sid) loop -dbms_output. for c1 in ( select * from sys.type.for c1 in ( select * from sys. 'UL'. ENQ'.put_line(chr(9)||c1.event).put_line('Session Waits:').prev_hash_value order by piece) loop dbms_output. for c1 in ( select /*+ ordered */ decode(l. 'CONTROL 'TX'.network_service_banner). -. dbms_output. 'DML/DATA ENQ'.put_line(chr(9)||c1. -.v_$session_connect_info where sid = s.sql_text).Short locks 'BL'. -.sid) loop dbms_output.Long locks 'TM'. 'BUF HASH TBL'. dbms_output. FILE'. 'PLS USR LOCK'.where HASH_VALUE = s.put_line('Locks:').state||': '||c1.v_$session_wait where sid = s.

'. 'LOG SW KICK 'MR'. '.'CI'. 'MOUNT/STRTUP'. 'DISTRIB 'IN'. 'SV'. 'LS'. 'SGA OPN FILE'. 'DIRECT LOAD '. '. '. 'ROW WAIT 'SM'. 'DF'. 'PROCESS 'SC'. 'LOG SWITCH 'MM'. 'DR'. 'PWFILE ENQ STRT'. 'DL'. 'SEQNO 'ST'. 'DLL ENQ SEG '. '. 'SEQNO ENQ TRANSC'. 'DATA 'DM'. 'REDO THREAD '. 'FILE SET NUM'. 'GENERIC ENQ 'TE'. 'IV'. 'SCN 'SN'. 'FI'. 'INSTANCE 'IS'. STATE '. 'RT'. '. 'SQ'. 'RW'. 'LIBCACHE INV'. 'RECO LOCK TRAN'. 'PF'. 'SEQNO VALUE '. 'SMON LOCK INSTCE'. '. 'EXTEND . '. '. '. '. 'CROSS INST F'. ENQ '. FILE '. 'INSTCE RECVR'. 'MOUNT DEF RECVRY'. 'FS'. 'GET 'KK'. 'TD'. 'SPACE 'TA'. 'CURSOR BIND '. 'MEDIA 'PR'. 'CU'. 'IR'. 'DX'.

5. 'MR'. to_char(l. 'RX'. decode(l. 'TM'. 'ENQUEUE'.type.id1. decode(l. 0.sid where sid and l.type) type. 'S'. 6.name. sys.lmode) ) lmode. 3. 'USER NAME '. 'X'.v_$lock l. 'TT'. o.id1.lmode.4. 'TX'.id2) objname from sys. 'NULL'. 'REDO LOG FILE#='||l. '. 'NULL'.name.id2. decode(l.1. 5. 0. 4. 'RW'. 'S'.request) ) lrequest. 'TYPE='||l. 'TEMP 'WL'. 'THREAD='||l.3)|| ' BLOCK#='||substr(l.5)||' ROW='||l. 0. 'ID1='||l. TABLE REDO '.id2.name. 'RS'. 'WRITE decode(l.id1 = o.'TS'. 'TD'.request. 'NONE'. 2. 1. 'RSX'. 'RT'.id1. 'UN'. 'X'. 'FILE#='||substr(l. 'RSX'. 4.id1. 'RS+SLOT#'||l.id1||' ID2='||l.obj#(+) ) loop .id2. 2.id1||' WRP#'||l. to_char(l. 'NEW BLOCK ALLOCATION'). 'RS'. 3. 1.obj$ o = s. o. 6. 'NONE'. 'TEMP SEGMENT'. 'TS'. 'WL'. o. 'RX'.

we can set the AUDIT_TRAIL parameter to any of the following values: • os: Oracle writes the audit records to an operating system audit trail.put_line('======================================== ==============='). audit records for the SYS user. • none: This value disables auditing. END. since the default value for this parameter is none. but also provides extended audit information like the SQLBIND and SQLTEXT columns of the SYS. Oracle will still write audit information to an operating system file for all database actions that are audited by default. undef 1 Oracle 10g Parameters related to Audit AUDIT_TRAIL The AUDIT_TRAIL parameter turns auditing on or off for the database.dbms_output. including audit records from the OS. In addition. • db: Oracle records the same type of auditing as with the os setting. end loop. which is an operating system file. but it directs all audit records to the database audit trail.2): • XML: This value for audit trail enables database auditing and writes audit details to OS files in XML format. On a UNIX system.put_line(chr(9)||c1.lmode||' R: '||c1.type||' H: '||c1. which disables database auditing. you have two XML-related AUDIT_TRAIL values (new in Oracle Database 10. The parameter is set as follows: AUDIT_TRAIL = db Default value: none Parameter type: Static Chapter 11 provides more information about auditing actions within an Oracle database. If we want auditing turned on. • db.lrequest||' .objname). dbms_output. • XML.'||c1. If we don’t want auditing to be turned on. which is the AUD$ table owned by SYS.AUD$ table. the .EXTENDED: This value prints all database audit records plus the SQLTEXT and SQLBIND values to OS files in the XML format. and those database actions that are always automatically audited. or false. do nothing. Tip Even if we don’t set the AUDIT_TRAIL parameter to any value.extended: This is similar to the db setting.

AUD$) will start growing and because is relies on SYSTEM tablespace you might have performance problems in the future. 1. We can also specify this parameter if we choose the XML or XML. You can modify this parameter with the ALTER SYSTEM . . from a 5TByte E-Business Suite. when we choose the operating system as the destination with the AUDIT_TRAIL parameter by specifying AUDIT_TRAIL=os. since the audit records are written to operating system files in both cases.AUD$ .EXTENDED options for the AUDIT_TRAIL option. See Chapter 11 for more details on this feature. we can specify a different directory if we wish. will audit all actions of the SYS user and any other user with a SYSDBA or SYSOPER role and will write the details to the operating system audit trail specified by the AUDIT_TRAIL parameter.AUD$_BU table stored in a different tablespace(AUDIT_DATA) where you will move all you auditing produced CREATE TABLESPACE AUDIT_DATA DATAFILE '/filesystem034/oradata/SID/audit_data_001. Default value: $ORACLE_HOME/rdbms/audit Parameter type: Dynamic. .default location for this file is the $ORACLE_HOME/rdbms/audit directory. By writing the audit information to a secure operating system location.AUD$_BU TABLESPACE AUDIT_DATA AS SELECT * FROM SYS. Auditing housekeeping must be setup. Here is a practical guide. we remove any possibility of the SYS user tampering with an audit trail that is located within the database. (stored in table SYS. AUDIT_SYS_OPERATIONS This parameter. Create a SYSTEM. if set to a value of true. Of course.dbf' SIZE 10000M AUTOEXTEND OFF LOGGING PERMANENT EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT MANUAL. The possible values are true and false. with 50MB auditing produced every day. AUDIT_FILE_DEST The AUDIT_FILE_DEST parameter specifies the directory in which the database will write the audit records. DEFERRED command. CREATE TABLE SYSTEM. Default value: false Parameter type: Static Auditing If you enable auditing then the auditing information.

'dd/mm/yyyy hh24:mi:ss') . END IF. Unit II Preparing for OCP DBA Exam 2: Database Administration Basics of the Oracle Database Architecture .aud$'.aud$). BEGIN SELECT COUNT(*) INTO rowCount FROM sys.INTERVAL => 'TRUNC(SYSDATE+1)' . CREATE INDEX SYSTEM.AUD$_BU_TIME_IDX ON SYSTEM.SUBMIT ( job => X .KEEP_SIZE_AUD_LOG.ksdwrt (3. BEGIN SYS.DBMS_JOB.' .Dbms_System.aud$_bu (SELECT * FROM sys.AUD$_BU you can create 2 indexes (one on timestamp# and the other to userid) CREATE INDEX SYSTEM. END Keep_Size_Aud_Log. 2.WHERE 1=2. Execute the procedure every day at midnight with a job DECLARE X NUMBER.AUD$_BU_USERID_IDX ON SYSTEM. sys.next_date => TO_DATE('27/02/2008 12:35:21'. END. EXECUTE IMMEDIATE 'truncate table sys. COMMIT.AUD$_BU (TIMESTAMP#) NOLOGGING TABLESPACE AUDIT_DATA.aud$ .AUD$_BU CREATE OR REPLACE PROCEDURE Keep_Size_Aud_Log IS rowCount NUMBER.AUD$_BU'). Create a procedure(Keep_Size_Aud_Log) that moves the rows from SYS.no_parse => FALSE ). Tip: To speed up searching on SYSTEM.AUD$_BU (USERID) NOLOGGING TABLESPACE AUDIT_DATA. INSERT /*+ APPEND */ INTO SYSTEM.AUD$ to SYSTEM. IF rowCount > 0 THEN COMMIT.'ORA-AUDIT TRAIL: rows moved from SYS.what => 'SYS.AUD$ to SYSTEM. / 3.

is understanding the Oracle database architecture. Some of these components are memory structures. and your day-to-day responsibilities as an Oracle DBA. and special resources designed to allow for recovering data from problems ranging from incorrect entry to disk failure. All three structures of the Oracle database server running together to allow users to read and modify data are referred to as an Oracle instance. This discussion will explain the components of the SGA and the PGA. Oracle Memory Structures Focus first on the memory components of the Oracle instance.000+ users in a global environment. it’s all here. The Oracle Architecture In this section. There are two basic memory structures on the Oracle instance. certification series. This set of memory components represents a "living" version of Oracle that is available only when the instance is running. You should review this chapter carefully. . and process components of the Oracle instance. you will understand and demonstrate knowledge in the following areas: The Oracle architecture Starting and stopping the Oracle instance Creating an Oracle database A major portion of your understanding of Oracle. while others are processes that execute certain tasks behind the scenes. The first and most important is called the System Global Area. you will cover the following topics related to the Oracle architecture: Oracle memory structures Oracle background processes Oracle disk utilization structures The Oracle database server consists of many different components. as the concepts presented here will serve as the foundation for material covered in the rest of the book. both to be a successful Oracle DBA and to be a successful taker of the OCP Exam 2 for Oracle database administration. There are also disk resources that store the data that applications use to track data for an entire organization. Figure 6-1 demonstrates the various disk. which is commonly referred to as the SGA. All of these features working together allow Oracle to handle data management for applications ranging from small "data marts" with fewer than five users to enterprise-wide client/server applications designed for online transaction processing for 50. and also cover the factors that determine the storage of information about users connected to the Oracle instance. or PGA. Oracle in action consists of many different items. to recovery mechanisms that allow the DBA to restore systems after seemingly unrecoverable problems. memory. The other memory structure in the Oracle instance is called the Program Global Area. About 22 percent of OCP exam 2 is on material in these areas. from memory structures. to special processes that make things run faster.In this chapter. Whatev er the Oracle feature.

The other mandatory component of the shared pool is the data dictionary cache. Of course. When DBAs talk about most things related to memory. Since all user processes and the Oracle database internal processes use the data dictionary. these database changes are kept in order to rebuild database objects in the event of a disk failure. They are designed to store data blocks recently used by user SQL statements in order to improve performance for subsequent selects and data changes. The shared SQL library cache is designed to store parse information for SQL statements executing against the database. The shared pool has two required components and one optional component. listed here. The final area of the SGA is the redo log buffer. This information is treated as a shared resource in the library cache. which stores online redo log entries in memory until they can be written to disk.The Oracle SGA The Oracle SGA is the most important memory structure in Oracle. The required components of the shared pool are the shared SQL library cache and the data dictionary cache. the database will recognize the opportunity for reuse and let the user process utilize the parse information already available in the shared pool. This memory structure is designed to store the data from the Oracle data dictionary in order to improve response time on data dictionary queries. The SGA consists of three different items. One fact that is important to remember about redo logs and user processes is that every process that makes a change to the database must write an entry to the redo log in order to allow Oracle to recover the change. the specific data returned by the query for each user will not reside in the shared pool. The optional component of the shared pool includes session information for user processes connecting to the Oracle instance. When the database is set up to archive redo logs. The buffer cache The shared pool The redo log buffer The buffer cache consists of buffers that are the size of database blocks. the database as a whole benefits in terms of performance from the presence of cached dictionary data in memory. By having all user processes writing those redo log records to memory. Explore the usage of the shared pool in the Oracle database architecture. and thus not be shared. Since every . If another user process comes along wanting to run the same query that Oracle has already parsed for another user. The redo log buffer allows user processes to write their redo log entries to a memory area in order to speed processing on the tracking of database changes. because sharing data between applications represents a data integrity/security issue. the Oracle database avoids contention for disk usage that would invariably cause database performance to slow down. The SGA stores several different components of memory usage that are designed to execute processes to obtain data for user queries as quickly as possible while also maximizing the number of concurrent users that can access the Oracle instance. The availability of a buffer for storing redo information in memory prevents the need for user processes to spend the extra time it takes to write an entry directly to disk. also referred to by many DBAs as the "row" cache. they are talking about the SGA. Parse information includes the set of database operations that the SQL execution mechanism will perform in order to obtain data requested by the user processes.

No user process ever interfaces directly with any record on a disk.data change process has to write a redo log entry. the DBA should know that the database already stores parse trees for recently executed SQL statements in a shared area called the library cache. Location of User Session Information The question of location for user session information is an important one to consider. sort areas. When the DBA uses the MTS configuration. Unit IV. When MTS is not used. then Oracle must locate the data block that contains the row. Oracle looks in the buffer cache to see if the data block that contains the row has already been loaded. and the purpose of the Server process appear in this discussion. all data is read into the database buffer cache by shared server processes acting on behalf of user processes. session information is stored in the shared pool of the SGA. When the DBA uses MTS. 2. the values that the user wants to execute the search or update upon cannot be shared. More information about shared vs. . After the user’s select statement has completed. The Oracle PGA The PGA is an area in memory that helps user processes execute. why do the users need their own area to execute? The reason users need their own area in memory to execute is that. dedicated servers. the PGA stores session information for each user running against Oracle. So. The procedure is the same for a data change. The PGA is used to store real values in place of bind variables for executing SQL statements. Whether user session information is stored in the PGA or the shared pool depends on whether the multithreaded server (MTS) option is used. even though the parse information for SQL or PL/SQL may already be available. From the prior discussion of the shared pool. it makes sense that processes be able to write that change as quickly as possible in order to boost speed and avoid problems. There is one overall performance gain that the buffer cache provides that is important to note . except that after Oracle writes the data to the row. Oracle keeps the block in memory according to a special algorithm that eliminates buffers according to how long ago they were used. and Unit V of this Guide. If not. . load it into memory. This fact is true for the redo log buffer as well. called the dirty buffer write queue. In the dedicated server process configuration. Exercises 1. and present the selected output to the user. the MTS architecture. If it has. MTS relates to how Oracle handles user processes connecting to the database. This area of memory allows for selective performance gains on obtaining and changing data. such as bind variable information. each user process has its own dedicated server process reading data blocks into the buffer cache. which simply means that some row in the buffer has been changed. What is the name of the main memory structure in Oracle. The buffer cache stores data blocks that contain row data that has been selected or updated recently. When the user wants to select data from a table. and other aspects of cursor handling. The final SGA resource is the buffer cache. and what are its components? What is the function of the PGA? . then the buffer cache has achieved its selective performance improvement by not having to look for the data block on disk. and it is designed to store those dirty buffers until the changes are written back to disk. Another structure exists in the buffer cache. the block that contains the row will then be called a dirty buffer.

there will be user processes accessing information. This process also writes the log sequence number of the current online redo log to th datafile headers and to the control file. DBWR The database writer process. This setup is allowed because the Oracle instance has its own background processes that handle everything from writing changed data blocks onto disk to securing locks on remote databases for record changes in situations where the Oracle instance is set up to run in a distributed environment. insert. In Oracle databases that archive their online redo logs." or backed out of the database reverted to their original form. It works in conjunctio the Oracle database buffer cache memory structure. LGWR handles initiating the process of clearing the dirty buffer w queue. those updated blocks are written to disk by DBW These events are called checkpoints. There are several background processes in the Oracle instance. Second. LGWR handles telling DBWR to write the changes. This background process handles all data block writes to disk. PMON watches the user processes on the database to make sure that they work co If for any reason a user process fails during its connection to Oracle.3. Likewise. In any Oracle instance. . or piecing the together. the SMON process handles disk sp management issues on the database by taking smaller fragments of space and "coalescing" them. SMON The system monitor process. the ARCH process handle automatically moving a copy of the online redo log to a log archive destination. ARCH (optional) The archiver process. using background processes. the Oracle instance will be doing some things behind the scenes. this background process hand resolution of distributed transactions against the database. It was mentioned in the discussion of the SGA that no user process ever interfaces directly with I/O. This background process handles the writing of redo log entries from the redo log buffer t online redo log files on disk. Finally. At various times. LGWR The log writer process. The following list presents each background process and its role in the Oracle instance. Where is user session information stored in memory on the Oracle instance? How is its location determined? Oracle Background Processes A good deal of the discussion around users thus far speaks of processes--user processes doing this or that. in the ev an instance failure—when the memory structures and processes that comprise the Oracle instance cannot contin run—the SMON process handles recovery from that instance failure. PMON The process monitor process. The usage and function of this Oracle background process is twofold. depending on database configuration. In Oracle databases using the distributed option. RECO (optional) The recoverer process. It prevents users from ever accessing a disk to perform a da change such as update. . First. PMON will clean up the remnants of its activ and make sure that any changes it may have made to the system are "rolled back. or delete.

the table acquires an extent to place the additional data in. The objects a DBA may place into a tablespace are things like . There are structures that are stored on disk that the DBA must understand how to manage. S999 The server process. The user process comes into the database v SQL*Net listener. Through another. Figure 6-2 demonstrates the concept of a logical and physical view of storage in the Oracle instance. D001. which connects the process to a dispatcher. Executes data reads from disk on behalf of user processes. CKPT can be used to handle writing log sequence numbers to the datafile headers and control file. and extents. From there. of which there can be as many as ten. To begin. the DBA sees the physical database files that store these logical database structures. LCK9 (optional) The lock processes. alleviating LGWR of that responsibility. Oracle must execute disk management processing in order to create. Figure 2: The logical and physical views of a database A tablespace is a logical database structure that is designed to store other logical database structures.. or series of rollback entries.CKPT (optional) The checkpoint process. In high-activity databases. depending on whether the DBA uses MTS or not. Name the background process that handles reading data into the buffer cache. S000. segments. These structures include tablespaces.. and recover an Oracle database. When the row data for a table exceeds the space allocated to it by the segment. A segment is a logical data object that stores the data of a table. and this section will identify and discuss the meaning of each structure in kind. they must obtain access to a shared server process via a dispatcher process. In databases that use the Parallel Server op this background process handles acquiring locks on remote tables for data changes. the dispatcher finds the user process shared server that will handle interacting with the database to obtain data on behalf of the user process. the difference is that an extent handles table growth. Through one lens. Which process handles writing data changes from the buffer cache back to disk? Which process handles writing redo log information from memory to disk? Which process can be configured to help it? Which background processes act as part of the multithreaded server (MTS) architecture? Which background process coalesces free space on disk? Oracle Disk Utilization Structures In addition to memory. when users conn the database. 3. index. This process acts as part of the Oracle MTS architecture to connect user proce shared server processes that will handle their SQL processing needs. In the MTS architecture. the DBA must first understand that there are two different "lenses" through which he or she must view the way Oracle looks at data stored on disk. Exercises 1. described below. LCK0. store. 2. An extent is similar to a segment in that the extent stores information corresponding to a table.. the DBA sees the disk utilization of the Oracle database consisting of logical data structures. D999 (optional) The dispatcher process. Access to Server processes can eit shared or dedicated. However. access.

Each redo log can consist of one or more redo log files." In cases where operating system authentication is used. can span across multiple datafiles. can have their segments and extents span across multiple datafiles belonging to that one tablespace. either on the machine or on the entire network. password files. Individual data objects. The use of operating system authentication will be covered in more detail in the next section. index. and any other objects that consist of segments and extents. If redo log archiving has been selected. the redo log is filled and LGWR switches writing redo log entries to the other redo log. The other lens through which the DBA will view the data stored on disk is the physical lens. starting the entire process again. After all redo logs are filled. Without a control file. The name of the control . The parameter file is another important physical database disk resource that is available to Oracle. the redo logs are archived as well. rollback segments. and others. Some parameters that init. this file specifies many initialization parameters that identify the database as a unique database. indexes. either automatically by the ARCH process or manually by the DBA. parameter files. Just as a table. any datafile on the database can contain data for only one tablespace. The database cannot start without init. Another database disk resource that is used by Oracle is the password file.ora sets include the size of various objects of the SGA. The final database disk resource that will be covered in this section is the control file. A logical database object such as a table or index can have multiple extents.ora. provided that all datafiles are part of the same tablespace. but those extents and segments can be stored in only one tablespace. The parameter file is commonly referred to as init. or rollback segments cannot span across multiple tablespaces. Underlying all the logical database objects in Oracle disk storage are the physical methods that Oracle uses to store those objects. Used upon database startup. The objects in a tablespace. In turn. the database name. These files are generally large enough to store many entries There are generally two (minimum) redo logs available to the LGWR process of the Oracle instance for the purpose of storing redo log entries. Data blocks store row data for segments and extents. the password file is not present on the Oracle database. Oracle database server would be unable to find its physical components. Datafiles correspond to the tablespace level of the logical Oracle disk storage architecture in that a tablespace may consist of one or more datafiles. however. The control file tells Oracle what the datafiles are called for all tablespaces and where they are located on the machine.tables.ora. so it is imperative that the file be present at database startup. also referred to as redo log "members. the blocks are taken together to comprise a datafile. This resource stores passwords for users who have administrative privileges over the Oracle database. LGWR begins reuse of the first redo log file it wrote records to. As the redo log entries are written to the logs. The control file to the physical structure of the Oracle database is like the data dictionary to the logical structure. Redo log files are used to store information about the changes users make to the database. the location of the control file." The operation of online redo logs occurs in this way: LGWR writes entries to the files of one of the two (or more) online redo logs. the files that comprise the current online redo log get fuller and fuller until they reach capacity. namely segments and extents corresponding to different tables. and redo log files. Once the capacity of all redo log members is reached. and thus it is imperative to have a control file. In addition to datafiles. The password file is only used on Oracle databases that use database authentication. as well as what the redo log member filenames are and where to find them. such as tables and indexes. The cornerstone of the physical method that Oracle uses to store data in the database is the Oracle data block. "Starting and Stopping the Oracle Instance. the structures that Oracle uses to store information about the database on disk include: control files.

file is specified in the init. To recap. 2. How are the two linked? Starting and Stopping the Oracle Instance In this section. the DBA must first answer an important question. That question is "How do I plan to support this database?" The answer to that question usually boils down to whether the DBA will be working on the same site as the host machine running Oracle primarily to support database administration tasks.ora file for the database instance. However. the main disk resources of Oracle are listed below: Datafiles Redo log files Control files Exercises 1. . Once installation is accomplished. Selecting an Authentication Method In order to determine what method of authentication to use for the Oracle database. Just as users supply a password. in order to gain entry into the database. The first step of configuring the Oracle server is managing the creation and startup of the Oracle instance. the DBA will start working on other aspects of the Oracle server before actually creating his or her first database. so too must the DBA. Security in Oracle server consists initially of user authentication. The act of installing the Oracle software is specific to the operating system on the machine used to host the Oracle database. 3. and the first step for managing the instance is password authentication. along with a password. with a monitoring server that manages the database administration for many other databases in addition to the one being set up. Oracle offers two options with respect to password authentication. The users of an Oracle system each have a username that they enter. What are the three logical resources on the Oracle instance? Explain the difference between a logical view of disk resources and a physical view of disk resources. or whether the DBA plans to monitor the site remotely. you will cover the following topics related to starting and stopping the instance: Selecting an authentication method Starting an Oracle instance and opening the database Shutting down the Oracle instance Altering database mode and restricting login The first order of business for the DBA in many environments is to install the Oracle software. Name five physical disk resources on the Oracle instance.

If the DBA can in fact obtain a secure connection with the host system running Oracle. If the DBA cannot obtain a secure connection remotely.1996 Oracle Corporation(c) All rights reserved. in a UNIX environment.98) Login: bobcat Password: User connected.3. However. If for some reason a user’s ID is compromised. or to grant the DBA special prioritization for executing processes on the host . The two methods available are to either allow Oracle to manage its own password authentication or to rely on the authentication methods provided by the operating system for Oracle access. with minimal typing and no chance that a password can be compromised at any time during the Oracle login process.45. not only is the host machine at risk to the extent that the user has access to the machine’s resources. then the DBA can use either the Oracle method of authentication or the operating system authentication method. For example. The decision-making flow may go something like this.The use of either depends on the answer to the question of whether the DBA will administer the database locally or remotely.0. If the database administrator is planning to administer the database from a remote location. using the operating system to perform authentication on the Oracle database leaves Oracle’s data integrity and security at the level that the operating system provides. then the question of whether or not a secure connection can be established with the host system running Oracle must be answered. To use operating system authentication first requires that a special group be created on the operating system level if that feature is supported. Connected to Oracle 7. and also on a matter of preference.67. Operating system authentication presents some advantages and disadvantages to using Oracle’s methods for user authentication. If the DBA plans to administer the database locally. it is recommended that where it does not hinder usage of the database and where it improves security.45. use the Oracle methods of user authentication. the DBA will be able to log onto the database simply by using the "/" character in place of a username and password. then the choice of whether to use operating system authentication or Oracle authentication is largely a matter of personal preference. When the user wants to access the Oracle database. then the DBA must use the Oracle method of user authentication.0 (c) 1979.3. Therefore. By using operating system authentication. he or she can simply use the "/" character at login time and Oracle will verify with the operating system that the user’s password is correct and allow access. but the Oracle database is at risk as well to the level that the user has access to Oracle resources.4 (23.67.2. the DBA thereby requires Oracle users to provide a password only when logging into the operating system on the machine hosting Oracle. Today is 12/17/99 14:15:34 [companyx] /home/bobcat/ --> sqlplus / SQL*PLUS Version 3. the login procedure for the DBA using operating system authentication may look something like the following: UNIX® SYSTEM V TTYP01 (23. and multithreaded server options Operating system authentication allows the user or DBA to access the database quickly and easily. Similarly. distributed. if the DBA logs onto the machine hosting Oracle and wants to execute some privileged activities such as creating users or otherwise administrating the database.98) With the parallel.

In the future. Choosing which privilege to grant to the user depends on what type of administrative functions the DBA may fulfill. it is better simply to grant sysdba or sysoper directly to the user who administers the system. In this case. The roles the DBA must have granted to them in this case are called osoper and osdba. it is possible for the DBA to simply connect as internal when the need arises to do any DBA-related activities. rather than dedicated servers. sysdba is a DBA privilege that is granted to the DBA for startup and shutdown recovery and backup. This step of some other operating system requirements must be fulfilled in order to connect to the database for startup and shutdown as internal. When the DBA connects to the database as internal. The sysoper and sysdba privileges provide some breakout of responsibilities and function with the privileges they allow the grantee to perform. However. The internal privilege is a special access method to the Oracle database that allows the DBA to start and stop the database. thus. Therefore. One additional constraint for connecting to the database as internal (in addition to having group privileges and proper process execution prioritization) is that the DBA must have a dedicated server connection. The sysdba keyword denotes a collection of privileges that are akin to those privileges granted with the internal keyword. for handling database reads for user processes. The sysdba privilege administers certain other privileges as well. the DBA can then perform certain operations to create databases and objects with operating system authentication. the use of sysoper and sysdba. the DBA cannot connect as internal when shared servers are used in conjunction with the MTS architecture. this is not advised in situations where the database is administered by multiple database administrators who may have limited access to accomplish various functions. The performance of these functions is contingent upon the DBA having certain roles granted to their userid. the DBA can connect to the database for the purposes of administration using the connect name/pass as sysdba command.. These two privileges are administrated via the operating system and cannot be revoked or administrated via Oracle. They have equivalents used with Oracle authentication —sysoper and sysdba. The sysoper privilege handles administration of the following privileges: Starting and stopping the Oracle instance Mounting or opening the database Backing up the database Initiating archival of redo logs Initiating database recovery operations Changing database access to restricted mode As shown by the types of privileges granted with sysoper. the sysdba and sysoper privileges are usually enabled as well. Once the DBA is connected as internal and the database instance is started. respectively--and from here on this book will assume the use of Oracle authentication. and other availability functions. and are used in conjunction with operating system authentication.system for Oracle. In effect. The ability to connect as internal is provided for backward compatibility. Those privileges are listed as follows: .

If too few values are specified and the DBA needs to add more. Entries can be reused as members of the DBA team come and go. if the DBA connects as internal and SYS and issues the alter user name identified by password command in order to change the password. By specifying a password for this file. These various settings have different meanings with respect to allowing remote database administration on the Oracle instance. the DBA simultaneously assigns the password for internal and SYS. This role is called DBA. When operating system authentication is used on the database. EXCLUSIVE. The location for the password file varies by database.pwd PASSWORD=phantom ENTRIES=5 Once this password file creation is complete. and it also has all system privileges granted to it. a filename for the password file that stores users that can log in as DBA must be specified. the REMOTE_LOGIN_PASSWORDFILE parameter may be set to NONE to disallow remote access to . the database administrator will be unable to execute administrative operations on the database. The first step is to set a value for an initialization parameter in the init. several items must be completed in order to continue with using Oracle’s authentication method to allow DBA access to the database without allowing access as internal. and the user’s and the password file’s passwords are changed. and SHARED. The actual execution of ORAPWD may look something like this from within Oracle: SQL> ORAPWD FILE=/home/oracle/dbs/orapworgdb01. This parameter is called REMOTE_LOGIN_PASSWORDFILE. The final item to be specified to the ORAPWD utility is the number of entries that are allowed to be entered into the password file. and should be executed with care to ensure that the DBA does not log off before the process is complete. The NONE setting means that the database will not allow privileged sessions to be established over nonsecured connections because no password file exists.ora file. The DBA first creates a file to store the authentication passwords for all persons that will be permitted to perform administrative tasks on the Oracle database. After creating the password file. First. The name of the password file can vary according to the operating system used by the machine hosting the Oracle instance. there is another role that is created upon installation of the Oracle software. This number will determine the number of users that will have administrator privileges allowed for their ID. he or she will not be able to do so without deleting and re-creating the password file. In addition. this is the role granted to the DBA ultimately responsible for the operation of the database in question. The password for administering the password file is the next parameter that the ORAPWD utility requires. Oracle’s method of user authentication for database administrators when operating system authentication is not used is called a password file. where the database name is substituted for sid. If the DBA does log off after deleting the password file. This process is dangerous. Care should be taken when specifying this value. This functionality is managed by a special utility called ORAPWD. and its permitted settings are NONE. The filename for the password file is usually orapwsid. but for the most part it can be found in the dbs subdirectory under the Oracle software home directory of the machine hosting the Oracle database.The sysoper privilege All system privileges granted with admin option The create database privilege Privileges required for time-based database recovery Obviously.

it is an important point to make that the DBA should not look for objects they may create using their own username as the owner. One is gaining information about the users listed in them. The final option is SHARED. While this fact of ownership may not be all that important. More on the data dictionary will be presented in this chapter.the database for administration purposes. 2. Then. The following code block shows how the DBA can set this parameter in the init. the REMOTE_LOGIN_PASSWORDFILE parameter should be set to EXCLUSIVE. which means that the password file allows access only by SYS and the DBA connected as internal. What is the name of the utility used to create a password file? Describe its usage. and the related parameter that must be set in INIT. Connection succeeded.ORA in order to use a password file for authentication.ora file: REMOTE_LOGIN_PASSWORDFILE=none REMOTE_LOGIN_PASSWORDFILE=exclusive REMOTE_LOGIN_PASSWORDFILE=shared The EXCLUSIVE setting indicates that the password file developed by the ORAPWD utility for security use on that database instance can be used for that instance and that instance only. When using password file authentication to administer a database remotely via a nonsecure connection. The other feature is that any object created in any login as sysdba or sysoper will be owned by the SYS schema. Exercises 1. allowing the DBAs to log into the database as themselves with all administrator privileges. especially given the ability to create and use public synonyms to obtain data without regard to schema ownership. One such user that is created when Oracle is installed is SYS. the objects they create will be owned by their schemas. the DBA will add users who will administer the Oracle instance to the password file and grant the sysoper and sysdba privileges directly to those userids. In this configuration. parameters. In the event that the DBAs simply log in as themselves without the as sysdba trailer. the other is related to schema ownership. the DBA can query a dynamic performance view from the Oracle data dictionary on the password file called V$PWFILE_USERS. 3. or simply mount the existing database. After creating the password file with the ORAPWD utility and setting the REMOTE_LOGIN_PASSWORDFILE parameter to EXCLUSIVE in order to administer a database remotely. the DBA can then connect to the database as some user with sysdba privileges. To find out which users are in the database password file. The DBA can log into the database as user SYS and create the database and other usernames as necessary. All administrative operations on the database must happen by a DBA who logs into the instance as SYS or as internal when this option is set. the other users that will administer the instance can log onto it as themselves and execute DBA tasks as needed. SQL> There are two important key points to remember with respect to password files. SQL> CONNECT john/mary AS SYSDBA. What are the two Oracle roles granted to DBAs in order to perform database administration? . What two methods of user authentication are available in Oracle? Explain some advantages and disadvantages for each.

The options available for starting up an Oracle database are starting the database without mounting it. In Server Manager. The Oracle database is a set of tables. Within the Server Manager tool there are several different options for database availability at system startup. 2. What is SYS? How is it used? Starting the Oracle Instance and Opening the Database There is an important distinction that sometimes gets blurry in the minds of DBAs and especially Oracle developers who don’t work with Oracle internals often enough to notice a difference. This option is used for preventing any problems with existing databases that are mounted at the time that a new database is created. For starting the instance without mounting the database. the startup command can be issued with an option called nomount. or starting the database and initializing recovery from failure. but will not open any other database that may be available to the Oracle instance. This set of options is listed below: Startup nomount Startup mount Startup open Startup restricted Startup force The first option available is starting up the instance without mounting the database. and other data objects that store information that applications place into storage in the Oracle product. the DBA should do the following: 1. The appropriate tool in this case is Server Manager or Enterprise Manager. Each startup feature has several associated facts about the access level permitted while the database is running in that mode. the command used for starting any database is the startup command. The DBA must supply the name of the database (also known as the SID) and the parameter file Oracle should use to start the database. mounting and opening for anyone’s use. and disk resources. with mounting but not opening. all working together to fulfill user data requests and changes.4. Another recommended safety measure for creating new databases in the same instance that . Using Server Manager. This step is the first that should be accomplished when creating a new database or allowing access to an existing database. an Oracle instance is NOT an Oracle database. Start the appropriate administrative tool and connect as sysdba or internal. background processes. With those points made. procedures. it should also be said that the Oracle instance is very close in similarity to the Oracle database. performing a forced start. indexes. mounting and opening in restricted mode. attention should now turn to starting the Oracle instance. There are several different options the DBA can use to specify the startup status of the database. These different options correspond to the level of access to the database once the database instance is running. use the startup start_option command to start the instance. The Oracle instance is the memory structures. To start the Oracle database instance. The distinction is between an Oracle instance and an Oracle database. First of all. With that distinction made. This option will start the instance for database creation.

such as the movement of redo log file members. and Oracle will start the instance and initiate the complete recovery at instance startup. the DBA can alter the control file. data files. From database startup. the DBA may want to start the instance and mount but not open an existing database for certain DBA maintenance activities. In other situations. any user with a valid username and password who has been granted the create session privilege or the CONNECT role can access the Oracle database. followed by a revocation of the privilege afterward to prevent possible data integrity issues in later maintenance cycles. A nonmounted database can be mounted to an instance after creation of that database using commands described in the section of this chapter titled "Altering Database Availability. such as in the case of reorganizing large tables that involves a large-volume data load. To accomplish the task. the DBA may grant the restricted session privilege to a developer who is assisting in the database maintenance work. the DBA may want to consider a temporary grant of restricted session to the developer. Oracle may require certain archived redo logs to be present for this option to complete successfully. In situations where the DBA needs to perform a full database recovery. The same startup command is used for starting the database in all modes. In this case. the DBA may want to open the database without letting users access the database objects. the DBA can execute the startup restrict command within Server Manager. the options considered now are called opening the database." TIP: In a database that is mounted. This is the most common situation for a DBA to start the database in when there is DBA maintenance activity required on the logical portion of the Oracle database. large-volume data loads. the DBA should mount but not open the database. or to specify the usage of Oracle’s archival of redo logs feature. In any event. and other DBA maintenance activities. Although any user on the database can have this privilege granted to them. typically only the database administrator will have it. However. In these situations. A complete discussion of backup and recovery occurs in Unit III. One of those two situations is when the database has experienced a failure of some sort that requires the DBA to perform a complete database recovery of the database and the instance. the DBA may need to work on some aspect of the physical database structure. the DBA will want to use the restrict option for logical database object maintenance such as reorganizing tablespaces. the DBA may want the instance to initiate its complete recovery at the time the instance is started. the DBA can issue the startup recover command from the Server Manager tool. both of which are used for circumstances outside of normal database activity. creating new indexes or fixing old ones. Once the DBA has opened the database. but the mode option used in this situation is the mount option. Hence. In this case. The DBA will need to specify the database name and the parameter file for this option to mount the database to the instance for the physical database object maintenance activities described above.already owns a database is to back up the existing database before creating the new one. first and foremost so that users and applications can access the database in order to work. The DBA will open the database for many reasons. In this case. . All other options for starting a database will allow access to the database in one form or another. In some cases. the DBA will execute a special command that restricts database access to only those users on the system with a special access privilege called restricted session. In order for the DBA to start the instance and then mount and open the database. In some cases. in addition to starting and opening the database. the DBA must use the startup open option. reorganizing or renaming objects. In cases where archiving is used. There are two special cases for database startup left to consider. This method is generally preferable to a permanent grant of restricted session to someone outside the DBA organization. the DBA will execute the startup option as before. Typically.

as there is usually a need for instance recovery in this type of situation. The second is that the database does not force users already logged onto the system to log . The DBA can give database startup an additional shove with the startup force command option.m.m. and receives the following message: ora-01090: shutdown in progress—connection is not permitted.m. the treatment of OCP Exam 3 on database backup and recovery. It is not recommended that the DBA use this option without extreme care. The first and lowest priority is normal. 3. the DBA may need to push things a bit. There are three rules that can be abstracted from this situation. The options for database shutdown are listed below: Shutdown normal Shutdown immediate Shutdown abort There are three priorities that can be specified by the DBA for shutting down the database. User Z is the last user logged off at 3:35 p. 4. 2. User X is logged onto the system at 2:30 and performs data entry until 3:15 p. there will be no need to perform a database recovery. This option will use a method akin to a shutdown abort (see the next section on database shutdown) in order to end the current instance having difficulty before starting the new instance. with the requirement to cease allowing access to the database and the requirement to accomplish the task while being logged on as internal. What is the tool used for starting the Oracle database? What connection must be used for the task? What are the five options for database startup? Shutting Down the Oracle Database Shutting down the Oracle instance works in much the same way as starting the instance. The first is that no new users will be permitted access to the system. User X will experience no interruption in database availability as a result of shutdown normal. In other words. either graphically with the use of the Shut Down menu under the Instance menu or with the shutdown command in line mode. When the DBA starts the database up again. DBA issues shutdown normal from Server Manager at 3 p. It is the lowest priority because Oracle will wait for many other events to play themselves out before actually shutting down the connection. 5. The following description of events illustrates specifically how the shutdown process works under normal priority: 1. The final option for database startup is used in unusual circumstances as well.the use of this option will be more carefully considered in the next unit. In these cases. the database will make the DBA wait for all other users to finish what they are doing before the database will actually close. 2.m. The database will now shut down. User Y attempts to log into the database at 3:05 p. Sometimes (rarely) there is a situation where the Oracle database cannot start the instance under normal circumstances or shut down properly due to some issue with memory management or disk resource management. The task must also be accomplished from the Server Manager. Exercises 1.

with no exceptions. the other issue associated with shutting down the database immediately is that the effect of the shutdown is not always immediate! In some cases. The database will most likely need instance recovery after an immediate shutdown. the database will shut down immediately. A power outage can be particularly detrimental to the database. Perhaps there are some problems with the database . the DBA may require changing the availability of the database in some way. What connection must be used for the task of database shutdown? What are the three options for database shutdown? Changing Database Availability and Restricting Login During the course of normal operation on the database. In all cases that this priority is used. there is no need for instance recovery. Otherwise. 2. However. Exercises 1. under normal shutdown situations. Instead. For example. Oracle terminates the user connections to the database immediately and rolls back any uncommitted transactions that may have been taking place. the DBA may have to initiate emergency maintenance on the database. The first is the issue of recovery.off in order to complete the shutdown. the DBA’s session will not allow the DBA to access any other options or issue any other commands until the shutdown process is complete. how many users are logged on to the system and on the shutdown priority issued by the DBA. Third. Oracle will not wait for a user to logoff as it did in points 2 and 4 above. it is usually best to avoid using this option entirely. This is the highest priority that can be assigned a shutdown activity. The time the process can take depends on several factors. While Oracle attempts to shut down the dat abase. Use of this priority when shutting down a database instance should be undertaken with care. This activity should not require much effort from the DBA. and use shutdown immediate in circumstances requiring the DBA to close the database quickly. therefore. as Oracle will handle the recovery of the database instance itself without much intervention. which is still handled by Oracle. Only in a situation where the behavior of the database is highly unusual or when the power to the database will cut off in less than two minutes should the shutdown abort option be employed. it is recommended that the DBA shut things down with immediate priority when a power outage is looming. the rollback portion of the database shutdown may take some time to execute. or in the situation where the database could experience a power outage in the near future. This option may be used in order to shut down an instance that is experiencing unusual problems. Normal database shutdown may take some time. However. There are two issues associated with shutting down the database with immediate priority. The final priority to be discussed with shutting down a database is the shutdown with abort priority. A higher-priority shutdown that the DBA can enact in certain circumstances is the shutdown immediate command. Some of the factors that the database shutdown will depend on are whether many users have active transactions executing at the time the shutdown command is issued. Shutting down a database with immediate priority is similar to using the normal priority in that no new users will be able to connect to the database once the shutdown command is issued. The additional item that a shutdown abort uses to prevent the database from waiting for rollback to complete is not to roll back uncommitted transactions. This approach requires more instance recovery activity. particularly in situations involving user processes running large-volume transactions against a database. which requires the database to be unavailable to the users.

This method is generally preferable to a permanent grant of restricted session to someone outside the DBA organization. or the CONNECT role. After the activities that required the database not to be mounted are complete. One fact that is important to remember about the Oracle database is that it can be accessed by multiple instances. In these situations. What statement is used to change the status of a database? Explain the use of the restricted session privilege. Mounting the database allows the DBA to do several database maintenance activities without allowing users the chance to access the database and cause contention. and needs to make some changes to the database. Some of these changes may include re-creating indexes. the DBA can alter the availability of the database in several ways. The following discussion will highlight some of those ways. the DBA may grant the restricted session privilege to a developer who is assisting in the database maintenance work. This option is handled in one way. mainly. After database work. Although any user on the database can have this privilege granted to them. In some cases. can access the database. In some situations. the DBA may want to consider a temporary grant of restricted session to the developer. the DBA can use either the graphical interface of Server Manager to mount the database or use the alter database mount statement to achieve that effect. To change the status of a database to be mounted. such as in the case of reorganizing large tables that involves a largevolume data load. The method used to close access to the database to all users except those with the restricted session privilege is alter database enable restricted session. the DBA can issue the alter database open statement from the SQL command prompt and open the database for user access. and other activities that require the database to be open but access to the data to be limited. Creating an Oracle Database In this section. typically only the database administrator will have it. you will cover the following topics related to creating an Oracle database: . This option is called the restricted session. the DBA will want to allow the users access to the database. the DBA can enable the database’s restricted session mode. tablespace reorganization. the DBA can use the graphical user interface to open the database for user access. but have the database still be closed and therefore unavailable to the users. In order to restore access to the database to all users without the restricted session privilege is to issue the following command: alter database enable restricted session. large-volume data loads. Alternately. The first way a DBA may want to alter the status and availability of the database instance is to change the mount status of a database. followed by a revocation of the privilege afterward to prevent possible data integrity issues in later maintenance cycles. or in the course of a manual startup. In cases where the DBA wants to limit access to the database without actually closing it. the DBA may need to start a database with the nomount option. Exercises 1. The final option to be covered corresponds to situations where the DBA has the database open for use. When the database is in open mode. This option prevents logging into the database for any user that does not have the restricted session privilege granted to the user. 2. then a database user with the create session privilege. the DBA will want to mount the database to the instance.that need to be resolved while the instance is still running but the database is unavailable. as discussed earlier in the section on starting the database. For this and many other reasons. Like mounting the database manually. This step can be accomplished in two ways.

receipts. they will first take those entities and map out the relationship. Creating a database involves three activities that will be discussed in this section. with the relationships between each entity represented by an arrow and a description. The first activity for creating a database is mapping a logical entity-relationship diagram that details a model for a process to the data model upon which the creation of database objects like indexes and tables will be based. Figure 6-3 illustrates each entity by a small illustration. expense sheets. and customer accounts receivable invoices. One fundamental tenet of database design is remembering that every database application is a model of reality. deducts money from account. the employees send their vouchers to the accounts payable organization. Now. The model for a database should be a model for the process that the database application will represent. then take the entity-relationship diagram and create a logical data model out of those entities and processes. In the employee expenditure system mentioned above. Then. A discussion of each element in the database creation process will be discussed now in detail.Entity relationships and database objects Creating a database in Oracle Creating the Oracle data dictionary Once the DBA has set up some necessary preliminary items for running the Oracle instance. payments. such as password authentication. employee expense vouchers. These entities and relationships can translate into several different types of visual representations or models of a business reality. on the other hand. Figure 6-4 shows the logical data model of the employee table and the invoice table. The final (and perhaps the most important) aspect of creating a database is creating the structures that comprise the Oracle data dictionary. Most of the time. the database is used to model some sort of business reality. . map loosely to the idea of a verb. payment of sales bonuses. a payment creator such as accounts payable. explore the combination of those entities and their relationships. A logical data model is a more detailed diagram than the entity-relationship diagram in that it fills in details about the process flow that the entity-relationship diagram attempts to model. which creates a check for the employee and mails the payment to the employee. The employee fills out the expense sheets for the expenses incurred on behalf of the company. The relationships. such as datafiles and redo log files. such as the tracking of inventory. Some actions that take place in this employee expenditure system may be submits expense sheet. the DBA can then create the database that users will soon utilize for data management. The second activity that the DBA will perform as part of creating a database is the creation of physical data storage resources in the Oracle architecture. The concept of an entity maps loosely to the nouns in the reality the database application is trying to model. the entities (or nouns) in the model may include employees. Entity Relationships and Database Objects The first part of creating a database is creating a model for that database. or action that takes place between two nouns. and pays check. but it accurately models the business process within an organization to reimburse an employee for his expenses. When the developers of a database application create the employee expenditure system modeled by the entity-relationship diagram above. The process is very simple. submits receipts. and a payer account for the company that is reimbursing the employee.

That is to say. Creating a physical database out of the logical data model requires considering several issues. the relationship of one table to another through foreign keys should correspond somewhat to the relationship that occurs between two entities in the process flow being modeled. In the case of the table structure in Figure 6-5. the employee will fill in various pieces of information. In the example in the diagram above. the empid is the tie that binds an expense sheet to the employee who created it. In the example above. in the logical data model. Some objects that the . including the expense ID number. This forecast of sizing for the database will allow the DBA some "breathing room" when the database application is deployed. while a zero (0) indicates that the relationship is optional. There is an interesting piece of information communicated above and below the line on the opposite side of each table as well. In terms of the entity-relationship diagram. The relationship between columns to tables corresponds loosely to the activity or relationship that exists between the two entities that the tables represent. This means that for any given record in the EMPLOYEE table. or many-to-many correspondence between records of one table and records of another table. Therefore. every expense sheet record in the EXPENSES table will correspond to an employee record. the entities are called tables and the relationships are called foreign keys. so that the DBA is not constantly trying to allocate more space to an application that continually runs out of it. the EMPID column in EXPENSE corresponds to the primary key column of the EMPLOYEE table. while each expense sheet corresponds to one and only one employee. and the expense amount. A one indicates that the relationship is mandatory for the pair. say two years. The line between the two entities is similar to a relationship. Some of these questions relate to Oracle-specific features. while the records of the EXPENSE table have a one-to-one relationship with records of the EMPLOYEE table. The second component of that pair indicates whether there is a one-to-one. each employee may have submitted one or more expense sheets. For example. the relationship between employee and expense sheet is optional for employees but mandatory for expense sheets. The first element of the pair identifies whether the relationship is mandatory from the perspective of the table appearing next to the pair. records in the EMPLOYEE table have a one-to-many relationship with the records of the EXPENSE table. The database designer may ask several questions related to the physical design of that system as follows: How many employees will be allowed to use the system? What sort of company chargeback system will be used to take the employee expense payment from the budget of the department for which the expense was incurred on behalf of the employee? How many expense sheets will be submitted per month and per year? The proper creation of a database in Oracle depends on answering these and many other questions regarding the physical relationship between the machine hosting Oracle and the data Oracle stores as part of the application model. This estimate of row count should be something that is forecasted over a period of time. one-to-many. there may or may not be expense sheets in the EXPENSES table. or none at all. however. This pair of facts is referred to as the ordinality of the database tables. the employee ID number. However.On the expense sheet. That piece of information identifies a pair of facts about the relationship. the designer of the database should know row count estimates for each object to be created in Oracle.

and the redo log files. The final step in creating an Oracle database is to create the logical structures of the data dictionary. This feature of database design is perhaps the hardest to nail down after the initial estimate of transaction activity for the database application. such as English. In addition. These physical structures are called the redo log files. These languages include Mandarin. area of all to consider at the onset of database system creation in the Oracle environment is how the user will preserve the data in the system from any type of failure inherent in the usage of computer machinery. Such methods may include full and partial backups for the database and the archiving (or storing) of redo logs created by Oracle to track changes made in the database. and Korean. Japanese. to find out information about the tables or indexes. . "Database Backup and Recovery. Exercises 1. for example. scoring a positive response from the users while also minimizing the impact of application activity on the Oracle instance. multibyte character sets. and languages read from right to left. Both the users and Oracle refer to the data dictionary in order to find information stored in tables or indexes. specifying the database’s character set is critical to the proper functioning of the database. the designer of the application should know what the users of the database will need regarding data access. or redo log members. Dutch. or the Pacific Rim. The distinct categories are single-byte character sets. In a point related to indexes. There are several different options for specifying character sets in the Oracle database. What is an entity-relationship diagram? Explain both concepts of entities and relationships. or to find out information about the underlying physical structure of the database. Examples of single-byte character sets are any of the Romance or Teutonic languages originating in Western Europe. and the tablespaces that will contain those tables and indexes. These languages fall into distinct categories with respect to the mechanisms on a computer that will store and display the characters that comprise those languages." There are three main steps in creating databases in the Oracle environment. the datafiles. or Italian. The first is creating the physical locations for data in tables and indexes to be stored in the database. See Unit III covering OCP Exam 3. Examples of the multibyte character sets available are the languages that originated in Eastern Asia. French. Southeast Asia. where possible. and also in this book. that searching a table on an indexed column is far preferable to searching on a nonindexed column. Examples of a language read right to left include Hebrew and Arabic. The developers of the application should. These physical locations are called datafiles. try to avoid providing users with free rein to access data via ad hoc queries. Spanish. for performance reasons. One final.designer will need to produce sizing estimates for are the tables and indexes. just as there are many different languages available for use by different peoples of the world. Providing the "canned" query access via graphical user interfaces or batch reporting allows the designers to tune the underlying queries that drive the screens or reports. The data dictionary comprises an integral portion of the database system. Backup and recovery are handled as a whole topic unto themselves in the OCP DBA Exam series. and perhaps the most important. as many users will not know. The reason for the difficulty is knowing what the users will want with respect to data access. German. The second step is to create the files that will store the redo entries that Oracle records whenever any process makes a data change to the Oracle database.

Usually. Oracle provides a generic copy of that parameter file INIT. This step prevents headaches later if there is a problem with database creation damaging an existing database. Steps 1 and 2 are critical in preserving the integrity of any existing databases that may already exist on the Oracle instance. Create and back up the new database. A parameter file is as unique as the database that uses it.ORA in the software distribution used to install Oracle server on the machine hosting Oracle.ora or parameter file. 4. 3. 5. optional relationships? What is a foreign key? Is a foreign key part of the entity-relationship diagram or the logical data model? To what item in the other model does the foreign key relate to? Creating a Database in Oracle Creation of the Oracle database is accomplished with the create database statement.ORA file. Verify the instance name. A critical resource used to start any instance is the file that contains any initialization parameter that the DBA cares to set for the Oracle database and instance being used. Generally.2. a database instance will have more than one parameter file used exclusively for starting it. the DBA will take this generic parameter file and alter certain parameters according to his or her needs. The list describes each parameter in some detail and offers some potential values if appropriate. . Create or edit the init. which causes the first database to be unusable. 4. Start the appropriate database management tool. There are several parameters that must be changed as part of setting up and running a new Oracle database. The first thing to remember about database creation is the Oracle recommended methodology for actually creating the database. Step 1 in the process is to back up the database.ora parameter file. More details will be given shortly about the required parameters that must be unique for database creation. Always remember to back up any existing database that uses the same instance and host machine. What is a logical data model? How does the logical data model correspond to the entity-relationship diagram? What structures in a data model relate loosely to the entities and the relationships of an entityrelationship diagram? What is ordinality? Explain the concept of mandatory vs. a DBA may have one parameter file for general use on starting the Oracle instance when users will access the system. The worst thing a DBA can face when creating a new database is when a datafile or log filename in a parameter file may not have been changed before creating the second database. This file is generally referred to as the init. Each database instance usually has at least one parameter file that corresponds to it and it only. The steps are as follows: 1. 2. to handle various situations that the DBA may want to configure the instance to handle. This situation leaves the first database vulnerable to being overwritten when the second database is created. Sometimes accidents do happen in database creation. and another parameter file designed to start the instance in proper configuration for DBA maintenance weekends. Start the instance. one parameter file that is specifically configured to handle an increase in processing associated with heavy transaction periods at the end of the year. Back up existing databases. The following list highlights key initialization parameters that have to be changed in order to correspond to a unique database. For example. 6. which can happen if the DBA attempts database creation without changing the DB_NAME parameter in the INIT. 3.

then Oracle will create a new control fil for the database at startup. PROCESSES The number of processes that can connect to Oracle at any given time. and one componen a database’s unique name within the network. It is the seco component of a database’s unique name within the network. Oracle will overwrite the contents o that file with the physical layout of the database being created. permanent damage may result in the event a database is created. CONTROL_FILES A name or list of names for the control files of the database. he/she can name them here. . ROLLBACK_SEGMENTS A list of named rollback segments that the Oracle instance will have to acquire at database startup. DB_BLOCK_BUFFERS The maximum number of data blocks that will be stored in the database buffer cach the Oracle SGA. If the name specified for this parame do not match filenames that exist currently. This value includes background processes (of which there are at least five) and user processes. DB_BLOCK_SIZE The size in bytes of data blocks within the system. If the file does exist. The control files docum the physical layout of the database for Oracle. Data blocks are unit components datafiles into which Oracle places the row data from indexes and tables. DB_DOMAIN Identifies the domain location of the database name within a network. If there are particular segments the DBA wants Oracle to acquire.DB_NAME The local name of the database on the machine hosting Oracle. This param cannot be changed for the life of the database. If this is not changed.

As an alternative to licensing by concurrent sessions DBA can limit the number of usernames created on the database by setting a nume value for this parameter.dat’ SIZE 10M MAXDATAFILES 20 ARCHIVELOG. the DBA will need to start the database instance while connected to the database as sysdba and while running Server Manager. To start the instance. Set to less than LICENSE_MAX_SESSIONS. ‘redo2b. This number determines the number of sessions tha users can establish with the Oracle database at any given time. the user must have the osdba or sysdba granted to them and enabled.log’) SIZE 1M. LICENSE_MAX_USERS Used for license management. The following code block contains a create database statement: CREATE DATABASE orgdb01 CONTROLFILE REUSE LOGFILE GROUP 1 (‘redo1a. After starting the instance without mounting a database. LICENSE_MAX_WARNING Used for license management.dat’ SIZE 30M AUTOEXTEND 10M MAXSIZE 100M.log’) SIZE 1M MAXLOGFILES 2 DATAFILE ‘data01. ‘redo1c.log’. ‘redo2c.log’. ‘rbs01. ‘temp01.log’. The task of connecting to the database as sysdba has already been discussed.dat’ SIZE 20M. the DBA can create the database with the create database command In order to create a database. .dat’ SIZE 30M. GROUP 2 (‘redo2a.LICENSE_MAX_SESSIONS Used for license management.dat’ SIZE 30M AUTOEXTEND 10M MAXSIZE 100M. ‘users01.log’. use the startup nomount command in order to run the instance without mounting a previously existing database. ‘redo1b. Following the creation of the appropriate initialization parameter file. Oracle w issue warnings to users as they connect if the number of users connecting has excee LICENCE_MAX_WARNING. ‘index01.

Other items created as part of the create database command are the datafiles and the redo log files. As covered. Redo logs are created with the logfile clause. A workaround for this problem is to use the autoextend option when defining datafiles. When autoextend is used. This size of the control file is related to the number of datafiles and redo log files that are used on the Oracle database. For now. This syntax is purely optional. Sometimes the SYSTEM tablespace is compared to the root directory of a machine’s file system. One of these resources is the SYSTEM tablespace. Another pair of options set at database creation time are called maxdatafiles and maxlogfiles. and it must be followed by an integer. If the create database statement specifies a datafile or a redo log file that currently exists on the system and the reuse keyword is used. the DBA should ensure that only the data dictionary and system . Redo logs are entries for changes made to the database. Many important database objects are stored in the SYSTEM tablespace. There must be one rollback segment in the SYSTEM tablespace for Oracle to acquire at database startup. Both have many powerful privileges and should be used carefully for administrative tasks on the database. Of the disk resources created. When archivelog is used. perhaps 250K for even a large database. In the interests of preserving the integrity of the Oracle database. but some important logical disk resources are created as well. Adding more datafiles and redo logs increases the size of a control file. As its name implies. This parameter is a keyword specified in the create database statement. the one most central to database operation is the control file. the control file identifies all other disk resources to the Oracle database. up to a total size specified by the maxsize keyword. Oracle archives the redo logs generated. which are designed to allow for performing important activities required throughout the life of a database. Some of those objects are the Oracle data dictionary and rollback segments. the maxdatafiles parameter indicates the maximum number of datafiles a database can have. If information about a datafile or redo log file is not contained in the control file for the database. In general.A new database is created by Oracle with several important features. the datafiles will automatically allocate more space when the datafile fills. Oracle will overwrite them. The SYSTEM tablespace certainly is a tablespace in the Oracle system that is HIGHLY important to the operation of the Oracle database. This parameter can be a potential limitation later when the database grows to a point where it cannot accommodate another datafile because the maxdatafiles parameter would be exceeded. The controlfile reuse clause is included in the create database statement to allow Oracle to reuse the file specified if it already exists. BEWARE OF REUSING CONTROL FILES. and furthermore. and the DBA will not be able to recover it if the disk containing it is lost. The names of the two users created by Oracle are SYS and SYSTEM. The datafiles are specified with the datafile clause. the password for SYS is CHANGE_ON_INSTALL. or else the database won’t start. the database will not know about it. then Oracle will overwrite that file with the data for the new redo log member or datafile for the database being created. The final and most important option included in the create database statement is the archivelog option. fewer datafiles that grow larger with the autoextend option and fewer redo logs decrease the size of control files. the DBA should remember that when the users SYS and SYSTEM are created. care should be taken when reusing files in order to prevent "accidental reuse" in a situation where a database already exists on the machine and the DBA creates another one that overwrites key files on the first database. The first item to remember about database creation is that the database will be created with two special users. and they are where Oracle physically stores the data in any and all tablespaces. An existing database will need recovery if its control file is overwritten by the creation of another database. and the password for SYSTEM is MANAGER. Control files are generally not very large. if is not used and the create database statement includes files that already exist. This feature should be enabled in all but read only databases. Not only are physical database resources and database administrative passwords created as part of the create database command.

which is used to process large-volume data loads from one system to another. catldr.sql Creates the SYS. along with special public synonyms for those views. Within the catalog. it is recommended to place the rest of the rollback segments available to the database in a special tablespace designed only to hold rollback segments. 3. The code for creating these dictionary views is not contained in catproc. discussed in the unit covering OCP Exam 3. the DBA will find the further allocation of rollback segments in addition to the rollback segment in the SYSTEM tablespace to be an important initial consideration on creating the database. such as tables. Also. Generally. Once the database is created. What resources are created as part of the creation of a database? What is the SYSTEM tablespace? What is its significance? What is a parameter file? What are some of the parameters a DBA must set uniquely for any database via the parameter file? Creating the Oracle Data Dictionary The data dictionary is the first database object created at the time a create database command is issued. Name some of the steps in creating a new Oracle database. The code that actually creates the objects is in several scripts called by this master . which tracks all audit trail information generated by Oracle when the auditing feature of the database is used. which are listed below: cataudit. Finally.AUD$ dictionary table. This script calls several other scripts in the process of creating several different data dictionary components used in everything procedural related to the Oracle database. After database creation. 2. Like DB_BLOCK_SIZE.sql.sql Creates views that are used for the SQL*Loader tool. "Database Backup and Recovery.SQL script.sql.sql script there are calls to several other scripts.sql Creates views that are used by the IMPORT/EXPORT utilities. the create database command specifies the character set used throughout the database. Some areas that the DBA may want to address right away are placement of redo logs and datafiles and the separation of tables from their corresponding indexes. the database that was just created is mounted and opened directly by Oracle for the DBA to begin placing data objects into it. catalog.sql and catproc." The other script generally run by the Oracle database when the data dictionary is created is the CATPROC. Oracle generally creates the data dictionary without any intervention from the DBA at database creation time with the use of catalog. and rollback segments. discussed later in this unit. Every object in the database is tracked in some fashion by the Oracle data dictionary. no data objects such as tables or indexes should be placed in the SYSTEM tablespace. runs a series of other scripts in order to create all the data dictionary views. Exercises 1.sql. The first script. indexes. the character set specified for the database should not be changed at any point after the database is created. catexp.rollback segments are placed in the SYSTEM tablespace. In particular. the DBA should consider some preliminary work on distributing the I/O load in order to simplify the maintainability of the database in the future.

Some of the objects created by the scripts called by catproc. DBWR moves data blocks out of the buffer cache. RECO and LCKn handle transaction processing on distributed database configurations. The next area covered by the chapter was on how to start the Oracle instance. disk resources. consists of a minimum of three components: the data block buffer cache. How is the data dictionary created? What two scripts are used as part of database creation? Chapter Summary This chapter covered introductory material related to Oracle database administration. or handle activities in the background on Oracle’s behalf. archiver (ARCH). The SGA. log writer (LGWR). or shared between many processes in the MTS architecture. The material in this chapter comprises about 22 percent of questions asked on OCP Exam 2. control files. The first area of discussion in this chapter was an overview of the various components of the Oracle database. The topics covered in this chapter included an overview of the Oracle architecture.sql are stored procedures. Before starting the instance. or both. Several memory structures exist on the Oracle database to improve performance on various areas of the database. segments. ARCH handles the automatic archiving of online redo log files. in turn. and certain utilities for PL/SQL constructs like alerts. SMON handles instance recovery at startup in the event of a failure. These disk resources are divided into two categories: physical resources and logical resources. The factors that weigh on that choice are whether the DBA wants to use remote administration via network or local administration directly on the . Server processes read data into the buffer cache on behalf of user processes. triggers. Exercises 1. The logical resources are tablespaces. packages.script. These different processes have functions that are related to activities that happen regularly in Oracle against the memory structures. mail. The options available are operating system authentication and Oracle authentication. and the tasks required for creating an Oracle database. dispatcher (Dnnn). Tying memory structures and disk resources together are several memory processes that move data between disk and memory. The core background processes available on the Oracle instance include data block writer (DBWR). memory structures. password files. and disk resources that comprise the Oracle instance. the appropriate cleanup activity and rollback occurs. checkpoint (CKPT). the shared pool. Corresponding to several of these memory areas are certain disk resources. snapshots. redo log files. recoverer (RECO). Figure 6-1 gives a clear idea of the background processes. and pipes. 2. locks. the DBA must figure out what sort of database authentication to use both for users and administrators. making large continuous free disk space out of smaller empty fragments. system monitor (SMON). Dnnn are dispatchers used to route user processes to a shared server in MTS configurations. and extents. and periodically sifts through tablespaces. PMON ensures that if a user process fails. and server (Snnn). They can either be dedicated to one user process. and also of the methods in which they act together to allow users to access information. The physical disk resources on the Oracle database are datafiles. lock (LCKn). the process of starting and stopping access to a database and to an Oracle instance. CKPT handles writing new redo log number information to datafiles and control files in the database at periodic intervals during the time the database is open. and the redo log buffer. The memory structures of an Oracle instance include the System Global Area (SGA) and the Program Global Area (PGA). process monitor (PMON). LGWR writes redo log entries out of the redo log buffer and into the online redo log. and parameter files.

The final option for shutting down a database is shutdown abort. a DBA must be granted certain privileges. and opens it for general user access. The open option starts the instance. When the DBA shuts down the database with the normal option. the SYSTEM tablespace. which disconnects current sessions without rolling back their transactions and prevents new connections to the database as well. The force option gives the database startup procedure some extra pressure to assist in starting an instance that either has trouble opening or trouble closing normally. Several options exist for shutting down the database as well. In order to start a database instance. The restrict option starts the instance. the DBA can then begin the work of creating the database. The mount option starts the instance and mounts but does not open the database. and the Oracle data dictionary for that database. To have database administrator privileges on the database. LICENSE_MAX_USERS. The final area covered in this chapter was the creation of a database. DB_BLOCK_BUFFERS. DB_BLOCK_SIZE. the database refuses new connections to the database by users and waits for existing connections to terminate. then the DBA must create a password file using the ORAPWD utility. After the parameter file is created. immediate. The next thing that should happen is the DBA should create a parameter file that is unique to the database being created. LICENSE_MAX_SESSIONS. recover. If the DBA chooses to use Oracle authentication. . They are called sysdba and sysoper in environments where Oracle authentication is used. The password file itself is protected by a password. ROLLBACK_SEGMENTS. The steps of database creation were discussed. and redo log files. and osdba or osoper where operating system authentication is used. LICENSE_MAX_WARNING. then the shutdown normal will complete. The first area covered was the process modeling that takes place when the database designer creates the entity-relationship diagram. The DBA issuing a shutdown immediate causes Oracle to prevent new connections while also terminating current ones. the DBA should back up existing databases associated with the instance. They are DB_NAME. open. After developing a model of the process to be turned into a database application. mounts the database. Once the last user has logged off the system. the designer of the application must then give a row count forecast for the application’s tables. The physical resources are datafiles. control files. and opens it for users who have been granted a special access privilege called restricted access. the SYS and SYSTEM users. restrict. in order to prevent data loss or accidental deletion of a disk file resource. Once this sizing is complete. There are two alter database statements that can be used to change database accessibility once the instance is started as well. The DBA must again connect to the database as internal using the Server Manager tool. the DBA must run Server Manager and connect to the database as internal. which creates all physical disk resources for the Oracle database. but leaves the database closed and starts the database recovery procedures associated with disk failure. the DBA can execute the create database command. it is recommended that the DBA back up the new database in order to avoid having to re-create the database from scratch in the event of a system failure. and force. They are nomount. one rollback segment in the SYSTEM tablespace.machine running Oracle. and this password is the same as the one used for authentication as user SYS and when connecting as internal. The command to start the instance from Server Manager is called startup. and abort. This row count forecast allows the DBA to size the amount of space in bytes that each table and index needs in order to store data in the database. First. After creating the database. mount. rolling back whatever transactions were taking place in the sessions just terminated. The recover option starts the instance. PROCESSES. if any. DB_DOMAIN. The nomount option starts the instance without mounting a corresponding database. The three options for shutting down the Oracle database are normal. There are several different options for starting the instance. mounts the database. Several initialization parameters were identified as needing to be set to create a database.

Two-Minute Drill Three major components of the Oracle architecture are memory structures that improve database performance. LGWR writes redo log entries between redo log buffer and online redo log on disk. . The first is catalog. rollback segments. disk resources that store Oracle data. and defragments small free spaces in tablespaces into larger ones. This script runs several other scripts that create everything required in the data dictionary to allow procedural blocks of code in the Oracle database. The storage of these logical disk resources is handled with segments and extents. password files to store passwords for DBAs when Oracle authentication is used. CKPT writes redo log sequence numbers to datafiles and control files when enabled. rollback segments. and background processes that handle disk writes and other time-consuming tasks in the background. The second is called catproc. It also writes redo log sequence numbers to datafiles and control files at checkpoints (also handled by CKPT when enabled) and tells DBWR to write dirty buffers to disk. triggers. This creation process happens automatically by Oracle. which are conglomerations of data blocks.sql. Disk resources in the Oracle architecture are divided into physical and logical categories. and datafiles that store tables. Physical disk resources are control files that store the physical layout of database. procedures. PMON monitors user processes and cleans up the database transactions in the event that they fail. The SGA consists of: the buffer cache for storing recently accessed data blocks. SMON automatically handles instance recovery at startup when necessary. namely packages. Logical disk resources are tablespaces for storing tables. redo log files that store redo entries on disk. There are two "master" scripts that everything else seems to hang off of. Several scripts are run in order to create the tables and views that comprise the data dictionary. The data dictionary must be created first in a database because all other database structure changes will be recorded in the data dictionary. This script creates all the data dictionary tables that document the various objects on the database. snapshots.sql.Of particular importance in the database creation process is the process by which the data dictionary is created. and the data dictionary. The fundamental unit of storage in a datafile is the data block. the data dictionary. Memory structures in the Oracle architecture are System Global Area (SGA) and Program Global Area (PGA). the redo log buffer for storing redo entries until they can be written to disk. DBWR writes data blocks back and forth between disk and the buffer cache. parameter files. indexes. and shared pool for storing parsed information about recently executed SQL for code sharing. This task can also be handled by LGWR. and certain packages for PL/SQL such as pipes and alerts. indexes. functions.

may connect to the database. When a database is open. There are two roles DBAs require to perform their function on the database. but existing sessions may take as long as they want to wrap up. Snnn (server process) reads data from disk on the database on behalf of the user process. Options available for alter database are mount. any user with a username and password. existing sessions are terminated.ARCH handles archiving of online redo logs automatically when set up. and their transactions rolled back. To start and stop a database. Under OS authentication. but restrict access to those users with restricted session privilege granted to them. and begin recovery for disk failure scenario. open. shutdown immediate—no new connections allowed. the privileges are called osdba and osoper. the DBA must create a password file using the ORAPWD utility. Startup restrict Start instance. To use Oracle authentication. Two user authentication methods exist in Oracle: operating system authentication and Oracle authentication. shutdown abort—no new . RECO resolves in-doubt transactions on distributed database environments. There are three options for closing a database: shutdown normal—no new existing connections allowed. the DBA must connect as internal or sysdba. mount and open database. Startup force Make an instance start that is having problems either starting or stopping. Closing or shutting down a database must be done by the DBA while running Server Manager and while the DBA is connected to the database as internal or sysdba. Startup recover Start instance. The tool used to start and stop the database is called Server Manager. leave database closed. There are at least six different options for starting a database: Startup nomount Start instance. and enable (disable) restricted session. LCKn obtains locks on remote databases. Startup open Start instance. The database availability can be changed at any time using the alter database command. mount and open database. Startup mount Start instance. Dnnn receives user processes from SQL*Net listener in multithreaded server (MTS) environments. do not mount a database. they are called sysdba and sysoper. mount but do not open the database. with the create session privilege or the CONNECT role granted to them. In Oracle authentication environments.

including the following: DB_NAME The local name for the database. the DBA should create a parameter file with unique values for several parameters. LICENSE_MAX_SESSIONS and LICENSE_MAX_WARNING are used for license tracking or LICENSE_MAX_USERS is used. DB_DOMAIN The network-wide location for the database. . Instance recovery is required after shutdown abort is used. DB_BLOCK_SIZE The size of each block in the database. The next step in creating a database is to back up any existing databases associated with the instance. On conclusion of the create database statement. LICENSE_MAX_USERS The maximum number of users that can be created in the Oracle instance. The default password for SYS is CHANGE_ON_INSTALL. The default password for SYSTEM is MANAGER. usually. The number of datafiles and redo log files created for the life of the database can be limited with the maxdatafiles and maxlogfiles options of the create database statement. bot not both. as well as the SYS and SYSTEM users.connections allowed. PROCESSES The maximum number of processes available on the database. which creates all physical database structures in the database. LICENSE_MAX_WARNING The sessions trying to connect above the number specified by this parameter will receive a warning message. ROLLBACK_SEGMENTS Named rollback segments that the database must acquire at startup. the DBA executes the create database command. transactions are not rolled back. unless the autoextend option is used. the database is created and open. This task is done first to capture the other database objects that are created in the database. The first step in creation of a database is to model the process that will be performed by the database application. After creating the parameter file. LICENSE_MAX_SESSIONS The maximum number of sessions that can connect to the database. DB_BLOCK_BUFFERS The number of blocks stored in the buffer cache. along with logical database structures like SYSTEM and an initial rollback segment. After that. The size of a datafile is fixed. The create database command also creates the Oracle data dictionary for that database. existing sessions are terminated.

procedures.The size of a control file is directly related to the number of datafiles and redo logs for the database. triggers.sql Creates all data dictionary tables and views that track database objects like tables. and special utility PL/SQL packages such as those used to manage pipes. snapshots. functions.sql Creates dictionary views for all procedural aspects of Oracle. locks. catproc. At least two scripts are used create the database: catalog. etc. . and rollback segments. indexes. alerts. like PL/SQL packages.