Monday 29 July 2013

Lesson 67 : LISTAGG

LISTAGG
This article describes the new LISTAGG function in Oracle 11g Release 2. LISTAGG is a built-in function that enables us to perform string aggregation natively. String aggregation is a popular technique, and there are several methods available on the web, so we will compare their performance to the new LISTAGG function later in this article.
sample data
For reference, we will use the following sample data for our examples.
    DEPTNO ENAME      HIREDATE
---------- ---------- ----------
        10 CLARK      09/06/1981
        10 KING       17/11/1981
        10 MILLER     23/01/1982
        20 ADAMS      12/01/1983
        20 FORD       03/12/1981
        20 JONES      02/04/1981
        20 SCOTT      09/12/1982
        20 SMITH      17/12/1980
        30 ALLEN      20/02/1981
        30 BLAKE      01/05/1981
        30 JAMES      03/12/1981
        30 MARTIN     28/09/1981
        30 TURNER     08/09/1981
        30 WARD       22/02/1981
 

what is string aggregation?

String aggregation is simply the grouping and concatenation of multiple rows of data into a single row per group. For example, consider the following resultset:
   DEPTNO ENAME
--------- ----------
       10 CLARK
       10 KING
       10 MILLER
       20 ADAMS
       20 FORD
       20 JONES
With string aggregation, this resultset would be grouped (by DEPTNO) as follows:
   DEPTNO AGGREGATED_ENAMES
--------- -------------------------
       10 CLARK,KING,MILLER
       20 ADAMS,FORD,JONES
 
We can see that the employee names have simply been grouped and concatenated into a single column (values are delimited by comma) per group. As stated, there are several techniques available to perform this aggregation (references are provided at the end of this article), but the new LISTAGG function makes it much easier, as we will see below.

listagg syntax overview

The LISTAGG function has the following syntax structure:
LISTAGG( [,]) WITHIN GROUP (ORDER BY ) [OVER (PARTITION BY )]
LISTAGG is an aggregate function that can optionally be used as an analytic (i.e. the optional OVER() clause). The following elements are mandatory:
  • the column or expression to be aggregated;
  • the WITHIN GROUP keywords;
  • the ORDER BY clause within the grouping.
We will now see some examples of the function below.

listagg as an aggregate function

We will begin with a simple example that aggregates the employee names for each department in the EMP table, using a comma as delimiter.
SQL> SELECT deptno
  2  ,      LISTAGG(ename, ',') WITHIN GROUP (ORDER BY ename) AS employees
  3  FROM   emp
  4  GROUP  BY
  5         deptno;
 
    DEPTNO EMPLOYEES
---------- ------------------------------------------------------------
        10 CLARK,KING,MILLER
        20 ADAMS,FORD,JONES,SCOTT,SMITH
        30 ALLEN,BLAKE,JAMES,MARTIN,TURNER,WARD
 
3 rows selected.
Note that we chose to order the employees within each aggregation by the employee name. It should be noted that ordering the elements of a string aggregation is not a trivial task in some of the alternative techniques to LISTAGG.
In the following example, we will aggregate the employee names but order them by their respective hire dates.
SQL> SELECT deptno
  2  ,      LISTAGG(ename, ',') WITHIN GROUP (ORDER BY hiredate) AS employees
  3  FROM   emp
  4  GROUP  BY
  5         deptno;
 
    DEPTNO EMPLOYEES
---------- ------------------------------------------------------------
        10 CLARK,KING,MILLER
        20 SMITH,JONES,FORD,SCOTT,ADAMS
        30 ALLEN,WARD,BLAKE,TURNER,MARTIN,JAMES
 
3 rows selected.
We can see that the order of employee names within each group differs from the first example.

Wednesday 10 July 2013

Welcome


