Monday, 11 March 2013

Proxy Server and Configuration


What is a proxy server? How do I get proxy server information? 

(An intermediary between your home machine and the rest of the computers on the internet).



A proxy server is an intermediary computer that is between the user's computer and the Internet. It can be used to log Internet usage and also to block access to a web site. The firewall at the proxy server blocks some web sites or web pages for various reasons. As a result, you may be unable to download Java Runtime Environment (JRE) or to run some Java applets.
Proxy servers:
  • Act as a firewall and content filter
    A security mechanism deployed by the ISP's or network administrators in an Intranet environment to disable access or filter content requests to certain web sites considered offensive or harmful for the network and users.
  • Improve performance
    Caches (stores) web pages accessed by hosts on the network for a certain amount of time. Whenever any host requests the same web page, the proxy server uses the cached information instead of retrieving it from the content provider. This leads to quicker access of the web pages.

Getting Proxy Server Information
Check with your Internet Service Provider (ISP) or system administrator:
  • To get proxy server information
  • If Java applets are disabled to run on your network
  • If you are trying to access a blocked web site 
In an enterprise that uses the Internet, a proxy server is a server that acts as an intermediary between a workstation user and the Internet so that the enterprise can ensure security, administrative control, and caching service. A proxy server is associated with or part of a gateway server that separates the enterprise network from the outside network and a firewall server that protects the enterprise network from outside intrusion.
A proxy server receives a request for an Internet service (such as a Web page request) from a user. If it passes filtering requirements, the proxy server, assuming it is also a cache server , looks in its local cache of previously downloaded Web pages. If it finds the page, it returns it to the user without needing to forward the request to the Internet. If the page is not in the cache, the proxy server, acting as a client on behalf of the user, uses one of its own IP addresses to request the page from the server out on the Internet. When the page is returned, the proxy server relates it to the original request and forwards it on to the user.

To the user, the proxy server is invisible; all Internet requests and returned responses appear to be directly with the addressed Internet server. (The proxy is not quite invisible; its IP address has to be specified as a configuration option to the browser or other protocol program.)
An advantage of a proxy server is that its cache can serve all users. If one or more Internet sites are frequently requested, these are likely to be in the proxy's cache, which will improve user response time. In fact, there are special servers called cache servers. A proxy can also do logging.
The functions of proxy, firewall, and caching can be in separate server programs or combined in a single package. Different server programs can be in different computers. For example, a proxy server may in the same machine with a firewall server or it may be on a separate server and forward requests through the firewall.


A server that sits between a client application, such as a Web browser, and a real server. It intercepts all requests to the real server to see if it can fulfill the requests itself. If not, it forwards the request to the real server.

