Jun 28

Table Partitions
Partitioned tables allow your data to be broken down into smaller, more manageable pieces called Partitions, or even Sub Partitions. Indexes can be partitioned in similar fashion. Each partition is stored in its own segment and can be managed individually.
SQL queries and DML statements do not need to be modified in order to access partitioned tables.
However, after partitions are defined, DDL statements can access and manipulate individual partitions rather than entire tables or indexes. This is how partitioning can simplify the manageability of large database objects and enables faster data access within an Oracle database.

Partitioning allows tables and indexes to be partitioned into smaller, more manageable units, providing database administrators with the ability to pursue a “divide and conquer” approach to data management. With partitioning, maintenance operations can be focused on particular portions of tables. For example, a database administrator could back up a single partition of a table, rather than backing up the entire table.

Advantages of Partitioning:
• It enables data management operations such as data loads, index creation and rebuilding, and backup/recovery at the partition level, rather than on the entire table. This results in significantly reduced times for these operations.
• It improves query performance. In many cases, the results of a query can be achieved by accessing a subset of partitions, rather than the entire table.
• It increases the availability of mission-critical databases if critical tables and indexes are divided into partitions to reduce the maintenance windows, recovery times, and impact of failures.

Figure 1 List, Range, and Hash Partitioning

Types of Table Partitions

There are several partitioning methods offered by Oracle Database. Here, we have to discuss three basic partitions:

Range Partitioning
Range partitioning is used when partitions based on ranges of column values. This type of partitioning is useful when dealing with data that has logical ranges into which it can be distributed; for example, months of the year. Performance is best when the data evenly distributes across the range.

Range Partitioning Example
CREATE TABLE Sales_Range
(salesman_id NUMBER(5),
salesman_name VARCHAR2(30),
sales_amount NUMBER(10), sales_date DATE)
PARTITION BY RANGE(sales_date)

(PARTITION sales_jan2010 VALUES LESS THAN(TO_DATE(’02/01/2010′,’DD/MM/YYYY’)),
PARTITION sales_feb2010 VALUES LESS THAN(TO_DATE(’03/01/2010′,’DD/MM/YYYY’)),
PARTITION sales_mar2010 VALUES LESS THAN(TO_DATE(’04/01/2010′,’DD/MM/YYYY’)),
PARTITION sales_apr2010 VALUES LESS THAN(TO_DATE(’05/01/2010′,’DD/MM/YYYY’))
);

Hash Partitioning
Use hash partitioning if your data does not easily lend itself to range partitioning, but you would like to partition for performance and manageability reasons. Hash partitioning provides a method of evenly distributing data across a specified number of partitions. Rows are mapped into partitions based on a hash value of the partitioning key.

Hash Partitioning Example
CREATE TABLE Sales_Hash
(salesman_id NUMBER(5),
salesman_name VARCHAR2 (30),
sales_amount NUMBER(10),
week_no NUMBER(2))
PARTITION BY HASH(salesman_id)
PARTITIONS 4 STORE IN (data1, data2, data3, data4)

The preceding statement creates a table sales_hash, which is hash partitioned on salesman_id field. The tablespace names are data1, data2, data3, and data4.

List Partitioning
List partitioning is used when you require explicit control over how rows map to partitions. You can specify a list of discrete values for the partitioning column in the description for each partition. This is different from range partitioning, where a range of values is associated with a partition, and from hash partitioning, where the user has no control of the row to partition mapping.

The list partitioning method is specifically designed for modeling data distributions that follow discrete values. This cannot be easily done by range or hash partitioning because:

• Range partitioning assumes a natural range of values for the partitioning column. It is not possible to group together out-of-range values partitions.
• Hash partitioning allows no control over the distribution of data because the data is distributed over the various partitions using the system hash function. Again, this makes it impossible to logically group together discrete values for the partitioning columns into partitions.

Unlike the range and hash partitioning methods, multicolumn partitioning is not supported for list partitioning. If a table is partitioned by list, the partitioning key can consist only of a single column of the table. Otherwise all columns that can be partitioned by the range or hash methods can be partitioned by the list partitioning method.

List Partitioning Example
CREATE TABLE Sales_List
(salesman_id NUMBER(5),
salesman_name VARCHAR2(30),
sales_state VARCHAR2(20),
sales_amount NUMBER(10), sales_date DATE)
PARTITION BY LIST(sales_state)
(PARTITION sales_west VALUES(‘California’, ‘Hawaii’),
PARTITION sales_east VALUES (‘New York’, ‘Virginia’, ‘Florida’),
PARTITION sales_central VALUES(‘Texas’, ‘Illinois’)
PARTITION sales_other VALUES(DEFAULT)
)
A row is mapped to a partition by checking whether the value of the partitioning column for a row falls within the set of values that describes the partition. For example, the rows are inserted as follows:
• (10, ‘Jones’, ‘Hawaii’, 100, ’05-JAN-2010′) maps to partition sales_west
• (21, ‘Smith’, ‘Florida’, 150, ’15-JAN-2010′) maps to partition sales_east
• (32, ‘Lee’, ‘Colorado’, 130, ’21-JAN-2010′) does not map to any partition in the table