Post Topics
1 Introduction Database
2 SQL*PLUS
3 How to execute sqlcommands
4 SQL* Plus commands
5 SQL command categories
6 Objects and schema in Oracle
7 Data Types in Oracle
8 Operators in Oracle
9 Database Tables
10 SELECT with WHERE clause
11 SELECT with ORDER BY Clause
12 Aggregate functions or Group by functions
13 SELECT with GROUP BY clause
14 SELECT with HAVING clause
15 UPDATE Statement
16 DELETE Statement
17 TRUNCATE TABLE  Statement
18 Built-in Functions - Arithmetic
19 Built-in Functions - Character types
20 Constraints
21 Sequences
22 SYNONYMS and PUBLIC SYNONYMS
23 VIEW
24 Union, Union all, Intersect and Minus
25 Date Functions 
26 SAVEPOINT
27 Rollback
28 Indexes
29 ROLLUP option in SELECT
30 Pseudocolumn - ROWID
31 CUBE in SELECT
32 Virtual Columns
33 Global temporary tables (GTT)
34 GRANT and REVOKE
35 COMMENT Statement
36 Pseudocolumn - ORA_ROWSCN
37 Pseudocolumn - ROWNUM
38 Roles
39 Important system viewes
40 How to change password
41 Oracle Reserved Words
42 LOCK Table
43 TEMPORARY TABLE
44 SELECT with ANY
45 Subquery
46 What is Recycle Bin ?
47 Oracle Clusterware and RAC
48 Single Instance vs RAC
49 Advantages of RAC
50 OracleRAC Software Components
51 What is OCR in Oracle RAC ?
52 What is Voting Disk in Oracle RAC ?
53 What does Oracle Clusterware do ?
54  What is Oracle ASM ?
55 ASM Benefits
56 ASM vs Databases
57 ASM Disks
58 ASM Disk Group
59 ASM files
60 Disk Group Redundancy
61 Groups & Privileges for ASM
62 What is Service in RAC
63 Service Types in RAC
64 What is TAF ?
65 TRASESS
66 What is FAN ?


Topics to come….

Bind Variables

Create Directory Statement

Cursors

Data Dictionary

Data Pump

Database Links

Special functions

DBMS JOBS

Decode

Exceptions

Explain Plan

External Table

Flashback

FOR loop

HINT

IF statement

Index Organised tables

Interview Questions on PL/SQL

Interview Questions on SQL

JAVA in Oracle

Joins

Materialised Views

Merge

Nested Tables

OOPS in Oracle

Packages

PL/SQL

Pseudocolumns

Roles

Set Transactions

SQL Loader

SQL queires using functions

SQL Trace

SQL Tuning

Stored function

Stored procedure

Subquries

Temporary tables

Triggers

User defined Data types



                           and more……


Lesson : 66 What is FAN

Fast Application Notification -FAN

FAN is an event notification mechanism to the Oracle clients. Instead of letting the clients to detect a failure of a cluster component, the clusterware itself notifies the clients upon a component failure or status changes etc. It enables client applications to quickly react to a situation rather than waiting and timing out.
Along with the cluster status change notification, it also notifies the LBA information to the clients. This helps the middle tier applications with connection pools to dynamically load balance the connections to the best serving instance.

Session : 65 TRCSESS

The trcsess is an Oracle utility that consolidates trace output from selected trace files based on several criteria:
  • Session ID
  • Client ID
  • Service name
  • Action name
  • Module name
After trcsess merges the trace information into a single output file, the output file could be processed by TKPROF.
trcsess is useful for consolidating the tracing of a particular session for performance or debugging purposes. Tracing a specific session is usually not a problem in the dedicated server model as a single dedicated process serves a session during its lifetime. You can see the trace information for the session from the trace file belonging to the dedicated server serving it. However, in a shared server configuration a user session is serviced by different processes from time to time. The trace pertaining to the user session is scattered across different trace files belonging to different processes. This makes it difficult to get a complete picture of the life cycle of a session.


21.2.1 Syntax for trcsess

The syntax for the trcsess utility is:
trcsess  [output=output_file_name]
         [session=session_id]
         [clientid=client_id]
         [service=service_name]
         [action=action_name]
         [module=module_name]
         [trace_files]
where
  • output specifies the file where the output is generated. If this option is not specified, then the utility writes to standard output.
  • session consolidates the trace information for the session specified. The session identifier is a combination of session index and session serial number, such as 21.2371. You can locate these values in the V$SESSION view.
  • clientid consolidates the trace information given client ID.
  • service consolidates the trace information for the given service name.
  • action consolidates the trace information for the given action name.
  • module consolidates the trace information for the given module name.
  • trace_files is a list of all the trace file names, separated by spaces, in which trcsess should look for trace information. You can use the wildcard character (*) to specify the trace file names. If you do not specify trace files, then trcsess takes all the files in the current directory as input.
