Replication Base Datos Oracle
Replication Base Datos Oracle
Replicación
Ing. Erick López Ch. M.R.I.
What is Replication
• Information Off-Loading
• Information Transport
Read-Only Table Snapshots
• SNAP$_snapshotname
Snapshot Refreshes
• You must decide how and when to refresh each
snapshot to make it a more current.
• Analyze application characteristics and requirements
to determine appropriate snapshot refresh intervals.
• To refresh snapshots, Oracle supports different types
of refreshes, “complete” and
“fast” snapshot refresh groups, as well as “manual”
and “automatic” refreshes.
Complete and Fast Refreshes
• Complete Refreshes
• The server that manages the snapshot executes
the snapshot's defining query.
• The result set of the query replaces the existing
snapshot data to refresh the snapshot.
• Oracle can perform a complete refresh for any
snapshot.
Complete and Fast Refreshes
• Fast Refreshes
• The server that manages the snapshot first identifies the
changes that occurred in the master since the most recent
refresh of the snapshot and then applies them to the
snapshot.
• Fast refreshes are more efficient than complete refreshes
when there are few changes to the master because
participating servers and networks replicate less data.
• Fast refreshes are available for snapshots only when the
master table has a snapshot log.
Complete and Fast Refreshes
• Complete Refreshes
• The server that manages the snapshot executes
the snapshot's defining query.
• The result set of the query replaces the existing
snapshot data to refresh the snapshot.
• Oracle can perform a complete refresh for any
snapshot.
Materialized View
• A materialized view is a database object that contains
the results of a query.
• The FROM clause of the query can name tables, views,
and other materialized views.
• Collectively these objects are called master tables (a
replication term) or detail tables (a data warehousing
term).
• A materialized view, or snapshot as they were
previously known, is a table segment whose contents
are periodically refreshed based on a query, either
against a local or remote table.
Prerequisites
• Disconnected Environments
• Advanced replication is useful for the
deployment of transaction processing
applications that operate using disconnected
components.
• Failover Site
• Protect the availability of a mission critical
database.
Advanced Replication Concepts
• Multimaster Replication
• Allows multiple sites, acting as equal peers, to
manage groups of replicated database objects.
• Applications can update any replicated table at
any site in a multimaster configuration.
Advanced Replication Configurations
Advanced Replication Configurations
• Hybrid Configurations
• Multimaster replication and updatable
snapshots can be combined in hybrid or
“mixed” configurations to meet different
application requirements.
• Can have any number of master sites and
multiple snapshot sites for each master.
Advanced Replication Configurations
Advanced Replication Configurations
• Differences between updatable snapshots and
replicated masters:
• Replicated masters must contain data for the full table
being replicated, whereas snapshots can replicate
subsets of master table data.
• Multimaster replication allows you to replicate
changes for each transaction as the changes occur.
• If conflicts occur from changes made to multiple
copies of the same data, master sites detect and resolve
the conflicts.
Replication Conflicts
• Uniqueness Conflicts
• A uniqueness conflict occurs when the replication of a
row attempts to violate entity integrity (a PRIMARY
KEY or UNIQUE constraint).
• Update Conflicts
• Occurs when the replication of an update to a row
conflicts with another update to the same row. Update
conflicts occur when two different transactions
originating from different sites update the same row at
nearly the same time.
Replication Conflicts
• Delete Conflicts
• Occurs when two transactions originate from different
sites, with one transaction deleting a row that the other
transaction updates or deletes.
Using Basic Replication
1. Design the basic replication environment. Decide
which master tables you want to replicate using
read-only table snapshots, and which databases
require such snapshots.
2. At each snapshot site, create the schemas and
database links necessary to support snapshots.
3. At the master site, create the snapshot logs
necessary to support fast refreshes of all
snapshots.
Using Basic Replication
• CONNECT system/manager@dbs2;
• CREATE USER scott IDENTIFIED BY tiger QUOTA
UNLIMITED ON data;
• GRANT CONNECT TO scott;
• CONNECT scott/tiger@dbs2;
• CREATE DATABASE LINK dbs1 CONNECT TO scott
IDENTIFIED BY tiger USING ‘dbs1’;
Step 3:
• CONNECT system/manager@dbs1;
• CREATE SNAPSHOT LOG ON scott.emp;
• CREATE SNAPSHOT LOG ON scott.dept;
Step 4:
Create Snapshots
• CONNECT system/manager@dbs2;
• CREATE SNAPSHOT scott.emp AS
SELECT * FROM [email protected];
• CREATE SNAPSHOT scott.dept AS
SELECT * FROM [email protected];
Step 5:
Create Snapshot Site Refresh Groups
• CONNECT system/manager@dbs2;
• DBMS_REFRESH.MAKE(
name => ’scott.refgrp1’,
list => ’scott.dept,scott.emp’,
next_date => SYSDATE,
interval => ’SYSDATE+1/24’); (1/1440)
• COMMIT;
Step 6:
Grant Access to Snapshots
• CONNECT scott/tiger@db2
• CREATE DATABASE LINK DB1.WORLD CONNECT TO scott
IDENTIFIED BY tiger USING 'DB1';
• CREATE MATERIALIZED VIEW emp_mv
BUILD IMMEDIATE
REFRESH FORCE
ON DEMAND
AS SELECT * FROM emp@db1
Gather stats - Step 2
BEGIN
DBMS_STATS.gather_table_stats(
ownname => 'SCOTT',
tabname => 'EMP_MV');
END;
/
Create Materialized View Logs – Step 3
• CONNECT scott/tiger@db1
• EXEC DBMS_MVIEW.refresh('EMP_MV');
Cleaning Up
CONNECT scott/tiger@db2
DROP MATERIALIZED VIEW emp_mv;
DROP DATABASE LINK DB1;
BEGIN
DBMS_REFRESH.destroy(
name => 'SCOTT.MINUTE_REFRESH');
END;
/
CONNECT scott/tiger@db1
DROP MATERIALIZED VIEW LOG ON scott.emp;