Proxy servers have two main purposes:




  • Improve Performance: Proxy servers can dramatically improve performance for groups of users. This is because it saves the results of all requests for a certain amount of time. Consider the case where both user X and user Y access the World Wide Web through a proxy server. First user X requests a certain Web page, which we'll call Page 1. Sometime later, user Y requests the same page. Instead of forwarding the request to the Web server where Page 1 resides, which can be a time-consuming operation, the proxy server simply returns the Page 1 that it already fetched for user X. Since the proxy server is often on the same network as the user, this is a much faster operation. Real proxy servers support hundreds or thousands of users. The major online services such as America Online, MSN and Yahoo, for example, employ an array of proxy servers.
  • Filter Requests: Proxy servers can also be used to filter requests. For example, a company might use a proxy server to prevent its employees from accessing a specific set of Web sites

  •   A Proxy

    Most internet browsers can be setup to run through proxies in just a matter of minutes.

    Internet Explorer Proxy Settings

    • Click Tools
    • Click Internet Options
    • Click the Connections Tab
    • Click LAN settings
    • Check the “Use a proxy server for your LAN” box
    • Enter the IP Address of the Proxy Server and the Port Number
    • Click OK
    • Go to WhatIsMyIP.com to check for proxy

    FireFox Proxy Settings

    • Click the FireFox Button(The button in the upper left corner)
    • Click Options
    • Click Options in the new tab
    • Click the Advanced Tab
    • Click Settings
    • Click Manual Proxy Settings
    • In the HTTP Proxy Box enter the IP Address of the proxy server and the Port number
    • Click OK
    • Go to WhatIsMyIP.com to check for proxy

    Google Chrome Proxy Settings

    • Click the Customize and Control Button(Button with the wrench picture in upper right corner
    • Click Under the Hood
    • Click Change proxy settings
    • Click LAN Settings
    • Check the “Use a proxy server for your LAN” box
    • Enter the IP Address of the Proxy Server and the Port Number
    • Click OK
    • Go to WhatIsMyIP.com to check for proxy

    Safari Proxy Settings

    • Click Safari
    • Click Preferences
    • Click Advanced
    • Click Change Settings
    • Check the Web Proxy(HTTP) box
    • Enter the IP Address of the Proxy Server and the Port Number
    • Click Apply Now
    • Go to WhatIsMyIP.com to check for proxy

    Proxy Detection

    Are you truly hidden? We do provide proxy detection at WhatIsMyIP.com. If your proxy is setup correctly you will see it’s IP address on the homepage and you may receive a message that a proxy was detected. It is impossible to detect all proxies. We may not detect your proxy but that does not mean that other sites can’t.


    How do I configure proxy settings for Java? 


    Proxy settings for running applets can be controlled through the Java Control Panel.

    Find the Java Control Panel
    Windows XP
    • Click on the Start button and then click on the Control Panel option.
    • Double click on the Java icon to open the Java Control Panel.
    Windows 7, Vista
    • Click on the Start button and then click on the Control Panel option.
    • In the Control Panel Search enter Java Control Panel.
    • Click on the Java icon to open the Java Control Panel.
    Windows 8
    Use search to find the Control Panel
    • Press Windows logo key + W to open the Search charm to search settings
      OR
      Drag the Mouse pointer to the bottom-right corner of the screen, then click on the Search icon.
    • In the search box enter Java Control Panel
    • Click on Java icon to open the Java Control Panel.

    Mac OS X 10.7.3 and above
    • Click on Apple icon on upper left of screen.
    • Go to System Preferences
    • Click on the Java icon to access the Java Control Panel.

      Java Control Panel


    Configure Proxies through the Java Control Panel
    1. In the Java Control Panel, click on Network Settings, located under the General tab.
    2. Select the Use Browser Settings checkbox.
    3. Click OK to save your changes.

      Network Settings for the Java Control Panel
    4. Close all browser windows. Restart the browser and try to load the applet.
    5. If the applet still does not load and you see the same connection error, try to configure your web browser's proxy settings.
    Common Error if Proxy is not set
    A common error that is seen if the proxy settings are not correct:


     
    While application is starting, a dialog like this appears including "ClassNotFoundException"

    General Exception


    Name: JavaAppplication

    ClassNotFoundException: JavaAppplication.class

     

     








    Sunday, 10 March 2013

    Sanity Check

    What do you mean by Sanity Check?

    sanity check: Verifying data and/or code does not contain careless errors. In the computer world, this often refers to checking that the output of a program produces the expected results and not inaccurate results from careless programming.

    A sanity check is routinely undertaken on possible errors that may appear in the initial process of setting up. Checking whether everything is ok or n't to make a program run or an application get start.

    Sanity check could mean a lot. Check whether

    1. SERVER:
    - any sign of hardware failure? (raid, ram, etc)
    - load is ok?
    - time and date are right?
    - is there enough disc space?
    - all logs are rotated?
    - do only necessary daemons run there?
    - is the operating system up2date?
    - any sign of intrusion?

    2.CONNECTIVITY:
    - all needed links are up, full duplex and gigabit/s (or 100mbit/s) ?
    - are interface errors?
    - all daemons, that shall be reached externally, can be reached?

    3.DATABASE:
    - does oracle show any errors?
    - is oracle up2date?
    - does the size of the database make sense?
    I am sure, there are a million things to check in oracle itself, but I am no expert there

    4.BACKUP:
    - does it backup the right data?
    - does it backup?
    - does a restore work?
    - does the backup finish in an appropriate time frame?

    Why is a Sanity Check Necessary?

    A sanity check is an essential procedure to check the presence of any errors in the initial process. A sanity check does not delve into the depths of the application; instead, it focuses on possible errors that may appear in the initial process of setting up. A sanity check is useful to ward off any inaccuracies in the calculation that can lead to grave errors in the final output. A quick sanity check would take lesser time than avoiding a sanity check altogether and then spending more time and effort to figure out the problem and steps that need to be taken to rectify the error.



     

    Friday, 8 March 2013

    Oracle Database 10g

    Oracle Database 10g is Oracle’s largest introduction of new functionality and is Oracle’s most innovative release, leading the database industry into new ground in clustering, automation, high availability and more. 

    As I discussed in the Oracle Server architecture 10g  that Oracle Server is complete a database management system which is used to solve the problem of the information system .
    Oracle Database is a complete package for the data to be secure on the database. It managed to provide the secure , high availability and resource allocation mechanism to the database .

    The important aspects of the Oracle database 10g is the word 'g' present over there. g stands for grid computing. Then,what is grid computing?

    Important to understand What is grid Computing?
    Grid computing systems work on the principle of pooled resources.
     Need the demo: here we go

     Let's say you and a couple of friends decide to go on a camping trip. You own a large tent, so you've volunteered to share it with the others. One of your friends offers to bring food and another says he'll drive the whole group up in his SUV. Once on the trip, the three of you share your knowledge and skills to make the trip fun and comfortable. If you had made the trip on your own, you would need more time to assemble the resources you'd need and you probably would have had to work a lot harder on the trip itself.

    A grid computing system uses that same concept: share the load across multiple computers to complete tasks more efficiently and quickly.

    Grid computing is a way of networking. it pools the server from different system and available in a computer and provide services as per the demand exist.


    The most important thing about grid computing is the utility of every resources. 
    At its most basic level, grid computing is a computer network in which each computer's resources are shared with every other computer in the system. Processing power, memory and data storage are all community resources that authorized users can tap into and leverage for specific tasks. A grid computing system can be as simple as a collection of similar computers running on the same operating system or as complex as inter-networked systems comprised of every computer platform you can think of.

    I think every one is know the concept of the Distributed Network. It is nothing but collection of the Systems in a to share the resources among different computers. In the ideal grid computing system, every resource is shared, turning a computer network into a powerful supercomputer. The only limitation to access this kind of things is to make your system to authorized. Every authorized computer would have access to enormous processing power and storage capacity  from other computers.


    Why Oracle and why oracle database? 


    Oracle Database 10g helps customers lower IT costs and deliver a higher quality of service by enabling consolidation onto database clouds and engineered systems like Oracle Exadata and Oracle Database Appliance. It's proven to be fast, reliable, secure and easy to manage for all types of database workloads including enterprise applications, data warehouses and big data analysis.

    1. Database Editions
    Whether you're a lone developer, a midsize business, or large corporate enterprise, there's an edition of the world's #1 database to meet your business and technical requirements. Database is mainly needed to continue the business. Business is nothing but the exchange of the data in the sever .

    2. Oracle Database Appliance
    The Oracle Database Appliance is an engineered system of software, servers, storage and networking that provides a simple, reliable, and affordable way to deploy, manage, and support high-availability database workloads.

    3. Data Warehousing
    Oracle Exadata and Oracle Database 10g, complete with in-database advanced analytic, offer a fast, cost-effective platform for data warehousing and Business Intelligence applications.

    High Availability
    With Oracle Database 10g and Oracle’s Maximum Availability Architecture you can reduce downtime costs by protecting your business from all common causes of planned and unplanned downtime, including human error.
    Storage Management
    Oracle Database 10g provides cost-effective storage management by automating processes, minimizing costly I/O operations, compressing data and maximizing the utilization of tiered storage resources for all your enterprise databases.
    Oracle Exadata
    Oracle Exadata is the only database machine that provides extreme performance for both data warehousing and OLTP applications, making it the ideal platform for consolidating mixed database workloads onto private clouds.
    Big Data
    Oracle offers a broad portfolio of products to help you acquire and organize diverse data sources and analyze them alongside your existing data to find new insights and capitalize on hidden relationships.

     Database Clouds
    Oracle offers a broad portfolio of software and hardware products and services to enable public, private, and hybrid clouds.

    Database Security
    Oracle provides a comprehensive portfolio of security solutions to ensure data privacy, protect against insider threats, and enable regulatory compliance.

    In-Memory
    Oracle TimesTen In-Memory Database is a full-featured relational database that’s designed to run OLTP and Business Intelligence applications in the middle-tier, store all data in main memory for fast performance and high-throughput with very low latency.
    Database Options
    Oracle Database 11g features a wide range of options to meet specific customer requirements in the areas of performance and availability, security and compliance, data warehousing and analytics, unstructured data and manageability.
    Now we can understand why Oracle is so important for the business application. Because of all these features are integrated in a single package it has provide a wide range of the data security and high availability. 


    For more details you can please refer:



    For video tutorial regarding the oracle concepts please visit the below link

     http://www.downloadmela.com/video-watch?sno=351









    Wednesday, 6 March 2013

    Oracle 10g Architecture

    Before going to explain about the oracle 10g it's better if we know some of the common terms that will mostly used in the database explanation.

    Introduction to Oracle Database:

    Data :
    Data is a collection of information

    Database:
    Database is regarded as a repository of data stored in an organised manner.

    Database Management System (DBMS):

    It's a software which provide a basic layer for storing,managing and accessing the database. Stored data must be usable. Storing/retrieving data, deletion of data, modification of existing data are the basic database operations. A software tool or programme that handles these operations is called Database Management System.

     

    RDBMS

    RDBMS= DBMS + Referential Integrity (enforces the concepts of foreign key and primary concepts)
    The database system in which the relationships among different tables are maintained is called Relational Database Management System. Both RDBMS and DBMS are used to store information in physical database.
    RDBMS solution is required when large amounts of data are to be stored as well as maintained. A relational data model consists of indexes, keys, foreign keys, tables and their relationships with other tables. Relational DBMS enforces the rules even though foreign keys are support by both RDBMS and DBMS.

    Difference between the DBMS and the RDBMS?

    Simple in DBMS .there was no concepts of the relation between the data and table which is supproted in the RDBMS. The Codd rule is mainly supported to RDBMS not to DBMS.

    DBMS vs. RDBMS
    • Relationship among tables is maintained in a RDBMS whereas this not the case DBMS as it is used to manage the database.
    • DBMS accepts the ‘flat file’ data that means there is no relation among different data whereas RDBMS does not accepts this type of design.
    • DBMS is used for simpler business applications whereas RDBMS is used for more complex applications.
    • Although the foreign key concept is supported by both DBMS and RDBMS but its only RDBMS that enforces the rules.
    • RDBMS solution is required by large sets of data whereas small sets of data can be managed by DBMS.

    How to interacting with the Oracle?
    • SQL------- The standard query language which is used to communicate with the database.
    • PL/SQL-----Need to be understand if you are DBA.
    • SQLPlus
    • iSQLPlus
    • DBCA
    • Enterprise Manager
    • Java and other Oracle Call Interfaces.(via concepts of JDBC and ODBC).
    What is 'g' in Oracle 10g?

     'g' stands for Grid Computing in Oracle 10g .
    
    Grid Computing is a concept in which the resources are
    allocated to the networked users according to their needs.
    
    Whenever a user is connected to the Oracle Database, it
    computes the statistics and use of database by the user and
    then provide the resources according to the usage by
    independent user in the networked environment. In this
    scenario the database become more scalable, available, high
    in performance and more cost effective.
    
    
    It makes the oracle database a automated Business application system.
     
    Oracle 10g(Oracle sever)is the combination of
    (Resources allocation + Information sharing + High availability)
     
    The purpose of the database server is just to support the multiuser envinoment access to the 
    data base and provide the data to them.It is also prevents unauthorized access and provides 
    efficient solutions for failure recovery. 
     
    Note:  grid computing provide
    
           resource sharing and automatic load balancing 
    
    eg: if database server is full it will create another. 
    
    
    
    

    The Oracle Architecture

    A database is a centralized repository of organizational data. The Oracle 10g Database Server allows you to create, store, manage and retrieve the data in the database. A database administrator who is responsible for administering a database should have acomplete and thorough understanding of the architecture of the database.

    The Oracle RDBMS stores data logically in the form of tablespaces and physically in the form of data files ("datafiles").Tablespaces can contain various types of memory segments, such as Data Segments, Index Segments, etc. Segments in turn comprise one or more extents. Extents comprise groups of contiguous data blocks. Data blocks form the basic units of data storage.

    TableSpace: It is a pert of the database. Each databse is divided into many logical parts known as tablespace.Tablespace is nothing but the collection of the datafiles.

    Every DATA BASE has a physical and a logical Structure.
    The PHYSICAL STRUCTURE of the database mainly the actually data that are stored in the data base.As above mentioned it is the collection of the datafiles. About datafile you will get to know shortly( have faith).

    The LOGICAL STRUCTURE of the database defines    
    > One or more tablespaces.
    > The database's schema objects (e.g., tables, views, indexes, clusters, sequences, stored procedures,triggers, packages etc.) 

    The Oracle 10gDatabase product is made up three main components and they are as follows:


    1.The Oracle Server – This is the Oracle database management system that is able to store, manage and manipulate data. It consists of all the files, structures, processes that form Oracle Database 10g. The 
    Note: Oracle server is made up of an Oracle instance and an Oracle database.

     
    2.The Oracle Instance –Consists of the memory(structures) components of Oracle and various  background processes.

     
    3. The Oracle database – This is the centralized repository where the data is stored. It has a physical structure that is visible to the Operating system made up of operating system files and a logical structure that is recognized only the Oracle Server.It is the physical operating system files.
    Oracle Database:
    The number of files that are mainly resided in the database is: 
                                                                       1. Data File
                                                                       2. Control File
                                                                       3. Redo Log File

    Data File: Oracle database data acutually stores in datafile .Whatever the data we are going to stored in the database those are automatic resided in the Data files.

    Control File: It is used to control all other files in the database.  Control file contain the data about the database (meta data),Control files records the status of the physical structure of database 
    Note:   (physical structure nothing but all database files)

    > All necessary database files and log files are identified in the control file.
    > The name of the database is stored in the control file.
    > A control file is required to mount, open, and access the database.
    Mounting  takes place before a computer can use any kind of storage device (such as a hard drive, CD-ROM, or network share).In some usages, it means to make a device physically accessible.

    Redo log file:  The changes done in the database i.e all the transactions made in the db is stored in this files.A log file is a recording of everything that goes in and out of a particular server.
    Important work of Redo log file is the recovery of the database when it gets failure due to software and hardware failure.  
     The minimum size of redo log file is four (4)-MB in 10g.
    Example: It's like a Black-box Testing concept of Software Engineer(focus on the inner architecture).
    Funny:  It is a concept much like the black box of an airplane that records everything going on with the plane in the event of a problem.

    Some supported Files which are optional for the Oracle Database:
     1.  Parameter File- This file is used to define how the instance will be configured. Simply     we can say this file represent characteristic of instance. Whenever the database starts it is always check the parameter files for configure.(init.ora) is a parameter file .It defines an initial model condition.

    A parameter file is a file that contains a list of initialization parameters and a value for each parameter. You specify initialization parameters in a parameter file that reflect your particular installation. Oracle supports the following two types of parameter files:
    • Server Parameter Files (spfile)
    • Initialization Parameter Files (pfile)

      Server Parameter Files

      A server parameter file is a binary file that acts as a repository for initialization parameters. The server parameter file can reside on the machine where the Oracle database server executes. Initialization parameters stored in a server parameter file are persistent, in that any changes made to the parameters while an instance is running can persist across instance shutdown and startup.Oracle Server parameters allow you to modify many aspects of the Oracle server.

      Initialization Parameter Files

      An initialization parameter file is a text file that contains a list of initialization parameters. The file should be written in the client's default character set.
      The following are sample entries in an initialization parameter file:
      PROCESSES = 100
      OPEN_LINKS = 12
      GLOBAL_NAMES = true
       
      To read more about Parameter files examples follow the below link:
       
      http://ss64.com/ora/syntax-parameters.html 

      https://confluence.sakaiproject.org/pages/viewpage.action?pageId=37290261

       http://docs.oracle.com/cd/B19306_01/server.102/b14237/initparams003.htm#i1124392

      2. Password Files: Oracle password file is used to allow some people to connect to the database with sysdba privileges.when someone wants to connect to the oracle database from a different client machine(remotely) then there should definetly be a oracle password file and the remote_login_passwordfile  parameter should be set to ‘exclusive’ in the init.ora file.

      To know more about password files go to the below link:
      http://www.oracleskill.com/oracle-world-wide-article/create-password-file-for-remote-login-as-sysdba.html

      3.Archived redo log files: An archived redo log file is a copy of one of the filled members of a redo log group. It includes the redo entries and the unique log sequence number of the identical member of the redo log group

      for more information on the this topic we can visit the following link:

      http://docs.oracle.com/cd/E11882_01/server.112/e25494/archredo001.htm

      The Oracle Instance:

      It is the combination of some of the background process and memory structure. 
      An instance is created in the memory every time the database is started.
      An oracle instance is the software which is mainly used for the executing and manage the data in the database. Same definition as of the DBMS.

      Memory Structure in oracle server: 


      It is divided into two parts : 1. Shared Memory(SGN=System Global Area)
                                                       2. Non-shared memory(ex. parameter files)

      It's better to you if you know about the dedicated server and shared server because it will help you to understand the concepts of the memory structure of the oracle server.

      Dedicated Server: The server which services only single user.
      Shared Server: the server which services to multiple user.

      SGN(System / Shared global Area) :

      <memory structures in the SGA are shared by every user in the database that's why the word shared used >

      Each Oracle instance uses a System Global Area or SGA—a shared-memory area—to store its data and control-information.
      Each Oracle instance allocates itself an SGA when it starts and de-allocates it at shut-down time
      The System Global Area (SGA) is a group of shared memory areas that are dedicated to an Oracle “instance” (an instance is your database programs and RAM).
      All Oracle processes use the SGA to hold information. The SGA is used to store incoming data (the data buffers as defined by the db_cache_size parameter), and internal control information that is needed by the database. You control the amount of memory to be allocated to the SGA by setting some of the Oracle “initialization parameters”.  These might include db_cache_size, shared_pool_size and log_buffer.
      In Oracle Database 10g you only need to define two parameters (sga_target and sga_max_size) to configure your SGA. If these parameters are configured, Oracle will calculate how much memory to allocate to the different areas of the SGA using a feature called Automatic Memory Management (AMM). As you gain experience you may want to manually allocate memory to each individual area of the SGA with the initialization parameters.

      Reference:  See the above figure you will get the idea what are the extra thing that the SGA contains.

      The SGA contains the following data structures:
      • the database buffer cache (db_cache_size)
      • the redo log buffer (log_buffer)
      • the shared pool
      • the large pool (optional)
      • the data dictionary cache
      • other miscellaneous information 

      Part of the SGA contains general information about the state of the database and the instance, which the background processes need to access; this is called the fixed SGA. No user data is stored here. The SGA also includes information communicated between processes, such as locking information. 


      a) The Database Buffer Cache:

      Buffer: It's nothing but the storage area.

      The Buffer Cache (also called the database buffer cache) is where Oracle stores data blocks.  With a few exceptions, any data coming in or going out of the database will pass through the buffer cache.It acts interface between the database and application.

      The total space in the Database Buffer Cache is sub-divided by Oracle into units of storage called “blocks”. Blocks are the smallest unit of storage in Oracle .

      For example, many Oracle professionals place indexes in a 32k block size and leave the data files in a 16k block size.

      The default size for the buffer pool (64k) is too small.

      Note:    The SGA's size and function are controlled by initialization (INIT.ORA or SPFILE) parameters. 

      Purpose of database buffer cache:

      No need to filter the database again & again for searching of a data. It minimize the  physical io. When a block is read by Oracle, it places this block into the buffer cache, because there is a chance that this block is needed again.
       

      Note: Reading a block from the buffer cache is less costly (in terms of time) than reading it from the disk.

      b) Redo log buffer(log_buffer) :

      The redo log buffer is the part of the System Global Area (SGA) that holds information about changes made to the database. Each of these changes generates a ‘redo entry’. Redo entries are needed to reconstruct these changes during the recovery process.

      The redo log buffer is a RAM area (defined by the initialization parameter log_buffer) that works to save changes to data, in case something fails and Oracle has to put it back into its original state (a “rollback”).  When Oracle SQL updates a table (a process called Data Manipulation Language, or DML), redo images are created and stored in the redo log buffer. Since RAM is faster than disk, this makes the storage of redo very fast.

      The Oracle redo log buffer provides the following functions within the Oracle SGA:
      • Serves for assistance with database recovery tasks
      • Records all changes made to database blocks
      • Places changes recorded to redo entries for redo logs. 

      c)Shared Pool

      It's like shared server concept . sharing the parsed sql statements with many number of users.

      The shared pool is a key component in SGA. The shared pool is like a buffer for SQL statements. It is to store the SQL statements so that the identical SQL statements do not have to be parsed each time they're executed.


      Again the shared divided into three parts as you she in the above figure.

      Library cache: It contains the recently executed sql, plsql code and the executed sql and plsql code.  For eg:- 

      If the user parses Sql statement, the library cache hold it,if the other user parses same sql statment it will give here.

      Data Dictionary cache:  

      Data dictionary contain information about database structures, contents, attributes and contain the defination and discription of the database object (tables,indexs,view etc).Oracle frequently refers to the data dictionary for its internal operations and updates it when your used creat,alter,drop objects. Just remeber the definition of the DDL (data definition language)

       

      Program Global Area:

       Note: Oracle server code: Each user has some Oracle server code executing on his or her behalf, which interprets and processes the application's SQL statements.

       

      The following table lists the different areas stored in the shared pool and their purpose:

       
      Background processes in oracle:

      To maximize performance and accommodate many users, a multiprocess Oracle Database system uses background processes. Because the basic concepts of the oracle is the (High availability, resources allocation and information sharing) and to support this mechanism oracle has run some of the back ground processes to handle the failures and crashes if any.

      Some of the background process that Oracle runs when an application starts are:

      1.SMON
      The System Monitor carries out a crash recovery when a crashed insance is started up again. It also cleans temporary segments. 

       2.PMON
      The Process Monitor checks if a user process fails and if so, does all cleaning up of resources that the user process has acquired. It mainly helps to free the resources ,so that other processes will use the resources freely.

      3. DBWR
      Database Writer or Dirty Buffer Writer process is responsible for writing dirty buffers from the database block cache to the database data files. Generally, DBWR only writes blocks back to the data files on commit, or when the cache is full and space has to be made for more blocks. The possible multiple DBWR processes in RAC must be coordinated through the locking and global cache processes to ensure efficient processing is accomplished.

      Writes the modified data to the files(i.e data files) on hard disk.

      4. LGWR -

       Log Writer process is responsible for writing the log buffers out to the redo logs. On regular intervals LGWR will move the redo from the redo log buffer to files on disk designed to store the redo called online redo log files.

      The simple define of the LGWR are: The Log Writer writes the redo log buffer from the SGA to the online redo log file.

       5.CKPT (checkpoint) :

        It tells the database writer is that boss now here the database gets changed.

      The checkpoint process is responsible for updating file headers in the database datafiles. A checkpoint occurs when Oracle moves new or updated blocks (called dirty blocks) from the RAM buffer cache to the database datafiles. A checkpoint keeps the database buffer cache and the database datafiles synchronized. This synchronization is part of the mechanism that Oracle uses to ensure that your database can always be recovered.

      6.Archiver (ARCn)

      One or more archiver processes copy the redo log files to archival storage when they are full or a log switch occurs.

      and remaining  are as follows:

      Recoverer (RECO) The recoverer process is used to resolve distributed transactions that are pending because of a network or system failure in a distributed database. At timed intervals, the local RECO attempts to connect to remote databases and automatically complete the commit or rollback of the local portion of any pending distributed transactions. For information about this process and how to start it, see Chapter 33, "Managing Distributed Transactions".
      Dispatcher (Dnnn) Dispatchers are optional background processes, present only when the shared server configuration is used. Shared server was discussed previously in "Configuring Oracle Database for Shared Server".
      Global Cache Service (LMS) In an Oracle Real Application Clusters environment, this process manages resources and provides inter-instance resource control.

        Program Global Area:

      It hold the session information and contains the private sql area

        DATA DICTIONARY :

      When you create a database ,you also create a data dictionary. Similarly when the status of the database gets changed according to that the data dictionary also gets updated.

      Oracle enterprise manager uses the data dictionary to get information about the database object in the database.

      For more information regarding the architecture of Oracle 10g you can visit the below 

      link: http://www.dba-oracle.com/concepts/

       

      http://careerride.com/oracle-db-architecture.aspx


       http://naveenkrishnadba.blogspot.in/2010/01/database-oracle-database-has-logical.html










       

     






     

     


    Sunday, 3 March 2013

    Thursday, 21 February 2013

    SQL Server Stored Procedure

    Before Learning SQL SERVER STORED PROCEDURE Its better if you have a knowledge on  the concepts of Pl/Sql because whatever the programming syntax we are going to use is the shadow of PL/SQL syntex. So here you go for some of the PL/SQL concepts.

    PL/SQL-  Procedural Language extension to SQL. And it is a technology mainly used in oracle database.

    PL/SQL is a combination of SQL along with the procedural features of programming languages. It was developed by Oracle Corporation in the early 90's to enhance the capabilities of SQL.
    PL/SQL is one of three key programming languages embedded in the Oracle Database, along with SQL itself and Java.


     Following are notable facts about PL/SQL:
    • PL/SQL is a completely portable, high-performance transaction-processing language.
    • PL/SQL provides a built-in interpreted and OS independent programming environment.
    • PL/SQL can also directly be called from the command-line SQL*Plus interface.
    • Direct call can also be made from external programming language calls to database.
    • PL/SQL's general syntax is based on that of ADA and Pascal programming language.
    • Apart from Oracle, PL/SQL is available in TimesTen in-memory database and IBM DB2.

    Features of PL/SQL

    PL/SQL has the following features:
    • PL/SQL is tightly integrated with SQL.
    • It offers extensive error checking.
    • It offers numerous data types.
    • It offers a variety of programming structures.
    • It supports structured programming through functions and procedures.
    • It supports object oriented programming.
    • It supports developing web applications and server pages.

    Advantages of PL/SQL

    PL/SQL has the following advantages:
    • SQL is the standard database language and PL/SQL is strongly integrated with SQL. PL/SQL supports both static and dynamic SQL.
      •  Static SQL supports DML operations and transaction control from PL/SQL block. 
      •  Dynamic SQL is SQL allows embedding DDL statements in PL/SQL blocks. 
    • PL/SQL allows sending an entire block of statements to the database at one time. This reduces network traffic and provides high performance for the applications.
    • PL/SQL give high productivity to programmers as it can query, transform, and update data in a database.
    • PL/SQL saves time on design and debugging by strong features, such as exception handling, encapsulation, data hiding, and object-oriented data types.
    • Applications written in PL/SQL are fully portable.
    • PL/SQL provides high security level.
    • PL/SQL provides access to predefined SQL packages.
    • PL/SQL provides support for Object-Oriented Programming.
    • PL/SQL provides support for Developing Web Applications and Server Pages.
     PL/SQL is not a stand-alone programming language; it is a tool within the Oracle programming environment. SQL* Plus is an interactive tool that allows you to type SQL and PL/SQL statements at the command prompt. These commands are then sent to the database for processing. Once the statements are processed, the results are sent back and displayed on screen.

    PL/SQL Command Prompt

    Text Editor

    Running large programs from command prompt may land you in inadvertently losing some of the work. So a better option is to use command files. To use the command files:
    • Type your code in a text editor, like Notepad, Notepad+, or EditPlus etc.
    • Save the file with the .sql extension in the home directory.
    • Launch SQL*Plus command prompt from the directory where you created your PL/SQL file.
    • Type @file_name at the SQL*Plus command prompt to execute your program.
    If you are not using a file to execute PL/SQL scripts, then simply copy your PL/SQL code and then right click on the black window having SQL prompt and use paste option to paste complete code at the command prompt. Finally, just press enter to execute the code, if it is not already executed.

    PL/SQL is a block-structured language, meaning that PL/SQL programs are divided and written in logical blocks of code. Each block consists of three sub-parts:
    S.N.Sections & Description
    1Declarations
    This section starts with the keyword DECLARE. It is an optional section and defines all variables, cursors, subprograms, and other elements to be used in the program.
    2Executable Commands
    This section is enclosed between the keywords BEGIN and END and it is a mandatory section. It consists of the executable PL/SQL statements of the program. It should have at least one executable line of code, which may be just a NULL command to indicate that nothing should be executed.
    3Exception Handling
    This section section starts with the keyword EXCEPTION. This section is again optional and contains exception(s) that handle errors in the program.
    Every PL/SQL statement end with a semicolon (;). PL/SQL blocks can be nested within other PL/SQL blocks using BEGIN and END. Here is the basic structure of a PL/SQL block:

    DECLARE
       <declarations section>
    BEGIN
       <executable command(s)>
    EXCEPTION
       <exception handling>
    END;

    The 'Hello World' Example:

    DECLARE
       message  varchar2(20):= 'Hello, World!';
    BEGIN
       dbms_output.put_line(message);
    END;
    /
    The end; line signals the end of the PL/SQL block. To run the code from SQL command line, you may need to type / at the beginning of the first blank line after the last line of the code. When the above code is executed at SQL prompt, it produces following result:
    Hello World
    
    PL/SQL procedure successfully completed.
    

    The PL/SQL Identifiers

    PL/SQL identifiers are constants, variables, exceptions, procedures, cursors, and reserved words. The identifiers consist of a letter optionally followed by more letters, numerals, dollar signs, underscores, and number signs and should not exceed 30 characters.
    By default, identifiers are not case-sensitive. So you can use integer or INTEGER to represent a numeric value. You cannot use a reserved keyword as an identifier.


    The PL/SQL Comments

    Program comments are explanatory statements that you can include in the PL/SQL code that you write and helps anyone reading it's source code. All programming languages allow for some form of comments.
    The PL/SQL supports single line and multi-line comments. All characters available inside any comment are ignored by PL/SQL compiler. The PL/SQL single-line comments start with the delimiter -- (double hyphen) and multi-line comments are enclosed by /* and */.


    DECLARE
       -- variable declaration
       message  varchar2(20):= 'Hello, World!';
    BEGIN
       /*
        *  PL/SQL executable statement(s)
        */
       dbms_output.put_line(message);
    END;
    /
    When the above code is executed at SQL prompt, it produces following result:
    Hello World
    
    PL/SQL procedure successfully completed. 
     
     
    and i requested to you please do some of the assignments on pl/sql.Here are some of the link
     
    http://www.codeproject.com/Articles/38682/Overview-of-SQL-Server-Stored-Procedure
    
    
     http://www.mssqltips.com/sqlservertutorial/164/using-try-catch-in-sql-server-stored-procedures/
     



    Now comes to our real Topic STORED PROCEDURE:-

    A stored procedure is nothing more than prepared SQL code (collection of the sql queries) that you save so you can reuse the code over and over again.  So if you think about a query that you write over and over again, instead of having to write that query each time you would save it as a stored procedure and then just call the stored procedure to execute the SQL code that you saved as part of the stored procedure.


    In addition to running the same SQL code over and over again you also have the ability to pass parameters to the stored procedure, so depending on what the need is the stored procedure can act accordingly based on the parameter values that were passed.



    Stored procedures are more than just tools for performing repetitive tasks. There are two main types of stored procedure – system stored procedures and user-defined stored procedures. We also have extended stored procedures that can reside as either system or user-defined types. Extended stored procedures give functionality that is not necessarily contained within SQL Server, like allowing DOS commands to run and working with e-mail. It is also possible to create your own extended stored procedures. 

    Creating a simple stored procedure

    As mentioned , a stored procedure is nothing more than stored SQL code that you would like to use over and over again.  In this example we will look at creating a simple stored procedure. 



    So the simple T-SQL code would be as follows which will return all rows from this table.

    SELECT * FROM Works.Person.Address
    


    To create a stored procedure to do this the code would look like this:

    CREATE PROCEDURE uspGetAddress
     
     AS
     
     SELECT * FROM Works.Person.Address
    GO
     
     
     
    To call the procedure to return the contents from the table specified, the code would be:

    EXEC uspGetAddress
    --or just simply
    uspGetAddress
    


    CREATE PROCEDURE dbo.StoredProcedureName
    /*
    (
    @parameter1 datatype = default value,

    @parameter2 datatype OUTPUT

    )

    */
    AS

    /* Place your Query here */
    RETURN

    Example 1:

    Create PROCEDURE dbo.GetAllEmployees
    As

    Select * from Employee

    Execution query :

    exec GetAllEmployees

    Example 2:

    ALTER PROCEDURE dbo.GetEmployee
    @empid int
    As

    Select * from Employee where Employee.EmployeeID=@empid

    Execution Query :

    exec dbo.GetEmployee 1

    Example 3:

    Create PROCEDURE dbo.UpdateEmpNationalID

    (

    @empid int
    ,@newcontactid int
    ,@oldcontactno int OUTPUT

    )

    AS

    Select @oldcontactno=[ContactID]
    FROM [dbo].[Employee] where [Employee].EmployeeID=@empid

    if(@oldcontactno=@newcontactid)
    begin

    RETURN 0

    end

    else
    begin

    update Employee set ContactID=@newcontactid where Employee.EmployeeID=@empid

    return 1
    end

    Execution Query:

    Declare @oldcontactno int
    Declare @returnvalue int
    exec @returnvalue=UpdateEmpNationalID 1,123,@oldcontactno output

    Select @oldcontactno 'Old Contact'
    Select @returnvalue 'Returned value'


    When creating a stored procedure you can either use CREATE PROCEDURE or CREATE PROC.  After the stored procedure name you need to use the keyword "AS" and then the rest is just the regular SQL code that you would normally execute.


    On thing to note is that you cannot use the keyword "GO" in the stored procedure.  Once the SQL Server compiler sees "GO" it assumes it is the end of the batch.


    Also, you can not change database context within the stored procedure such as using "USE dbName" the reason for this is because this would be a separate batch and a stored procedure is a collection of only one batch of statements.

     HOW TO CALL STORED PROCEDURE?

    The simple answer for this question is by passing parameters

    How to create a SQL Server stored procedure with parameters:

    The real power of stored procedures is the ability to pass parameters and have the stored procedure handle the differing requests that are made.  In this topic we will look at passing parameter values to a stored procedure. 
     ExplanationJust like you have the ability to use parameters with your SQL code you can also setup your stored procedures to except one or more parameter values.

    One Parameter
    In this example we will query the Person.Address table from the Works database, but instead of getting back all records we will limit it to just a particular city.  This example assumes there will be an exact match on the City value that is passed.

    CREATE PROCEDURE uspGetAddress @City nvarchar(30)
    AS
    SELECT * 
    FROM Works.Person.Address
    WHERE City = @City
    GO
    

    To call this stored procedure we would execute it as follows:

    EXEC uspGetAddress @City = 'India'


    We can also do the same thing, but allow the users to give us a starting point to search the data.  Here we can change the "=" to a LIKE and use the "%" wildcard.

    CREATE PROCEDURE uspGetAddress @City nvarchar(30) 
    AS 
    SELECT * 
    FROM Works.Person.Address 
    WHERE City LIKE @City + '%' 
    GO
    

    In both of the proceeding examples it assumes that a parameter value will always be passed. If you try to execute the procedure without passing a parameter value you will get an error message such as the following:

    Msg 201, Level 16, State 4, Procedure uspGetAddress, Line 0
    
    Procedure or function 'uspGetAddress' expects parameter '@City', which was not supplied.


    Default Parameter Values
    In most cases it is always a good practice to pass in all parameter values, but sometimes it is not possible.  So in this example we use the NULL option to allow you to not pass in a parameter value.  If we create and run this stored procedure as is it will not return any data, because it is looking for any City values that equal NULL.


    CREATE PROCEDURE uspGetAddress @City nvarchar(30) = NULL
    AS
    SELECT *
    FROM Works.Person.Address
    WHERE City = @City
    GO
    

    We could change this stored procedure and use the ISNULL function to get around this.  So if a value is passed it will use the value to narrow the result set and if a value is not passed it will return all records.

    CREATE PROCEDURE uspGetAddress @City nvarchar(30) = NULL
    AS
    SELECT *
    FROM Works.Person.Address
    WHERE City = ISNULL(@City,City)
    GO

    Multiple Parameters
    Setting up multiple parameters is very easy to do.  You just need to list each parameter and the data type separated by a comma as shown below.

    CREATE PROCEDURE uspGetAddress @City nvarchar(30) = NULL, @AddressLine1 nvarchar(60) = NULL
    AS
    SELECT *
    FROM Works.Person.Address
    WHERE City = ISNULL(@City,City)
    AND AddressLine1 LIKE '%' + ISNULL(@AddressLine1 ,AddressLine1) + '%'
    GO
    

    To execute this you could do any of the following:
    EXEC uspGetAddress @City = 'Calgary'
    --or
    EXEC uspGetAddress @City = 'Calgary', @AddressLine1 = 'A'
    --or
    EXEC uspGetAddress @AddressLine1 = 'Acardia'
    -- etc...
     
     
     User Defined Functions (UDFs)

    User defined functions are routines that encapsulates SQL logic inside it. Like stored procedures User
    defined functions can also be passed input parameters but user defined functions are compiled and
    executed at runtime so pretty slower than stored procedures.

    Syntax:

    CREATE FUNCTION dbo.Function
    (
    /*
    @parameter1 datatype = default value,
    @parameter2 datatype
    */
    )
    RETURNS /* datatype */
    AS

    BEGIN
    /* sql statement ... */
    RETURN /* value */
    END

    Certain limitations for User defined functions:

    i)
      UDF can’t perform DML (data manipulation language) operations like Insertion,  Update and Deletion on the base table.

    ii)
      UDF can’t return non deterministic values like GETDATE () etc.

    iii) Stored procedure can’t be called from inside a UDF whereas a stored procedure can call a  user defined function or another stored procedure inside it.



    There are three types of user defined functions:

    1) Scalar Functions (returns a single value)

    Example:

    CREATE FUNCTION EmployeeContactID(@Empid int)
    RETURNS int
    AS
    BEGIN

    Declare @returnvalue int
    Select @returnvalue=Employee.ContactID from Employee where
    Employee.EmployeeID=@Empid
    RETURN
    @returnvalue
    END

    Execution:
    select dbo.EmployeeContactID(1)

    2) Inline Functions (returns a table)

    Example:

    CREATE FUNCTION dbo.GetEmployeeFunction(@empid int)
    RETURNS TABLE
    AS
    RETURN SELECT *
    FROM employee where employee.EmployeeID=@empid

    Execution:

    select * from dbo.GetEmployeeFunction(1)

    3) Table valued Functions ( multiple operations, complex logic just like Stored procedures)

    Example:

    CREATE FUNCTION dbo.multi_test(@empid int)
    RETURNS @Result TABLE
    (
    name varchar(20)
    )
    AS
    BEGIN
    INSERT INTO @Result
    (name)
    SELECT [name] from employee where EmployeeID=1

    UPDATE @Result
    SET name = 'N'

    RETURN

    END

    Exectution :

    Select * from dbo.multi_test(1)



    Difference between Stored procedures and User defined functions:

    i)
    A stored procedure is pre compiled while a User defined function is compiled and executed at runtime.

    ii)
    A Stored procedure is more flexible than user defined function like you can write complex logic (for example exceptional handling using try catch block is possible in stored procedures which is not possible in user defined functions)

    iii)
    A stored procedure can call another stored procedure or user defined function inside it but a user defined function can’t call stored procedure inside it.

    iv)
    A stored procedure can return non deterministic values but a user defined function can’t return a non deterministic values like Get Date () function.

    v)
    A user defined functions does not support DML operations like insertion, deletion and update on the base table but it is possible via stored procedure.

    vi)
    A user defined function is easier to execute and can be used inside selection and even for joins but stored procedure can’t be used inside selection queries and it can’t be used to join with other tables.