Friday, December 31, 2010

What are ORACLE PRE-COMPILERS?

  • Using ORACLE PRE-COMPILERS, SQL statements and PL/SQL blocks can be contained inside 3GL programs written in C,C++,COBOL,PASCAL, FORTRAN,PL/1 AND ADA. 
  • The Precompilers are known as Pro*C,Pro*Cobol,This form of PL/SQL is known as embedded pl/sql,the language in which pl/sql is embedded is known as the host language. 
  • The pre-compiler translates the embedded SQL and pl/sql ststements into calls to the precompiler runtime library.The output must be compiled and linked with this library to create an executable.

How you can coalesce free space in oracle?

  • SMON coalesces free space (extents) into larger, contiguous extents every 2 hours and even then, only for a short period of time. 
  • SMON will not coalesce free space if a tablespace's default storage parameter "pctincrease" is set to 0. 
  • With Oracle 7.3 one can manually coalesce a tablespace using the ALTER TABLESPACE tblspace_temp COALESCE; command, until then use 
          SQL> alter session set events 'immediate trace name coalesce level n'
          Where 'n' is the tablespace number.
          SELECT TS#, NAME FROM SYS.TS$;
  • You can get status information about this process by selecting from the SYS.DBA_FREE_SPACE_COALESCED dictionary view.

What is the need of rebuilding of an index?

          ANALYZE INDEX  INDEX_NAME VALIDATE STRUCTURE;
  • Using above statement we can rebuild a Index.
  • Each command creates a single row in the V$INDEX_STATS view. This row is overwritten by the next ANALYZE INDEX command, so copy the contents of the view into a local table after each ANALYZE. 
  • The 'badness' of the index can then be identified DEL_LF_ROWS/LF_ROWS.

Tuesday, October 12, 2010

What is Row Level Lock in Oracle?

  • Oracle automatically acquires locks which are row-level locks. A transaction can held no of row locks and oracle does not work on it.
  • Row locking provides the lowest level of locking. It provides the best possible transaction concurrency.Readers of data do not wait for writers of the same data rows.  
  • A modified row is always locked exclusively so that other users cannot modify the row until the transaction holding the lock is committed or rolled back.
  • If a transaction obtains a row lock for a row, the transaction also acquires a table lock for the corresponding table. The table lock prevents conflicting DDL operations that would override data changes in a current transaction.
  • A Transaction gets an exclusive DML row level lock for each row modified by any of the following statements: INSERT, UPDATE, DELETE, and SELECT with the FOR UPDATE clause.

What are the options for SHUTDOWN a DATABASE?

SHUTDOWN NORMAL
Normal database shutdown proceeds with the following conditions:
  • No new connections are allowed after the statement is issued.
  • Before the database is shut down, Oracle waits for all currently connected users to disconnect from the database.
  • The next startup of the database will not require any instance recovery procedures.
SHUTDOWN IMMEDIATE
Use immediate database shutdown only in the following situations:
  • A power shutdown is going to occur soon.
  • The database or one of its applications is functioning irregularly.
  • Immediate database shutdown proceeds with the following conditions:
  • Any uncommitted transactions are rolled back. (If long uncommitted transactions exist, this method of shutdown might not complete quickly, despite its name.)
  • Oracle does not wait for users currently connected to the database to disconnect; Oracle implicitly rolls back active transactions and disconnects all connected users.

The SHUTDOWN IMMEDIATE statement disconnects all existing idle connections and shuts down the database. If, however, you have submitted processes (for example, inserts, selects or updates) that are awaiting results, the SHUTDOWN TRANSACTIONAL statement allows the process to complete before disconnecting.

SHUTDOWN TRANSACTIONAL
When you wish to perform a planned shutdown of an instance while allowing active transactions to complete first, use the SHUTDOWN command with the TRANSACTIONAL option:
  • After submitting this statement, no client can start a new transaction on this instance. If clients attempt to start a new transaction, they are disconnected. After all transactions have completed, any client still connected to the instance is disconnected. At this point, the instance shuts down just as it would when a SHUTDOWN IMMEDIATE statement is submitted.
  • A transactional shutdown prevents clients from losing work, and at the same time, does not require all users to log off. 

SHUTDOWN ABORT
You can shut down a database instantaneously by aborting the database's instance. If possible, perform this type of shutdown only in the following situations:
  • The database or one of its applications is functioning irregularly and neither of the other types of shutdown work.
  • You need to shut down the database instantaneously (for example, if you know a power shutdown is going to occur in one minute).
You experience problems when starting a database instance.
Aborting an instance shuts down a database and yields the following results:
  • Current client SQL statements being processed by Oracle are immediately terminated.
  • Uncommitted transactions are not rolled back.
  • Oracle does not wait for users currently connected to the database to disconnect; Oracle implicitly disconnects all connected users.

Sunday, September 12, 2010

How to switch a NOARCHIVELOG mode database into ARCHIVELOG mode? Please explain.

In order to switch to ARCHIVELOG mode from NOARCHIVELOG mode do the following:
edit your init.ora or spfile with the following information

1. create a archive log directory in a path and specify it in init.ora file.

log_archive_dest="/oradata/archlog"
log_archive_format="%t_%s.dbf"
log_archive_start=true

2. Once specifying the path-shut down the database and follow below steps:

shutdown database;
startup mount;
alter database archivelog;
alter database open;

Now, the database is in archivelog. Check it using
SELECT LOG_MODE FROM SYS.V$DATABASE;

Saturday, September 4, 2010

How the Explain Plan Works?

Whenever any read or write data in Oracle, it issuing an SQL statement. One of Oracle's task when it receives such a statement is to build a query execution plan.

An execution plan defines how Oracle finds or writes the data. For example, an important decision that Oracle has to take is if it uses indexes or not. And if there are more indexes, which of these is used. All this is contained in an execution plan.

If one wants to explore such an execution plan, Oracle provides the SQL statement EXPLAIN PLAN to determine this.

The general syntax of EXPLAIN PLAN is:
explain plan for your-precious-sql-statement;

If you do an EXPLAIN PLAN, Oracle will analyze the statment and fill a special table with the Execution plan for that statement. You can indicate which table has to be filled with the following SQL command:
explain plan into table_name for your-precious-sql-statement;
If you omit the INTO TABLE_NAME clause, Oracle fills a table named PLAN_TABLE by default.

The Plan Table

The plan table is the table that Oracle fills when you have it explain an execution plan for an SQL statement. You must make sure such a plan table exists. Oracle ships with the script UTLXPLAN.SQL which creates this table, named PLAN_TABLE (which is the default name used by EXPLAIN PLAN).

UTLXPLAN.SQL located under $ORACLE_HOME\RDBMS\ADMIN.