Vous êtes sur la page 1sur 11

December 2011 Bachelor of Computer Application (BCA) Semester 4

BC0050 Oracle & Distributed Databases 4 Credits (Book ID: B0894)


Assignment Set 1 (40 Marks)

Answer all the questions 4 x 10 = 40 1. Write a PL/SQL code for find Sum of N numbers using WHILE Loop set serveroutput on; declare n number := &n; a number ; b number ; begin a := 1; b := 0; while(a <= n) loop b := b + a; a := a+1; end loop; dbms_output.put_line('sum ofnatural numbers'||b); end; 2. Differentiate between PL/SQL functions and procedures. 1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT parameter. 2. Function can be called from SQL statements where as procedure can not be called from the sql statements 3. Functions are normally used for computations where as procedures are normally used for executing business logic. 4. You can have DML (insert update delete) statements in a function. But you cannot call such a function in a SQL query 5. Function returns 1 value only. Procedure can return multiple values (max 1024). 6. Stored Procedure : supports deferred name resolution. Example while writing a stored procedure that uses table named tabl1 and tabl2 etc.. but actually not exists in database is allowed only in during creation but runtime
Page 1

throws error Function wont support deferred name resolution. 7. Stored procedure returns always integer value by default zero. where as function return type could be scalar or table or table values 8. Stored procedure is precompiled execution plan where as functions are not. 9. A procedure may modify an object where a function can only return a value The RETURN statement immediately completes the execution of a subprogram and returns control to the caller. 3. Draw a diagram of oracle architecture and explain it briefly. The Oracle server consists of physical files and memory components. The Oracle 9i Database product is made up three main components namely:
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 9i. The Oracle server is made up of an Oracle instance and an Oracle database.
2. The Oracle Instance Consists of the memory 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. The figure 3.1 displays the architecture of the Oracle Database 9i. It is broadly divided into the memory components which form the Oracle instance and the physical database components where different kinds of data are stored.

Page 2

4. Draw the diagram of logical structure of oracle database and explain it in brief. Fig below shows the logical structure of oracle database.

Page 3

The Oracle database is divided into increasingly smaller logical units to manage, store, and retrieve dataefficiently and quickly. The figure shows the relationships between the logical structures of the database. Logical structure mainly consists of tablespace,segments,extents, andoracle data blocks TABLESPACE Each database is logically divided into one or more tablespaces . One or more datafiles are explicitlycreated for each tablespace to physically store the data of all logical structures in a tablespace. Thecombined size of the datafiles in a tablespace is the total storage capacity of the tablespace. SEGMENT A segment is a set of extents allocated for a certain logical structure. The segments can be of one of following type data segment, index segment, temporary segment, rollback segment.

Page 4

EXTENT The next level of logical database space is an extent. An extent is a specific number of contiguous datablocks, obtained in a single allocation, and used to store a specific type of information. ORACLE DATABLOCKS At the finest level of granularity, Oracle database data is stored in data blocks. One data blockcorresponds to a specific number of bytes of physical database space on disk. The standard block size isspecified by the DB_BLOCK_SIZE initialization parameter. In addition, you can specify up to five otherblock sizes

Page 5

December 2011 Bachelor of Computer Application (BCA) Semester 4

BC0050 Oracle & Distributed Databases 4 Credits (Book ID: B0894)


Assignment Set 2 (40 Marks)

Answer all the questions 4 x 10 = 40 1. Discuss the objectives of Query Processing. The main objectives of query processing in a distributed environment is to form a high levelquery on a distributed database, which is seen as a single database by the users, into an efficientexecution strategy expressed in a low level language on local databases. An important point of query processing is query optimization. Because many execution strategiesare correct transformations of the same high-level query, the one that optimizes (minimizes)resource consumption should be retained. The good measures of resource consumption are: The total cost that will be incurred in processing the query. It is the some of all times incurred in processing the operations of the query at various sites and intrinsic communication. The resource time of the query. This is the time elapsed for executing the query. Since operations can be executed in parallel at different sites, the response time of a query may be significantly less than its cost. Obviously the total cost should be minimized. In a distributed system, the total cost to be minimized includes CPU, I/O, and communication costs. These costs can be minimized by reducing the number of I/O operations through fast access methods to the data and efficient use of main memory. The communication cost is the time needed for exchanging the data between sites participating in the execution of the query. In centralized systems, only CPU and I/O cost have to be considered 2. Discuss the Features of the Heterogeneous Services. The following are the features of Heterogeneous Services. Not all features listed below are necessarily supported by your Heterogeneous Services agent or Oracle Gateway. 1. Distributed Transactions : A transaction can span both Oracle and nonOracle systems, while still guaranteeing, through Oracles two phase commit mechanism, that changes are either all committed or all rolled back.
Page 1

2. Transparent SQL access : Integrate data from non-Oracle systems into the