Jun 28
You would like to communicate with a 3rd-party application from your PL/SQL program, for example you want to run a UNIX command. Or perhaps you’d like to communicate directly with another Oracle session. Whatever your specific communication needs are, DBMS_PIPE is your solution. 

What is DBMS_PIPE? 

DBMS_PIPE is a package provided by Oracle that allows two or more sessions in the same instance to communicate.  

The DBMS_PIPE package provides a non-secure mechanism for inter-session messaging. It is considered non-secure because messages can be lost from the pipe if the instance crashes or is shutdown before they are processed. Advanced Queues are arguably a better mechanism when secure messaging and greater flexibility are required.. 

Types: 

There are two types of pipes 

Implicit Pipes- These are created automatically when a message is sent with an unknown pipe name using the SEND_MESSAGE function. Implicit pipes disappear when they are empty. 

Explicit Pipes- These are created using the CREATE_PIPE function. Explicit created pipes must be removed using the REMOVE_PIPE function. 

Security: 

Depending upon your security requirements, you may choose to use either a public or a private pipe. 

Public Pipes- You may create a public pipe either implicitly or explicitly. For implicit public pipes, the pipe is automatically created when it is referenced for the first time, and it disappears when it no longer contains data. Because the pipe descriptor is stored in the SGA, there is some space usage overhead until the empty pipe is aged out of the cache. 

 You can create an explicit public pipe by calling the CREATE_PIPE function with the private flag set to FALSE. You must deallocate explicitly-created pipes by calling the REMOVE_PIPE function. 

The domain of a public pipe is the schema in which it was created, either explicitly or implicitly. 

Private Pipes- You explicitly create a private pipe by calling the CREATE_PIPE  function. Once created, the private pipe persists in shared memory until you explicitly deallocate it by calling the REMOVE_PIPE  function. A private pipe is also deallocated when the database instance is shut down. 

You cannot create a private pipe if an implicit pipe exists in memory and has the same name as the private pipe you are trying to create. In this case, CREATE_PIPE returns an error. 

Access to a private pipe is restricted to: 

  • Sessions running under the same userid as the creator of the pipe
  • Stored subprograms executing in the same userid privilege domain as the pipe creator
  • Users connected as SYSDBA or INTERNAL

An attempt by any other user to send or receive messages on the pipe, or to remove the pipe, results in an immediate error. Any attempt by another user to create a pipe with the same name also causes an error. 

In short we can say that oracle pipes are similar in concept to the pipes used in UNIX, but Oracle pipes are not implemented using the operating system pipe mechanisms. It is called a pipe because it connects two (or more) sessions, and messages are queued up inside, just like a pipe. Each session can take the next received item out of a pipe, or insert the next item to send. Anybody (with access) can insert or remove something from the pipe, in any order. Messages can only be removed and read once – two people can’t remove the same message from a pipe. 

In more real terms, these pipes are buffers in the system global area (the SGA). Messages are prepared for loading using PACK_MESSAGE, loaded into a pipe using SEND_MESSAGE, and read similarly (RECEIVE_MESSAGE then UNPACK_MESSAGE). 

Required grant to the user: 

GRANT EXECUTE ON SYS.DBMS_PIPE TO [user]  

The following example used the CREATE_PIPE function to create explicit public and private pipes. 

Public and Private Pipe

Let us see, does above code realy create pipes for us. To displays information about the pipes, we use V$DB_PIPES view. 

View Pipes

The following example uses REMOVE_PIPE function to remove the pipes, created previously. 

Remove Pipe

Let us see, does above code realy removes pipes that we created recently. 

Display Pipe

Writing and Reading Pipes

Each public pipe works asynchronously. Any number of schema users can write to a public pipe, as long as they have EXECUTE permission on the DBMS_PIPE package, and they know the name of the public pipe. However, once buffered information is read by one user, it is emptied from the buffer, and is not available for other readers of the same pipe. The sending session builds a message using one or more calls to the PACK_MESSAGE procedure. This procedure adds the message to the session’s local message buffer. The information in this buffer is sent by calling the SEND_MESSAGE function, designating the pipe name to be used to send the message. When SEND_MESSAGE is called, all messages that have been stacked in the local buffer are sent. 

 A process that wants to receive a message calls the RECEIVE_MESSAGE function, designating the pipe name from which to receive the message. The process then calls the UNPACK_MESSAGE procedure to access each of the items in the message. 

 For this test, open up two sessions as the SAME user on the SAME instance. Make sure your user has access to the DBMS_PIPE package. 

