what is different between truncate and delete

86
What is different between TRUNCATE and DELETE? The Delete command will log the data changes in the log file where as the truncate will simply remove the data without it. Hence Data removed by Delete command can be rolled back but not the data removed by TRUNCATE. Truncate is a DDL statement whereas DELETE is a DML statement What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function? 1000000 Can you use a commit statement within a database trigger? Yes, if you are using autonomous transactions in the Database triggers. What is an UTL_FILE? What are different procedures and functions associated with it? The UTL_FILE package lets your PL/SQL programs read and write operating system (OS) text files. It provides a restricted version of standard OS stream file input/output (I/O). Subprogram -Description FOPEN function-Opens a file for input or output with the default line size. IS_OPEN function -Determines if a file handle refers to an open file. FCLOSE procedure -Closes a file. FCLOSE_ALL procedure -Closes all open file handles. GET_LINE procedure -Reads a line of text from an open file. NEW_LINE procedure-Writes one or more OS-specific line terminators to a file. FFLUSH procedure-Physically writes all pending output to a file. FOPEN function -Opens a file with the maximum line size specified. What are between database triggers and form triggers?

Upload: dev-annup

Post on 22-Nov-2014

117 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: What is Different Between TRUNCATE and DELETE

What is different between TRUNCATE and DELETE?

The Delete command will log the data changes in the log file where as the truncate will simply remove the data without it. Hence Data removed by Delete command can be rolled back but not the data removed by TRUNCATE. Truncate is a DDL statement whereas DELETE is a DML statement

What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?

1000000

Can you use a commit statement within a database trigger?

Yes, if you are using autonomous transactions in the Database triggers.

What is an UTL_FILE? What are different procedures and functions associated with it?

The UTL_FILE package lets your PL/SQL programs read and write operating system (OS) text files. It provides a restricted version of standard OS stream file input/output (I/O).Subprogram -DescriptionFOPEN function-Opens a file for input or output with the default line size.IS_OPEN function -Determines if a file handle refers to an open file.FCLOSE procedure -Closes a file.FCLOSE_ALL procedure -Closes all open file handles.GET_LINE procedure -Reads a line of text from an open file.NEW_LINE procedure-Writes one or more OS-specific line terminators to a file.FFLUSH procedure-Physically writes all pending output to a file.FOPEN function -Opens a file with the maximum line size specified.

What are between database triggers and form triggers?

Database triggers are fired whenever any database action like INSERT, UPATE, DELETE, LOGON LOGOFF etc occurs. Form triggers on the other hand are fired in response to any event that takes place while working with the forms, say like navigating from one field to another or one block to another and so on.

What is OCI. What are its uses?

OCI is Oracle Call Interface. When applications developers demand the most powerful interface to the Oracle Database Server, they call upon the Oracle Call Interface (OCI). OCI provides the most comprehensive access to all of the Oracle Database functionality. The newest performance, scalability, and security features appear first in the OCI API. If you write applications for the Oracle Database, you likely already depend on OCI. Some types of applications that depend upon OCI are:

Page 2: What is Different Between TRUNCATE and DELETE

· PL/SQL applications executing SQL· C++ applications using OCCI· Java applications using the OCI-based JDBC driver· C applications using the ODBC driver· VB applications using the OLEDB driver· Pro*C applications· Distributed SQL

What are ORACLE PRECOMPILERS?

A precompiler is a tool that allows programmers to embed SQL statements in high-level source programs like C, C++, COBOL, etc. The precompiler accepts the source program as input, translates the embedded SQL statements into standard Oracle runtime library calls, and generates a modified source program that one can compile, link, and execute in the usual way. Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java etc.

What is syntax for dropping a procedure and a function? Are these operations possible?

Drop Procedure/Function ; yes, if they are standalone procedures or functions. If they are a part of a package then one have to remove it from the package definition and body and recompile the package.

What Is Oracle?

Oracle is a company. Oracle is also a database server, which manages data in a very structured way. It allows users to store and retrieve related data in a multiuser environment so that many users can concurrently access the same data. All this is accomplished while delivering high performance. A database server also prevents unauthorized access and provides efficient solutions for failure recovery.

What Is an Oracle Database?

An Oracle database is a collection of data treated as a big unit in the database server.

What Is an Oracle Instance?

Every running Oracle database is associated with an Oracle instance. When a database is started on a database server (regardless of the type of computer), Oracle allocates a memory area called the System Global Area (SGA) and starts one or more Oracle processes. This combination of the SGA and the Oracle processes is called an Oracle instance. The memory and processes of an instance manage the associated database's data efficiently and serve the one or multiple users of the database.

Page 3: What is Different Between TRUNCATE and DELETE

What Is a Parameter File?

A parameter file is a file that contains a list of initialization parameters and a value for each parameter. You specify initialization parameters in a parameter file that reflect your particular installation. Oracle supports the following two types of parameter files:

Server Parameter Files - Binary version. Persistent. Initialization Parameter Files - Text version. Not persistent.

What Is a Server Parameter File?

A server parameter file is a binary file that acts as a repository for initialization parameters. The server parameter file can reside on the machine where the Oracle database server executes. Initialization parameters stored in a server parameter file are persistent, in that any changes made to the parameters while an instance is running can persist across instance shutdown and startup.

What Is a Initialization Parameter File?

An initialization parameter file is a text file that contains a list of initialization parameters. The file should be written in the client's default character set. Sample initialization parameter files are provided on the Oracle distribution medium for each operating system. A sample file is sufficient for initial use, but you will probably want to modify the file to tune the database for best performance. Any changes will take effect after you completely shut down and restart the instance.

What is System Global Area (SGA)?

The SGA is a chunk of memory that is allocated by an Oracle Instance (during the nomount stage) and is shared among Oracle processes, hence the

name. It contains all sorts of information about the instance and the database that is needed to operate.The SGA is allocated in memory when an Oracle database instance is started, and any change in the value will take effect at the next startup.

What is PGA?

The PGA (Program or Process Global Area) is a memory area (RAM) that stores data and control information for a single process. When you start a user process, that process has a private RAM area, used for sorting SQL results and managing special joins called “hash” joins. This private RAM is known as the Program Global Area (PGA). Each individual PGA memory area is allocated each time a new user connects to the database.

What Is a User Account?

A user account is defines the user's attributes AND identified by a user name, including the following

Page 4: What is Different Between TRUNCATE and DELETE

Password for database authentication Privileges and roles Default tablespace for database objects Default temporary tablespace for query processing work space

What Is the Relation of a User Account and a Schema?

User accounts and schemas have a one-to-one relation. When you create a user, you are also implicitly creating a schema for that user. A schema is a logical container for the database objects (such as tables, views, triggers, and so on) that the user creates. The schema name is the same as the user name, and can be used to unambiguously refer to objects owned by the user.

What Is a User Role?

A user role is a group of privileges. Privileges are assigned to users through user roles. You create new roles, grant privileges to the roles, and then grant roles to users.

What is a Database Schema?

A schema is a collection of logical structures of data, or schema objects. A schema is owned by a database user and has the same name as that user. Each user owns a single schema. Schema objects can be created and manipulated with SQL and include: tables, views, and other types of data objects.

What Is a Database Table?

A database table is a basic unit of data logical storage in an Oracle database. Data is stored in rows and columns. You define a table with a table name, such as employees, and a set of columns. You give each column a column name, such as employee_id, last_name, and job_id; a datatype, such as VARCHAR2, DATE, or NUMBER; and a width. The width can be predetermined by the datatype, as in DATE. If columns are of the NUMBER datatype, define precision and scale instead of width. A row is a collection of column information corresponding to a single record.

What Is a Table Index?

Index is an optional structure associated with a table that allow SQL statements to execute more quickly against a table.

Page 5: What is Different Between TRUNCATE and DELETE

What Is an Oracle Tablespace?

A tablespace is a logical storage unit - multiple application objects can be stored in one tablespace. A database can contain multiple tablespaces. Each tablespace in an Oracle database consists of one or more files called datafiles,

What Is an Oracle Data File?

An Oracle data file is a big unit of physical storage in the OS file system. One or many Oracle data files are organized together to provide physical storage to a single Oracle tablespace.

What Is a Static Data Dictionary?

Data dictionary tables are not directly accessible, but you can access information in them through data dictionary views. To list the data dictionary views available to you, query the view DICTIONARY. Many data dictionary tables have three corresponding views:

An ALL_ view displays all the information accessible to the current user, including information from the current user's schema as well as information from objects in other schemas, if the current user has access to those objects by way of grants of privileges or roles.

A DBA_ view displays all relevant information in the entire database. DBA_ views are intended only for administrators. They can be accessed only by users with the SELECT ANY TABLE privilege. This privilege is assigned to the DBA role when the system is initially installed.

A USER_ view displays all the information from the schema of the current user. No special privileges are required to query these views.

What Is a Dynamic Performance View?

Dynamic performance views, or "V$" views, are useful for identifying instance-level performance problems. All V$ views are listed in the V$FIXED_TABLE view. These views are called dynamic performance views because they are continuously updated while a database is open and in use, and their contents relate primarily to performance.You can select from these views, but you can never update or alter them.

What Is a Recycle Bin?

Recycle bin is a logical storage to hold the tables that have been dropped from the database, in case it was dropped in error. Tables in recycle bin can be recovered back into database by the Flashback Drop action. Oracle database recycle save the same purpose as the recycle bin on your Windows desktop.

Page 6: What is Different Between TRUNCATE and DELETE

Recycle bin can be turned on or off in the recyclebin=on/off in your parametere file.

What Is SQL*Plus?

SQL*Plus is an interactive and batch query tool that is installed with every Oracle Database Server or Client installation. It has a command-line user interface, a Windows Graphical User Interface (GUI) and the iSQL*Plus web-based user interface.

What Is Transport Network Substrate (TNS)?

TNS, Transport Network Substrate, is a foundation technology, built into the Oracle Net foundation layer that works with any standard network transport protocol.

What Is Open Database Communication (ODBC)?

ODBC, Open Database Communication, a standard API (application program interface) developed by Microsoft for Windows applications to communicate with database management systems.

Oracle offers ODBC drivers to allow Windows applications to connect Oracle server through ODBC.

TABLESPACE AND DATAFILE

What Is an Oracle Tablespace?

An Oracle tablespace is a big unit of logical storage in an Oracle database. It is managed and used by the Oracle server to store structures data objects, like tables and indexes.

What Is an Oracle Data File?

An Oracle data file is a big unit of physical storage in the OS file system. One or many Oracle data files are organized together to provide physical storage to a single Oracle tablespace.

How a Tablespace Is Related to Data Files?

Each tablespace in an Oracle database consists of one or more files called datafiles, which are physical structures that conform to the operating system in which Oracle is running.

How a Database Is Related to Tablespaces?

A database's data is collectively stored in the datafiles that constitute each tablespace of the database. For example, the simplest Oracle database would have one tablespace and one datafile. Another database can have three tablespaces, each consisting of two datafiles (for a total of six datafiles).

Page 7: What is Different Between TRUNCATE and DELETE

How To View the Tablespaces in the Current Database?

If you want to get a list of all tablespaces used in the current database instance, you can use the DBA_TABLESPACES view as shown in the following SQL script example:

SQL> connect SYSTEM/fyicenterConnected.

SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS 2 FROM USER_TABLESPACES;TABLESPACE_NAME STATUS CONTENTS------------------------------ --------- ---------SYSTEM ONLINE PERMANENTUNDO ONLINE UNDOSYSAUX ONLINE PERMANENTTEMP ONLINE TEMPORARYUSERS ONLINE PERMANENT

What Are the Predefined Tablespaces in a Database?

When you create a new database, Oracle server will create 4 required tablespaces for the new database:

SYSTEM Tablespace - Every Oracle database contains a tablespace named SYSTEM, which Oracle creates automatically when the database is created. The SYSTEM tablespace is always online when the database is open.

SYSAUX Tablespace - The SYSAUX tablespace was installed as an auxiliary tablespace to the SYSTEM tablespace when you created your database. Some database components that formerly created and used separate tablespaces now occupy the SYSAUX tablespace.

UNDO Tablespace - UNDO tablespaces are special tablespaces used solely for storing undo information. You cannot create any other segment types (for example, tables or indexes) in undo tablespaces. Each database contains zero or more undo tablespaces. In automatic undo management mode, each Oracle instance is assigned one (and only one) undo tablespace. Undo data is managed within an undo tablespace using undo segments that are automatically created and maintained by Oracle.

TEMP Tablespace - When the SYSTEM tablespace is locally managed, you must define at least one default temporary tablespace when creating a database. A locally managed SYSTEM tablespace cannot be used for default temporary storage.

How To View the Data Files in the Current Database?

If you want to get a list of all tablespaces used in the current database instance, you can use the DBA_TABLESPACES view as shown in the following SQL script example:

SQL> connect SYSTEM/fyicenterConnected.

SQL> col tablespace_name format a16;SQL> col file_name format a36;SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES

Page 8: What is Different Between TRUNCATE and DELETE

2 FROM DBA_DATA_FILES;TABLESPACE_NAME FILE_NAME BYTES--------------- ------------------------------- ---------USERS \ORACLEXE\ORADATA\XE\USERS.DBF 104857600SYSAUX \ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440UNDO \ORACLEXE\ORADATA\XE\UNDO.DBF 94371840SYSTEM \ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840

How To Create a new Oracle Data File?

There is no dedicated statement to create a data file. Data files are created as part of statements that manages other data structures, like tablespace and database.

How To Create a New Tablespace?

If you want a new dataspace, you can use the CREATE TABLESPACE ... DATAFILE statement as shown in the following script:

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS 2 FROM USER_TABLESPACES;TABLESPACE_NAME STATUS CONTENTS---------------- --------------- ---------SYSTEM ONLINE PERMANENTUNDO ONLINE UNDOSYSAUX ONLINE PERMANENTTEMP ONLINE TEMPORARYUSERS ONLINE PERMANENTMY_SPACE ONLINE PERMANENT

SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES 2 FROM DBA_DATA_FILES;TABLESPACE_NAME FILE_NAME BYTES--------------- -------------------------------- ---------USERS \ORACLEXE\ORADATA\XE\USERS.DBF 104857600SYSAUX \ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440UNDO \ORACLEXE\ORADATA\XE\UNDO.DBF 94371840SYSTEM \ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840MY_SPACE \TEMP\MY_SPACE.DBF 10485760

So one statement created two structures: a tablespace and a data file. If you check your file system with Windows file explorer, you will see the data file is located in the \temp directory of. The data file size is about 10MB. Its contents should be blank and full of \x00 at this time.

How To Rename a Tablespace?

You can easily rename a tablespace by using the ALTER TABLESPACE ... RENAME TO statement as shown in the example below:

Page 9: What is Different Between TRUNCATE and DELETE

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> ALTER TABLESPACE my_space RENAME TO your_space;Tablespace created.

SQL> SELECT TABLESPACE_NAME, STATUS, CONTENTS 2 FROM USER_TABLESPACES;TABLESPACE_NAME STATUS CONTENTS---------------- --------------- ---------SYSTEM ONLINE PERMANENTUNDO ONLINE UNDOSYSAUX ONLINE PERMANENTTEMP ONLINE TEMPORARYUSERS ONLINE PERMANENTYOUR_SPACE ONLINE PERMANENT

How To Drop a Tablespace?

If you have an existing tablespace and you don't want it anymore. You can delete a tablespace by using the DROP TABLESPACE statement as shown in the example below:

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> DROP TABLESPACE my_space;Tablespace dropped.

What Happens to the Data Files If a Tablespace Is Dropped?

If a tablespace is dropped, what happens to its data files? By default, data files will remain in OS file system, even if the tablespace they are mapped is dropped. Of course, you delete the data files using OS commands, if they are no longer needed.

Another way of deleting data files is to use the INCLUDING clause in the DROP TABLESPACE statement. Here is a SQL sample script:

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> DROP TABLESPACE my_space INCLUDING CONTENTS 2 AND DATAFILES;Tablespace dropped.

How To Create a Table in a Specific Tablespace?

Page 10: What is Different Between TRUNCATE and DELETE

After you have created a new tablespace, you can give it to your users for them to create tables in the new tablespace. To create a table in a specific tablespace, you need to use the TABLESPACE clause in the CREATE TABLE statement. Here is a sample script:

SQL> connect SYSTEM/fyicenterConnected.

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> connect HR/fyicenterConnected.

SQL> CREATE TABLE my_team TABLESPACE my_space 2 AS SELECT * FROM employees;Table created.

SQL> SELECT table_name, tablespace_name, num_rows 2 FROM USER_TABLES 3 WHERE tablespace_name in ('USERS', 'MY_SPACE');

TABLE_NAME TABLESPACE_NAME NUM_ROWS------------------------------ ---------------- ----------MY_TEAM MY_SPACE - EMPLOYEES USERS 107 ...

How To See Free Space of Each Tablespace?

One of the important DBA tasks is to watch the storage usage of all the tablespaces to make sure there are enough free space in each tablespace for database applications to function properly. Free space information can be monitored through the USER_FREE_SPACE view. Each record in USER_FREE_SPACE represents an extent, a contiguous area of space, of free space in a data file of a tablespace.

Here is SQL script example on how to see free space of a tablespace:

SQL> connect HR/fyicenterConnected.

SQL> SELECT TABLESPACE_NAME, FILE_ID, BYTES 2 FROM USER_FREE_SPACE 3 WHERE TABLESPAE_NAME IN ('USERS', 'MY_SPACE');TABLESPACE_NAME FILE_ID BYTES------------------------------ ---------- ----------MY_SPACE 5 10354688USERS 4 101974016USERS 4 65536USERS 4 65536USERS 4 65536USERS 4 65536USERS 4 65536

Page 11: What is Different Between TRUNCATE and DELETE

USERS 4 65536USERS 4 65536USERS 4 65536USERS 4 65536USERS 4 65536USERS 4 65536USERS 4 65536

This tells us that:

MY_SPACE has a single free extent of 10MB. USERS has one big free extent of 100MB, and many small free extents of 64KB.

How To Bring a Tablespace Offline?

If you want to stop users using a tablespace, you can bring it offline using the ALTER TABLESPACE ... OFFLINE statement as shown in the following script:

SQL> connect HR/fyicenterConnected.

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> ALTER TABLESPACE my_space OFFLINE NORMAL;Tablespace altered.

How To Bring a Tablespace Online?

If you have brought a tablespace offline, now you want to make it available to users again, you can use the ALTER TABLESPACE ... ONLINE statement as shown in the following script:

SQL> connect HR/fyicenter

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> ALTER TABLESPACE my_space OFFLINE NORMAL;Tablespace altered.

...

SQL> ALTER TABLESPACE my_space ONLINE;Tablespace altered.

How To Add Another Datafile to a Tablespace?

Page 12: What is Different Between TRUNCATE and DELETE

If you created a tablespace with a data file a month ago, now 80% of the data file is used, you should add another data file to the tablespace. This can be done by using the ALTER TABLESPACE ... ADD DATAFILE statement. See the following sample script:

SQL> connect HR/fyicenter

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> ALTER TABLESPACE my_space 2 DATAFILE '/temp/my_space_2.dbf' SIZE 5M;Tablespace altered.

SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES 2 FROM DBA_DATA_FILES;TABLESPACE_NAME FILE_NAME BYTES--------------- --------------------------------- ---------USERS C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600SYSAUX C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440UNDO C:\ORACLEXE\ORADATA\XE\UNDO.DBF 94371840SYSTEM C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840MY_SPACE C:\TEMP\MY_SPACE.DBF 10485760MY_SPACE C:\TEMP\MY_SPACE_2.DBF 5242880

SQL> SELECT TABLESPACE_NAME, FILE_ID, BYTES 2 FROM USER_FREE_SPACE 3 WHERE TABLESPAE_NAME IN ('MY_SPACE');TABLESPACE_NAME FILE_ID BYTES------------------------------ ---------- ----------MY_SPACE 6 5177344MY_SPACE 5 10354688

This script created one tablespace with two data files.

What Happens If You Lost a Data File?

After you shuting down an Oracle database, you accidently deleted a data file from the operating system. If you try to start the database again you will get error when Oracle tries to open the database after mounting the database. The following tutorial examples shows you what will happen if the data file c:\temp\my_space.dbf is deleted. Oracle can still start the database instance and mount the database. But it will fail on openning the database as shown below in a SQL*Plus session:

>sqlplus /nolog

SQL> connect SYSTEM/fyicenter AS SYSDBA

SQL> STARTUPORACLE instance started.

Total System Global Area 100663296 bytesFixed Size 1285956 bytes

Page 13: What is Different Between TRUNCATE and DELETE

Variable Size 58720444 bytesDatabase Buffers 37748736 bytesRedo Buffers 2908160 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 5 - see DBWR trace fileORA-01110: data file 5: 'C:\TEMP\MY_SPACE.DBF'

SQL> SHUTDOWN;ORA-01109: database not openDatabase dismounted.ORACLE instance shut down.

How Remove Data Files befor opening a Database?

Let's say you have a corrupted data file or lost a data file. Oracle can mount the database. But it will not open the database. What you can do is to set the bad data file as offline befor opening the database. The tutorial exercise shows you how to set two data files offline and open the database without them:

>sqlplus /nolog

SQL> connect SYSTEM/fyicenter AS SYSDBA

SQL> STARTUP MOUNT;ORACLE instance started.

Total System Global Area 100663296 bytesFixed Size 1285956 bytesVariable Size 58720444 bytesDatabase Buffers 37748736 bytesRedo Buffers 2908160 bytesDatabase mounted.

SQL> ALTER DATABASE DATAFILE '\temp\my_space.dbf' 2 OFFLINE DROP;Database altered.

SQL> ALTER DATABASE DATAFILE '\temp\my_space_2.dbf' 2 OFFLINE DROP;Database altered.

SQL> ALTER DATABASE OPEN;Database altered.

SQL> col file_name format a36;SQL> col tablespace_name format a16;SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES 2 FROM DBA_DATA_FILES;

TABLESPACE_NAME FILE_NAME BYTES--------------- --------------------------------- ---------USERS C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600SYSAUX C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 503316480UNDO C:\ORACLEXE\ORADATA\XE\UNDO.DBF 94371840

Page 14: What is Different Between TRUNCATE and DELETE

SYSTEM C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 367001600MY_SPACE C:\TEMP\MY_SPACE.DBFMY_SPACE C:\TEMP\MY_SPACE_2.DBF

How To Bring a Tablespace Online?

If you have brought a tablespace offline, now you want to make it available to users again, you can use the ALTER TABLESPACE ... ONLINE statement as shown in the following script:

SQL> connect HR/fyicenter

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> ALTER TABLESPACE my_space OFFLINE NORMAL;Tablespace altered.

...

SQL> ALTER TABLESPACE my_space ONLINE;Tablespace altered.

How To Add Another Datafile to a Tablespace?

If you created a tablespace with a data file a month ago, now 80% of the data file is used, you should add another data file to the tablespace. This can be done by using the ALTER TABLESPACE ... ADD DATAFILE statement. See the following sample script:

SQL> connect HR/fyicenter

SQL> CREATE TABLESPACE my_space 2 DATAFILE '/temp/my_space.dbf' SIZE 10M;Tablespace created.

SQL> ALTER TABLESPACE my_space 2 DATAFILE '/temp/my_space_2.dbf' SIZE 5M;Tablespace altered.

SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES 2 FROM DBA_DATA_FILES;TABLESPACE_NAME FILE_NAME BYTES--------------- --------------------------------- ---------USERS C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600SYSAUX C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 461373440UNDO C:\ORACLEXE\ORADATA\XE\UNDO.DBF 94371840SYSTEM C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 356515840MY_SPACE C:\TEMP\MY_SPACE.DBF 10485760MY_SPACE C:\TEMP\MY_SPACE_2.DBF 5242880

SQL> SELECT TABLESPACE_NAME, FILE_ID, BYTES 2 FROM USER_FREE_SPACE

Page 15: What is Different Between TRUNCATE and DELETE

3 WHERE TABLESPAE_NAME IN ('MY_SPACE');TABLESPACE_NAME FILE_ID BYTES------------------------------ ---------- ----------MY_SPACE 6 5177344MY_SPACE 5 10354688

This script created one tablespace with two data files.

What Happens If You Lost a Data File?

After you shuting down an Oracle database, you accidently deleted a data file from the operating system. If you try to start the database again you will get error when Oracle tries to open the database after mounting the database. The following tutorial examples shows you what will happen if the data file c:\temp\my_space.dbf is deleted. Oracle can still start the database instance and mount the database. But it will fail on openning the database as shown below in a SQL*Plus session:

>sqlplus /nolog

SQL> connect SYSTEM/fyicenter AS SYSDBA

SQL> STARTUPORACLE instance started.

Total System Global Area 100663296 bytesFixed Size 1285956 bytesVariable Size 58720444 bytesDatabase Buffers 37748736 bytesRedo Buffers 2908160 bytesDatabase mounted.ORA-01157: cannot identify/lock data file 5 - see DBWR trace fileORA-01110: data file 5: 'C:\TEMP\MY_SPACE.DBF'

SQL> SHUTDOWN;ORA-01109: database not openDatabase dismounted.ORACLE instance shut down.

How Remove Data Files befor opening a Database?

Let's say you have a corrupted data file or lost a data file. Oracle can mount the database. But it will not open the database. What you can do is to set the bad data file as offline befor opening the database. The tutorial exercise shows you how to set two data files offline and open the database without them:

>sqlplus /nolog

SQL> connect SYSTEM/fyicenter AS SYSDBA

SQL> STARTUP MOUNT;ORACLE instance started.

Page 16: What is Different Between TRUNCATE and DELETE

Total System Global Area 100663296 bytesFixed Size 1285956 bytesVariable Size 58720444 bytesDatabase Buffers 37748736 bytesRedo Buffers 2908160 bytesDatabase mounted.

SQL> ALTER DATABASE DATAFILE '\temp\my_space.dbf' 2 OFFLINE DROP;Database altered.

SQL> ALTER DATABASE DATAFILE '\temp\my_space_2.dbf' 2 OFFLINE DROP;Database altered.

SQL> ALTER DATABASE OPEN;Database altered.

SQL> col file_name format a36;SQL> col tablespace_name format a16;SQL> SELECT TABLESPACE_NAME, FILE_NAME, BYTES 2 FROM DBA_DATA_FILES;

TABLESPACE_NAME FILE_NAME BYTES--------------- --------------------------------- ---------USERS C:\ORACLEXE\ORADATA\XE\USERS.DBF 104857600SYSAUX C:\ORACLEXE\ORADATA\XE\SYSAUX.DBF 503316480UNDO C:\ORACLEXE\ORADATA\XE\UNDO.DBF 94371840SYSTEM C:\ORACLEXE\ORADATA\XE\SYSTEM.DBF 367001600MY_SPACE C:\TEMP\MY_SPACE.DBFMY_SPACE C:\TEMP\MY_SPACE_2.DBF

How To Use Windows User to Connect to the Server?

During the installation process, 10g XE will create a special Windows user group called ORA_DBA, and put your Windows user into this group. Any Windows users in this group can be connected to Oracle server with SYSDBA privilege without any Oracle server user account. This process is called connecting the server as SYSDBA with OS Authentication. Here is how to do this with a special form of the "connect" command:

(Log in with the same user you used to install 10g XE)>cd (OracleXE home directory)>.\bin\startdb>.\bin\sqlplus /nolog

SQL> connect / AS SYSDBAConnected.

SQL> quit

So if "connect" is used without user name and password, the current Windows user will be trusted if he/she is in the ORA_DBA user group on the Windows system.

Page 17: What is Different Between TRUNCATE and DELETE

How To List All User Accounts?