Oracle environment as if the data is stored in one single, local database. SQL statements issued by the application are transparently transformed into SQL statement understood by the non-Oracle system 3. Procedural Access : Procedural systems, like messaging and queuing systems, are accessedfrom an Oracle9i server using PL/SQL remote procedure calls. 4. Data Dictionary translations : To make the non-Oracle system appear as another Oracle server, SQL statements containing references to Oracle's data dictionary tables are transformed into SQL statements containing references to a non-Oracle systems data dictionary tables. 5. Pass-through SQL : Optionally, application programmers can directly access a non-Oracle system from an Oracle application using the non-Oracle systems SQL dialect. 6. Accessing stored procedures : Stored procedures in SQL-based nonOracle systems are accessed as if they were PL/SQL remote procedures. 7. National Language Support : Heterogeneous Services supports multi-byte character sets, and translate character sets between a non-Oracle system and the Oracle9i server. 8. Multi-Threaded Agents : Multi-threaded agents take advantage of your operating system's threading capabilities. Multi-threaded agents reduce the number of required processes by taking advantage of multi-threaded server capabilities. 9. Agent Self-Registration : Agent self-registration automates the process of updating Heterogeneous Services configuration data on remote hosts, ensuring correct operation over heterogeneous database links. 10. Management Interface : Provides a graphic representation of active Heterogeneous Services agents and of which user sessions are accessing those agents. 3. Explain the steps involved in recovery of distributed transactions. The issue of recovery mechanism is important in the case of revoking the system to perform normal database operations after a failure. Thus, before discussing about recovery, let us first analyze about the different kinds of failure that can occur in a centralized database. Now let us consider recovery problems in distributed databases. For this purpose, let us assume that at each site a Local Transaction Manager is available. Each agent can issue begin_transaction, commit, and abort primitives to its LTM.
Page 2

After having issued a begin_transaction to its LTM, an agent will possess the properties of a local transaction. We will call an agent that has issued a begin_transaction primitive to its local transaction manager a Sub-transaction. Also to distinguish the begin_transaction, commit, and abort primitives of the distributed transaction from the local primitives issued by each agent to its LTM, we will call the later as local_begin, local_commit, and local_abort. For building a Distributed Transaction Manager (DTM), the following properties are expected from the LTM: Ensuring the atomicity of sub-transaction Writing some records on stable storage on behalf of the distributed transaction manager We need the second requirement, as some additional information must also be recorded in such away that they can be recovered in case of failure. In order to make sure that either all actions of a distributed transaction are performed or none is performed at all, two conditions are necessary: At each site either all actions are performed or none is performed All sites must take the same decision with respect to the commitment or abort of sub transaction.

Page 3

Begin_transaction: When it is issued by the root agent, DTM will have to issue a local_begin primitive to the LTM at the site of origin and all the sites at which there are already active agents of the same application, thus transforming all agents into sub-transactions; from this time on the activation of a new agent by the same distributed transaction requires that the local_begin be issued to the LTM where the agent is activated, so that the new agent is created as a Subtransaction. The example of FUND TRANSFER is taken for explaining this concept. The fig 8.1 explains this. Abort: When an abort is issued by the root agent, all existing sub-transactions must be aborted. Issuing local_aborts to the LTMs at all sites where there is an active sub transaction performs this. Commit: The implementation of the commit primitive is the most difficult and expensive. The main difficulty originates from the fact that the correct commitment of a distributed transaction requires that al sub-transactions commit locally even if there are failures.

Page 4

In order to implement this primitive for a distributed transaction, the general idea of 2-Phase commit Protocol has been developed. It is discussed in detail in the next section. What are the different Troubleshooting problems in Distributed Transaction?
4. A network or system failure can cause the following types of problems: A two-phase commit being processed when a failure occurs may not be completed at all nodes of the session tree. If a failure persists (for example, if the network is down for a long time), the data exclusively locked by in-doubt transactions is unavailable to statements of other transactions. The following sections describe these situations. Failures that Interrupt Two-Phase Commit The user program that commits a distributed transaction is informed of a problem by one of the following error messages: A robust application should save information about a transaction if it receives any of the above errors. This information can be used later if manual distributed transaction recovery is desired. Failures that Prevent Data Access When a user issues a SQL statement, Oracle9i attempts to lock the required resources to successfully execute the statement. However, if the requested data is currently being held by statements of other uncommitted transactions and continues to remain locked for an excessive amount of time, a time-out occurs. Transaction Time-Out A DML SQL statement that requires locks on a remote database may be blocked from doing so if another transaction (distributed or non-distributed) currently own locks on the requested data. If these locks continue to block the requesting SQL statement, a time-out occurs, the statement is rolled back, and the following error message is returned to the user: ORA-02049: time-out: distributed transaction waiting for lock Because no data has been modified, no actions are necessary as a result of the timeout. Applications should proceed as if a deadlock has been encountered. The user who executed the statement can try to re-execute the statement later. If the lock persists, the user should contact an administrator to report the problem. Lock From In-Doubt Transaction A query or DML statement that requires locks on a local database may be Page 5

blocked from doing so indefinitely due to the locked resources of an in-doubt distributed transaction. In this case, the following error message is immediately returned to the user: In this case, the SQL statement is rolled back immediately. The user who executed the statement can try to re-execute the statement later. If the lock persists, the user should contact an administrator to report the problem, including the ID of the indoubt distributed transaction. Manually Overriding In-Doubt Transactions A database administrator can manually force the COMMIT or ROLLBACK of a local in-doubt distributed transaction. However, a specific in-doubt transaction should be manually overridden only when the following situations exist: The in-doubt transaction locks data that is required by other transactions. An in-doubt transaction prevents the extents of a rollback segment to be used by other transactions. The failure that did not allow the two-phase commit phases to complete will not be corrected in an acceptable time period.

Page 6

Vous aimerez peut-être aussi