Sunday, December 4, 2011

RDBMS Concepts

1. what is a database?
Ans: A database is a logically collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose.

2.
What is DBMS?
Ans:
It is a collection of programs that enables user to create and maintain a database.In other words it is general purpose software that provides the users with the processes of defining, constructing and manipulating the database for various applications.

3. What is a database system?
Ans:
The Database and DBMS software together is called Database system.

4.What are the Advantages of DBMS?
Ans:

  • Redundancy is controlled
  • Unauthorised access is retricted.
  • Providing multiple user interfaces
  • Enforsing integrity constraints.
  • Providing Backup and Recovery.
5. What are the Disadvantages in file processing System?
Ans:

  • Data redundancy and inconsistancy
  • Difficult in accessing in data
  • Data isolation
  • Data integrity
  • Concurrent access is not possible
  • Security problems
6. Describe the three levels of data abstraction?
The are three levels of abstraction:
Physical level: The lowest level of abstraction describes how data are stored.
Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data.
View level: The highest level of abstraction describes only part of entire database.
7. Define the "integrity rules"
There are two Integrity rules.
Entity Integrity: States that “Primary key cannot have NULL value”

Referential Integrity: States that “Foreign Key can be either a NULL value or should be Primary Key value of other relation.
8. What is extension and intension?
Extension -
It is the number of tuples present in a table at any instance. This is time dependent.
Intension -
It is a constant value that gives the name, structure of table and the constraints laid on it.
9. What is System R? What are its two major subsystems?
System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be used in a real life environment to solve real life problems, with performance at least comparable to that of existing system.
Its two subsystems are
Ø Research Storage
Ø System Relational Data System.
10. How is the data structure of System R different from the relational structure?
Unlike Relational systems in System R
Ø Domains are not supported
Ø Enforcement of candidate key uniqueness is optional
Ø Enforcement of entity integrity is optional
Ø Referential integrity is not enforced
11. What is Data Independence?
Data independence means that “the application is independent of the storage structure and access strategy of data”. In other words, The ability to modify the schema definition in one level should not affect the schema definition in the next higher level.
Two types of Data Independence:
Physical Data Independence: Modification in physical level should not affect the logical level.
Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve
12. What is a view? How it is related to data independence?
A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is instead derived from one or more underlying base table. In other words, there is no stored file that direct represents the view instead a definition of view is stored in data dictionary.
Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from the effects of restructuring and growth in the database. Hence accounts for logical data independence.
13. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and constraints.
14. What is E-R model?
This data model is based on real world that consists of basic objects called entities and of relationship among these objects. Entities are described in a database by a set of attributes.
15. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance variables with in the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain same types of values and the same methods are grouped together into classes.
16. What is an Entity?
It is a 'thing' in the real world with an independent existence.
17. What is an Entity type?
It is a collection (set) of entities that have same attributes.
18. What is an Entity set?
It is a collection of all entities of particular entity type in the database.
19. What is an Extension of entity type?
The collections of entities of a particular entity type are grouped together into an entity set.
20. What is Weak Entity set?
An entity set may not have sufficient attributes to form a primary key, and its primary key compromises of its partial key and primary key of its parent entity, then it is said to be Weak Entity set.
21. What is an attribute?
It is a particular property, which describes the entity.
22. What is a Relation Schema and a Relation?
A relation Schema denoted by R(A1, A2, …, An) is made up of the relation name R and the list of attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-values t=(v1,v2, ..., vn).
23. What is degree of a Relation?
It is the number of attribute of its relation schema.
24. What is Relationship?
It is an association among two or more entities.


DBA Queries

Performance Tuning:

SUGGESTED MINIMUM SHARED POOL SIZE

SELECT cr_shared_pool_size,sum_obj_size, sum_sql_size,sum_user_size,(sum_obj_size + sum_sql_size+sum_user_size)* 1.3 min_shared_pool

