Friday, June 24, 2011

CTET Detail

You can find your admission card in Below given link .
Provisional Admit Card Information 
http://www.cbseonline.ernet.in/ctet/adminfo.aspx

General Information
http://hyd.tcs-itontap.com/dotcom/CBSE/


Tuesday, June 21, 2011

What is the best backup strategy for RMAN backup on production database?


The question of strategy really depends on your environment, if your database is small,
I recommend using full backup every day. if you have a larger bank to use incremental backup and
full week on the weekend, if you have a DataGuard and want a bit more secure you can also perform
backup of your DataGuard instead of a backup of your database production more for this you need a
little more attention..



Thursday, June 16, 2011

Unlocking the locked table

Some times we get an error while running a DDL statement on a table. something like below

SQL> drop table aa;
drop table aa
*
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already
in use
This happens because some other session is using this table or having a lock on this table.
Following is the simple procedure to kill the session holding the lock on this table and drop the table.
Note that this should be done only if you are sure that this table is no more required and all sessions holding lock on this table can be deleted
1. Get the object ID of the table to be dropped
SQL> select object_id from dba_objects where object_name = 'AA';
 OBJECT_ID
----------
   3735492
2. Get the session ID which is holding lock on this object from v$locked_object view
SQL> select OBJECT_ID, SESSION_ID, ORACLE_USERNAME, PROCESS from v$locked_object where OBJECT_ID = 3735492;
 OBJECT_ID SESSION_ID ORACLE_USERNAME                PROCESS
---------- ---------- ------------------------------ ------------------------
   3735492       1124 MSC                            4092@AKPRADH-LAP

3. Get the serial# of the SID using v$session
SQL> select sid, serial# from v$session where sid = 1124;
       SID    SERIAL#
---------- ----------
      1124      51189

Kill the session by connecting as sysdba and try dropping the table
SQL> alter system kill session '1124, 51189';
System altered.
SQL> drop table aa;
Table dropped.

Once the locks are removed, you should be able to drop the table.

Transparent Application Failover TAF

1. BASIC METHOD
ADD THE ENTRIES TO THE RAC DATABASE NODE1 tnsnames.ora file
CDBS_TAF =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = node1-vip.localdomain)(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = node2-vip.localdomain)(PORT = 1521))
    (LOAD_BALANCE = yes)
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdbs)
      (FAILOVER_MODE=
      (TYPE=SELECT)
      (METHOD=BASIC)
     )
    )
  )
Make sure all the resources are up and running.
root@node1 bin]# ./crs_stat -t
Name           Type           Target    State     Host
------------------------------------------------------------
ora....s1.inst application    ONLINE    ONLINE    node1
ora....s2.inst application    ONLINE    ONLINE   node2
ora....bs1.srv application    ONLINE    ONLINE    node1
ora....bs2.srv application    ONLINE    ONLINE   node2
ora...._srv.cs application    ONLINE    ONLINE   node2
ora.cdbs.db    application    ONLINE    ONLINE   node2
ora....SM1.asm application    ONLINE    ONLINE    node1
ora....E1.lsnr application    ONLINE    ONLINE    node1
ora....de1.gsd application    ONLINE    ONLINE    node1
ora....de1.ons application    ONLINE    ONLINE    node1
ora....de1.vip application    ONLINE    ONLINE    node1
ora....SM2.asm application    ONLINE    ONLINE   node2
ora....E2.lsnr application    ONLINE    ONLINE   node2
ora....de2.gsd application    ONLINE    ONLINE   node2
ora....de2.ons application    ONLINE    ONLINE   node2
ora....de2.vip application    ONLINE    ONLINE   node2
[oracle@node1 admin]$ sqlplus system/oracle@CDBS_TAF
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Aug 26 17:36:45 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
SQL> show user;
USER is "SYSTEM"
SQL> col osuser format a10
SQL> col username format a10
SQL> col failover_type format a15
SQL> col failover_method format a18
SQL> select username,osuser,failover_method,failover_type from v$session
  2  where username='SYSTEM';
USERNAME   OSUSER     FAILOVER_METHOD    FAILOVER_TYPE
---------- ---------- ------------------ ---------------
SYSTEM     oracle     BASIC              SELECT

SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
cdbs1
SQL> select count(*) from demotb;
  COUNT(*)
----------
       954
SQL> select * from demotb;
run the long running query

simultaneously open another terminal and give shutdown abort instance cdbs1
SQL> shu abort
ORACLE instance shut down.
but the query runs smoothly without any interruption after the completion of the query, verify the instance name
SQL>select instance_name from v$instance;
INSTANCE_NAME
----------------
cdbs2
automatically it switch over to the instance cdbs2 , because of this user can access the database and no failure in queries. users can access without interruption.
USER will not receive any error message while running query.
2. PRECONNECT METHOD
Add the entries to the tnsnames.ora file on both nodes.
CDBS1_TAF =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = node1-vip.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdbs)
      (INSTANCE_NAME = cdbs1)
      (FAILOVER_MODE=
      (BACKUP=CDBS2_TAF)
      (TYPE=SELECT)
      (METHOD=PRECONNECT)
     )
    )
  )

CDBS2_TAF =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = node2-vip.localdomain)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = cdbs)
      (INSTANCE_NAME = cdbs2)
      (FAILOVER_MODE=
      (BACKUP=CDBS1_TAF)
      (TYPE=SELECT)
      (METHOD=PRECONNECT)
     )
    )
  )