You must specify one of the session, clientid, service, action, or module options. If more then one of the session, clientid, service, action, or module options is specified, then the trace files which satisfies all the criteria specified are consolidated into the output file.

Lession : 64 What is TAF ?

Transparent Application Failover - TAF

TAF offers Run-Time failover capability to the client connections. For example, if the client connects to the instance 1 and if that instance crashes, then this connection will be automatically and transparently failed over to the one of the other instance. After the failover it can resume any SELECT query that was in process or it can only fail over the SESSION and do not replay the SELECT query. These are called two types of TAF i.e. SESSION and SELECT.There are also two methods of TAF, BASIC and PRECONNECT. In the BASIC method, the client first makes only one connection to the database, if that connection fails then it initiates another connection as part of failover operation. In the case of PRECONNECT method, the client makes two connection at the initial stages itself. If the first connection crashes, then it immediately starts using the second connection. It saves connection establishment time during failover.TAF can be configured at the client side in tnsnames.ora or at the server side with the srvctlcommand. You actually create a service which is TAF enabled with the srvctlcommand.
415

Lesson : 63 Service Types in RAC

Service Types

Every instance by default has one service associated with it in the format
DB_UNIQUE_NAME.DB_DOMAIN. There is also two internal services defined automatically.

•SYS$BACKGROUND: Background processes will be running under this service name

•SYS$USERS: Any user connection who had not used a service name to connect to the database will come under this serviceThese internal services can not be deleted or altered. In addition to these default services, you can create number of services up to the 115 services per database

Lesson 62 : What is Service in RAC

What is Service in RAC ?

Services are the entry point to the database. Service names will be used by the clients to connect to the database. Services are created and started on an instance. The service can be configured to run on any instance and thus the client do not need to know which instance it is connecting to. Services offer greater flexibility in maintaining client connections.

You should always use srvctlto manage services in RAC environment. Do not use service_namesdatabase initialization parameter or DBMS_SERVICES packages to create and manage services. Because services are automatically started and stopped on the individual instances by the clusterware by setting the service_namesparameter. Hence you manually modify this parameter, that will interfere with the clusterware operation.

Tuesday 9 July 2013

Lesson 61 : Groups and Privileges for ASM

Groups and Privileges for ASM

During Oracle ASM installation, you can use one operating system group for all users or divide system privileges so that database administrators, storage administrators, and database operators each have distinct operating system privilege groups.Whether you create separate operating system privilege groups or use one group to provide operating system authentication for all system privileges,

you should use SYSASM to administer an Oracle ASM instance.

 The SYSDBA privilege cannot be used to administer an Oracle ASM instance.

If you use the SYSDBA privilege to run administrative commands on an Oracle ASM instance, the operation results in an error.

The SYSDBA privilege is intended to be used by the database to access disk groups.Operating system authentication using membership in the group or groups designated as OSDBA, OSOPER, and OSASM is valid on all Oracle platforms.

Connecting to an Oracle ASM instance as SYSASM grants you full access to all of the available Oracle ASM disk groups and management functions.

Lesson 60 : Disk Group Redundancy

Disk Group Redundancy

DiskGroup redundancy defines the mirroring level for files stored in the diskgroup. Mirroring protects data integrity by storing copies of data on multiple disks. When you create a disk group, you specify an Oracle ASM disk group type based on one of the following three redundancy levels:

1) Normal for 2-way mirroring

2) High for 3-way mirroring

3) External –No ASM mirroring


The redundancy level controls how many disk failures are tolerated without dismounting the disk group or losing data. Eachmirrored copy is placed on different disks. Hence 2-way mirroring requires minimum of two disks. Similarly, 3-way mirroring requires minimum of three disks assigned to the diskgroup.

Lesson 59 : ASM files

ASM Files

Files that are stored in Oracle ASM disk groups are called Oracle ASM files. Each Oracle ASM file is contained within a single Oracle ASM disk group. Oracle Database communicates with Oracle ASM in terms of files. This is similar to the way Oracle Database uses files on any file system. You can store the various file types in Oracle ASM disk groups, including:

