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. 

[/caption]

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

Public and Private Pipe

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

[/caption]

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

Display Pipe

Remove 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. 

[/caption]

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

View Pipe

Create Pipe

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

[/caption]

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

Receive Message

Send 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.

Instead, researchers suggest taking the time to provide learners with information on what exactly they did well, and what may still need improvement

21,605 Responses to “DBMS_PIPE – For Inter-Session Communication”

  1. TandimlKr says:

    online no deposit casino bonus
    casino no deposit
    best online casino usa

  2. CharlesFuh says:

    darknet market links 2022 reddit tor websites reddit

  3. Geraldbox says:

    how to access the dark web reddit best fraud market darknet

  4. RichardBit says:

    most reliable darknet markets dn market

  5. Wendelljab says:

    illegal fish on the darknet market best darknet markets

  6. DonaldMig says:

    ketamine darknet market darknet site

  7. Grantnof says:

    oniondir deep web link directory onion link search engine

  8. MichaelZof says:

    market street darknet cp onion

  9. SirKah says:

    reliable darknet markets reddit deep cp links

Leave a Reply

preload preload preload