User accounts can be accessed through a system view called ALL_USERS. A simple SELECT statement can be used to get a list of all user accounts. Try the following script:

>.\bin\sqlplus /nolog

SQL> connect SYSTEM/fyicenterConnected.

SQL> SELECT * FROM ALL_USERS;

USERNAME USER_ID CREATED------------------------------ ---------- ---------FLOWS_020100 35 07-FEB-06FLOWS_FILES 34 07-FEB-06HR 33 07-FEB-06MDSYS 32 07-FEB-06ANONYMOUS 28 07-FEB-06XDB 27 07-FEB-06CTXSYS 25 07-FEB-06DBSNMP 23 07-FEB-06TSMSYS 20 07-FEB-06DIP 18 07-FEB-06OUTLN 11 07-FEB-06SYSTEM 5 07-FEB-06SYS 0 07-FEB-06

How To Create a New User Account?

If you want to create a new user account, you can log in as SYSTEM and use the CREATE USER command as shown in the following example:

>.\bin\sqlplus /nolog

SQL> connect SYSTEM/fyicenterConnected.

SQL> CREATE USER DEV IDENTIFIED BY developer ACCOUNT UNLOCK;User created.

Note that CREATE is a SQL statement, so you need to terminate it with ";". This command creates a user called "DEV", with a password of "developer". You can test this account by log in with DEV from SQL*Plus.

How To Change User Password?

If you want to change a user's password, you can log in as SYSTEM and use the ALTER USER command as shown in the following example:

>.\bin\sqlplus /nolog

Page 18: What is Different Between TRUNCATE and DELETE

SQL> connect SYSTEM/fyicenterConnected.

SQL> ALTER USER DEV IDENTIFIED BY beginner;User altered.

Note that ALTER is SQL statement, so you need to terminate it with ";". This command resets DEV's password to "beginner".

How To Delete a User Account?

If you want to delete a user account and its associated schema, you can log in as SYSTEM and use the DROP USER command as shown in the following example:

>.\bin\sqlplus /nolog

SQL> connect SYSTEM/fyicenterConnected.

SQL> DROP USER DEV CASCADE;User dropped.

SQL> CREATE USER DEV IDENTIFIED BY developer ACCOUNT UNLOCK;User created.

Note that CASCADE tells the server drop the associated schema.

What Privilege Is Needed for a User to Connect to Oracle Server?

Oracle deny connection to users who has no CREATE SESSION privilege. Try the following tutorial exercise, you will find out how Oracle denies connection:

>.\bin\sqlplus /nologSQL> connect SYSTEM/fyicenter

SQL> CREATE USER DEV IDENTIFIED BY developer ACCOUNT UNLOCK;User created.

SQL> disconnectSQL> CONNECT DEV/developerORA-01045: user DEV lacks CREATE SESSION privilege; logon denied

Oracle error message is pretty clear.

How To Grant CREATE SESSION Privilege to a User?

If you want give a user the CREATE SESSION privilege, you can use the GRANT command. The following tutorial exercise shows you how to grant DEV the privilege to connect to the server:

Page 19: What is Different Between TRUNCATE and DELETE

>.\bin\sqlplus /nologSQL> connect SYSTEM/fyicenter

SQL> GRANT CREATE SESSION TO dev;Grant succeeded.

SQL> disconnectSQL> CONNECT DEV/developerConnected.

How To Revoke CREATE SESSION Privilege from a User?

If you take away the CREATE SESSION privilege from a user, you can use the REVOKE command as shown in the following example script:

>.\bin\sqlplus /nologSQL> connect SYSTEM/fyicenter

SQL> REVOKE CREATE SESSION FROM dev;Revoke succeeded.

SQL> GRANT CREATE SESSION TO dev;Grant succeeded.

This script restored the CREATE SESSION privilege to user "dev", so you can continue other example scripts below.

How To Lock and Unlock a User Account?

If you want to lock a user account for a short period of time, and unlock it later, you can use the ALTER USER ... ACCOUNT command. The following sample script shows how to use this command:

>.\bin\sqlplus /nologSQL> connect SYSTEM/fyicenter

SQL> ALTER USER dev ACCOUNT LOCK;User altered.

SQL> disconnectSQL> CONNECT DEV/developerORA-28000: the account is locked

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> ALTER USER dev ACCOUNT UNLOCK;User altered.

SQL> disconnectSQL> CONNECT DEV/developerConnected.

Page 20: What is Different Between TRUNCATE and DELETE

What Privilege Is Needed for a User to Create Tables?

To be able to create tables in a user's own schema, the user needs to have the CREATE TABLE privilege, or the CREATE ANY TABLE privilege, which is more powerful, and allows the user to create tables in other user's schema. The following tutorial exercise gives you a good example on CREATE TABLE privilege:

>.\bin\sqlplus /nologSQL> CONNECT DEV/developer

SQL> CREATE TABLE fyi (id NUMBER);ORA-01031: insufficient privileges

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> GRANT CREATE TABLE TO dev;Grant succeeded.

SQL> disconnectSQL> CONNECT DEV/developer

SQL> CREATE TABLE fyi (id NUMBER);ORA-01950: no privileges on tablespace 'SYSTEM'

The above error message tells that user "dev" is not allowed to use the tablespace "SYSTEM". See the next question for answers.

How To Assign a Tablespace to a Users?

When you create a new user, Oracle will assign the SYSTEM tablespace to the user by default. If you want to change this, you can assign a different table space to a user using the ALTER USER command. The following tutorial exercise changes user dev's default tablespace, and assigns 4MB of space to dev:

>.\bin\sqlplus /nologSQL> CONNECT DEV/developer

SQL> ALTER USER dev DEFAULT TABLESPACE USERS;User altered.

SQL> ALTER USER dev QUOTA 4M ON USERS;User altered.

SQL> disconnectSQL> CONNECT DEV/developer

SQL> CREATE TABLE fyi (id NUMBER);Table created.

SQL> DROP TABLE fyi;Table dropped.

Page 21: What is Different Between TRUNCATE and DELETE

SQL> CREATE TABLE fyi (id NUMBER);Table created.

As you can see, "dev" can create and drop tables now. You can also let "dev" to create tables in any tablespace without any restriction by granting him the UNLIMITED TABLESPACE system privilege.

What Privilege Is Needed for a User to Create Views?

To be able to create views in a user's own schema, the user needs to have the CREATE VIEW privilege, or the CREATE ANY VIEW privilege, which is more powerful, and allows the user to create views in other user's schema. The following tutorial exercise gives you a good example on CREATE VIEW privilege:

>.\bin\sqlplus /nologSQL> CONNECT DEV/developer

SQL> CREATE VIEW fyi_view AS SELECT * FROM fyi;ORA-01031: insufficient privileges

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> GRANT CREATE VIEW TO dev;Grant succeeded.

SQL> disconnectSQL> CONNECT DEV/developer

SQL> CREATE VIEW fyi_view AS SELECT * FROM fyi;View created.

SQL> DROP VIEW fyi_view;View dropped.

SQL> CREATE VIEW fyi_view AS SELECT * FROM fyi;View created.

As you can see, "dev" can create and drop views now.

What Privilege Is Needed for a User to Create Indexes?

For a user to create indexes, he/she needs the same privilege as the creating tables. Just make sure he/she has the CREATE TABLE privilege. The following tutorial exercise gives you a good example on creating view privilege:

>.\bin\sqlplus /nologSQL> connect SYSTEM/fyicenter

SQL> GRANT CREATE TABLE TO dev;Grant succeeded.

Page 22: What is Different Between TRUNCATE and DELETE

SQL> disconnectSQL> CONNECT DEV/developer

SQL> CREATE INDEX fyi_index ON fyi(id);Index created.

SQL> DROP INDEX fyi_index;Index dropped.

SQL> CREATE INDEX fyi_index ON fyi(id);Index created.

This exercise assumes that you followed previous exercises in the FAQ collection.

What Privilege Is Needed for a User to Query Tables in Another Schema?

For a user to run queries (SELECT statements) on tables of someone else's schema, he/she needs the SELECT ANY TABLE privilege. The following tutorial exercise gives you a good example of granting "dev" to query tables in "hr" schema:

>.\bin\sqlplus /nologSQL> CONNECT DEV/developer

SQL> SELECT COUNT(*) FROM hr.employees;ORA-01031: insufficient privileges

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> GRANT SELECT ANY TABLE TO dev;Grant succeeded.

SQL> disconnectSQL> CONNECT DEV/developer

SQL> SELECT COUNT(*) FROM hr.employees; COUNT(*)---------- 107

As you can see, "dev" can query tables in any schema now.

You also need to remember that table name must be prefixed with the schema name (same as owner user name).

What Privilege Is Needed for a User to Insert Rows to Tables in Another Schema?

For a user to insert rows into tables of someone else's schema, he/she needs the INSERT ANY TABLE privilege. The following tutorial exercise gives you a good example of granting "dev" to insert rows in "hr" schema:

>.\bin\sqlplus /nolog

Page 23: What is Different Between TRUNCATE and DELETE

SQL> CONNECT DEV/developer

SQL> INSERT INTO hr.jobs VALUES ('DV.FYI', 'Dev FYI Consultant', 7700, 8800);ORA-01031: insufficient privileges

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> GRANT INSERT ANY TABLE TO dev;Grant succeeded.

SQL> disconnectSQL> CONNECT DEV/developer

SQL> INSERT INTO hr.jobs VALUES ('DV.FYI', 'Dev FYI Consultant', 7700, 8800);1 row created.

As you can see, "dev" can insert rows in any schema now. But you should be careful when giving this privilege to a regular developer.

What Privilege Is Needed for a User to Delete Rows from Tables in Another Schema?

For a user to delete rows from tables of someone else's schema, he/she needs the DELETE ANY TABLE privilege. The following tutorial exercise gives you a good example of granting "dev" to delete rows in "hr" schema:

>.\bin\sqlplus /nologSQL> CONNECT DEV/developer

SQL> DELETE FROM hr.jobs WHERE job_id = 'DV.FYI';ORA-01031: insufficient privileges

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> GRANT DELETE ANY TABLE TO dev;Grant succeeded.

SQL> disconnectSQL> CONNECT DEV/developer

SQL> DELETE FROM hr.jobs WHERE job_id = 'DV.FYI';1 row deleted.

As you can see, "dev" can delete rows in any schema now. But you should be careful when giving this privilege to a regular developer.

How To Find Out What Privileges a User Currently Has?

Page 24: What is Different Between TRUNCATE and DELETE

Privileges granted to users are listed in two system views: DBA_SYS_PRIVS, and USER_SYS_PRIVS. You can find out what privileges a user currently has by running a query on those views as shown in the tutorial exercise below:

>.\bin\sqlplus /nologSQL> CONNECT DEV/developer

SQL> SELECT username, privilege FROM USER_SYS_PRIVS;USERNAME PRIVILEGE------------------------------ ----------------------DEV SELECT ANY TABLEDEV INSERT ANY TABLEDEV CREATE SESSIONDEV CREATE VIEWDEV DELETE ANY TABLEDEV CREATE ANY TABLE

SQL> disconnectSQL> connect SYSTEM/fyicenter

SQL> GRANT DELETE ANY TABLE TO dev;Grant succeeded.

SQL> SELECT GRANTEE, PRIVILEGE FROM DBA_SYS_PRIVS WHERE GRANTEE = 'HR';GRANTEE PRIVILEGE------------------------------ -----------------------HR CREATE VIEWHR UNLIMITED TABLESPACEHR DEBUG CONNECT SESSIONHR CREATE DATABASE LINKHR CREATE SEQUENCEHR CREATE SESSIONHR DEBUG ANY PROCEDUREHR ALTER SESSIONHR CREATE SYNONYM

Looks like "hr" has move privileges than "dev".

How To Create an Oracle Database?

There are two ways to create a new database:

Use the Database Configuration Assistant (DBCA) to create a database interactively. Use the CREATE DATABASE statement to create a database manually.

How To Create an Oracle Database Manually?

Based on Oracle's Administrator Guide, there are 11 steps to create a database with the CREATE DATABASE statement:

Step 1: Decide on Your Instance Identifier (SID)

Page 25: What is Different Between TRUNCATE and DELETE

Step 2: Establish the Database Administrator Authentication Method Step 3: Create the Initialization Parameter File Step 4: Connect to the Instance Step 5: Create a Server Parameter File (Recommended) Step 6: Start the Instance Step 7: Issue the CREATE DATABASE Statement Step 8: Create Additional Tablespaces Step 9: Run Scripts to Build Data Dictionary Views Step 10: Run Scripts to Install Additional Options (Optional) Step 11: Back Up the Database.

Other items in this FAQ collection will follow those steps to help you creating a new database manually from beginning to end.

How To Select an Oracle System ID (SID)?

This is Step 1. If you are planning to create a new database, you need to select an Oracle System ID (SID). This ID will be used to identify the new Oracle database and its Oracle instance. SID must be unique if you want to run multiple databases on a single server.

Let's set SID for the new database to be: FYI.

How To Establish Administrator Authentication to the Server?

This is Step 2. There are two ways to establish administrator authentication to a new database.

Use a password file. Use operating system (OS) authentication.

Using OS authentication is easier on Windows system. If you used your own Windows user account to install Oracle server, it will put your Windows user account into a special Window's user group called SYSDBA. This Window's user group will be fully trusted by Oracle server with SYSDBA privilege.

To continue with other steps, make sure you logged into the Windows system with a user account in the SYSDBA group.

How To Create an Initialization Parameter File?

This is Step 3. To run an Oracle database as an Oracle instance, you need to create an initialization parameter file, which contains a set of initialization parameters.

The easiest way to create an initialization parameter file to copy from the sample file provided by Oracle. You can do this in a command window as shown below:

>cd $ORACLE_HOME

Page 26: What is Different Between TRUNCATE and DELETE

>copy .\config\scripts\init.ora .\database\initFYI_ini.ora

>edit .\database\initFYI_ini.ora(replace XE by FYI)