1) Control files

2) Data files, temporary data files, and data file copies

3) SPFILEs

4) Online redo logs, archive logs, and Flashback logs

5) RMAN backups

6)Disaster recovery configurations

7)Change tracking bitmaps

8)Data Pump dumpsets

Lesson : 58 ASM Disk Group

ASM Disk Group

A disk group consists of multiple disks and is the fundamental object that Oracle ASM manages. Each disk group contains the metadata that is required for the management of space in the disk group. Files are allocated from disk groups. Any Oracle ASM file is completely contained within a single disk group. However, a disk group might contain files belonging to several databases and a single database can use files from multiple disk groups.

Lesson 57 : ASM Disks

ASM Disks

Oracle  ASM disks are the storage devices that are provisioned to Oracle ASM disk groups. Examples of Oracle ASM disks include:

1) A disk or partition from a storage array

2)An entire disk or the partitions of a disk

3) Logical volumes

4)Network-attached files (NFS)


When adding a disk to ASM, you can assign an Oracle ASM disk name or Oracle ASM assigns the Oracle ASM disk name automatically. This name is different from the path name used by the operating system. In a cluster, a disk may be assigned different operating system device names on different nodes, but the disk has the same Oracle ASM disk name on all of the nodes.

Lesson 56 : ASM vs Databases

ASM and Databases

Irrespective of the number of databases running on a node, you only require one ASM instance on a node. ASM can support both single instance database and Oracle RAC databases at the same time. ASM is a light weight instance, itsrole is only to manage the metadatainformation and to make the underlying disks accessible for the databases. Oracle databases directly accesses the disks for reading and writing. Oracle database needs to maintain a connection to ASM instance to have metadata information about the storage layout. Without ASM, Oracle database can not directly access any disks that is managed by the ASM.

Lesson 55: ASM Benefits

ASM Benefits

Data is divided into multiple parts(chunks) and is stored across multiple disks. This is called Striping. Striping has two primary purposes,

1) To balance loads across all of the available disks.

2) To reduce I/O latencyMirroring protects data integrity by storing copies of data on multiple disks. If one diskis lost, the data can be retrieved from the other disk. Thus mirroring increases the availability of the data.

There is no file system overhead as ASM manages the disks directly. ASM is cluster-aware, thus serving as a shared storage for Oracle RAC.

Monday 8 July 2013

Lesson 54 : What is Oracle ASM ?

What is Oracle ASM

Oracle ASM(Automatic Storage Management) is a volume manager and a file system for Oracle database files that supports single-instance Oracle Database and Oracle Real Application Clusters (Oracle RAC) configurations. ASM is storage management solution that provides an alternative to conventional volume managers, file systems, and raw devices. Disksare directly provided to ASM. ASM then automatically manages the storage inside the disk without much manual intervention.

Lesson 53 : What does Oracle Clusterware do ?

What does Oracle Clusterware do ?

Oracle Clusterware performs the following tasks.

1) Node Monitoring: It manages node membership details. As cluster contains multiple nodes, so it has to keep a record of the nodes that are part of the cluster. And the details about the nodes which are down, and node that are running and part of the cluster.

2)  Network Management: Every node in cluster is connected over a network. Oracle Clusterware manages these network component. Clusterware managed Node-VIP, SCAN VIP, GNS-VIP, etc.

3) Event Services: Events such as node going down, instance going down are published to Oracle Clients.

4) Time Synchronization: Having synchronized time between each node is crucial. Oracle Clusterware synchronizes the time of all the participating node.

5) Cluster Management: Eventually Oracle Clusterware manages Oracle Database. It performs actions such as starting/stopping Oracle Database

Lesson 51 : What is OCR in Oracle RAC ?

Oracle Cluster Registry(OCR)

This is a configurationfile that stores the information about the resources that is managed by the clusterware.

Clusterware manages resources such as database, instances, network. Characteristics and attributes of each

resources are stored in OCR.

Lesson 52 : What is Voting Disk in Oracle RAC ?

Voting Disk

