Index   Search   Add FAQ   Ask Quesmtion  
 

Please note: This page is not maintained anymore. Please visit the new and improved FAQ at http://www.orafaq.com/faq/advanced_replication

Oracle Replication FAQ

$Date: 23-May-2002 $
$Revision: 2.02 $
$Author: Frank Naudé $

Topics

  • What is replication and why should one use it?
  • Can one replicate between Oracle and non-Oracle databases?
  • What is the difference between BASIC and ADVANCED replication?
  • What is the difference between a snapshot and a materialized view?
  • How does one implement basic snapshot replication?
  • What object types can and cannot be replicated?
  • What is the difference between master definition and master destination sites?
  • What is a surrogate repadmin user and how is one created?
  • How does one set up multi-master replication?
  • How does one monitor replication?
  • The DBA_REPCATLOG view is not getting empty, what can one do?
  • What happens if two or more sites change the same data?
  • What happens if one of the sites is unavailable?
  • How does one change the definition of a replicated table?
  • How does one resolve replication conflicts?
  • How does one relocate the master definition site to a different location?
  • Can sequences be replicated?
  • I get "NO DATA FOUND" errors. How does one handle this?
  • How does one delete all local def errors?
  • Can one switch off replication while fixing replication errors?
  • Can one avoid a loop when remote tables are updating each other via triggers?
  • Any replication notes?
  • Where can one get more info about replication?

  • Back to Oracle FAQ Index

    What is replication and why should one use it?

    Replication is the process of creating and maintaining replica versions of database objects (e.g. tables) in a distributed database system.

    Replication can improve performance and increase availability of applications because alternate data access options becomes available. For example, users can access a local database rather than a remote server to minimize network traffic. Furthermore, the application can continue to function if parts of the distributed database are down as replicas of the data might still accessible.

  • Back to top of file

  • Can one replicate between Oracle and non-Oracle databases?

    Oracle does not support replication to non-Oracle databases like DB2, Informix, Sybase, SQL Server, etc. Some third-party vendors provide products that can replicate heterogeneous databases. One such company is Sybase. Contact these companies for more information about their respective product offerings.

  • Back to top of file

  • What is the difference between BASIC and ADVANCED replication?

    Oracle Server supports two different forms of replication: basic and advanced replication.

    Basic replication is implemented using standard CREATE SNAPSHOT or CREATE MATERIALIZED VIEW statements. It can only replicate data (not procedures, indexes, etc), replication is always one-way, and snapshot copies are read only.

    Advanced replication supports various configurations of updateble-snapshot, multi-master and update anywhere replication. It is more difficult to configure but allows data and other database objects like indexes and procedures to be replicated.

  • Back to top of file

  • What is the difference between a snapshot and a materialized view?

    They are the same. Keywords "snapshot" and "materialized views" can be used interchangeably. Oracle 8i implements snapshots and materialized views as a single table, previous releases implemented it as a view with an underlying SNAP$_% table.

  • Back to top of file

  • How does one implement basic snapshot replication?

    Start by creating an optional snapshot log on the master database. If you do not want to do fast refreshes, you do not need to create a log. Also note that fast refreshes are not supported for complex queries. Create a snapshot/materialized view on the snapshot site. Look at this example:

    MASTER SITE:

            SQL> create materialized view log on table EMP;
    
    SNAPSHOT SITE:
            SQL> create materialized view emp
                   refresh fast with primary key
                   start with sysdate
                   next  sysdate + 1/(24*60)
                   as (select * from emp);

  • Back to top of file

  • What object types can and cannot be replicated?

    The following can be replicated: The following cannot be replicated:

  • Back to top of file

  • What is the difference between master definition and master destination sites?

    If you are planning to implement Master-to-Master Replication, you need to decide which of your Oracle Database servers will become the Master Definition site. The remainder of your servers will become Master Destination sites. Replication support is configured from the Master Definition Site.

  • Back to top of file

  • What is a surrogate repadmin user and how is one created?

    If one creates a surrogate replication administrator at a remote site, one does not need to have SYS to SYS database links between the sites. The surrogate replication administrator performs actions on behalf of the symmetric replication facility at the remote site.

    The surrogate user is thus an optional replacement user for SYS. To make an existing user a surrogate, execute the following API call:

            SQL> EXECUTE DBMS_REPCAT_AUTH.GRANT_SURROGATE_REPCAT(userid => 'surrogate_user_name');
    
  • Back to top of file

  • How does one set up multi-master replication?

  • Back to top of file

  • How does one monitor replication?

    Look for the following:

  • Back to top of file

  • The DBA_REPCATLOG view is not getting empty, what can one do?

    The SYS.DBA_REPCATLOG view list pending admin requests. One needs to wait until all admin requests are completed before continuing to configure replication support. Some reasons why this view is not getting empty, or taking a long time to get empty is as follows: Manually running the push job will speed up the execution of deferred admin requests. Query the user_jobs view to get the job number, and do a EXEC DBMS_JOB.RUN(jobno);.

  • Back to top of file

  • What happens if two or more sites change the same data?

    If two sites change the same data within the data replication interval, you have an update conflict. The more frequently you propagate your changes (that is, the smaller your replication interval), the fewer update conflicts will occur. Oracle detects update conflicts by comparing the old values for a row from the remote (or propagating) site with the current values at the local (or receiving) site. If they are the same, no conflict has occurred and the new values are applied at the local site. If they are different, a conflict is detected.

    Oracle attempts to resolve the conflict by using the conflict resolution method that you specified when you first replicated the table. You can choose from among several Oracle-supplied conflict resolution methods (such as, latest timestamp, site priority, additive, etc.) or you can write your own. If you do not supply a method, or if the method that you supply cannot successfully resolve the conflict, Oracle logs the conflicting transaction in an error queue at the local site. The replication administrator can then decide how best to resolve the conflict.

  • Back to top of file

  • What happens if one of the sites is unavailable?

    In an asynchronous (store-and-forward) replication environment, local updates are stored in a deferred transaction queue until the remote site becomes available. When the remote site comes back up, these transactions are propagated and applied at the remote site in the order that they were originally applied at the local site. You can continue to make updates at any remaining replication sites.

    In addition to replicating the objects that you specify as part of your replication group, Oracle also replicates the replication catalog to each site. The replication catalog is a set of tables that determine which objects are being replicated, where they are being replicated, how often their changes are propagated, and so on. Replicating the replication catalog ensures that there is no single point of failure in a replicated environment.

  • Back to top of file

  • How does one change the definition of a replicated table?

    Oracle advanced replication will replicate DML changes (inserts, updates, and deletes) and all DDL (create, alter, delete) changes made to all master sites for a replication group. So, if you decide to add a column to a replicated table, this column will be added at all of your master sites. Additionally, you can change the members of a replication group, for example, if you decide to add an index to a table, you can choose to have this index replicated to all of your master sites.

  • Back to top of file

  • How does one resolve replication conflicts?

    Use the supplied packages:

    - DBMS_REPCAT.ADD_UPDATE_RESOLUTION - NO_DATA_FOUND
    - DBMS_REPCAT.ADD_DELETE_RESOLUTION - DUP_VAL_ON_INDEX
    - DBMS_REPCAT.ADD_UNIQUE_RESOLUTION - TOO_MANY_ROWS
    - Add user defined conflict resolution

  • Back to top of file

  • How does one relocate the master definition site to a different location?

    Use DBMS_REPCAT.RELOCATE_MASTERDEF. Example:
            execute DBMS_REPCAT.RELOCATE_MASTERDEF( -
                    GNAME                 => 'BANKING',
                    OLD_MASTERDEF         => 'NYBANK.WORLD',
                    NEW_MASTERDEF         => 'HKBANK.WORLD',
                    NOTIFY_MASTERS        => TRUE,
                    INCLUDE_OLD_MASTERDEF => TRUE);

  • Back to top of file

  • Can sequences be replicated?

    No, the best way to handle sequences, assuming you are using them as primary key values, is to concatenate then with something unique to the site. For example, use a sequence number concatenated with the database name, site name or something similar. One could also start the sequences at one site as odd numbers (1, 3, 5, etc) and the other site as even numbers (2, 4, 6 etc).

  • Back to top of file

  • I get "NO DATA FOUND" errors. How does one handle this?

    An ORA-1403 (No Data Found) error is signalled within a replicated environment when there is a conflict in data. Here is an illustration of what happens in most scenarios featuring this error:

    Let's say we need to update a table and set column x=1 where x=9. When the first change occurs on the source database, Oracle checks to ensure that x=9. Once this transaction commits, it is queued for execution on the destination site(s). When the transaction is applied to the destinations, Oracle first check to verify that x=9 (the old value); if it does, then Oracle applies the update (update table set x = 1 where x = 9); if it does not, an entry to the DEFERROR table is logged indicating ORA-1403.

    If the application is updating primary key values, one can also expect plenty "NO DATA FOUND" errors. Primary keys should NEVER be updated. If one updates primary key values, conflict resolution also becomes extremely difficult.

  • Back to top of file

  • How does one delete all local def errors?

    Before one indiscriminately deletes all errors, understand why they occurred first. It might be better to re-apply all failed transactions. If you still wants to delete all of them, execute the following statements from SQL*Plus:
            SQL> connect repadmin/repadmin
            SQL> execute dbms_defer_sys.delete_error(NULL,NULL);
            SQL> commit;   
    
    Also look at this slightly more complicated example. This example will first try to re-apply the error before deleting it:
            SQL> spool apply_errors.sql
            SQL> select 'exec dbms_defer_sys.execute_error(''' || deferred_tran_id ||''','''||
            SQL>        destination || ''')'
            SQL> from   deferror;
            SQL> spool off
            SQL> @apply_errors
            SQL> commit;
    		
            SQL> spool delete_errors.sql
            SQL> select 'exec dbms_defer_sys.delete_error(''' || deferred_tran_id ||''','''||
            SQL>        destination || ''')'
            SQL> from   deferror;
            SQL> spool off
            SQL> @delete_errors
            SQL> commit;
    

  • Back to top of file

  • Can one switch off replication while fixing replication errors?

    One can switch off replication for a session. This is handy when one needs to fix replication problems. Look at this example:
            SQL> exec DBMS_REPUTIL.REPLICATION_OFF;
            SQL> insert into tabX select * from tabX@remote MINUS select * from tabX;
            SQL> commit;
            SQL> exec DBMS_REPUTIL.REPLICATION_ON;		  
    

  • Back to top of file

  • Can one avoid a loop when remote tables are updating each other via triggers?

    Triggers can easily cause replication errors and even infinite loops in a replicated environment. This happens as the trigger fire more than once on the same data. For example, consider a trigger that inserts a row into a table. When this row is replicated to a remote database(s), the trigger will fire again on the same data, and re-insert a duplicate row into the table.

    This problem can be solved by using the DBMS_REPUTIL.FROM_REMOTE function. Look at this example:

            IF dbms_reputil.from_remote = true THEN  -- Trigger was already fired on a remote DB
               return;                               -- Exit the trigger
            END IF;

  • Back to top of file

  • Any replication notes?

  • Back to top of file

  • Where can one get more info about replication?

  • Back to top of file
  • HOME | ASK QUESTION | ADD FAQ | SEARCH | E-MAIL US