📄 1786.html
字号:
<tr>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif">
<div align=center><font class=normalfont>搜索文章:
<input type=hidden value=result name=action2>
<input type=radio checked value=title name=type>标题
<input type=radio value=content name=type>内容
<input type=image src="images/button_go.gif" tppabs="http://www.linuxhero.com/docs/images/button_go.gif" border=0 name=image2>
</font></div>
</td>
</tr>
<tr>
<td noWrap>
<div align="center">
<input maxlength=100 size=30 name=keyword2>
</div>
</td>
</tr></tbody>
</table>
</form>
</TD>
<TD rowSpan=2><IMG src="images/header_r1_c7.gif" tppabs="http://www.linuxhero.com/docs/images/header_r1_c7.gif" width=26 border=0 name=header_r1_c7></TD>
<TD><IMG height=83 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1 border=0></TD></TR>
<TR>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif"><IMG height=22
src="images/header_r2_c1.gif" tppabs="http://www.linuxhero.com/docs/images/header_r2_c1.gif" width=296 border=0
name=header_r2_c1></TD>
<TD background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colSpan=5>
<DIV align=right><FONT class=normalfont>当前位置:
<A href="index.html" tppabs="http://www.linuxhero.com/docs/index.html">本站首页</A>
<font color="#FF6699">>></font>
<A href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</A> | <A href="copyright.html" tppabs="http://www.linuxhero.com/docs/copyright.html">版权说明</A></font></DIV>
</TD>
<TD><IMG height=22 src="images/spacer.gif" tppabs="http://www.linuxhero.com/docs/images/spacer.gif" width=1
border=0></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=10 cellPadding=0 width="100%" bgColor=#ffffff
border=0>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%" border=0>
<TR>
<TD vAlign=top align=middle width="60%">
<TABLE cellSpacing=0 cellPadding=0 width="100%"
background="images/back.gif" tppabs="http://www.linuxhero.com/docs/images/back.gif" border=0>
<TBODY>
<TR>
<TD vAlign=top width="80%">
<DIV align=center>
<FORM action="search.html" tppabs="http://www.linuxhero.com/docs/search.html" method=get>
</FORM>
<TABLE cellSpacing=0 cellPadding=0 width="95%"
border=0><TBODY>
<TR>
<TD background="images/bgi.gif" tppabs="http://www.linuxhero.com/docs/images/bgi.gif"
height=30></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=3 width="95%"
align=center border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=3 width="100%"
border=0>
<TBODY>
<TR>
<TD vAlign=top>
<p><FONT class=normalfont><B><font color=blue>在Oracle中实现数据库的复制</font></B></FONT><BR><FONT class=smallfont color=#ff9900>2004-04-23 15:18 pm</FONT><BR><FONT class=normalfont>作者:余枫<br>来自:Linux知识宝库<br>联系方式:无名<br><br>在Internet上运作数据库经常会有这样的需求:把遍布全国各城市相似的数据库应用统一起来,一个节点的数据改变不仅体现在本地,还反映到远端。复制技术给用户提供了一种快速访问共享数据的办法。<br>
一、实现数据库复制的前提条件<br>
1、数据库支持高级复制功能<br>
您可以用system身份登录数据库,查看v$option视图,如果其中Advanced replication为TRUE,则支持高级复制功能;否则不支持。<br>
2、数据库初始化参数要求<br>
①、db_domain = test.com.cn<br>
指明数据库的域名(默认的是WORLD),这里可以用您公司的域名。<br>
②、global_names = true<br>
它要求数据库链接(database link)和被连接的数据库名称一致。<br>
现在全局数据库名:db_name+”.”+db_domain<br>
③、有跟数据库job执行有关的参数<br>
job_queue_processes = 1<br>
job_queue_interval = 60<br>
distributed_transactions = 10<br>
open_links = 4<br>
第一行定义SNP进程的启动个数为n。系统缺省值为0,正常定义范围为0~36,根据任务的多少,可以配置不同的数值。<br>
第二行定义系统每隔N秒唤醒该进程一次。系统缺省值为60秒,正常范围为1~3600秒。事实上,该进程执行完当前任务后,就进入睡眠状态,睡眠一段时间后,由系统的总控负责将其唤醒。<br>
如果修改了以上这几个参数,需要重新启动数据库以使参数生效。<br>
二、实现数据库同步复制的步骤<br>
假设在Internet上我们有两个数据库:一个叫深圳(shenzhen),一个叫北京(beijing)。<br>
具体配置见下表:<br>
数据库名 shenzhen beijing<br>
数据库域名 test.com.cn test.com.cn<br>
数据库sid号 shenzhen beijing<br>
Listener端口号 1521 1521<br>
服务器ip地址 10.1.1.100 10.1.1.200<br>
1、确认两台数据库之间可以互相访问,在tnsnames.ora里设置数据库连接字符串。<br>
①、例如:深圳这边的数据库连接字符串是以下的格式<br>
beijing =<br>
(DESCRIPTION =<br>
(ADDRESS_LIST =<br>
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.1.1.200)(PORT = 1521))<br>
)<br>
(CONNECT_DATA =<br>
(SERVICE_NAME = beijing)<br>
)<br>
)<br>
运行$tnsping beijing<br>
出现以下提示符:<br>
Attempting to contact (ADDRESS=(PROTOCOL=TCP)(HOST=10.1.1.200)(PORT=1521))<br>
OK(n毫秒)<br>
表明深圳数据库可以访问北京数据库。<br>
②、在北京那边也同样配置,确认$tnsping shenzhen 是通的。<br>
2、改数据库全局名称,建公共的数据库链接。<br>
①、用system身份登录shenzhen数据库<br>
SQL>alter database rename global_name to shenzhen.test.com.cn;<br>
用system身份登录beijing数据库:<br>
SQL>alter database rename global_name to beijing.test.com.cn;<br>
②、用system身份登录shenzhen数据库<br>
SQL>create public database link beijing.test.com.cn using 'beijing';<br>
测试数据库全局名称和公共的数据库链接<br>
SQL>select * from global_name@beijing.test.com.cn;<br>
返回结果为beijing.test.com.cn就对了。<br>
用system身份登录beijing数据库:<br>
SQL>create public database link shenzhen.test.com.cn using 'shenzhen';<br>
测试数据库全局名称和公共的数据库链接<br>
SQL>select * from global_name@shenzhen.test.com.cn;<br>
返回结果为shenzhen.test.com.cn就对了。<br>
3、建立管理数据库复制的用户repadmin,并赋权。<br>
①、用system身份登录shenzhen数据库<br>
SQL>create user repadmin identified by repadmin default tablespace users temporary tablespace temp;<br>
SQL>execute dbms_defer_sys.register_propagator('repadmin');<br>
SQL>grant execute any procedure to repadmin;<br>
SQL>execute dbms_repcat_admin.grant_admin_any_repgroup('repadmin');<br>
SQL>grant comment any table to repadmin;<br>
SQL>grant lock any table to repadmin;<br>
②、同样用system身份登录beijing数据库,运行以上的命令,管理数据库复制的用户repadmin,并赋权。<br>
说明:repadmin用户名和密码可以根据用户的需求自由命名。<br>
4、在数据库复制的用户repadmin下创建私有的数据库链接。<br>
①、用repadmin身份登录shenzhen数据库<br>
SQL>create database link beijing.test.com.cn connect to repadmin identified by repadmin;<br>
测试这个私有的数据库链接:<br>
SQL>select * from global_name@beijing.test.com.cn;<br>
返回结果为beijing.test.com.cn就对了。<br>
②、用repadmin身份登录beijing数据库<br>
SQL>create database link shenzhen.test.com.cn connect to repadmin identified by repadmin;<br>
测试这个私有的数据库链接<br>
SQL>select * from global_name@shenzhen.test.com.cn;<br>
返回结果为shenzhen.test.com.cn就对了。<br>
5、创建或选择实现数据库复制的用户和对象,给用户赋权,数据库对象必须有主关键字。<br>
假设我们用ORACLE里举例用的scott用户,dept表。<br>
①、用internal身份登录shenzhen数据库,创建scott用户并赋权<br>
SQL>create user scott identified by tiger default tablespace users temporary tablespace temp;<br>
SQL>grant connect, resource to scott;<br>
SQL>grant execute on sys.dbms_defer to scott;<br>
②、用scott身份登录shenzhen数据库,创建表dept<br>
SQL>create table dept<br>
(deptno number(2) primary key,<br>
dname varchar2(14),<br>
loc varchar2(13) );<br>
③、如果数据库对象没有主关键字,可以运行以下SQL命令添加:<br>
SQL>alter table dept add (constraint dept_deptno_pk primary key (deptno));<br>
④、在shenzhen数据库scott用户下创建主关键字的序列号,范围避免和beijing的冲突。<br>
SQL> create sequence dept_no increment by 1 start with 1 maxvalue 44 cycle nocache;<br>
(说明:maxvalue 44可以根据应用程序及表结构主关键字定义的位数需要而定)<br>
⑤、在shenzhen数据库scott用户下插入初始化数据<br>
SQL>insert into dept values (dept_no.nextval,'accounting','new york');<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -