Saturday 27 February 2016

Hi everyone,
while working as an oracle dba I've come across many people who have doubt on what ORACLE_HOME and ORACLE_BASE is? I'll try to explain what these two terms exactly are.

What is ORACLE_HOME?

* The ORACLE_HOME is an environment variable which is used to set and define the path of Oracle Home (server) Directory.
* The ORACLE_HOME is an environment variable which contains the path of Oracle Home directory. It in turn contains all the sub directories, binaries, executables, scripts, etc. used by Oracle Database.
* The directory is generally used by ORACLE software and the user who installed the oracle software on the system.
* If the ORACLE_HOME variable is defined as an environment variable, then during the installation process, the Oracle Home Path will be set to the directory defined as default. If the variable is not defined, then the Oracle will take its own default location. i.e. The ORACLE_HOME variable does not have to be preset as an environment variable, it can be set during the installation process.
* Generally, ORACLE_HOME variable is referred using ORACLE_BASE directory:
ORACLE_HOME=$ORACLE_BASE/product/10.2.0.

What is the use of ORACLE_BASE directory?

* The ORACLE_BASE is like ORACLE_HOME is an environment variable used for defining base/root level directory. This is where you will have the Oracle Database directory tree : ORACLE_HOME is a level below ORACLE_BASE in the directory tree.
Therefore, ORACLE_BASE directory is a higher-level directory, than ORACLE_HOME. Which is used for installing various Oracle Software Products and for having more than one oracle installation.


How to see if ORACLE_HOME is set already?

On Unix/Linux Systems:

$ echo $ORACLE_HOME

To check all the environment variables set:

$ env

On Windows Systems:

To check specific environment variable set:


C:\echo %ORACLE_HOME%

To check all the environment variables set:

C:\> env

One can also check ORACLE_HOME from registry.

WINDOWS+R-> Regedit (enter)
Go to following :
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE

How to set the ORACLE_HOME?

On Unix/Linux Systems:

Define the ORACLE_HOME value in the user profile file i.e. .bash_profile or .profile

ORACLE_HOME=$ORACLE_BASE/product/10.2.0
export ORACLE_HOME


On Windows Systems:

Goto:
My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> New/Edit/Delete (to set the variables)

Then open a new cmd prompt and type:
C:\echo %ORACLE_HOME%


Another way using command prompt:

C:\> set ORACLE_HOME=C:\oracle\app\product\10.2.0
C:\> echo %ORACLE_HOME%

Note: Refer to oracle documentation for more exhaustive information on above topics.

Thursday 25 February 2016

INTRODUCTION TO DATABASES


DATA

Datum is any fact that can be recorded.
And set of datum is data.

eg: {12, apple, 3.14} is data, or set of datum.

DATABASE

Database is a collection of data, which is related. But what do we exactly mean by the term 'related'?

As we stated earlier, data is a set. Now suppose we have two sets NAME and PET_NAME as follows:

NAME={RAM, HARRY, JEFF, SUPRIYA}
PET_NAME={SCOOBY, BRUT, TAMAYA, FOO, DOZO}

Now, if elements from set NAME are having pets having names PET_NAME, and we have following relations given:
  • RAM has a dog named SCOOBY
  • HARRY has a cat names TAMAYA and a mouse named FOO
  • JEFF has a dog named BRUT
  • SUPRIYA has a dog named DOZO
Then to represent this data, we may want to uset sets as we did earlier right?
But how to represent these mappings??
ANSWER: We use ordered pair. It is a pair representing a pair of related objects from different sets.

To represent above set:

{(RAM,SCOOBY),(HARRY,TAMAYA),(HARRY,FOO),(JEFF,BRUT),(SUPRIYA,DOZO)}


This set of ordered pairs is called a RELATION. 

And sets NAME and PET_NAME are said to be related.:)



Hope that clears the definition of database. Lets move firther now!!

FUNCTIONAL DEPENDENCIES


PREREQUISITES
Before we start with functional dependencies it is important to review the topics sets, relations and functions, as the whole database revolves around it. Also the term from one set to another.


SETS, RELATIONS AND FUNCTIONS


SETS

A set is a well defined collection of objects.
By ‘well defined’ we mean that given any object, we could look at it and say if it belongs to the set or not.
Example:
·       Collection of driving licenses of people of a country is a set
·       Collection of cources in a university is a set
·       Collection of smart students in a class is not a set, as it is ambiguous to say if a student is smart or not and is more of a personal opinion.

