17.2 DBMS_DEFER_SYS: Managing Deferred TransactionsThe DBMS_DEFER_SYS package provides a number of programs for administrative tasks associated with deferred transactions. 17.2.1 Getting Started with DBMS_DEFER_SYSThe DBMS_DEFER_SYS package is created when the Oracle database is installed. The dbmsdefr.sql script (found in the built-in packages source directory, as described in Chapter 1, Introduction ) contains the source code for this package's specification. This script is called by catrep.sql , which must be run to install the advanced replication packages. The wrapped sql script prvtrctf.sql creates the public synonym DBMS_DEFER_SYS. No EXECUTE privileges are granted on DBMS_DEFER_SYS; only the owner (SYS) and those with the EXECUTE ANY PROCEDURE system privilege may execute the package. 17.2.1.1 DBMS_DEFER_SYS programsTable 17.10 lists the programs available in the DBMS_DEFER_SYS package.
17.2.1.2 DBMS_DEFER_SYS exceptionsThe DBMS_DEF_SYS package may raise the following exception:
17.2.1.3 DBMS_DEFER_SYS nonprogram elementsThe following table defines the constants defined in the DBMS_DEFER_SYS package. These constants are used internally in the package.
17.2.2 Adding and Deleting Default DestinationsThe DBMS_DEFER_SYS package's ADD_DEFAULT_DEST and DELETE_DEFAULT_DEST procedures add and delete records in the DEFDEFAULTDEST data dictionary view. 17.2.2.1 The DBMS_DEFER.SYS.ADD_DEFAULT_DEST procedureThe ADD_DEFAULT_DEST procedure adds records in the DEFDEFAULTDEST data dictionary view. Adding a record to this view effectively specifies a default destination for deferred RPCs. The specification is, PROCEDURE DBMS_DEFER_SYS.ADD_DEFAULT_DEST (dblink IN VARCHAR2); where dblink is the global name of the destination site being added. There are no restrictions on calling ADD_DEFAULT_DEST. 17.2.2.1.1 ExceptionsThe ADD_DEFAULT_DEST procedure may raise the following exception:
17.2.2.1.2 ExampleThe following call adds the default destination named D7NY.BIGWHEEL.COM to DEFDEFAULTDEST: BEGIN DBMS_DEFER_SYS.ADD_DEFAULT_DEST('D7NY.BIGWHEEL.COM'); END; Of course, the appropriate database links must be in place for deferred transactions to reach your intended destinations. Also, remember that the DBMS_DEFER package queues RPCs to the locations in DEFDEFAULTDEST if and only if you have not passed the nodes parameter to DBMS_DEFER.CALL or DBMS_DEFER.TRANSACTION.
17.2.2.2 The DBMS_DEFER.SYS.DELETE_DEFAULT_DEST procedureThe DELETE_DEFAULT_DEST procedure deletes records in the DEFDEFAULTDEST data dictionary view. Deleting a record effectively removes a default destination for deferred RPCs. The specification is, PROCEDURE DBMS_DEFER_SYS.DELETE_DEFAULT_DEST (dblink IN VARCHAR2); where dblink is the global name of the destination site being deleted. There are no restrictions on calling DELETE_DEFAULT_DEST, and the procedure raises no exceptions. 17.2.2.2.1 ExampleThe following example removes the default destination named D7OH.BIGWHEEL.COM from DEFDEFAULTDEST: BEGIN DBMS_DEFER_SYS.DELETE_DEFAULT_DEST('D7OH.BIGWHEEL.COM'); END; As with other DBMS_DEFER_SYS programs, these deletions affect only future calls. 17.2.3 Copying Deferred Transactions to New DestinationsIf you want the deferred RPCs that are already in the queue to be propagated to the newly added destinations, you can use the DBMS_DEFER_SYS.COPY procedure to make a copy of the existing deferred transaction(s). 17.2.3.1 The DBMS_DEFER_SYS.COPY procedureThe COPY procedure copies a specified deferred transaction. Oracle queues the copied transaction to the new destinations that you specify. Here's the specification: PROCEDURE DBMS_DEFER_SYS.COPY (deferred_tran_id IN VARCHAR2, deferred_tran_db IN VARCHAR2, destination_list IN dbms_defer.node_list_t, destination_count IN BINARY_INTEGER); Parameters are summarized in the following table.
There are no restrictions on calling COPY.
17.2.3.1.1 ExceptionsThe COPY procedure may raise the following exception:
17.2.3.1.2 ExampleSuppose that you have a new site in Hawaii, and you want to include it as a destination for RPCs that are already queued. First, add the Hawaiian site to the list of default destinations like this: BEGIN DBMS_DEFER_SYS.ADD_DEFAULT_DESTINATION('D7HI.BIGWHEEL.COM'); END; Next, query DEFCALLDEST to get the transaction ID of a the queued RPC(s). You need this information to copy the transaction: SQL> select * from defcalldest; Deferred Deferred Tran Tran Call No ID DB DB Link -------------- -------- ------------------- -------------------- 6631429919536 2.59.13 D7CA.BIGWHEEL.COM D7OR.BIGWHEEL.COM 6631429919536 2.59.13 D7CA.BIGWHEEL.COM D7WA.BIGWHEEL.COM 2 rows selected. Now, use DBMS_DEFER_SYS.COPY to queue this transaction to the destination named D7HI.BIGWHEEL.COM: DECLARE vNodes DBMS_DEFER.NODE_LIST_T; BEGIN vNodes(1) := 'D7HI.BIGWHEEL.COM'; dbms_defer_sys.copy( '2.59.13', 'D7CA.BIGWHEEL.COM', vNodes, 1); END; 17.2.4 Maintenance ProceduresThere are several maintenance procedures available in the DBMS_DEFER_SYS package. These procedures round out the deferred RPC repertoire by providing a means of cleaning up errors and temporarily disabling queue pushes. 17.2.4.1 The DBMS_DEFER_SYS.DELETE_ERROR procedureThe DELETE_ERROR procedure allows you to delete transactions from the DEFERROR data dictionary view. The procedure also deletes the related entries from DEFCALL, DEFTRAN, and DEFTRANDEST. Use DELETE_ERROR if you have manually resolved a transaction that initially failed. Here is the specification: PROCEDURE DBMS_DEFER_SYS.DELETE_ERROR (deferred_tran_id IN VARCHAR2, deferred_tran_db IN VARCHAR2, destination IN VARCHAR2); Parameters are summarized in the following table.
There are no restrictions on calling DELETE_ERROR. 17.2.4.1.1 ExceptionsThe DELETE_ERROR procedure may raise the following exception:
17.2.4.1.2 ExamplesThe nice thing about the DELETE_ERROR procedure is that you can pass NULL to any or all of the three parameters to treat it as a wildcard. Here's how to delete all errors: BEGIN DBMS_DEFER_SYS.DELETE_ERROR( null, null, null); END; Here's how to delete all errors having D7NY.BIGWHEEL.COM as a destination: BEGIN DBMS_DEFER_SYS.DELETE_ERROR(null, null, 'D7NY.BIGWHEEL.COM' ); END; Here's how to delete all errors from RPC calls that originated at D7CA.BIGWHEEL.COM: BEGIN DBMS_DEFER_SYS.DELETE_ERROR(NULL, 'D7CA.BIGWHEEL.COM', NULL); END; 17.2.4.2 The DBMS_DEFER_SYS.DELETE_TRAN procedureThe DELETE_TRAN procedure deletes deferred transactions. You might want to do this if you have applied the call manually or if you remove a node from your environment. The procedure deletes the call from the DEFTRANDEST data dictionary view and also from DEFCALLDEST (if it is an RPC). If the original call has been applied to all other destinations, then the procedure also removes the entries from DEFCALL and DEFTRAN. As with the DELETE_ERROR procedure, DELETE_TRAN also treats NULL parameter values as wildcards (see the examples under DELETE_ERROR). Here is the specification: PROCEDURE DBMS_DEFER_SYS.DELETE_TRAN (deferred_tran_id IN VARCHAR2, deferred_tran_db IN VARCHAR2, destination IN VARCHAR2); Parameters are summarized in the following table.
There are no restrictions on calling DELETE_TRAN. 17.2.4.2.1 ExceptionsThe DELETE_TRAN procedure may raise the following exception:
17.2.4.3 The DBMS_DEFER_SYS.DISABLED functionThe DISABLED function returns the BOOLEAN value TRUE if the deferred RPC calls to the specified destination have been disabled (with SET_DISABLED), and returns FALSE otherwise. The specification is, FUNCTION DBMS_DEFER_SYS.DISABLED (destination IN VARCHAR2) RETURN BOOLEAN; where destination is the global name of the destination database. There are no restrictions on calling the DISABLED function. 17.2.4.3.1 ExceptionsThe DISABLED function may raise the following exception:
17.2.4.4 The DBMS_DEFER_SYS.EXECUTE_ERROR procedureThe EXECUTE_ERROR procedure forces execution of a transaction that originally failed, leaving a record in DEFERROR. You might call this procedure if you have repaired the error (for example, a conflict in the advanced replication option) and you now wish to re-attempt the transaction. If another error occurs during EXECUTE_ERROR, the attempt is aborted and the last error encountered is returned as an exception. Upon successful completion, the procedure deletes the entries from the DEFERROR data dictionary view. If the original call has been applied to all other destinations, then the procedure also removes the entries from DEFCALL and DEFTRAN. As with the DELETE_ERROR and DELETE_TRAN procedures, you may pass NULLs to indicate wildcards. Here is the specification for this procedure: PROCEDURE DBMS_DEFER_SYS.EXECUTE_ERROR (deferred_tran_id IN VARCHAR2, deferred_tran_db IN VARCHAR2, destination IN VARCHAR2); Parameters are summarized in the following table.
17.2.4.4.1 ExceptionsEXECUTE_ERROR may raise the following exception:
If execution stops because of an exception, the EXECUTE_ERROR procedure raises the last exception encountered. 17.2.4.4.2 RestrictionsNote the following restrictions on calling EXECUTE_ERROR:
17.2.4.4.3 ExampleFor an example, see the fixdefer.sql file on the companion disk. The example lists all deferred transactions that have encountered errors, and generates calls to DBMS_DEFER_SYS.EXECUTE_ERROR to reexecute the calls. 17.2.4.5 The DBMS_DEFER_SYS.SET_DISABLED procedureThe SET_DISABLED procedure disables or enables propagation to the specified destination. If you are managing a replicated environment, you might want to disable propagation to a given site while you perform maintenance.
The specification follows: PROCEDURE DBMS_DEFER_SYS.SET_DISABLED (destination IN VARCHAR2, disabled IN BOOLEAN := TRUE); Parameters are summarized in the following table.
17.2.4.5.1 ExceptionsThe SET_DISABLED procedure may raise the following exception:
17.2.4.5.2 RestrictionsYou must execute a COMMIT after a call to the SET_DISABLED procedure for the changes to take effect. 17.2.4.5.3 ExampleThe following example disables propagation of deferred RPCs to D7NY.BIGWHEEL.COM: BEGIN DBMS_DEFER_SYS.SET_DISABLED('D7NY.BIGWHEEL.COM', FALSE); END The following example enables propagation: BEGIN DBMS_DEFER_SYS.SET_DISABLED('D7NY.BIGWHEEL.COM', TRUE); END; 17.2.5 Propagating Deferred RPCsThe DBMS_DEFER.CALL procedure, which we'll discuss later in this chapter, neither executes nor pushes transactions to the destination databases: it simply queues them. In order to propagate the deferred call to the destinations and to execute it there, you must use the DBMS_DEFER_SYS package's EXECUTE procedure. Use SCHEDULE_EXECUTION to schedule execution at prescribed intervals, and UNSCHEDULE_EXECUTION to stop propagation.
17.2.5.1 Scheduling strategiesThe granularity of the DBMS_JOB facility is one second, so you could schedule propagation of your deferred RPC calls for once per second if you wanted to. However, such an aggressive schedule is not advisable. In fact, scheduling propagation to occur more often than once every five minutes is rarely wise. Of course, your ideal schedule is a function of your application, business requirements, and resources. Nevertheless, a lengthy interval is seldom justifiable. Why the restrictions?
In short, you should avoid the temptation to schedule deferred transactions to be propagated on a subminute interval unless your application truly requires it. Five-minute intervals are the shortest that Oracle Corporation recommends. 17.2.5.2 The DBMS_DEFER_SYS.EXECUTE procedureThe EXECUTE procedure propagates a deferred call to the destination database and executes it there. Here is the specification: PROCEDURE DBMS_DEFER_SYS.EXECUTE (destination IN VARCHAR2, stop_on_error IN BOOLEAN := FALSE, transaction_count IN BINARY_INTEGER := 0, execution_seconds IN BINARY_INTEGER := 0, execute_as_user IN BOOLEAN := FALSE, delay_seconds IN NATURAL := 0, batch_size IN NATURAL := 0); Parameters are summarized in the following table.
There are no restrictions on calling the EXECUTE procedure. 17.2.5.2.1 ExceptionsIf execution stops because of an exception, the EXECUTE procedure raises the last exception encountered. 17.2.5.2.2 ExamplesAlthough the EXECUTE procedure includes several parameters, you can use it in its simplest form to push all queued transactions to a given destination. For example, to send the transaction that was queued to D7TX.BIGWHEEL.COM in the example of DBMS_DEFER.TRANSACTION, we would simply make this call: BEGIN DBMS_DEFER_SYS.EXECUTE('D7TX.BIGWHEEL.COM'); END; This call propagates and executes all deferred RPCs bound for D7TX.BIGWHEEL.COM. The EXECUTE procedure includes various optional parameters (described in the next section) to accommodate applications that may queue tens or hundreds or thousands of deferred RPC calls. The advanced replication option has this potential. (In such cases, you may need to control the rate and volume of transactions, privilege domains, and error handling.) 17.2.5.2.3 Advanced usage: using the EXECUTE parametersThe items in the following list describe in greater detail how you use the EXECUTE parameters:
17.2.5.3 The DBMS_DEFER_SYS. SCHEDULE_EXECUTION procedureIf you are using the advanced replication option, or if your application queues deferred RPC calls on a continual basis, then you should schedule the calls to the DBMS_DEFER_SYS.EXECUTE procedure at prescribed intervals for each destination. The SCHEDULE_EXECUTION procedure does just that by placing calls to the EXECUTE procedure in the job queue. Here is the specification: PROCEDURE DBMS_DEFER_SYS.SCHEDULE EXECUTION (dblink IN VARCHAR2, interval IN VARCHAR2, next_date IN DATE, reset IN BOOLEAN default FALSE, stop_on_error IN BOOLEAN := NULL, transaction_count IN BINARY_INTEGER := NULL, execution_seconds IN BINARY_INTEGER := NULL, execute_as_user IN BOOLEAN := NULL, delay_seconds IN NATURAL := NULL, batch_size IN NATURAL := NULL); Parameters are summarized in the following table.
This procedure looks like a cross between DBMS_JOB.SUBMIT and DBMS_DEFER.EXECUTE, because it is. The interval and next_date parameters behave in exactly the same way as the parameters by the same names passed to DBMS_JOB.SUBMIT; the parameters stop_on_error, transaction_count, execution_seconds, execute_as_user, delay_seconds, and batch_size are passed directly to the DBMS_DEFER_SYS.EXECUTE call that is put in the job queue (dblink is passed to the destination). Setting the reset parameter to TRUE sets columns LAST_TXN_COUNT, LAST_ERROR, and LAST_MSG to NULL in the DEFSCHEDULE data dictionary view. The SCHEDULE_EXECUTION procedure does not raise any exceptions, nor are there any restrictions on calling this procedure. 17.2.5.3.1 ExampleThe following example shows how to schedule automatic propagation of deferred RPC calls to D7WA.BIGWHEEL.COM. These calls will be propagated every 15 minutes, starting at midnight tonight. BEGIN DBMS_DEFER_SYS.SCHEDULE_EXECUTION( - db_link => 'D7WA.BIGWHEEL.COM', - interval => 'SYSDATE + 15/1440', - /* 1440 minutes in a day*/ next_date => TRUNC(SYSDATE + 1), - reset => TRUE); END; / For additional examples, see the defsched.sql and jobs.sql files on the companion disk. The defsched.sql example lists RPCs that have been scheduled with DBMS_DEFER_SYS.SCHEDULE_EXECUTION, including last and next execution times in hours, minutes, and seconds. The jobs.sql example lists all jobs in the job queue, including last and next execution times in hours, minutes, and seconds, aslong with the package call that is being executed. 17.2.5.4 The DBMS_DEFER_SYS.UNSCHEDULE_EXECUTION procedureWhen you need to stop the propagation of deferred calls to a given destination, you can do so with the UNSCHEDULE_EXECUTION procedure. The specification is, PROCEDURE DBMS_DEFER_SYS.UNSCHEDULE_EXECUTION (dblink IN VARCHAR2); where dblink is the global name of the destination database. Calling this procedure is analogous to calling DBMS_JOB.REMOVE to remove the job that DBMS_DEFER_SYS.SCHEDULE_EXECUTION scheduled. The job is removed from the queue, and automatic propagation to the database specified by dblink ceases. There are no restrictions on calling UNSCHEDULE_EXECUTION. 17.2.5.4.1 ExceptionsThe UNSCHEDULE_EXECUTION procedure may raise the following exception:
17.2.6 Scheduling Propagation (Oracle8 only)Oracle8 uses a slightly different mechanism to propagate transactions to remote databases. Instead of deleting transactions from the local queue as soon as they are delivered to a remote site, Oracle purges the queue as a separate process. This strategy enhances performance because there is no need for a two-phase commit when transactions are propagated. In addition, Oracle8 includes support for parallel propagation, which means that multiple transactions can be delivered to the destinations simultaneously if they are not dependent on each other.
Here are the DBMS_DEFER_SYS programs that support propagation in Oracle8 are:
17.2.6.1 The DBMS_DEFER_SYS.EXCLUDE_PUSH function (Oracle8 only)The EXCLUDE_PUSH function acquires a lock to disable deferred pushes. The specification is, FUNCTION DBMS_DEFER_SYS.EXCLUDE_PUSH (timeout IN INTEGER) RETURN INTEGER; where timeout is the time to wait to acquire a lock that disables pushes. Specify DBMS_LOCK.MAXWAIT to wait indefinitely. The EXCLUDE_PUSH function may return the values shown in the following table.
17.2.6.2 The DBMS_DEFER_SYS.PURGE function (Oracle8 only)The PURGE procedure purges transactions that have been propagated from the deferred transaction queue. Here is the specification: FUNCTION DBMS_DEFER_SYS.PURGE( purge_method IN BINARY_INTEGER := purge_method_quick, rollback_segment IN VARCHAR2 := NULL, startup_seconds IN BINARY_INTEGER := 0, execution_seconds IN BINARY_INTEGER := seconds_infinity, delay_seconds IN BINARY_INTEGER := 0, transaction_count IN BINARY_INTEGER := transactions_infinity, write_trace IN BOOLEAN := FALSE ) RETURN BINARY_INTEGER; Parameters are summarized in the following tables.
The return values for PURGE are listed in the following table.
17.2.6.2.1 ExceptionsThe PURGE function raises the following exceptions:
17.2.6.3 The DBMS_DEFER_SYS.PUSH functionThe PUSH function pushes a queued transaction to a destination node. Here is the specification: FUNCTION DBMS_DEFER_SYS.PUSH( destination IN VARCHAR2, parallelism IN BINARY_INTEGER := 0, heap_size IN BINARY_INTEGER := 0, stop_on_error IN BOOLEAN := FALSE, write_trace IN BOOLEAN := FALSE, startup_seconds IN BINARY_INTEGER := 0, execution_seconds IN BINARY_INTEGER := seconds_infinity, delay_seconds IN BINARY_INTEGER := 0, transaction_count IN BINARY_INTEGER := transactions_infinity, delivery_order_limit IN NUMBER := delivery_order_infinity ) RETURN BINARY_INTEGER; Parameters are summarized in the following table.
Return values for PUSH are listed in the following table.
17.2.6.3.1 ExceptionsPUSH raises the following exceptions:
17.2.6.4 The DBMS_DEFER_SYS.SCHEDULE_PURGE procedure (Oracle8 only)The SCHEDULE_PURGE procedure schedules the automatic purge of transactions that have been propagated from the queue. Here is the specification: PROCEDURE DBMS_DEFER_SYS.SCHEDULE_PURGE( interval IN VARCHAR2, next_date IN DATE, reset IN BOOLEAN := FALSE, purge_method IN BINARY_INTEGER := NULL, rollback_segment IN VARCHAR2 := NULL, startup_seconds IN BINARY_INTEGER := NULL, execution_seconds IN BINARY_INTEGER := NULL, delay_seconds IN BINARY_INTEGER := NULL, transaction_count IN BINARY_INTEGER := NULL, write_trace IN BOOLEAN := NULL ); Parameters are summarized in the following table.
17.2.6.5 The DBMS_DEFER_SYS.SCHEDULE_PUSH procedure (Oracle8 only)The SCHEDULE_PUSH procedure schedules automatic pushes to the destination node. Here is the specification: PROCEDURE DBMS_DEFER_SYS.SCHEDULE_PUSH( destination IN VARCHAR2, interval IN VARCHAR2, next_date IN DATE, reset IN BOOLEAN := FALSE, parallelism IN BINARY_INTEGER := NULL, heap_size IN BINARY_INTEGER := NULL, stop_on_error IN BOOLEAN := NULL, write_trace IN BOOLEAN := NULL, startup_seconds IN BINARY_INTEGER := NULL, execution_seconds IN BINARY_INTEGER := NULL, delay_seconds IN BINARY_INTEGER := NULL, transaction_count IN BINARY_INTEGER := NULL ); Parameters are summarized in the following table.
17.2.6.6 The DBMS_DEFER_SYS.UNSCHEDULE_PURGE procedure (Oracle8 only)The UNSCHEDULE_PURGE procedure is the complement to the SCHEDULE_PURGE procedure. This procedure unschedules the automatic purge of transactions that have been propagated to the queue. The specification is simply: PROCEDURE DBMS_DEFER_SYS.UNSCHEDULE_PURGE; 17.2.6.7 The DBMS_DEFER_SYS.UNSCHEDULE_PUSH procedure (Oracle8 only)The UNSCHEDULE_PUSH procedure is the complement to the SCHEDULE_PUSH procedure. This procedure unschedules automatic pushes to the destination node. The specification is, PROCEDURE DBMS_DEFER_SYS.UNSCHEDULE_PUSH(dblink IN VARCHAR2); where dblink is the global name of the database to which pushes are to be unscheduled. 17.2.6.7.1 ExceptionsUNSCHEDULE_PUSH raises the following exception:
17.2.6.8 The DBMS_DEFER_SYS.REGISTER_PROPAGATOR procedure (Oracle8 only)The REGISTER_PROPAGATOR procedure makes a designated user the propagator for the local database. The specification is, PROCEDURE DBMS_DEFER_SYS.REGISTER_PROPAGATOR (username IN VARCHAR2); where username is the name of the account to which privileges are to be granted. 17.2.6.8.1 ExceptionsREGISTER_PROPAGATOR raises the following exceptions:
17.2.6.9 The DBMS_DEFER_SYS.UNREGISTER_PROPAGATOR procedure (Oracle8 only)The UNREGISTER_PROPAGATOR procedure revokes the privileges granted to make a particular user the local database propagator. The specification follows: PROCEDURE DBMS_DEFER_SYS.UNREGISTER_PROPAGATOR (username IN VARCHAR2, timeout IN INTEGER DEFAULT dbms_lock.maxwait); Parameters are summarized in the following table.
17.2.6.9.1 ExceptionsUNREGISTER_PROPAGATOR raises the following exceptions:
Copyright (c) 2000 O'Reilly & Associates. All rights reserved. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|