For a normal functioning of the cluster, every node should be able to communicate with every other node through cluster interconnect. Primary communication between nodes are through Cluster Interconnect. When there is a failure in reachingother nodes through interconnect, then voting disk is used to determine which nodes are part of cluster. Each node updates the voting file with information about the list of nodes it can reach through interconnect, and the list of nodes it is not able to reach through interconnect. This information is used to determine the list of nodes that can communicate among themselves. The remaining nodes that can not communicate are evicted out of the cluster. Eviction means that that node is rebooted or the clusterware stack on that node is rebooted.
Every node in cluster should access the shared storage only if it can communicate to other nodes via the cluster interconnect. Because cluster interconnect is used for co-ordinatedaccess to shared database files, to avoid any file corruption.
If the cluster interconnect communication fails, then each node can think that the other node is not available, and hence each node accesses the shared database files on its own without any co-ordination, thus corrupting the file. This is called split-brain situation in cluster environment. Voting Disk is used to avoid split-brain scenario in cluster environment.

Lesson 50 : OracleRAC Software Components

OracleRAC Software Components

Oracle Database 11gRelease 2 Grid Infrastructure is the software used to install Oracle Clusterware. This software is available for download from the URLhttp://otn.oracle.com. This software is available for multiple operating systems like for Linux, Solaris, HP-UX, AIXand Windows. Oracle Grid Infrastructure software contains both Oracle Clusterware and the Oracle ASM component. Oracle ASM is used to manage storage for RAC. More about ASM will be discussed in the next chapter. Only one instance of Grid Infrastructure software can be installed on a node. This software is installed on its own Oracle Home. This home is often referred as GRID HOME.

Oracle Database 11gRelease 2 is the software used to install Oracle RAC. This is installed on its own Oracle Home. This home is often referred as RDBMS HOME of RAC. There can be multiple RDBMS HOMEs on a node. There can also be multiple RAC Databases running on a node. Note that the GRID_HOME version should always be the equal or higher than all of the RDBMS_HOME of RAC.
8

Lesson 49 : Advantages of RAC

Advantages of RAC

High Availability: Oracle RAC helps protect database against a node failure, OS failure. If one or few of the nodes in the cluster fails, Oracle Database can still be accessed through the remaining functioning nodes. Thus, greatly increasing the availability of the Database.

Scalability: If the Oracle Database needs to support more number of users and loads, then additional nodes can be added to Oracle Clusterware. With the additional node addition, Database can now support more users without any downtime of migrating to a new bigger hardware. Thus, greatly increasing the scalability.
 
Load Balancing/Failover: Oracle RAC is an active/active model cluster. Incoming client connections can be load balanced among the available nodes. Thus each node in the cluster shares the workload. In case of a node failure, the connections can be redirected(failed over) to one of the available nodes transparently.

Lesson 48 : Single Instance vs RAC

Single Instance vs RAC

Single Instance database contains one database and one Instance on a single server machine.There is one to one mapping between database and the Instance. In the case of RAC, there can be multiple server machines.
The server machines are referred to as node. Each node will be running an instance and a listener. Every node is connected to the database that is placed on a shared storage. In RAC, there is one database to many instance mapping. Every instance is working in a well co-ordinatedmanner and accessing the same database files. Every node is connected over a network.

Single Instance Database = One Database and One Instance

RAC = One Database with multiple Instances.

Oracle RAC supports up to 100 nodes in a cluster. Though it is technically possible to have 100 nodes, in real world scenario it has been noted with about 32 node RAC configuration by the Oracle Customers.

Lesson 47 : Oracle Clusterware and RAC

Oracle Clusterware and RAC

Cluster enables servers to communicate with each other, so that they appear to function as a collective unit. This combination of servers is commonly known as a cluster. Although the servers are standalone servers, each server has additional processes that communicate with other servers. In this way the separate servers appear as if they are one system to applications and end users.

Oracle Clusterware provides the infrastructure necessary to createcluster. It is responsible for grouping the individual computers and making it part of a cluster. Oracle Clusterware provides the infrastructure necessary to run Oracle Real Application Clusters (Oracle RAC). OracleClusterware is needed to have Oracle RAC.

Oracle RAC means clustered Oracle database. Multiple instances running on serveralserver machines will be clustered and provided as a single database to the end user.