In this example, only the SID is changed from XE to FYI. All other parameters are maintained as is.

How To Connect the Oracle Server as SYSDBA?

This is Step 4. The best way to connect to the Oracle server as an administrator is to use SQL*Plus. You need to run SQL*Plus with /nolog option and use the CONNECT with blank user name, blank password and AS SYSDBA option. Here is a sample session:

>cd $ORACLE_HOME>.\bin\sqlplus /nolog

SQL> CONNECT / AS SYSDBAConnected.

How To Create a Server Parameter File?

This is Step 5. The initialization parameter file is good to get an Oracle database instance started. But it is not ideal run an instance as production. You need to convert the initialization parameter file into a Server Parameter File (SPFile) using the CREATE SPFILE statement. The script below shows you how do this:

SQL> CREATE SPFILE=$ORACLE_HOME/dbs/SPFILEFYI.ora 2 FROM PFILE=$ORACLE_HOME/database/initFYI_ini.ora;File created.

Note that $ORACLE_HOME should be replaced by the real path name where your Oracle server is intalled.

The SPFile should be located in the expected directory and named as SPFILE($SID).ora.

How To Start an Oracle Instance?

This is Step 6. Now you are ready to start the new Oracle Instance without any database. This instance will be used to create a database. Starting an instance without database can be done by using STARTUP NOMOUNT statement as shown below:

>.\bin\sqlplus /nolog

SQL> CONNECT / AS SYSDBAConnected.

SQL> SHUTDOWNORACLE instance shut down.

Page 27: What is Different Between TRUNCATE and DELETE

SQL> STARTUP NOMOUNTORA-00821: Specified value of sga_target 16M is too small, needs to be at least 20M

The SHUTDOWN command is need to bring the default instance XE down.

The STARTUP NOMOUNT command failed because it tried to start the default instance XE, and there is a bad parameter in the XE instance SPFile.

See the next FAQ question to find another way to start the new instance FYI.

How To Start a Specific Oracle Instance?

A simple way to start a specific Oracle instance is to start the instance with the PFILE option as shown in the following example:

>.\bin\sqlplus /nolog

SQL> CONNECT / AS SYSDBAConnected.

SQL> STARTUP NOMOUNT PFILE=$ORACLE_HOME/database/initFYI_ini.ora

ORA-02778: Name given for the log directory is invalid

The PFILE option allows you to specify the initialization parameter file of a specific Oracle instance. But the initialization parameter file created in Step 3 has some problem with the log directory.

How To Start Instance with a Minimal Initialization Parameter File?

The sample initialization parameter file provided by Oracle seems to be not working. But we can try to start the new instance with a minimal initialization parameter file (PFile). First you can create another PFile, $ORACLE_HOME/database/initFYI_ini_min.ora, as shown below:

db_name=FYIcontrol_files=("\oraclexe\oradata\FYI\control.dbf")undo_management=AUTO

Then start the FYI instance again:

SQL> CONNECT / AS SYSDBAConnected.

SQL> STARTUP NOMOUNT PFILE=$ORACLE_HOME/database/initFYI_ini_min.ora

ORACLE instance started.

Page 28: What is Different Between TRUNCATE and DELETE

Total System Global Area 113246208 bytesFixed Size 1286028 bytesVariable Size 58720372 bytesDatabase Buffers 50331648 bytesRedo Buffers 2908160 bytes

How To Run CREATE DATABASE Statement?

This is Step 7. Oracle Administrator Guide provided a sample CREATE DATABASE statement. But it is a long statement. You can modify and same it in a file, $ORACLE_HOME/configscripts/create_database_fyi.sql, and run the file within SQL*Plus. Here is a copy of the modified CREATE DATABASE statement:

CREATE DATABASE FYIUSER SYS IDENTIFIED BY fyicenterUSER SYSTEM IDENTIFIED BY fyicenterLOGFILE GROUP 1 ('/oraclexe/oradata/FYI/redo01.log') SIZE 10M, GROUP 2 ('/oraclexe/oradata/FYI/redo02.log') SIZE 10M, GROUP 3 ('/oraclexe/oradata/FYI/redo03.log') SIZE 10MMAXLOGFILES 5MAXLOGMEMBERS 5MAXLOGHISTORY 1MAXDATAFILES 100MAXINSTANCES 1CHARACTER SET US7ASCIINATIONAL CHARACTER SET AL16UTF16DATAFILE '/oraclexe/oradata/FYI/system01.dbf' SIZE 32M REUSEEXTENT MANAGEMENT LOCALSYSAUX DATAFILE '/oraclexe/oradata/FYI/sysaux01.dbf' SIZE 32M REUSEDEFAULT TABLESPACE tbs_1DEFAULT TEMPORARY TABLESPACE tempts1 TEMPFILE '/oraclexe/oradata/FYI/temp01.dbf'SIZE 20M REUSEUNDO TABLESPACE undotbs DATAFILE '/oraclexe/oradata/FYI/undotbs01.dbf' SIZE 20M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

Here is how to run this long CREATE DATABASE statement:

SQL> @$ORACLE_HOME\config\scripts\create_database_fyi.sql;CREATE DATABASE FYI*ERROR at line 1:ORA-01501: CREATE DATABASE failedORA-00200: control file could not be createdORA-00202: control file: 'C:\ORACLEXE\ORADATA\FYI\CONTROL.DBF'ORA-27040: file create error, unable to create fileOSD-04002: unable to open fileO/S-Error: (OS 3) The system cannot find the path specified.

Don't worry about the error messages. They are caused by the missing directory for data files in file system.

Page 29: What is Different Between TRUNCATE and DELETE

How To Do Clean Up If CREATE DATABASE Failed?

To better organize data files, you should create a dedicated directory for each Oracle database. This can be done by using Windows file explorer to create the \oraclexe\oradata\fyi\ directory. Try the CREATE DATABASE statement again, when you have the directory ready.

If your CREATE DATABASE statement failed half way again, you may have to clean up the partial result of the CREATE DATABASE statement. Here is a list of suggestions for you:

Run SHUTDOWN command to stop the partial started database instance. Remove all files in FYI directory: \oraclexe\oradata\fyi\ Run STARTUP NOMOUNT PFILE command to start the empty instance again to be

ready for CREATE DATABASE statement.

How To Run CREATE DATABASE Statement Again?

After cleaning up the results of a previously failed CREATE DATABASE statement, you can run the CREATE DATABASE statement again as shown below:

SQL> @$ORACLE_HOME\config\scripts\create_database_fyi.sql;CREATE DATABASE FYI*ERROR at line 1:ORA-01092: ORACLE instance terminated. Disconnection forced

Something went wrong again. This time it might related the limitation that Oracle 10g XE only supports one database instance. With the default instance called "XE" already defined, creating another database instance might be not allowed.

How To Create Additional Tablespaces for an New Database?

This is Step 8. Creating additional tablespaces can be done by using the CREATE TABLESPACE statement as shown in the following sample script:

SQL> CREATE TABLESPACE users 2 DATAFILE '/oraclexe/oradata/FYI/users01.dbf' SIZE 10M;

SQL> CREATE TABLESPACE indx 2 DATAFILE '/oraclexe/oradata/FYI/indx01.dbf' SIZE 10M;

How To Build Data Dictionary View an New Database?

This is Step 9. The Oracle Administrator Guide suggests to run two SQL scripts provided by Oracle as shown bellow:

SQL> @/u01/oracle/rdbms/admin/catalog.sql

SQL> @/u01/oracle/rdbms/admin/catproc.sql

Page 30: What is Different Between TRUNCATE and DELETE

What Is the Simplest Tool to Run Commands on Oracle Servers?

The simplest tool to connect to an Oracle server and run commands to manage data is SQL*Plus. It is an Oracle database client tool that works as a command-line user interface to the database server. SQL*Plus allows you:

Format, perform calculations on, store, and print from query results. Examine table and object definitions. Develop and run batch scripts. Perform database administration.

What Is the Quickest Way to Export a Table to a Flat File?

The quickest way to export a table to a flat file is probably to use the SQL*Plus SPOOL command. It allows you to record SELECT query result to a text file on the operating system. The following tutorial exercise shows you how control the output format, start the spooler, and dump all record from a table to a flat text file:

>mkdir \oraclexe\test>sqlplus /nolog

SQL> connect HR/fyicenter

SQL> SET HEADING OFF;SQL> SET FEEDBACK OFF;SQL> SET LINESIZE 1000;SQL> SPOOL \oraclexe\test\employees.txt;SQL> SELECT * FROM EMPLOYEES;......SQL> SPOOL OFF;

You should get all records in employees.txt with fixed length fields.

How To Export Data with a Field Delimiter?

The previous exercise allows you to export data with fixed field lengths. If you want export data with variable field lengths and field delimiters, you can concatenate your fields with an expression in the SELECT clause as shown in the tutorial exercise bellow:

SQL> SET HEADING OFF;SQL> SET FEEDBACK OFF;SQL> SET LINESIZE 1000;SQL> SPOOL \oraclexe\test\fyi_links.txt;SQL> SELECT id ||','|| url ||','|| notes ||','|| counts ||','|| created FROM fyi_links;......SQL> SPOOL OFF;

You should see all records in fyi_links.txt with ',' delimited fields as shown here:

Page 31: What is Different Between TRUNCATE and DELETE

101,fyicenter.com,Session 1,,17-MAY-06110,centerfyi.com,Session 1,,17-MAY-06

What Is SQL*Loader?

SQL*Loader is a database tool that allows to load data from external files into database tables. SQL*Loader is available as part of the free Oracle 10g Expression Edition. It has some interesting features as:

Can load data from multiple data files into multiple tables in one load session. Can specify character set of the data. Can generate sophisticated error reports. Can load data directly to Oracle datafiles, bypassing normal record inserting process.

What Is a SQL*Loader Control File?

A SQL*Loader control file a text that defines how data files should be loaded into the database. It allows you to specify:

Where is the input data file. The format of the input date file. The target table where the data should be loaded. How input data fields should be mapped to target table columns. Select criteria to select input records for loading. Where to output errors.

How To Load Data with SQL*Loader?

Let's say you have a table defined as:

CREATE TABLE student (id NUMBER(5) PRIMARY KEY, first_name VARCHAR(80) NOT NULL, last_name VARCHAR(80) NOT NULL, birth_date DATE NOT NULL, social_number VARCHAR(80) UNIQUE NOT NULL);

There is an input data file stored at \oraclexe\text\student.txt with the following records:

1,Steven,King,17-JUN-77,515.123.45672,Neena,Kochhar,21-SEP-79,515.123.45683,Lex,De Haan,13-JAN-83,515.123.45694,Alexander,Hunold,03-JAN-80,590.423.45675,Bruce,Ernst,21-MAY-81,590.423.45686,David,Austin,25-JUN-87,590.423.45697,Valli,Pataballa,05-FEB-88,590.423.45608,Diana,Lorentz,07-FEB-89,590.423.55679,Nancy,Greenberg,17-AUG-84,515.124.456910,Daniel,Faviet,16-AUG-84,515.124.4169

Page 32: What is Different Between TRUNCATE and DELETE

You can create a control file at \oraclexe\test\student.ctl as:

LOAD DATA APPEND INTO TABLE STUDENT FIELDS TERMINATED BY ',' (id, first_name, last_name, birth_date, social_number)

When you are ready to load data, you can run the SQL*Loader with the "sqlldr" command:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN>sqlldr userid=hr/fyicenter, control=\oraclexe\test\student.ctl, data=\oraclexe\test\student.txt, log=\oraclexe\test\student.log

SQL*Loader: Release 10.2.0.1.0 -Commit point reached - logical record count 10

To see details of the loading process, you should check the log file \oraclexe\test\student.log.

What Is an External Table?

An external table is a table defined in the database with data stored outside the database. Data of an external table is stored in files on the operating systems. Accessing data of external tables are done through data access drivers. Currently, Oracle supports two data access drivers: ORACLE_LOADER and ORACLE_DATAPUMP.

External tables can be used to load data from external files into database, or unload data from database to external files.

How To Load Data through External Tables?

If you have data stored in external files, you can load it to database through an external table by the steps below:

Create an external table with columns matching data fields in the external file. Create a regular table with the same columns. Run an INSERT INTO ... SELECT statement to load data from the external file to the

regular table through the external table.

What Are the Restrictions on External Table Columns?

When creating external table columns, you need to watch out some restrictions:

"PRIMARY KEY" is not allowed. "NOT NULL" is not allowed. "DEFAULT value" is not allowed.

Page 33: What is Different Between TRUNCATE and DELETE

What Is a Directory Object?

A directory object is a logical alias for a physical directory path name on the operating system. Directory objects can be created, dropped, and granted access permissions to different users. The following tutorial exercise shows you some good examples:

>sqlplus /nolog

SQL> connect SYSTEM/fyicenter

SQL> CREATE DIRECTORY test_dir AS '/oraclexe/test';Directory created.

SQL> GRANT READ ON DIRECTORY test_dir TO hr;Grant succeeded.

SQL> GRANT WRITE ON DIRECTORY test_dir TO hr;Grant succeeded.

SQL> CREATE DIRECTORY temp_dir AS '/oraclexe/temp';Directory created.

SQL> DROP DIRECTORY temp_dir;Directory dropped.

How To Define an External Table with a Text File?

You can use the CREATE TABLE statement to create external tables. But you need to use ORGANIZATION EXTERNAL clause to specify the external file location and the data access driver. The tutorial exercise below shows you how to define an external table as a text file:

>sqlplus /nolog

SQL> connect HR/fyicenter

SQL> CREATE TABLE ext_fyi_links ( id NUMBER(4), url VARCHAR2(16), notes VARCHAR2(16), counts NUMBER(4), created DATE ) ORGANIZATION EXTERNAL ( TYPE ORACLE_LOADER DEFAULT DIRECTORY test_dir LOCATION ('ext_fyi_links.txt') );Table created.

SQL> SELECT table_name, tablespace_name, num_rows FROM USER_TABLES;TABLE_NAME TABLESPACE_NAME NUM_ROWS--------------------- ---------------------- ----------