connect to the database on node1
[oracle@node1 ~]$ sqlplus system/oracle@CDBS1_TAF
SQL*Plus: Release 10.2.0.1.0 - Production on Fri June 16 12:23:11 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Real Application Clusters, OLAP and Data Mining options
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
cdbs1
SQL> COL USERNAME FOR a10
SQL> col osuser for a10
SQL> col failover_type format a15
SQL> col failover_method for a18
SQL> select username,failover_type,failover_method from v$session
  2  where username='SYSTEM';
USERNAME   FAILOVER_TYPE   FAILOVER_METHOD
---------- --------------- ------------------
SYSTEM     SELECT          PRECONNECT
SQL> select count(*) from demo;
  COUNT(*)
----------
     49783
run the long running query.
SQL> select * from demo;
simultaneously issue shutdown abort in new terminal
SQL> shu abort;
ORACLE instance shut down.
SQL>
the query runs smoothly, user will not receive any kind of error messages.
then check the instance name in node1 machine.
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
cdbs2
SQL> select username,osuser,failover_type,failover_method from v$session
  2  where username='SYSTEM';
USERNAME   OSUSER     FAILOVER_TYPE   FAILOVER_METHOD
---------- ---------- --------------- ------------------
SYSTEM     oracle     SELECT          PRECONNECT
SQL>
checking node2 machine before and after TAF.
Before TAF
SQL> select username,osuser,failover_type,failover_method from v$session
  2  where username='SYSTEM';
USERNAME                       OSUSER                         FAILOVER_TYPE
------------------------------ ------------------------------ -------------
FAILOVER_M
----------
SYSTEM                         oracle                         NONE
NONE

SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
cdbs2
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
cdbs2
After TAF.
SQL> select username,osuser,failover_type,failover_method from v$session
  2  where username='SYSTEM';
USERNAME                       OSUSER                         FAILOVER_TYPE
------------------------------ ------------------------------ -------------
FAILOVER_M
----------
SYSTEM                         oracle                         SELECT
PRECONNECT




Connecting to RAC using SQLDeveloper

The following are two definition in tnsnames.ora pointing to the same RAC database. The first one uses name (racora1),
the second (racora) uses actual IP address:

racora1 = (DESCRIPTION =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = TCP)(HOST = db1.testoracle.COM)(PORT = 1521))    (ADDRESS = (PROTOCOL = TCP)(HOST = db2.testoracle.COM)(PORT = 1521))    (LOAD_BALANCE = yes)  )  (CONNECT_DATA =    (SERVER = DEDICATED)    (SERVICE_NAME = ORCL.testoracle.COM)    (FAILOVER_MODE =      (TYPE = SELECT)      (METHOD = BASIC)      (RETRIES = 180)      (DELAY = 5)    )  ))

racora2 = (DESCRIPTION =  (ADDRESS_LIST =    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.155.1.1)(PORT = 1521))    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.155.1.2)(PORT = 1521))    (LOAD_BALANCE = yes)  )  (CONNECT_DATA =    (SERVER = DEDICATED)    (SERVICE_NAME = ORCL.testoracle.COM)    (FAILOVER_MODE =      (TYPE = SELECT)      (METHOD = BASIC)      (RETRIES = 180)      (DELAY = 5)    )  ))

If you use SQL Developer to connect
to racora1 using the TNS, you will encounter the following error:
Status: Failure - Test failed: (null).

It works fine if you connect to racora. Apparently, it is not able to perform a nslookup to obtain the IP address when using TNS. It works fine if you use advance and use thin client to connect as in:
Strangely, if you use Advanced and put the following string, it works:
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = db1.testoracle.COM)(PORT = 1521))(ADDRESS = (PROTOCOL = TCP)(HOST = db2.testoracle.COM)(PORT = 1521))(LOAD_BALANCE = yes))(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME = ORCL.testoracle.COM)(FAILOVER_MODE=(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5))))

Wednesday, June 15, 2011

How to find what is locking a table.


How to find what is locking a table.
       1. Query from DBA_OBJECTS to find the object_name of the table getting locked.
       2. Query from V$LOCK where id1 = 'table_name', get sid.
       3. Query from v$PROCESS where pid = sid. THis has info on what is locking the table.

Select Randomly from Table
This feature allows you to randomly "sample" from a table. This feature has many great uses. The syntax is as follows:
SELECT COUNT(*) * 100
FROM EMP SAMPLE (1);
This will randomly sample 1% of the rows, multiple the count of them x 100 to get a rough estimate of the amount of rows in the table.
You can also randomly sample by blocks for better performance but possibly less random:
SELECT *
FROM EMP SAMPLE BLOCK (1);
Again, this samples roughly 1% of the table by blocks, which may not be 1% of the actual rows. But this will cause fewer blocks to be visited and decrease the elapsed time, but if the data is grouped in the table, it may not be very random.
This tool can be used to get a rough idea of the data in the table, or give good estimates when using group functions. For example, a great use of this would be on a 40 million row table:
SELECT AVG(number_of children) * 20
FROM dependants sample (5);
This will give you an average of the number of dependants by only sampling 5% of the table by only visiting 2 million rows and not 40 million.