RELATIONS

Consider the following example :
Set A={Harry, Mark, Russell, Bruce}
Set B={Suzy, Jessica, Chritine}
Suppose Suzy has two brothers Harry and Mark,
Jessica has one brother Russell, and Chritine has one brother Bruce.
If we define a relation R " is a brother of" between the elements of A and B then clearly.
Harry R Suzy, Mark R Suzy, Russell R Jessica, Bruce R Chritine.
Instead of writing R between two names these can be written in the form of ordered pairs as :
(Harry, Suzy), (Mark, Suzy), (Russell, Jessica), (Bruce, Chritine).
The above information can also be written in the form of a set R of ordered pairs as
R= {(Harry, Suzy), (Mark, Suzy), (Russell, Jessica), Bruce, Chritine}
Clearly R Í A´B, i.e.R = {(a,b):aÎ Î A,b B and aRb}
If A and B are two sets then a relation R from A to B is a sub set of A×B



FUNCTIONS

Consider the relation:
                                                     f : {(a, 1), (b, 2), (c, 3), (d, 5)}


In this relation we see that each element of A has a unique image in B
This relation f from set A to B where every element of A has a unique image in B is defined as a function from A to B.
Therefore, we can say function is a relation in which no two ordered pairs have the same first element.
We also see that an element of B, i.e., 4 which does not have its preimage in A.
Symbolically, this function can be written as
f : A ->B




Now that we have understood the concepts of sets, relations and functions, lets move on with Functional Dependencies!!!

DATABASE DESIGN USING ER MODELS


The entity relationship model (or ER model) is a way to represent data in a database, and how different data is related to each other. It is one of the first steps to create a database.

Using ER diagrams simplifies the database design process, and involved the least technicalities.

It is used to create a blueprint of the database from the requirements of the client.  

The ER model was first proposed by Peter Pin-Shan Chen of Massachusetts Institute of Technology(MIT).

BUILDING BLOCKS OF ER MODELS

1.Entity: 
Entity is a collection of same type of data. For example, in a school collection of names of all the students is an entity.

Therefore, entities are nothing but set of data of same type.

While designing ER diagrams, we usually take all the common nouns as entities.

Example: Suppose we have to design a university database. The entities required may be:
  • Students
  • Teachers
  • Courses
  • Departments
....and so on

2.Attribute:
Every entity is a common noun. And common nouns are nothing but set of real life objects. Every real life objects has some properties, for example: A car is an object(or entity, or common noun, anything that floats your boat ;) ). A car has following properties:
  • Registration Number
  • Number Place
  • Model Name
  • Car manufacturer
Therefore all of above are Attributes of the entity CAR

3.Relationship:
As in INTRODUCTION TO DATABASES, I've discussed that database is a collection of related data, and what exactly do we mean by 'related'.

In ER modelling, we determine all the verbs involved in the requirement of the client and make them as relationships.
Example: According to client following are the requirements:

  • Entity STUDENTS
  • Entity TEACHER
  • TEACHER teaches STUDENTS

Therefore, here, TEACHES is a relationship




INTRODUCTION TO FUNCTIONAL DEPENDENCIES


As we discussed in previous section, a relation R from set A to B is a function,

if and only if, For every element in A, there is only one unique image in B.

Extending this concept to tables.

Lets say in a table there are two columns, A and B.

Both A and B contain values or data, thus they are both sets.

A->B, means that there is a function from A to B.

A
B
1
a
2
b
3
a
4
c
5
d
6
d
As we can see in the table each element in A is mapped to a unique element in B.

FORMALLY

A->B,
Means, 
           If, 
               row1(A)=a AND there is another row2 such that row2(A)=a
           Then,
                row1(A)=row2(B)=b 

In simple terms if in a table we have two rows with same value ‘a’ in column A, then as A->B,

‘a’ is associated with a unique value ‘b’ in B. Thus whenever we see ‘a’  we can say that value in column B will be ‘b’



TEST YOURSELF

Which of the functional dependencies are valid for the given tables:


1.

Eid
Ename
1
a
2
b
3
b
a.) Eid->Ename
b.) Ename->Eid
c.) none

2.

A
B
1
1
1
2
2
2
a.) A->B
b.) B->A
c.) None

3.

A
B
C
1
1
4
1
2
4
2
1
3
2
2
3
2
4
3