FROM (SELECT SUM(sharable_mem) sum_obj_size FROM v$db_object_cache where type<> 'CURSOR'),

(SELECT sum(sharable_mem) sum_sql_size FROM v$sqlarea),

(SELECT sum(250*users_opening) sum_user_size FROM v$sqlarea),

(SELECT to_Number(b.ksppstvl) cr_shared_pool_size

FROM x$ksppi a, x$ksppcv b, x$ksppsv c WHERE a.indx = b.indx and a.indx = c.indx AND a.ksppinm ='__shared_pool_size' );

1)

HOW TO CHECK ORACLE DATABASE FOR LONG RUNNING QUERIES?

QUERIES CURRENTLY RUNNING FOR MORE THAN 60 SECONDS. NOTE THAT IT PRINTS MULTIPLE LINES PER RUNNING QUERY IF THE SQL HAS MULTIPLE LINES.

LOOK AT THE SID,SERIAL# TO SEE WHAT BELONGS TOGETHER.

SELECT S.USERNAME,S.SID,S.SERIAL#,S.LAST_CALL_ET/60 MINS_RUNNING,Q.SQL_TEXT

    FROM V$SESSION S

        JOIN V$SQLTEXT_WITH_NEWLINES Q

            ON S.SQL_ADDRESS = Q.ADDRESS

                 WHERE STATUS='ACTIVE'

                    AND TYPE <>'BACKGROUND'  AND LAST_CALL_ET> 60

                    and username='DBO_ASIC_APR_LATEST'

ORDER BY SID,SERIAL#,Q.PIECE ;

2)

THE FOLLOWING SQL THAT IS CURRENTLY "ACTIVE":-

SELECT S.USERNAME, S.SID, S.OSUSER, T.SQL_ID, SQL_TEXT

    FROM V$SQLTEXT_WITH_NEWLINES T,V$SESSION S

        WHERE T.ADDRESS =S.SQL_ADDRESS

            AND T.HASH_VALUE = S.SQL_HASH_VALUE  AND S.STATUS = 'ACTIVE'  AND S.USERNAME <> 'SYSTEM'   and username='DBO_ASIC_FEB_DEMO'

ORDER BY S.SID,T.PIECE;

SELECT S.USERNAME, S.SID, S.OSUSER,  T.SQL_ID,A.SQL_FULLTEXT,S.LOGON_TIME ,S.STATUS

    FROM V$SQLTEXT_WITH_NEWLINES T,V$SESSION S ,v$sql a

        WHERE T.ADDRESS =S.SQL_ADDRESS

            AND T.HASH_VALUE = S.SQL_HASH_VALUE

            AND A.SQL_ID=T.SQL_ID AND S.STATUS = 'ACTIVE'  AND S.USERNAME <> 'SYSTEM' and username='DBO_ASIC_FEB_DEMO'

ORDER BY S.SID,T.PIECE;

SELECT

  SST.VALUE CPU, S.USERNAME, S.SID, S.SERIAL#, SQL_TEXT

FROM

  V$SESSION S,

  V$SQLTEXT_WITH_NEWLINES T,

  V$SESSTAT SST

WHERE S.SQL_ID IS NOT NULL

AND S.SQL_ID = T.SQL_ID

AND SST.SID = S.SID

AND SST.STATISTIC# = (SELECT STATISTIC# FROM V$STATNAME SN WHERE SN.NAME = 'CPU used by this session')

ORDER BY 1 DESC, S.SID,T.PIECE;

3)

THIS SHOWS LOCKS. SOMETIMES THINGS ARE GOING SLOW, BUT IT'S BECAUSE IT IS BLOCKED WAITING FOR A LOCK

