Oracle数据复制是实现分布式数据环境的一种技术,通过在不同的物理站点拷贝数据来建立分布式数据环境。它与分布式数据库不同,在
Oracle数据复制是实现分布式数据环境的一种技术,通过在不同的物理站点拷贝数据来建立分布式数据环境。它与分布式数据库不同,在分布式数据库中,虽然每个数据对象也对所有的站点可用,但是特定的数据对象只存在于一个特定的站点中。而数据复制实现所有的站点都有相同数据对象的可用拷贝。
在一个典型的分布式商业应用中经常需要把个地区的数据备份到总部的数据库中,一方面可以作为一种备份方式,另一方面也方便总部应用中的综合统计。这是Oracle数据复制中的简单应用,本文将以这样一个例子,讲述如何实现Oracle数据复制。
实际情况是,A公司总部在北京,有三个营业部分别位于上海(ORACLE.SHANGHAI.COM)、杭州(ORACLE.HANGZHOU.COM)和武汉(ORACLE.
WUHAN.COM)。三个营业部的软件系统相同,数据库结构也相同。现在需要把三个营业部的数据全部备份到总部的数据库中。
准备工作
在进行复制之前需要准备的东西很多,当然最基础就是网络必须畅通,之后需要收集一些复制环境的基本信息:
1.需要复制的数据库站点的数量
2.每个站点的Oracle版本号
3.每个需要复制的数据库的大小
4.每个数据库所使用的字符集
5.每个需要复制的数据所用的方案名
收集完环境信息,可以开始建立总部的集中数据库,集中数据库要求版本高于所有主战点的版本,最好所有的数据库都是用相同的字符集。建好库后为每个主站点的备份数据分别建一个表空间,表空间大于需要复制的数据量,至于预留以后的发展空间视实际情况而定。
为每个主站点的对应复制数据建立方案,如果各个主站点所使用的方案名不同,,在集中数据库站点分别建立名称相同的对应方案。否则为各主站点的复制数据分别建立相应的方案名。实际情况是后者,各营业部的数据库都是用Oracle的方案名,这里我们建立三个对应方
案:SHORACL、HZORACL和WHORACL。所有数据库的版本都是9i。
基本概念
复制之前先解释一下复制中的几个概念:
1.主站点(MaterSite):在复制过程中提供数据源的站点。如上图中的上海数据库站点。
2.实体化视图站点(MaterializedViewSite):实体化视图复制中的目标站点。如上图中的北京数据库站点。
3.多主体站点复制(MultimasterReplication):复制环境中的站点都是主站点,对复制的数据库对象有相同的管理权限。
4.实体化视图复制(MaterializedViewReplication):一个主体站点提供源复制对象,一个实体化视图站点拷贝主站点数据。
5.实体化视图(MaterializedView):在实体化视图站点为每个复制表或者视图建立一个对应的表保存相应的数据,该表只能通过Oracle的复制机制进行增删改数据的操作。
6.快速刷新、完全刷新和强制刷新:复制过程中的三种刷新方式。快速刷新只复制源数据对象的改变部分;完全刷新每次都拷贝一遍源数据对象;强制刷新是数据库的一个折衷方案,如果快速刷新失败则使用完全刷新。
7.主体组(MasterGroup):主体站点中被复制的源数据对象的集合。
8.实体化视图组(MaterializedViewSite):实体化视图站点中复制对象的集合。
9.实体化视图日志(MaterializedViewLog):实体化视图复制中使用快速刷新时记录主体源数据对象操作日志的表。
同步复制和异步复制就不解释了,本例采用每天一次的异步复制。
进行复制
配置好本地服务名分别为:上海站点:SH,杭州站点:HZ,武汉站点:WH,北京站点:BJ,进入没有登录的sqlplus,让我们开始复制!
一.设置主站点。
这里以上海主站点设置为例。
1.连接主站点,创建复制管理员并授予相应的权限,复制管理员是管理整个复制环境并创建复制对象的用户。只有数据管理员可以建立主体组和实体化视图组。
connectsystem/passwd@SH
createuserrepadminidentifiedbyrepadmin;
begin
dbms_repcat_admin.grant_admin_any_schema(
username=>’repadmin’);
end;
/
grantcommentanytabletoREPADMIN;
grantlockanytabletoREPADMIN;
后面的两个grant语句使复制管理员可以为任何表建立实体化视图日志。如果想改用户可以使用视图管理器,还需要下面的命令:
grantselectanydictionarytoREPADMIN;
2.注册传播方,传播方会将主体站点的延迟事务队列推入其他主体站点或者实体化视图站点。
begin
dbms_defer_sys.register_purpagator(username=>’repadmin’);
end;
3.调度清除作业,该作业会定时清除延迟事务队列并用传播方将延迟事务推入其他主体站点或者实体化视图站点。先更换用户:
disconnect;
connectrepadmin/repadmin@SH;
begin
dbms_defer_sys.schedule_purge(
next_date=>sysdate,interval=>’sysdate+1’,delay_seconds=>0);
end;
next_date:下一次执行日期,sysdate表示立即。
interval:间隔时段,sysdate+1表示间隔一天,sysdate+1/24表示间隔一小时
delay_seconds:当延迟队列没有延迟事件时停止被次清除操作的延迟时间。
4.为实体化视图站点建立复制代理。创建复制代理用户并授予视图接受方权限。复制代理是复制接收方连接主体站点的用户
disconnect;
connectsystem/passwd@SH;
createuserproxy_bjoracleidentifiedbyproxy_bjoracle;
begin
dbms_repcat_admin.register_user_repgroup(
user_name=>’proxy_bjoracle,
privilege_type=>’proxy_snapadmin’,list_of_gnames=>NULL);
end;
/
grantselect_catalog_roletoproxy_bjoracle;
5.创建主体组。
disconnect;
connectrepadmin/repadmin@SH;
begin
dbms_repcat.create_master_repgroup(gname=>’sh_rep’);
end;
/
6.向主体组中添加复制对象
a)添加表:
begin
dbms_repcat.create_master_repobject(
gname=>’sh_rep’,
type=>’TABLE’,
oname=>’CREDIT_CARD’
sname=>’SHORACL’
use_existing_object=>TRUE,
copy_rows=>TRUE);
end;
b)添加索引
begin
dbms_repcat.create_master_repobject(
gname=>’sh_rep’,
type=>’INDEX’,
oname=>’INDEX_CREDIT_CARD’
sname=>’SHORACL’
use_existing_object=>TRUE,
copy_rows=>FALSE);
end;
/
7.如果添加的表没有主键需要设置可以代替主键的列或者列的集合
begin
dbms_repcat.set_columns(
sname=>’SHORACL’,
oname=>’CREDIT_CARD’,
column_list=>’CREDIT_CARD_ID’);
end;
/
8.在主体组中的数据对象可以被复制之前,必须为他们生成复制支持。该方法为复制创建必要的触发器、包或者存储过程:
begin
dbms_repcat.generate_replication_support(
sname=>’SHORACL’,
oname=>’CREDIT_CARD’,
type=>’TABLE’,
min_communication=>TRUE);
end;
/
9.为快速刷新创建实体化视图日志:
creatematerializedviewlogonSHORACL.CREDIT_CARD;
如果是没有主键的表示用一下语句:
creatematerializedviewlogonSHORACL.CREDIT_CARDwith
rowidexcludingnewvalues;
10.启动复制:
begin
dbms_repcat.resume_master_activity(
name=>’sh_rep’);
end;
/

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.