We are going to have the first instance create the pipe, send in an SQL command, and have the second instance retrieve that message and execute it. 

 Below is the step by step procedure to implement communication between two sessions 

 1) Create a Pipe: Depending upon the need create pubic of private pipe. For this we use DBMS_PIPE.CREATE_PIPE Function. 

Create Pipe

 2) Checking the Pipes in the Database, by using v$db_pipes view. 

View Pipe

3) Sending message through session #1. For this we use PACK_MESSAGE and SEND_MESSAGE functions of the DBMS_PIPE package. 

Send Message

4) Receiving message in session #2, For this we use Receive_Message and UNPACK_Message functions of DBMS_PIPE package. 

Receive Message

Pipe Uses

The pipe functionality has several potential applications. Some of these are mentioned below: 

  • External service interface: You can communicate with user-written services that are external to the RDBMS. This can be done in a (effectively) multi-threaded manner, so that several instances of the service are executing simultaneously. Additionally, the services are available asynchronously. The requestor of the service does not need to block a waiting reply. The requestor can check (with or without timeout) at a later time. The service can be written in any of the 3GL languages that Oracle supports.
  • Independent transactions: The pipe can communicate to a separate session which can perform an operation in an independent transaction (such as logging an attempted security violation detected by a trigger).
  • Alerters (non-transactional): You can post another process without requiring the waiting process to poll. If an “after-row” or “after-statement” trigger were to alert an application, then the application would treat this alert as an indication that the data probably changed. The application would then read the data to get the current value. Because this is an “after” trigger, the application would want to do a “select for update” to make sure it read the correct data.
  • Debugging: Triggers and stored procedures can send debugging information to a pipe. Another session can keep reading out of the pipe and display it on the screen or write it to a file.
  • Concentrator: This is useful for multiplexing large numbers of users over a fewer number of network connections, or improving performance by concentrating several user-transactions into one DBMS transaction.
May 03

There has been a lot of talk about SaaS applications with SFDC and Oracle CRM on Demand being the frontrunners in the space. Something that the development community and the business users always want is results “quickly”.

What is APEX?

Oracle Application Express APEX is one such tool which is a RAD (Rapid Application web Development) tool that can be used over an Oracle Database. With application resulting in a rich user interface, it’s easy to learn, easy to use and organizations using Oracle Databases can highly benefit out of it.

APEX is written using PL/SQL and runs entirely inside a web browser; it’s an IDE and a runtime environment. No client software is required to develop, deploy, or run Application Express applications. New built-in capabilities for Application Express include Forms Conversion and additional security enhancements. The important thing to remember is that APEX is designed to be tightly integrated with Oracle Database, to be a fully capable web development environment, and be easy enough for savvy business users to extend applications for themselves.

How is APEX an RAD tool?

Application Express provides three primary tools: 

  • Application Builder – to create dynamic database driven web applications
  • SQL Workshop – to browse your database objects, run ad-hoc SQL queries, as well as a graphical query builder
  • Utilities – allows for data to be loaded and unloaded from both flat files and spreadsheets

Since APEX is so tightly integrated to Oracle database, you can prototype screens right there and then. The object browser allows you to create and view database objects like tables and build reports, charts around those objects. APEX being declarative, changes can be easily made in real time via the built in wizards.

Users are demanding more user interactivity and client-side functionality whereby the application responds as soon as a value is changed or the user leaves a field (wysiwyg, the new buzz word). Such functionality can be readily built into applications today using JavaScript and AJAX, providing you knows how to program in such languages. Dynamic actions are designed to make implementing such functionality declarative, allowing every APEX developer to enhance the user experience without needing to master JavaScript and AJAX. Such an implementation also makes maintenance and debugging a much simpler task.

Out of the box development features include Report, Forms, Charts, Email Services. All of the normal web widgets are available too: radio groups, buttons, drop down lists, date pickers etc. It comes with built in applications such as Project Task Tracker, Bug tracker, Project Issue tracker etc. Output from the application can be directed to the screen or to PDF, Flash, Excel or even integrated into a web service. You can even integrate your javascript code should you need it.

Who can use APEX?

APEX is targeted at the Rapid Application Development (RAD) developer. It is best suited to Departmental / Targeted applications. Not to say it can’t be used for enterprise applications or developed by end-users, there are many examples of both which have been implemented. Its advantage over scripting languages is the declarative framework and longevity as based on PL/SQL. If your business logic is in the database tier, APEX is the way to go. If your business logic is in the middle tier, J2EE maybe a better choice.

You can try APEX by signing up for a hosted account:

http://tryapexnow.com/

Next Blog: “How to” in APEX!

More resources:

Tagged with:
preload preload preload