SELECT OBJECT_NAME,OBJECT_TYPE,  SESSION_ID,  TYPE,-- TYPE OR SYSTEM/USER LOCK

        LMODE, -- LOCK MODE IN WHICH SESSION HOLDS LOCK

        REQUEST,BLOCK,CTIME                 -- TIME SINCE CURRENT MODE WAS GRANTED

            FROM  V$LOCKED_OBJECT, ALL_OBJECTS, V$LOCK

                WHERE V$LOCKED_OBJECT.OBJECT_ID = ALL_OBJECTS.OBJECT_ID AND V$LOCK.ID1 = ALL_OBJECTS.OBJECT_ID AND V$LOCK.SID = V$LOCKED_OBJECT.SESSION_ID

ORDER BY SESSION_ID, CTIME DESC, OBJECT_NAME;

4)

THIS IS A GOOD ONE FOR FINDING LONG OPERATIONS (E.G. FULL TABLE SCANS). IF IT IS BECAUSE OF LOTS OF SHORT OPERATIONS, NOTHING WILL SHOW UP.

SELECT sid, to_char(start_time,'hh24:mi:ss') stime,message,( sofar/totalwork)* 100 percent

    FROM v$session_longops

        WHERE sofar/totalwork < 1;

5)

   v$session_longops if you look for sofar != totalwork you'll see ones that haven't completed but the entries aren't removed when the operation completes so you can see a lot of history there too.

YOU CAN DETERMINE WHAT THE LONG OPERATIONS ARE BY RUNNING THE FOLLOWING QUERY:

SELECT SID,MESSAGE || '(' || TIME_REMAINING || ')' "LONG OPS"

    FROM V$SESSION_LONGOPS

        WHERE TIME_REMAINING > 600;

6)

HERE IS A QUERY THAT ONLY SHOWS QUERIES THAT ARE LONG RUNNING (WHICH MEANS TAKE MORE THAN 6 SECONDS), HAVE SOME TIME REMAINING (SO THEY ARE ACTIVE),

AND SHOWS YOU WHO IS RUNNING AND WHAT IS BEING RUN.

SELECT A.SID,(A.SOFAR/A.TOTALWORK)*100 "% DONE",TO_CHAR(A.LAST_UPDATE_TIME, 'HH24:MI:SS'),A.USERNAME,A.TIME_REMAINING "TIME LEFT",A.OPNAME ,b.status,S.SQL_TEXT

    FROM V$SESSION_LONGOPS A, V$SESSION B, V$SQLTEXT S

        WHERE A.SID =B.SID AND B.SQL_ADDRESS = S.ADDRESS AND A.SOFAR <> A.TOTALWORK

ORDER BY B.SID, LAST_UPDATE_TIME

7)

select

'alter system kill session    '||''''||SID||','||SERIAL#||''';'

from v$session where USERNAME='DBO_ASIC_APR_LATEST'  and PROGRAM ='sqlplusw.exe'

----

----alter system kill session    '19,23383';

8)

select a.sid,

to_char(a.last_update_time, 'HH24:MI:SS'),

a.username,a.time_remaining "Time Left", b.status,

s.sql_text

from v$session_longops a, v$session b, v$sqltext s

where a.sid =b.sid and b.sql_address = s.address

and a.sofar <> a.totalwork;

9)

select package_name, object_name, nvl(overload,0) "ovload",

decode(min(position),0,'Function','Procedure') "Type",

count(argument_name) "Parameters"

from all_arguments

where package_name like upper('&pkg_name') group by package_name, object_name, overload;

10)

select * from all_objects where objecT_name LIKE'%RMAN%'

11)

select * from dba_directories

12)

    Tacefile

 

select

  u_dump.value   || '/'     ||

  db_name.value  || '_ora_' ||

  v$process.spid ||

  nvl2(v$process.traceid,  '_' || v$process.traceid, null )

  || '.trc'  "Trace File"

from

             v$parameter u_dump

  cross join v$parameter db_name

  cross join v$process

        join v$session

          on v$process.addr = v$session.paddr

where

 u_dump.name   = 'user_dump_dest' and

 db_name.name  = 'db_name'        and

 v$session.audsid=sys_context('userenv','sessionid');