a.) A->B
b.) B->C
c.) B->A
d.) C->B
e.) A->C
f.) C->A





Answers:
1-a 
2-c
3-e,f


NEXT:

VARIOUS USAGES OF FUNCTIONAL DEPENDENCIES:

1) Identifying additional functional dependencies from given functional dependencies
2) Identifying candidate keys
3) Identifying equivalent functional dependencies
4) Finding minimal functional dependencies

METHOD USED (Not the only method)


  • CLOSURE SET of attributes





10 Most Frequently Used Linux/UNIX Commands


Hi everyone, today I’m posting a list of most frequently used linux commands that I use.

1.ls command

Display filesize in human readable format (e.g. KB, MB etc.,)
$ ls -lh
-rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr


2.sort command 
Sort a file in ascending order
$ sort file.txt
Sort a file in descending order
$ sort -r file.txt

3.grep command 
Search for a given string in a file (case in-sensitive search).



$ grep -i "the" example_file
Print the matched line, along with the 5 lines after it.
$ grep -A 5 -i "example" example_text
Search for a given string in all files recursively
$ grep -r "Sam" *

4. find command

Find files using file-name ( case in-sensitve find)
# find -iname "HelloWorld.c"
Execute commands on files found by the find command

$ find -iname "MyCProgram.c" -exec md5sum {} \;

5.ssh command
Login to remote host
ssh -l ramu remotehost.example.com
Debug ssh client
ssh -v -l ramu remotehost.example.com

6.vim command
Go to the 100th line of file
$ vim +100 filename.txt
Go to the first match of the specified
$ vim +/search-term my_file.txt
Open the file in read only mode.
$ vim -R /etc/oratab


7. export command
To view oracle related environment variables.
$ export | grep ORACLE
declare -x ORACLE_BASE="/u01/app/oracle"
declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"
declare -x ORACLE_SID="med"
declare -x ORACLE_TERM="xterm"


8.gzip command
To create a *.gz compressed file:
$ gzip test.txt
To uncompress a *.gz file:
$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l
$ gzip -l *.gz
         compressed        uncompressed  ratio uncompressed_name
              23709               97975  75.8% asp-patch-rpms.txt

9.shutdown command examples
Shutdown the system and turn the power off immediately.
# shutdown -h now
Shutdown the system after 10 minutes.
# shutdown -h +10
Reboot the system using shutdown command.
# shutdown -r now

10.ftp command
To connect to a remote server and download multiple files.
$ ftp IP/hostname
ftp> mget *.html
To view the file names located on the remote server before downloading, mls ftp command as shown below.
ftp> mls *.html -
/test/hello.html
/test/employees.html
/test/tools.html
/test/sampletest.html
/test/users.html








PROCESS MANAGEMENT IN OPERATING SYSTEMS


The main use of operating systems is to execute programs. But in multiprogramming environment more than one programs need to be executed. However, since we have limited CPU’s(generally one), only a set of programs are actually using the cpu at a particular time.

Therefore, we have programs which are ready to be executed and which are currently using cpu or running.

Therefore, to distinguish between such programs we have states.

Also note, that whether a program is running or is ready to run it is kept in main memory or RAM as fetching programs again and again from disk upon state change will be very costly.

What is a process?


Def: A process is a program which is residing in the main memory or RAM.

Now, since we may have many processes in the main memory we will need to distinguish between them. For this purpose we have a special data structure associated with every process. It is called Process Control Block or PCB

What is PCB?


A PCB essentially contains following information:

·       Process ID
o   It is a unique identifying number assigned by OS during process creation
·       Process State
o   Contains the current state info for the process
·       Program Counter
o   Contains the address of the next instruction to be executed in the process
·       Priority
o   Parameter assigned by the process during process creation. Representation of how important a process is wrt other processes
·       General Purpose registers
·       List of open files
·       List of open devices
·       Security and protection information


Various states of a process are:






·       

      New
o   The process is under creation , and when the process is created it moves to the ready state
·       Ready
o   In ready state, there are a number of processes, out of which one is selected to e executed
·       Running
o   In this state the CPU executes the instruction of the running process. Only one process can be in running state for a single processor system.
·       Wait(for I/P or some other event)
o   When process performs I/O operation, the process moves to this state.
·       Completed
o   When the process has reached the end and no more requires any resource
·       Suspend ready
·       Suspend wait


Following operations are performed on process:

·       Process creation
·       Process scheduling
·       Process execution
·       Termination/Completion