Page 34: What is Different Between TRUNCATE and DELETE

REGIONS USERS 4LOCATIONS USERS 23DEPARTMENTS USERS 27JOBS USERS 19EMPLOYEES USERS 107JOB_HISTORY USERS 10FYI_LINKS USERS 2EXT_FYI_LINKSCOUNTRIES 25

How To Run Queries on External Tables?

If you have an external table defined as a text file with the ORACLE_LOADER driver, you can add data to the text file, and query the text file through the external table. By default, data fields in the text file should be terminated by ','. The tutorial exercise below shows you how add data to the external table defined in the previous exercise:

>edit /oraclexe/test/ext_fyi_links.txt1101,dba.fyicenter,Link #1,88,07-MAY-061110,dev.fyicenter,Link #2,88,07-MAY-06

>sqlplus /nolog

SQL> connect HR/fyicenter

SQL> SELECT * FROM ext_fyi_links; ID URL NOTES COUNTS CREATED--------- ---------------- ----------- -------- --------- 1101 dba.fyicenter Link #1 88 07-MAY-06 1110 dev.fyicenter Link #2 88 07-MAY-06

How To Load Data from External Tables to Regular Tables?

Once you have your data entered in a text file, and an external table defined to this text file, you can easily load data from this text file to a regular table. The following tutorial exercise shows you how to load data from the text file and the external table defined in the previous exercises to a regular table:

SQL> CREATE TABLE fyi_links ( id NUMBER(4) PRIMARY KEY, url VARCHAR2(16) NOT NULL, notes VARCHAR2(16), counts NUMBER(4), created DATE DEFAULT (sysdate) );

SQL> INSERT INTO fyi_links SELECT * FROM ext_fyi_links;2 rows created.

SQL> SELECT * FROM fyi_links; ID URL NOTES COUNTS CREATED--------- ---------------- ----------- -------- --------- 101 fyicenter.com Session 1 07-MAY-06

Page 35: What is Different Between TRUNCATE and DELETE

110 centerfyi.com Session 1 07-MAY-06 1101 dba.fyicenter Link #1 88 07-MAY-06 1110 dev.fyicenter Link #2 88 07-MAY-06

What Is the Data Pump Export Utility?

Oracle Data Pump Export utility is a standalone programs that allows you to export data objects from Oracle database to operating system files called dump file set, which can be imported back to Oracle database only by Oracle Data Pump Import utility.

The dump file set can be imported on the same system or it can be moved to another system and loaded there.

The dump file set is made up of one or more disk files that contain table data, database object metadata, and control information. The files are written in a proprietary, binary format. During an import operation, the Data Pump Import utility uses these files to locate each database object in the dump file set. Because the dump files are written by the server, rather than by the client, the data base administrator (DBA) must create directory objects.

What Is the Data Pump Import Utility?

Oracle Data Pump Import utility is a standalone programs that allows you to import data objects from an Oracle dump file set into Oracle database. Oracle dump file set is written in a proprietary binary format by the Data Pump Export utility.

Import can also be used to load a target database directly from a source database with no intervening dump files. This allows export and import operations to run concurrently, minimizing total elapsed time. This is known as a network import. Data Pump Import enables you to specify whether a job should move a subset of the data and metadata from the dump file set or the source database (in the case of a network import), as determined by the import mode. This is done using data filters and metadata filters, which are implemented through Import commands.

How To Invoke the Data Pump Export Utility?

The Data Pump Export utility is distributed as executable file called "expdp.exe". To invoke this utility, you should go to the "bin" directory of your Oracle server installation and run the "expdp" command. Here is tutorial exercise on how to invoke the export utility:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>expdp help=yExport: Release 10.2.0.1.0 -

The Data Pump export utility provides a mechanism fortransferring data objects between Oracle databases. The utility is invoked with the following command:

Page 36: What is Different Between TRUNCATE and DELETE

Example: expdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Export runs by entering the 'expdp'command followed by various parameters:

Format: expdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)

Example: expdp scott/tiger DUMPFILE=scott.dmp DIRECTORY=dmpdir SCHEMAS=scott or TABLES=(T1:P1,T1:P2)

USERID must be the first parameter on the command line.

