Wednesday, January 25, 2012

Change open_cursors Value


The Oracle initialization parameter OPEN_CURSORS specifies the number of cursors a session can have open at any one time. The default value is 300.
If the session attempts to open a new cursor but already has the maximum number of cursors open, the Oracle error -1000 will be returned.
Your client application may hit the following error :
ORA-01000: maximum open cursors exceeded

You can do two things,
1) Change the inti.ora parameter open_cursors = <increased-no>
init.ora file location = ORACLE_HOME\dbs
A database restart is needed to affect the above change.
You can check the value by below sql.
SQL> show parameter OPEN_CURSORS;
Note:
If you are using a spfile you can do it through below statement.
alter system set open_cursors=xxx scope=both;


2) In your application code , use For ...Cursors, because that automatically closes the cursor.
    If you cannot use For..Cursor, take care to close the cursors. Otherwise the opened cursors will persist in memory and increase the open_cursors count unnecessarily.



Tuesday, January 17, 2012

How to Enable Archive log Mode

If you are using an spfile



With the database open, issue
ALTER SYSTEM SET log_archive_start = true SCOPE=spfile;
ALTER SYSTEM SET log_archive_dest_1 = "location=D:\Oracle\oradata\orcl\archive" SCOPE=spfile;
ALTER SYSTEM SET log_archive_format = %%ORACLE_SID%%T%TS%S.ARC SCOPE spfile;


Then do the shutdown and mount the database.


connect sys/<pwd> as sysdba
startup mount;
ALTER DATABASE ARCHIVELOG; 
ALTER DATABASE OPEN; 
ALTER SYSTEM SWITCH LOGFILE; (To force the archive generation)
archive log list ; (for see that database is runing on archive or not)




If you are using a pfile


shutdown the database
in the INIT<SID>.ORA set
log_archive_start = true
log_archive_dest_1 = "location=D:\Oracle\oradata\orcl\archive" 
log_archive_format = %%ORACLE_SID%%T%TS%S.ARC


Then do the shutdown and mount the database.


connect sys/<pwd> as sysdba
startup mount;
ALTER DATABASE ARCHIVELOG; 
ALTER DATABASE OPEN; 
ALTER SYSTEM SWITCH LOGFILE; (To force the archive generation) 
archive log list(for see that database is runing on archive or not)







Friday, January 13, 2012

Flash Recovery Area renamed to Fast Recovery Area in 11g

Flash Recovery Area renamed to Fast Recovery Area in 11g
Curious about this renaming? Is it just a word change or is there something else behind ? 

It is just a name/word change. 

Suppose Oracle wanted it to better reflect the meaning - Ultimate goal of Fast Recovery


http://docs.oracle.com/cd/E11882_01/server.112/e10595/whatsnew003.htm#BGGBBGFI

Thursday, January 12, 2012

How to Check SGA size in Oracle Database

Use below sql statements to check the SGA size of a Oracle Database.


sql> SHOW SGA;
or
sql> SELECT name,value/1024/1024 "SGA (MB)" "FROM v$sga;


You can check the Total SGA size from below sql statement.


sql> SELECT sum(value)/1024/1024 "TOTAL SGA (MB)" FROM v$sga;











Using ORADIM to Create Instance on Oracle - Windows Platform

Oradim is an Oracle utility that creates a Service to a database. 
If a database is created upon install, or if you use Database Assistant to create a db, it will automatically use this utility to create a service to the db upon creation of the db. If you double click on the Services icon in Control Panel, you will see all the services that are available to the machine. If a machine has a db running on it, you will see a service by the name of OracleService(SID) with a manual or automatic startup type. If the startup is set to automatic, the db will shutdown/startup whenever the machine is restarted, else you will have to shutdown/startup manually. 


So you have to use oradim only when you create a database without using the Database Configuration Assistant. You have to use Oradim to create services if you created the database manually. 


Example of Oradim to create a service for an 9i database:

Create an instance by specifying the following options:
(type at command prompt) --->

 ORADIM -NEW -SID sid | -SRVC srvc | -ASMSID sid | -ASMSRVC srvc [-SYSPWD pass]
 [-STARTMODE auto|manual] [-SRVCSTART system|demand] [-PFILE file | -SPFILE]
 [-SHUTMODE normal|immediate|abort] [-TIMEOUT secs] [-RUNAS osusr/ospass]



Eg:

C:\oracle\bin\oradim –new –sid MYSID –intpwd <pwd> –maxusers 20 startmode auto –pfile initMYSID.ora







Monday, January 9, 2012

Oracle Spool Command (Output To File)

You can use Oracle SPOOL command to output of a query in SQL Plus in Oracle to an output file.


Below is an example.


SQL> Spool on
SQL> Spool c:\abc.log
SQL> Query
SQL> Spool off



Spool the output to a file without column names included.



SQL> Spool on
SQL> set heading off 
SQL> Spool c:\abc.log
SQL> Query
SQL> Spool off



Difference between ALTER DATABASE RECOVER & RECOVER DATABASE

Do you know the difference between below two commands/methods of recovery..?
You may get confused over these two commands.


1.ALTER DATABASE RECOVER;


2.RECOVER DATABASE;
   or
   RECOVER DATABASE UNTIL CANCEL; 


Both above commands are intend to achieve same task..but only difference is..


(1)Use ALTER DATABASE if you want to do the recoverying step by step, manually , issuing each and every single command to recover the database.


(2)Use the SQLPLUS  'RECOVER' command to have sqlplus automate the steps in (1) for you. 


RECOVER is not even a SQL command, rather it is a SQLPlus command.It is an automated command to do the normal recovery steps.


Oracle Corporation recommends that you use the SQL*Plus RECOVER statement.





Friday, January 6, 2012

Setting ORACLE_SID

The Oracle System ID (SID) is used to uniquely identify a particular database on a system


How to set ORACLE_SID:
Windows:
set ORACLE_SID=orcl


Unix/ Linux:
export ORACLE_SID=orcl


SID is case sensitive in Unix / Linux environments.




How to check the current ORACLE_SID:
Windows:
Go to the commnand prompt and type as


C:\> set ORACLE_SID (This will show if any ORACLE_SID is already set).
C:\> set (To know all the parameters set)


Unix/ Linux:
echo $ORACLE_SID