Keyword Description (Default)------------------------------------------------------------ATTACH Attach to existing job, e.g. ATTACH [=job nameCOMPRESSION Reduce size of dumpfile contents where valid keyword values are: (METADATA_ONLY) and NONE.DIRECTORY Directory object to be used for dumpfiles DUMPFILE List of destination dump files (expdat.dmp).FLASHBACK_SCN SCN used to set session snapshot back to.FULL Export entire database (N).HELP Display Help messages (N).......

How To Invoke the Data Pump Import Utitlity?

The Data Pump Import utility is distributed as executable file called "impdp.exe". To invoke this utility, you should go to the "bin" directory of your Oracle server installation and run the "impdp" command. Here is tutorial exercise on how to invoke the import utility:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>impdp help=yImport: Release 10.2.0.1.0 -

The Data Pump Import utility provides a mechanism for transferring data objects between Oracle databases. The utility is invoked with the following command:

Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

You can control how Import runs by entering the 'impdp' command followed by various parameters.

Format: impdp KEYWORD=value or KEYWORD=(value1,value2,...,valueN)

Example: impdp scott/tiger DIRECTORY=dmpdir DUMPFILE=scott.dmp

Page 37: What is Different Between TRUNCATE and DELETE

USERID must be the first parameter on the command line.

Keyword Description (Default)----------------------------------------------------------ATTACH Attach to existing job, e.g. ATTACH [=job name]DIRECTORY Directory object to be used for dump, log, ... DUMPFILE List of dumpfiles to import from (expdat.dmp)FULL Import everything from source (Y).HELP Display help messages (N).......

What Are Data Pump Export and Import Modes?

Data pump export and import modes are used to determine the type and portions of database to be exported and imported. Oracle 10g supports 5 export and import modes:

Full: Exports and imports a full database. Use the FULL parameter to specify this mode. Schema: Enables you to export and import all objects that belong to a schema. Use the

SCHEMAS parameter to specify this mode. This is the default mode. Table: Enables you to export and import specific tables and partitions. Use the TABLES

parameter to specify this mode. Tablespace: Enables a privileged user to move a set of tablespaces from one Oracle

database to another. Use the TABLESPACES parameter to specify this mode. Tablespace: Enables a privileged user to move metadata from the tables within a

specified set of tablespaces from one Oracle database to another. Use the TRANSPORT_TABLESPACES parameter to specify this mode.

How To Estimate Disk Space Needed for an Export Job?

If you just want to know how much disk space for the dump without actually exporting any data, you can use the ESTIMATE_ONLY=y parameter on the expdp command. The following tutorial exercise shows you how a system user wants to see the disk space estimates on a full database export:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>expdp SYSTEM/fyicenter FULL=y ESTIMATE_ONLY=yStarting "SYSTEM"."SYS_EXPORT_FULL_01": SYSTEM/**** FULL=y ESTIMATE_ONLY=y

Estimate in progress using BLOCKS method...Processing object DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATA. estimated "FLOWS_020100"."WWV_FLOW_PAGE_PLUGS" 42 MB. estimated "FLOWS_020100"."WWV_FLOW_STEP_ITEMS" 27 MB. estimated "FLOWS_020100"."WWV_FLOW_STEP_PROCESSING" 16 MB....... estimated "SYSTEM"."SQLPLUS_PRODUCT_PROFILE" 0 KB. estimated "TSMSYS"."SRS$" 0 KBTotal estimation using BLOCKS method: 169.8 MBJob "SYSTEM"."SYS_EXPORT_FULL_01" successfully completed

Page 38: What is Different Between TRUNCATE and DELETE

Now you know that you need 170 MB disk space to export the entire data base.

Oracle also records the screen output in a log file called export.log at \oraclexe\app\oracle\admin\XE\dpdump.

How To Do a Full Database Export?

If you are ready to do a full database export, you can use the FULL=y parameter on the expdp command, as shown in the following tutorial exercise:

>expdp SYSTEM/fyicenter FULL=y ESTIMATE_ONLY=yStarting "SYSTEM"."SYS_EXPORT_FULL_01": SYSTEM/**** FULL=y Estimate in progress using BLOCKS method...Processing object DATABASE_EXPORT/SCHEMA/TABLE/TABLE_DATATotal estimation using BLOCKS method: 169.8 MBProcessing object type DATABASE_EXPORT/TABLESPACEProcessing object type DATABASE_EXPORT/SYS_USER/USERProcessing object type DATABASE_EXPORT/SCHEMA/USER....... . exported FLOWS_020100.WWV_FLOW_PAGE_PLUGS 32.51MB. . exported FLOWS_020100.WWV_FLOW_STEP_ITEMS 21.68MB. . exported FLOWS_020100.WWV_FLOW_STEP_PROCESSING 11.17MB......Master table "SYSTEM"."SYS_EXPORT_FULL_01" unloaded**********************************************************Dump file set for SYSTEM.SYS_EXPORT_FULL_01 is: C:\ORACLEXE\APP\ORACLE\ADMIN\XE\DPDUMP\EXPDAT.DMPJob "SYSTEM"."SYS_EXPORT_FULL_01" successfully completed

Where Is the Export Dump File Located?

If you are not specifying the dump directory and file name, the dump file will be stored in the default dump directory with the default file name. The tutorial exercise below tells you find what is your default dump directory and locate the dump file.

>sqlplus /nolog

SQL> connect SYSTEM/fyicenter

SQL> COL owner FORMAT A8;SQL> COL directory_name FORMAT A16;SQL> COL directory_path FORMAT A40;SQL> SELECT * FROM dba_directories;OWNER DIRECTORY_NAME DIRECTORY_PATH----- -------------- -------------------------------------SYS DATA_PUMP_DIR \oraclexe\app\oracle\admin\XE\dpdump\SYS TEST_DIR /oraclexe/testSYS ORACLECLRDIR \oraclexe\app\oracle\product\10.2.0\ server\bin\clr

Page 39: What is Different Between TRUNCATE and DELETE

Obviously, the default dump directory is directory object defined to \oraclexe\app\oracle\admin\XE\dpdump\. If you go to that directory, you will find the full database dump file is called "expdat.dmp".

How To Export Your Own Schema?

If you have a non-system user account and you want to export all data objects in the schema associated with your account, you can use the "expdp" command with the SCHEMAS parameter. Running "expdp" command with a non-system user account requires a directory object granted to this user account. The following tutorial exercise shows you how to define a directory object and export a schema:

>mkdir \oraclexe\hr_dump

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>sqlplus /nologSQL> connect SYSTEM/fyicenter

SQL> CREATE DIRECTORY hr_dump AS '\oraclexe\hr_dump';Directory created.

SQL> GRANT READ ON DIRECTORY hr_dump TO hr;Grant succeeded.

SQL> GRANT WRITE ON DIRECTORY hr_dump TO hr;Grant succeeded.

SQL> quit

>expdp hr/fyicenter SCHEMAS=hr DIRECTORY=hr_dump DUMPFILE=schema.dmp LOGFILE=schema.log

Starting "HR"."SYS_EXPORT_SCHEMA_01": hr/******** SCHEMAS=hr DIRECTORY=hr_dump DUMPFILE=schema.dmp LOGFILE=schema.logEstimate in progress using BLOCKS method...Processing object type SCHEMA_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 960 KBProcessing object type SCHEMA_EXPORT/PRE_SCHEMA/PROCACT_SCHProcessing object type SCHEMA_EXPORT/SEQUENCE/SEQUENCEProcessing object type SCHEMA_EXPORT/TABLE/TABLE....... . exported "HR"."COUNTRIES" 6.085 KB 25 rows. . exported "HR"."DEPARTMENTS" 6.632 KB 27 rows. . exported "HR"."EMPLOYEES" 15.76 KB 107 rows. . exported "HR"."EMPLOYEES_TEMP" 15.86 KB 107 rows......Master table "HR"."SYS_EXPORT_SCHEMA_01" loaded/unloaded*********************************************************Dump file set for HR.SYS_EXPORT_SCHEMA_01 is: C:\ORACLEXE\HR_DUMP\SCHEMA.DMPJob "HR"."SYS_EXPORT_SCHEMA_01" successfully completed

Page 40: What is Different Between TRUNCATE and DELETE

How To Export Several Tables Together?

If you don't want to export the entire schema and only want to export several tables only, you can use the "expdp" command with the "TABLES" parameter as shown in the following tutorial exercise:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>expdp hr/fyicenter TABLES=employees,departments DIRECTORY=hr_dump DUMPFILE=tables.dmp LOGFILE=tables.log

Starting "HR"."SYS_EXPORT_TABLE_01": hr/******** TABLES=employees,departments DIRECTORY=hr_dump DUMPFILE=tables.dmp LOGFILE=tables.logEstimate in progress using BLOCKS method...Processing object type TABLE_EXPORT/TABLE/TABLE_DATATotal estimation using BLOCKS method: 128 KBProcessing object type TABLE_EXPORT/TABLE/TABLEProcessing object type TABLE_EXPORT/TABLE/INDEX/INDEXProcessing object type TABLE_EXPORT/TABLE/CONSTRAINT/CON...Processing object type TABLE_EXPORT/TABLE/INDEX/STATISTI...Processing object type TABLE_EXPORT/TABLE/COMMENTProcessing object type TABLE_EXPORT/TABLE/CONSTRAINT/REF...Processing object type TABLE_EXPORT/TABLE/TRIGGERProcessing object type TABLE_EXPORT/TABLE/STATISTICS/TAB.... . exported "HR"."DEPARTMENTS" 6.632 KB 27 rows. . exported "HR"."EMPLOYEES" 15.76 KB 107 rowsMaster table "HR"."SYS_EXPORT_TABLE_01" loaded/unloaded***********************************************************Dump file set for HR.SYS_EXPORT_TABLE_01 is: C:\ORACLEXE\HR_DUMP\TABLES.DMPJob "HR"."SYS_EXPORT_TABLE_01" successfully completed

What Happens If the Imported Table Already Exists?

If the import process tries to import a table that already exists, the Data Pump Import utility will return an error and skip this table. The following exercise shows you a good example:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN>impdp hr/fyicenter TABLES=employees DIRECTORY=hr_dump DUMPFILE=tables.dmp LOGFILE=tables.log

Master table "HR"."SYS_IMPORT_TABLE_01" loaded/unloadedStarting "HR"."SYS_IMPORT_TABLE_01": hr/** TABLES=employees DIRECTORY=hr_dump DUMPFILE=tables.dmp LOGFILE=tables.logProcessing object type TABLE_EXPORT/TABLE/TABLEORA-39151: Table "HR"."EMPLOYEES" exists. All dependent metadata and data will be skipped due to table_exists_action of skipProcessing object type TABLE_EXPORT/TABLE/TABLE_DATAProcessing object type TABLE_EXPORT/TABLE/INDEX/INDEX......

Page 41: What is Different Between TRUNCATE and DELETE

How To Import One Table Back from a Dump File?

If you only want to import one table back to the database, you can use a dump file that was created by full export, schema export or a table export. The following tutorial exercise shows you how to import the "fyi_links" table from a dump file created by a schema export:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>sqlplus /nologSQL> connect HR/fyicenter

SQL> DROP TABLE fyi_links;Table dropped.

SQL> exit;

>impdp hr/fyicenter TABLES=fyi_links DIRECTORY=hr_dump DUMPFILE=schema.dmp LOGFILE=tables.log

Master table "HR"."SYS_IMPORT_TABLE_01" loaded/unloadedStarting "HR"."SYS_IMPORT_TABLE_01": hr/** TABLES=fyi_links DIRECTORY=hr_dump DUMPFILE=schema.dmp LOGFILE=tables.logProcessing object type SCHEMA_EXPORT/TABLE/TABLEProcessing object type SCHEMA_EXPORT/TABLE/TABLE_DATA. . imported "HR"."FYI_LINKS" 6.375 KB 4 rowsProcessing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CON...Processing object type SCHEMA_EXPORT/TABLE/INDEX/STATISTI...Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TAB...Job "HR"."SYS_IMPORT_TABLE_01" successfully completed.

What Are the Original Export and Import Utilities?

Oracle original Export and Import utilities are standalone programs that provide you a simple way for you to transfer data objects between Oracle databases, even if they reside on platforms with different hardware and software configurations.

When you run Export against an Oracle database, objects (such as tables) are extracted, followed by their related objects (such as indexes, comments, and grants), if any. The extracted data is written to an export dump file. The Import utility reads the object definitions and table data from the dump file.

An export file is an Oracle binary-format dump file that is typically located on disk or tape. The dump files can be transferred using FTP or physically transported (in the case of tape) to a different site. The files can then be used with the Import utility to transfer data between databases that are on systems not connected through a network. The files can also be used as backups in addition to normal backup procedures.

Export and Import utilities are now being replaced by Data Pump Export and Import utilities in Oracle 10g. But you can still use them.

Page 42: What is Different Between TRUNCATE and DELETE

How To Invoke the Original Export Import Utilities?

If you really want to run the original export import utilities, you can still go to "bin" directory of the Oracle server path and run the "exp" or "imp" command. The tutorial exercise below tells you how to run the export and import utilities in help modes:

>cd \oraclexe\app\oracle\product\10.2.0\server\BIN

>exp help=yYou can let Export prompt you for parameters by entering theEXP command followed by your username/password:

Example: EXP SCOTT/TIGER

Or, you can control how Export runs by entering the EXPcommand followed by various arguments. To specify parameters, you use:

Format: EXP KEYWORD=value or KEYWORD=(value1,value2,...,valueN)

Example: EXP SCOTT/TIGER GRANTS=Y TABLES=(EMP,DEPT,MGR) or TABLES=(T1:P1,T1:P2), if T1 is partitioned table......

>imp help=y......

What Is Open Database Communication (ODBC)?

ODBC, Open Database Communication, a standard API (application program interface) developed by Microsoft for Windows applications to communicate with database management systems.

Oracle offers ODBC drivers to allow Windows applications to connect Oracle server through ODBC.

How To Install Oracle ODBC Drivers?

Oracle offers different ODBC drivers for different versions of Oracle servers. When you install an Oracle server or a client tools on your Windows system, the appropriate ODBC driver will be installed for you automatically.

If you want to install a specific ODBC driver, you need to go to http://www.oracle.com/technology/software/tech/windows/odbc/index.html. Download the right ODBC driver and follow the instructions to install it.

Page 43: What is Different Between TRUNCATE and DELETE

How To Find Out What Oracle ODBC Drivers Are Installed?

To find out what Oracle ODBC drivers are installed on your Windows system, you can use the ODBC manager to look at them:

Go to Control Panel. Go to Administrative Tools. Run Data Sources (ODBC). Go to System DSN tab. Click the Add button.

You should a list of all ODBC drivers installed on your system. Oracle ODBC drivers should be on the list. For example, your installed ODBC driver list could look like the one the picture bellow with two Oracle ODBC drivers, "Oracle in OraClient10g_home1" and "Oracle in XE":

How Can Windows Applications Connect to Oracle Servers?

A Windows application can connect to an Oracle server directly, if it knows how to use the Oracle TNS technology.

A Windows application can connect to an Oracle server indirectly through Windows ODBC manager, becaused offers ODBC drivers to support the ODBC API. The diagram below shows how MS Access can connect to an Oracle server through the ODBC driver:

Page 44: What is Different Between TRUNCATE and DELETE

How To Create Tables for ODBC Connection Testing?

If you want to follow the tutorial exercises in the sections below, you need to create a user account and a table for ODBC connection testing as shown here:

SQL> CONNECT system/retneciyfConnected.

SQL> CREATE USER fyi IDENTIFIED BY retneciyf ACCOUNT UNLOCK;User created.

SQL> GRANT CREATE SESSION TO fyi;Grant succeeded.

SQL> GRANT CREATE TABLE TO fyi;Grant succeeded.

SQL> ALTER USER fyi DEFAULT TABLESPACE USERS;User altered.

SQL> ALTER USER dev QUOTA 4M ON USERS;User altered.

SQL> connect fyi/retneciyf;Connected.

SQL> CREATE TABLE dev_faq (id NUMBER);SQL> INSERT INTO dev_faq VALUES (3);SQL> INSERT INTO dev_faq VALUES (5);SQL> INSERT INTO dev_faq VALUES (7);

How To Check the Oracle TNS Settings?

If you have installed an Oracle server or an Oracle client tool on your local system, the TNS is automatically installed with a simple configuration file, tnsnames.ora, to define Oracle connect identifiers.

Page 45: What is Different Between TRUNCATE and DELETE

For example, if you have Oracle XE server installed, you will have the tnsnames.ora located at \oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN. It should contain a connect identifier called XE defined as:

XE = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost) (PORT = 1521) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE) ) )

How To Define a Data Source Name (DSN) in ODBC Manager?

DSN (Data Source Name) is an ODBC connection identifier for Windows applications. Here is how you can define a DSN on your Windows system:

Go to Control Panel. Go to Administrative Tools. Run Data Sources (ODBC). Go to System DSN tab. Click the Add button. Select the "Oracle in XE" driver. Enter Data Source Name: FYI_DSN. Enter Description: FYIcenter DSN Oracle Setting. Enter TNS Service Name: XE. Click the Test Connection button. Enter User Name: fyi. Enter Password: retneciyf. Click the OK button.

You should see a "Connection successful" as shown in the following picture:

Page 46: What is Different Between TRUNCATE and DELETE

How To Connect MS Access to Oracle Servers?

Once you got a DSN defined in the ODBC manager that connects to an Oracle server, you can connect a normal MS Access document to the Oracle server, and link an Access table to Oracle table. The tutorial below gives you a good example:

Start MS Access with a new database file. Go to File menu. Select Get External Data. Select Import.... The Import dialog box shows up. Select Files of type: ODBC Database(). The Select Data Source dialog box shows up. Click the Machine Data Source tab. You should see the DSN name "FYI_DSN" you

defined earlier. Select "FYI_DSN". Enter User Name: fyi. Enter Password: retneciyf.

You should see the Oracle ODBC Driver Connect dialog box as shown in the picture below:

Page 47: What is Different Between TRUNCATE and DELETE

Click the OK button to continue. You should see a list of tables available for you to import from the Oracle server as shown in the picture below:

How To Connect ASP Pages to Oracle Servers?

If you are running Windows IIS Web server and serving ASP Web pages, you can get data from Oracle servers into your ASP pages through ODBC drivers. To do this, you need to install the correct Oracle ODBC driver and define a DSN on the IIS Web server.

Then you can use ADODB objects to connect to the Oracle server over the ODBC driver in your ASP pages. The tutorial example below gives you a good example:

<% Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open "DSN=FYI_DSN;UID=fyi;PWD=retneciyf" Set oRS = oConn.Execute("SELECT * FROM dev_faq")

Page 48: What is Different Between TRUNCATE and DELETE

Response.write("<p>Data from Oracle server via ODBC:") Response.write("<pre>") Do While NOT oRS.EOF Response.Write(oRS("ID") & vbcrlf) oRS.MoveNext Loop Response.write("</pre>") oRS.close oConn.close %>

DBA

1. Give one method for transferring a table from one schema to another:

Level:Intermediate

Expected Answer: There are several possible methods, export-import, CREATE TABLE... AS SELECT, or COPY.

2. What is the purpose of the IMPORT option IGNORE? What is it's default setting?

Level: Low

Expected Answer: The IMPORT IGNORE option tells import to ignore "already exists" errors. If it is not specified the tables that already exist will be skipped. If it is specified, the error is ignored and the tables data will be inserted. The default value is N.

3. You have a rollback segment in a version 7.2 database that has expanded beyond optimal, how can it be restored to optimal?

Level: Low

Expected answer: Use the ALTER TABLESPACE ..... SHRINK command.

4. If the DEFAULT and TEMPORARY tablespace clauses are left out of a CREATE USER command what happens? Is this bad or good? Why?

Level: Low

Expected answer: The user is assigned the SYSTEM tablespace as a default and temporary tablespace. This is bad because it causes user objects and temporary segments to be placed into the SYSTEM tablespace resulting in fragmentation and improper table placement (only data dictionary objects and the system rollback segment should be in SYSTEM).

Page 49: What is Different Between TRUNCATE and DELETE

5. What are some of the Oracle provided packages that DBAs should be aware of? Level: Intermediate to High

Expected answer: Oracle provides a number of packages in the form of the DBMS_ packages owned by the SYS user. The packages used by DBAs may include: DBMS_SHARED_POOL, DBMS_UTILITY, DBMS_SQL, DBMS_DDL, DBMS_SESSION, DBMS_OUTPUT and DBMS_SNAPSHOT. They may also try to answer with the UTL*.SQL or CAT*.SQL series of SQL procedures. These can be viewed as extra credit but aren?t part of the answer.

6. What happens if the constraint name is left out of a constraint clause?

Level: Low

Expected answer: The Oracle system will use the default name of SYS_Cxxxx where xxxx is a system generated number. This is bad since it makes tracking which table the constraint belongs to or what the constraint does harder.

7. What happens if a tablespace clause is left off of a primary key constraint clause?

Level: Low

Expected answer: This results in the index that is automatically generated being placed in then users default tablespace. Since this will usually be the same tablespace as the table is being created in, this can cause serious performance problems.

8. What is the proper method for disabling and re-enabling a primary key constraint?

Level: Intermediate

Expected answer: You use the ALTER TABLE command for both. However, for the enable clause you must specify the USING INDEX and TABLESPACE clause for primary keys.

9. What happens if a primary key constraint is disabled and then enabled without fully specifying the index clause?

Level: Intermediate

Expected answer: The index is created in the user?s default tablespace and all sizing information is lost. Oracle doesn?t store this information as a part of the constraint definition, but only as part of the index definition, when the constraint was disabled the index was dropped and the information is gone.

10. (On UNIX) When should more than one DB writer process be used? How many should be used?

Level: High

Page 50: What is Different Between TRUNCATE and DELETE

Expected answer: If the UNIX system being used is capable of asynchronous IO then only one is required, if the system is not capable of asynchronous IO then up to twice the number of disks used by Oracle number of DB writers should be specified by use of the db_writers initialization parameter.

11. You are using hot backup without being in archivelog mode, can you recover in the event of a failure? Why or why not?

Level: High

Expected answer: You can't use hot backup without being in archivelog mode. So no, you couldn't recover.

12. What causes the "snapshot too old" error? How can this be prevented or mitigated?

Level: Intermediate

Expected answer: This is caused by large or long running transactions that have either wrapped onto their own rollback space or have had another transaction write on part of their rollback space. This can be prevented or mitigated by breaking the transaction into a set of smaller transactions or increasing the size of the rollback segments and their extents.

13. How can you tell if a database object is invalid?

Level: Low

Expected answer: By checking the STATUS column of the DBA_, ALL_ or USER_OBJECTS views, depending upon whether you own or only have permission on the view or are using a DBA account.

14. A user is getting an ORA-00942 error yet you know you have granted them permission on the table, what else should you check?

Level: Low

Expected answer: You need to check that the user has specified the full name of the object (SELECT empid FROM scott.emp; instead of SELECT empid FROM emp;) or has a synonym that points to the object (CREATE SYNONYM emp FOR scott.emp;)

15. A developer is trying to create a view and the database won?t let him. He has the "DEVELOPER" role which has the "CREATE VIEW" system privilege and SELECT grants on the tables he is using, what is the problem? Level: Intermediate Expected answer: You need to verify the developer has direct grants on all tables used in the view. You can't create a stored object with grants given through a role.

Page 51: What is Different Between TRUNCATE and DELETE

16. If you have an example table, what is the best way to get sizing data for the production table implementation?

Level: Intermediate

Expected answer: The best way is to analyze the table and then use the data provided in the DBA_TABLES view to get the average row length and other pertinent data for the calculation. The quick and dirty way is to look at the number of blocks the table is actually using and ratio the number of rows in the table to its number of blocks against the number of expected rows.

17. How can you find out how many users are currently logged into the database? How can you find their operating system id?

Level: high Expected answer: There are several ways. One is to look at the v$session or v$process views. Another way is to check the current_logins parameter in the v$sysstat view. Another if you are on UNIX is to do a "ps -ef|grep oracle|wc -l? command, but this only works against a single instance installation.

18. A user selects from a sequence and gets back two values, his select is:

SELECT pk_seq.nextval FROM dual; What is the problem?

Level: Intermediate

Expected answer: Somehow two values have been inserted into the dual table. This table is a single row, single column table that should only have one value in it.

19. How can you determine if an index needs to be dropped and rebuilt?

Level: Intermediate

Expected answer: Run the ANALYZE INDEX command on the index to validate its structure and then calculate the ratio of LF_BLK_LEN/LF_BLK_LEN+BR_BLK_LEN and if it isn?t near 1.0 (i.e. greater than 0.7 or so) then the index should be rebuilt. Or if the ratio BR_BLK_LEN/ LF_BLK_LEN+BR_BLK_LEN is nearing 0.3.

Installation/Configuration

1. Define OFA.

Level: Low

Expected answer: OFA stands for Optimal Flexible Architecture. It is a method of placing directories and files in an Oracle system so that you get the maximum flexibility for future tuning and file placement.

Page 52: What is Different Between TRUNCATE and DELETE

2. How do you set up your tablespace on installation? Level: Low

Expected answer: The answer here should show an understanding of separation of redo and rollback, data and indexes and isolation os SYSTEM tables from other tables. An example would be to specify that at least 7 disks should be used for an Oracle installation so that you can place SYSTEM tablespace on one, redo logs on two (mirrored redo logs) the TEMPORARY tablespace on another, ROLLBACK tablespace on another and still have two for DATA and INDEXES. They should indicate how they will handle archive logs and exports as well. As long as they have a logical plan for combining or further separation more or less disks can be specified.

3. What should be done prior to installing Oracle (for the OS and the disks)?

Level: Low

Expected Answer: adjust kernel parameters or OS tuning parameters in accordance with installation guide. Be sure enough contiguous disk space is available.

4. You have installed Oracle and you are now setting up the actual instance. You have been waiting an hour for the initialization script to finish, what should you check first to determine if there is a problem?

Level: Intermediate to high

Expected Answer: Check to make sure that the archiver isn?t stuck. If archive logging is turned on during install a large number of logs will be created. This can fill up your archive log destination causing Oracle to stop to wait for more space.

5. When configuring SQLNET on the server what files must be set up?

Level: Intermediate

Expected answer: INITIALIZATION file, TNSNAMES.ORA file, SQLNET.ORA file

6. When configuring SQLNET on the client what files need to be set up?

Level: Intermediate

Expected answer: SQLNET.ORA, TNSNAMES.ORA

7. What must be installed with ODBC on the client in order for it to work with Oracle?

Level: Intermediate

Expected answer: SQLNET and PROTOCOL (for example: TCPIP adapter) layers of the transport programs.

Page 53: What is Different Between TRUNCATE and DELETE

8. You have just started a new instance with a large SGA on a busy existing server. Performance is terrible, what should you check for?

Level: Intermediate

Expected answer: The first thing to check with a large SGA is that it isn?t being swapped out.

9. What OS user should be used for the first part of an Oracle installation (on UNIX)?

Level: low

Expected answer: You must use root first.

10. When should the default values for Oracle initialization parameters be used as is?

Level: Low

Expected answer: Never

11. How many control files should you have? Where should they be located?

Level: Low

Expected answer: At least 2 on separate disk spindles. Be sure they say on separate disks, not just file systems.

12. How many redo logs should you have and how should they be configured for maximum recoverability?

Level: Intermediate

Expected answer: You should have at least three groups of two redo logs with the two logs each on a separate disk spindle (mirrored by Oracle). The redo logs should not be on raw devices on UNIX if it can be avoided.

13. You have a simple application with no "hot" tables (i.e. uniform IO and access requirements). How many disks should you have assuming standard layout for SYSTEM, USER, TEMP and ROLLBACK tablespaces?

Expected answer: At least 7, see disk configuration answer above.

UNIX

1. How can you determine the space left in a file system?

Level: Low Expected answer: There are several commands to do this: du, df, or bdf

Page 54: What is Different Between TRUNCATE and DELETE

2. How can you determine the number of SQLNET users logged in to the UNIX system? Level: Intermediate Expected answer: SQLNET users will show up with a process unique name that begins with oracle, if you do a ps -ef|grep oracle|wc -l you can get a count of the number of users.

3. What command is used to type files to the screen? Level: Low Expected answer: cat, more, pg

4. What command is used to remove a file? Level: Low Expected answer: rm

5. Can you remove an open file under UNIX? Level: Low Expected answer: yes

6. How do you create a decision tree in a shell script? Level: intermediate Expected answer: depending on shell, usually a case-esac or an if-endif or fi structure

7. What is the purpose of the grep command? Level: Low Expected answer: grep is a string search command that parses the specified string from the specified file or files

8. The system has a program that always includes the word nocomp in its name, how can you determine the number of processes that are using this program? Level: intermediate Expected answer: ps -ef|grep *nocomp*|wc -l

9. What is an inode? Level: Intermediate Expected answer: an inode is a file status indicator. It is stored in both disk and memory and tracts file status. There is one inode for each file on the system.

10. The system administrator tells you that the system hasn?t been rebooted in 6 months, should he be proud of this? Level: High Expected answer: Maybe. Some UNIX systems don?t clean up well after themselves. Inode problems and dead user processes can accumulate causing possible performance and corruption problems. Most UNIX systems should have a scheduled periodic reboot so file systems can be checked and cleaned and dead or zombie processes cleared out.

11. What is redirection and how is it used? Level: Intermediate Expected answer: redirection is the process by which input or output to or from a process is redirected to another process. This can be done using the pipe symbol "|", the greater than symbol ">" or the "tee" command. This is one of the strengths of UNIX allowing the output from one command to be redirected directly into the input of another command.

12. How can you find dead processes? Level: Intermediate Expected answer: ps -ef|grep zombie -- or -- who -d depending on the system.

13. How can you find all the processes on your system? Level: Low Expected answer: Use the ps command

14. How can you find your id on a system? Level: Low Expected answer: Use the "who am i" command.

Page 55: What is Different Between TRUNCATE and DELETE

15. What is the finger command? Level: Low Expected answer: The finger command uses data in the passwd file to give information on system users.

16. What is the easiest method to create a file on UNIX? Level: Low Expected answer: Use the touch command

17. What does >> do? Level: Intermediate Expected answer: The ">>" redirection symbol appends the output from the command specified into the file specified. The file must already have been created.

18. If you aren?t sure what command does a particular UNIX function what is the best way to determine the command? Expected answer: The UNIX man -k command will search the man pages for the value specified. Review the results from the command to find the command of interest.

[edit]

Oracle Troubleshooting

1. How can you determine if an Oracle instance is up from the operating system level? Level: Low Expected answer: There are several base Oracle processes that will be running on multi-user operating systems, these will be smon, pmon, dbwr and lgwr. Any answer that has them using their operating system process showing feature to check for these is acceptable. For example, on UNIX a ps -ef|grep pmon will show what instances are up.

2. Users from the PC clients are getting messages indicating : Level: Low ORA-06114: (Cnct err, can't get err txt. See Servr Msgs & Codes Manual) What could the problem be? Expected answer: The instance name is probably incorrect in their connection string.

3. Users from the PC clients are getting the following error stack: Level: Low ERROR: ORA-01034: ORACLE not available ORA-07318: smsget: open error when opening sgadef.dbf file. HP-UX Error: 2: No such file or directory What is the probable cause? Expected answer: The Oracle instance is shutdown that they are trying to access, restart the instance.

4. How can you determine if the SQLNET process is running for SQLNET V1? How about V2? Level: Low Expected answer: For SQLNET V1 check for the existence of the orasrv process. You can use the command "tcpctl status" to get a full status of the V1 TCPIP server, other protocols have similar command formats. For SQLNET V2 check for the presence of the LISTENER process(s) or you can issue the command "lsnrctl status".

5. What file will give you Oracle instance status information? Where is it located? Level: Low Expected answer: The alert.ora log. It is located in the directory specified by the background_dump_dest parameter in the v$parameter table.

6. Users aren?t being allowed on the system. The following message is received: Level: Intermediate ORA-00257 archiver is stuck. Connect internal only, until freed What is the

Page 56: What is Different Between TRUNCATE and DELETE

problem? Expected answer: The archive destination is probably full, backup the archive logs and remove them and the archiver will re-start.

7. Where would you look to find out if a redo log was corrupted assuming you are using Oracle mirrored redo logs? Level: Intermediate Expected answer: There is no message that comes to the SQLDBA or SRVMGR programs during startup in this situation, you must check the alert.log file for this information.

8. You attempt to add a datafile and get: Level: Intermediate ORA-01118: cannot add anymore datafiles: limit of 40 exceeded What is the problem and how can you fix it? Expected answer: When the database was created the db_files parameter in the initialization file was set to 40. You can shutdown and reset this to a higher value, up to the value of MAX_DATAFILES as specified at database creation. If the MAX_DATAFILES is set to low, you will have to rebuild the control file to increase it before proceeding.

9. You look at your fragmentation report and see that smon hasn?t coalesced any of you tablespaces, even though you know several have large chunks of contiguous free extents. What is the problem? Level: High Expected answer: Check the dba_tablespaces view for the value of pct_increase for the tablespaces. If pct_increase is zero, smon will not coalesce their free space.

10. Your users get the following error: Level: Intermediate ORA-00055 maximum number of DML locks exceeded What is the problem and how do you fix it? Expected answer: The number of DML Locks is set by the initialization parameter DML_LOCKS. If this value is set to low (which it is by default) you will get this error. Increase the value of DML_LOCKS. If you are sure that this is just a temporary problem, you can have them wait and then try again later and the error should clear.

11. You get a call from you backup DBA while you are on vacation. He has corrupted all of the control files while playing with the ALTER DATABASE BACKUP CONTROLFILE command. What do you do?

Level: High Expected answer: As long as all datafiles are safe and he was successful with the BACKUP controlfile command you can do the following: CONNECT INTERNAL STARTUP MOUNT (Take any read-only tablespaces offline before next step ALTER DATABASE DATAFILE .... OFFLINE;) RECOVER DATABASE USING BACKUP CONTROLFILE ALTER DATABASE OPEN RESETLOGS; (bring read-only tablespaces back online) Shutdown and backup the system, then restart If they have a recent output file from the ALTER DATABASE BACKUP CONTROL FILE TO TRACE; command, they can use that to recover as well. If no backup of the control file is available then the following will be required: CONNECT INTERNAL STARTUP NOMOUNT CREATE CONTROL FILE .....; However, they will need to know all of the datafiles, logfiles, and settings for MAXLOGFILES, MAXLOGMEMBERS, MAXLOGHISTORY, MAXDATAFILES for the database to use the command

Page 57: What is Different Between TRUNCATE and DELETE

Oracle RAC(Real Application Cluster) DBA Interview Questions

 What is RAC?RAC stands for Real Application cluster. It is a clustering solution from Oracle Corporation that ensures high availability of databases by providing instance failover, media failover features.Mention the Oracle RAC software components:-Oracle RAC is composed of two or more database instances. They are composed of Memory structures and background processes same as the single instance database.Oracle RAC instances use two processes GES(Global Enqueue Service), GCS(Global Cache Service) that enable cache fusion.Oracle RAC instances are composed of following background processes:ACMS—Atomic Controlfile to Memory Service (ACMS)GTX0-j—Global Transaction ProcessLMON—Global Enqueue Service MonitorLMD—Global Enqueue Service DaemonLMS—Global Cache Service ProcessLCK0—Instance Enqueue ProcessRMSn—Oracle RAC Management Processes (RMSn)RSMN—Remote Slave Monitor

What is GRD?GRD stands for Global Resource Directory. The GES and GCS maintains records of the statuses of each datafile and each cahed block using global resource directory.This process is referred to as cache fusion and helps in data integrity.Give Details on Cache Fusion:-Oracle RAC is composed of two or more instances. When a block of data is read from datafile by an instance within the cluster and another instance is in need of the same block,it is easy to get the block image from the insatnce which has the block in its SGA rather than reading from the disk. To enable inter instance communication Oracle RAC makes use of interconnects. The Global Enqueue Service(GES) monitors and Instance enqueue process manages the cahce fusion. Give Details on ACMS:-ACMS stands for Atomic Controlfile Memory Service.In an Oracle RAC environment ACMS is an agent that ensures a distributed SGA memory update(ie)SGA updates are globally committed on success or globally aborted in event of a failure.Give details on GTX0-j :-The process provides transparent support for XA global transactions in a RAC environment.The database autotunes the number of these processes based on the workload of XA global transactions.Give details on LMON:-This process monitors global enques and resources across the cluster and performs global enqueue recovery operations.This is called as Global Enqueue Service Monitor.Give details on LMD:-This process is called as global enqueue service daemon. This process  manages incoming remote resource requests within each instance.Give details on LMS:-This process is called as Global Cache service process.This process maintains statuses of datafiles and each cahed block by recording information in a Global Resource

Page 58: What is Different Between TRUNCATE and DELETE

Dectory(GRD).This process also controls the flow of messages to remote instances and manages global data block access and transmits block images between the buffer caches of different instances.This processing is a part of cache fusion feature.Give details on LCK0:-This process is called as Instance enqueue process.This process manages non-cache fusion resource requests such as libry and row cache requests.Give details on RMSn:-This process is called as Oracle RAC management process.These pocesses perform managability tasks for Oracle RAC.Tasks include creation of resources related Oracle RAC when new instances are added to the cluster.Give details on RSMN:-This process is called as Remote Slave Monitor.This process manages background slave process creation andd communication on remote instances. This is a background slave process.This process performs tasks on behalf of a co-ordinating process running in another instance.

What components in RAC must reside in shared storage?All datafiles, controlfiles, SPFIles, redo log files must reside on cluster-aware shred storage.

What is the significance of using  cluster-aware shared storage in an Oracle RAC environment?All instances of an Oracle RAC can access all the datafiles,control files, SPFILE's, redolog files

when these files are hosted out of cluster-aware shared storage which are group of shared disks.Give few examples for solutions that support cluster storage:-ASM(automatic storage management),raw disk devices,network file system(NFS), OCFS2 and OCFS(Oracle Cluster Fie systems).

What is an interconnect network?an interconnect network is a private network that connects all of the servers in a cluster. The interconnect network uses a switch/multiple switches that only the nodes in the cluster can access.

How can we configure the cluster interconnect?Configure User Datagram Protocol(UDP) on  Gigabit ethernet for cluster interconnect.On unia and linux systems we use UDP and RDS(Reliable data socket) protocols to be used by Oracle Clusterware.Windows clusters use the TCP protocol.

Can we use crossover cables with Oracle Clusterware interconnects?No, crossover cables are not supported with Oracle Clusterware intercnects.

Page 59: What is Different Between TRUNCATE and DELETE

What is the use of cluster interconnect?Cluster interconnect is used by the Cache fusion for inter instance communication.

How do users connect to database in an Oracle RAC environment?Users can access a RAC database using a client/server configuration or through one or more middle tiers ,with or without connection pooling.Users can use oracle services feature to connect to database.

What is the use of a service in Oracle RAC environemnt?Applications should use the services feature to connect to the Oracle database.Services enable us to define rules and characteristics to control how users and applications connect to database instances.

What are the characteriscs controlled by Oracle services feature?The charateristics include a unique name, workload balancing and failover options,and high availability characteristics.

Which enable the  load balancing of applications in RAC?Oracle Net Services enable the load balancing of application connections across all of the instances in an Oracle RAC database.

What is a virtual IP address or VIP?A virtl IP address or VIP is an alternate IP address that the client connectins use instead of the standard public IP address. To configureVIP address, we need to reserve a spare IP address for each node, and the IP addresses must use the same subnet as the public network.

What is the use of VIP?If a node fails, then the node's VIP address fails over to another node on which the VIP address can accept TCP connections but it cannot accept Oracle connections.Give situations under which VIP address failover happens:-VIP addresses failover happens when the node on which the VIP address runs fails, all interfaces for the VIP address fails, all interfaces for the VIP address are disconnected from the network.

What is the significance of VIP address failover?When a VIP address failover happens, Clients that attempt to connect to the VIP address receive a rapid connection refused error .They don't have to wait for TCP connection timeout messages.

Page 60: What is Different Between TRUNCATE and DELETE

What are the administrative tools used for Oracle RAC environments?Oracle RAC cluster can be administered as a single image using OEM(Enterprise Manager),SQL*PLUS,Servercontrol(SRVCTL),clusterverificationutility(cvu),DBCA,NETCA

How do we verify that RAC instances are running?Issue the following query from any one node connecting through SQL*PLUS.$connect sys/sys as sysdbaSQL>select * from V$ACTIVE_INSTANCES;The query gives the instance number under INST_NUMBER column,host_:instancename under INST_NAME column.

What is FAN?Fast application Notification as it abbreviates to FAN relates to the events related to instances,services and nodes.This is a notification mechanism that Oracle RAc uses to notify other processes about the configuration and service level information that includes service status changes such as,UP or DOWN events.Applications can respond to FAN events and take immediate action.

Where can we apply FAN UP and DOWN events?FAN UP and FAN DOWN events can be applied to instances,services and nodes.

State the use of FAN events in case of a cluster configuration change?During times of cluster configuration changes,Oracle RAC high availability framework publishes a FAN event immediately when a state change occurs in the cluster.So applications can receive FAN events and react immediately.This prevents applications from polling database and detecting a problem after such a state change.

Why should we have seperate homes for ASm instance?It is a good practice to have ASM home seperate from the database hom(ORACLE_HOME).This helps in upgrading and patching ASM and the Oracle database software independent of each other.Also,we can deinstall the Oracle database software independent of the ASM instance.

What is the advantage of using ASM?Having ASM is the Oracle recommended storage option for RAC databases as the ASM maximizes performance by managing the storage configuration across the disks.ASM does this by distributing the database file across all of the available storage within our cluster database environment.

Page 61: What is Different Between TRUNCATE and DELETE

What is rolling upgrade?It is a new ASM feature from Database 11g.ASM instances in Oracle database 11g release(from 11.1) can be upgraded or patched using rolling upgrade feature. This enables us to patch or upgrade ASM nodes in a clustered environment without affecting database availability.During a rolling upgrade we can maintain a functional cluster while one or more of the nodes in the cluster are running in different software versions.

Can rolling upgrade be used to upgrade from 10g to 11g database?No,it can be used only for Oracle database 11g releases(from 11.1).

State the initialization parameters that must have same value for every instance in an Oracle RAC database:-Some initialization parameters are critical at the database creation time and must have same values.Their value must be specified in SPFILE or PFILE for every instance.The list of parameters that must be identical on every instance are given below:ACTIVE_INSTANCE_COUNTARCHIVE_LAG_TARGETCOMPATIBLECLUSTER_DATABASECLUSTER_DATABASE_INSTANCECONTROL_FILESDB_BLOCK_SIZEDB_DOMAINDB_FILESDB_NAMEDB_RECOVERY_FILE_DESTDB_RECOVERY_FILE_DEST_SIZEDB_UNIQUE_NAMEINSTANCE_TYPE (RDBMS or ASM)PARALLEL_MAX_SERVERSREMOTE_LOGIN_PASSWORD_FILEUNDO_MANAGEMENTCan the DML_LOCKS and RESULT_CACHE_MAX_SIZE be identical on all instances?These parameters can be identical on all instances only if these parameter values are set to zero.What two parameters must be set at the time of starting up an ASM instance in a RAC environment?The parameters CLUSTER_DATABASE and INSTANCE_TYPE must be set.Mention the components of Oracle clusterware:-Oracle clusterware is made up of components like voting disk and Oracle Cluster Registry(OCR). What is a CRS resource?Oracle clusterware is used to manage high-availability operations in a cluster.Anything that Oracle Clusterware manages is known as a CRS resource.Some examples of CRS resources are database,an instance,a service,a listener,a VIP address,an application process etc.What is the use of OCR?Oracle clusterware manages CRS resources based on the configuration information of CRS

Page 62: What is Different Between TRUNCATE and DELETE

resources stored in OCR(Oracle Cluster Registry).

How does a Oracle Clusterware manage CRS resources?Oracle clusterware manages CRS resources based on the configuration information of CRS resources stored in OCR(Oracle Cluster Registry).

Name some Oracle clusterware tools and their uses?OIFCFG - allocating and deallocating network interfacesOCRCONFIG - Command-line tool for managing Oracle Cluster RegistryOCRDUMP - Identify the interconnect being usedCVU - Cluster verification utility to get status of CRS resources

What are the modes of deleting instances from ORacle Real Application cluster Databases?We can delete instances using silent mode or interactive mode using DBCA(Database Configuration Assistant).

How do we remove ASM from a Oracle RAC environment?We need to stop and delete the instance in the node first in interactive or silent mode.After that asm can be removed using srvctl tool as follows:srvctl stop asm -n node_namesrvctl remove asm -n node_nameWe can verify if ASM has been removed by issuing the following command:srvctl config asm -n node_name

How do we verify that an instance has been removed from OCR after deleting an instance?Issue the following srvctl command:srvctl config database -d database_namecd CRS_HOME/bin./crs_stat

How do we verify an existing current backup of OCR?We can verify the current backup of OCR using the following command : ocrconfig -showbackup

What are the performance views in an Oracle RAC environment?We have v$ views that are instance specific. In addition we have GV$ views called as global views that has an INST_ID column of numeric data type.GV$ views obtain information from individual V$ views.

Page 63: What is Different Between TRUNCATE and DELETE

What are the types of connection load-balancing?There are two types of connection load-balancing:server-side load balancing and client-side load balancing.

What is the differnece between server-side and client-side connection load balancing?Client-side balancing happens at client side where load balancing is done using listener.In case of server-side load balancing listener uses a load-balancing advisory to redirect connections to the instance providing best service.Give the usage of srvctl:-srvctl start instance -d db_name -i "inst_name_list" [-o start_options]srvctl stop instance -d name -i "inst_name_list" [-o stop_options]srvctl stop instance -d orcl -i "orcl3,orcl4" -o immediatesrvctl start database -d name [-o start_options]srvctl stop database -d name [-o stop_options]srvctl start database -d orcl -o mount

Oracle Dataguard 11g - Redo Transport Services - Synchronous Redo Transport (SYNC)

Oracle dataguard 11g is the latest high availability solution from Oracle Corporation.It uses the concept of primary database and one or more standby databases to provide high availability.Basic mechanism behind standby database configuration is the Redo Transport Services, wherein redo data is shipped from Primary database to one or more standby databases.

http://neworacledba.blogspot.com/2009/10/oracle-dataguard-11g-redo-transport_16.html

A comprehensive set of Oracle dataguard processes help in redo shipping.Some important processes are :

1) Log Network Server (LNS) - Runs on primary database. It reads the redo information directly from redo log buffer in SGA and ships it to standby databases with the help of Oracle Net Services

2) RFS (Remote File Server) - This is the LNS counterpart at standby database site. It recevies the redo information sent by LNS and writes them to standby Redo Log File (SRL)

Depending on method in which redo transport services work, there are two types of redo transport services :

1) Synchronous Redo Transport (SYNC). Also known as zero data loss

2) Asynchronous redo transport (ASYNC)

We'll be discussing about synchronous redo transport(SYNC)/zero data loss in detail in this post.

1) Whenever an user commits a transaction, corresponding redo vectors are written from redo log buffer in SGA to online redo log file using the process LGWR (Log Writer).

Page 64: What is Different Between TRUNCATE and DELETE

2) At the same time Log Network Server (LNS) reads the redo information from redo log buffer in SGA and ships it to standby sites with the help of Oracle Net Services.

3) Remote File Server (RFS) process at the standby site receives the information sent by LNS from primary database site and writes them to standby redo log files (SRL).

Both Linux and Solaris are flavours of UNIX. Solaris is the form of unix customized by Sun Microsystems. It is now acquired by Oracle Corporation. Linux is an open source. It is now being customized by many different companies like ORacle Corporation,Red Hat, SuSe, Debian etc. Some unix commands are common to both linux and solaris whereas some commands differ.

Linux is a freeware and some vendors like fedora core offer linux whichcan be downloaded and installed for free.

Solaris is licenced version from sun microsystems (can be fixed or floating licence).

Both are operating systems upon which all the applications run.

Sun has its own form of hardware called as sun servers which are used to host solaris.

Check the documentation of the vendor before installing linux to confirm the compatability of linux in the particular hardware.

There are many open source forms and groups that helps us information on linux.

Storage Manager) 11g - ASMCMD Copy Command

From Oracle database 11g, ASMCMD has COpy option included to it.It is used to copy database files into and out of ASM diskgroups in local system or an remote system.ASMCMD copy command can be used to transfer files. It doesn't require an active database instance.Following files can be transferred using ASMCMD Copy Command :

1) Data files

2) archived redo log files

3) password file

4) Initialization parameter file

http://neworacledba.blogspot.com/2009/10/oracle-asm-automatic-storage-manager_22.html

Usage :

cp - ifr connect_string:source_filename connect_string:targetfilename

Page 65: What is Different Between TRUNCATE and DELETE

Where options are,

i - Interactive copy. Prompt before copying or overwriting the file

f - If the destination file already exists, remove it and try again without user interaction

r - recursive copy. Same as normal copy command. Copies all subdirectories

source_filename - Source file name. It can be fully qualified filename(full path), an ASM alias

target_filename - target file name

target_directory - target directory

connection_string - connection string used in case of remote instance copy. Not needed for local system. It is of form host:port. In case of local system port number is 1521

Oracle Dataguard 11g - Redo Transport Services - Synchronous Redo Transport (SYNC)

Oracle dataguard 11g is the latest high availability solution from Oracle Corporation.It uses the concept of primary database and one or more standby databases to provide high availability.Basic mechanism behind standby database configuration is the Redo Transport Services, wherein redo data is shipped from Primary database to one or more standby databases.

http://neworacledba.blogspot.com/2009/10/oracle-dataguard-11g-redo-transport_16.html

A comprehensive set of Oracle dataguard processes help in redo shipping.Some important processes are :

1) Log Network Server (LNS) - Runs on primary database. It reads the redo information directly from redo log buffer in SGA and ships it to standby databases with the help of Oracle Net Services

2) RFS (Remote File Server) - This is the LNS counterpart at standby database site. It recevies the redo information sent by LNS and writes them to standby Redo Log File (SRL)

Depending on method in which redo transport services work, there are two types of redo transport services :

1) Synchronous Redo Transport (SYNC). Also known as zero data loss

2) Asynchronous redo transport (ASYNC)

We'll be discussing about synchronous redo transport(SYNC)/zero data loss in detail in this post.

Page 66: What is Different Between TRUNCATE and DELETE

1) Whenever an user commits a transaction, corresponding redo vectors are written from redo log buffer in SGA to online redo log file using the process LGWR (Log Writer).

2) At the same time Log Network Server (LNS) reads the redo information from redo log buffer in SGA and ships it to standby sites with the help of Oracle Net Services.

3) Remote File Server (RFS) process at the standby site receives the information sent by LNS from primary database site and writes them to standby redo log files (SRL).

For full story read :

http://neworacledba.blogspot.com/2009/10/oracle-dataguard-11g-redo-transport_16.html