服务器 频道

Sybase 数据库复制

  第II部分: SYBASE Replication 的安装配置:

  一、 用sybload安装产品;$SYBASE/rs_init配置Replication Server

  若rs_init起不来:

  # cd /usr/shlib

  # ln -s ./libdnet_stub.so libdnet.so

  In user environment, setenv _RLD_ARGS "-ignore_version libdnet_stub.so"

  二、 复制服务器安装范例:一般复制环境

  1:安装SQL Server和创建数据库,为一般的安装SYBASE数据库和创建数据库步骤,参考《SYBASE 数据库基础》部分:

  主结点:

  SQL Server Name: SQL1

  Database Name: DB1

  复制结点:

  SQL Server Name: SQL2

  Database Name: DB2

  2:安装复制服务器,RS Server:

  以sybase用户身份,在~sybase/install目录,执行rs_init:

  Replication Server Name: REP

  ID Server: yes

  RSSD位置: SQL Server Name: SQL1

  Database Name: RSSD

  Need LTM: no

  Stable queue: Physical path: /data1/sybase/dbfile/rs_queue1.dat

  Logical Name: queue1

  3:Add The First Database to Replication System

  使用:rs_init;

  Replication Server Name: REP

  Replication SA User: sa (Password is null unless you changed)

  SQL Server Name: SQL1

  Database Name: DB1

  Need LTM: yes (Primary Database -yes, Replication Database - no)

  LTM Name:DB1_LTM

  4:Add The Second Database to Replication System

  使用:rs_init;

  Replication Server Name: REP

  Replication SA User: sa (Password is null unless you changed)

  SQL Server Name: SQL2

  Database Name: DB2

  Need LTM: yes

  LTM Name:DB2_LTM

  5:Checking Whether All Server Is Running normally.

  SQL Server: SQL1 and SQL2

  Replication Server: REP

  LTM for DB1: DB1_LTM

  LTM for DB2: DB2_LTM

  使用 isql -Usa -SREP

  1 >admin who_is_down

  2 >go

  The result should be empty.

  6:Create Table

  isql -Usa -SSQL1

  >use DB1

  >go

  >create table tab1 (a int, b char(10), c int)

  >go

  >sp_setreplicate tab1, true

  >go

  >create table tab2 (a int, c char(10), e int)

  >go

  >insert into tab1 values(1, "AAAAA", 1)

  >go

  >grant all on tab2 to public

  >go

  >create table tab3(a int, b char(10), c int)

  >go

  >sp_setreplicate tab3, true

  >go

  >grant all on tab3 to public

  >go

  >insert into tab3 values(1, "CCCCC", 1)

  >go

  isql -Usa -SSQL2

  >use DB2

  >go

  >create table tab1 (a int, b char(10), c int)

  >go

  >grant all on tab1 to public

  >go

  >create table tab2 (a int, b char(10), c char(10), d int, e int)

  >go

  >insert into tab2 values(1, "AAAAA","BBBBB", 1, 1)

  >go

  > sp_setreplicate tab2, true

  >go

  >create table tab3(a int, b char(10), c int)

  >go

  >sp_setreplicate tab3, true

  >go

  >grant all on tab3 to public

  >go

  >insert into tab3 values(10000, "DDDDD", 1)

  >go

  注释:Now, We create three table tab1, tab2, tab3 in two database, SQL1.DB1, SQL2.DB2.We show three representative examples:

  Relicate data from SQL1.DB1.tab1 to SQL2.DB2.tab1;

  Replicate partial columns data from SQL2.DB2.tab2 to SQL1.DB1.tab2;

  Replicate data only a<10000 from SQL1.DB1.tab3 to SQL2.DB2.tab3, and replicate data only a>=10000 from SQL2.DB2.tab3 to SQL1.DB1.tab3.

  The first example help you testing whether or not replication succeed. The second show you that replication server can hidirection replicate data between two databases. The third show you that replication server can hidirection replicate data between two tables, this require data divide into two part, the first part from A to B, and the second part from B to A.

  7:Create Replication Definition

  Example 1:

  isql -Usa -SREP

  >create replication definition rep_tab1 with primary at SQL1.DB1

  >with all table named ''tab1'' (a int, b char(10), c int) primary key(a)

  >go

  >create subscription sub_tab1 for rep_tab1 with replicate at SQL2.DB2

  >go

  isql -Usa -SSQL2

  1>use DB2

  2>go

  1>select * from tab1

  2>go

  You should see there are a row (1, "AAAAA", 1) in the table tab1. If you can''t see, you should wait a moment and retry.

  You should sure that the password of user sa of replication server REP has the same as the password of sa of SQL Server SQL1. If not, you can execute the following command:

  isql -Usa -SREP

  1>alter user sa set password password

  2>go

  And, you can execute the following command to check the replication status:

  Isql -Usa -SREP

  1> check subscription sub_tab1 for rep_tab1 with replicate at SQL2.DB2

  2> go

  If the result contains two VALID, you can execute the following command:

  isql -Usa -SSQL1

  1>use DB1

  2>go

  1>insert into tab1 values(2, "AAA01", 2)

  2>go

  isql -Usa -SSQL2

  1>use DB2

  2>go

  1>select * from tab2

  2>go

  The results should contain two rows, and now replication is normal. You may do other testing to check.

  Example 2:

  isql -Usa -SREP

  1>create replication definition rep_tab2 with primary at SQL2.DB2

  2> with all tables named ''tab2''(a int, c char(10), e int) primary key (a )

  3>go

  1>create subscription sub_tab2 for rep_tab2 with replicate at SQL1.DB1

  2>go

  You can use the previous method to check.

  isql -Usa -SSQL2

  1>use DB2

  2>go

  1>insert into tab2 values(2, "aaaaa", "bbbbb", 2, 2)

  2>go

  isql -Usa -SSQL1

  1>use DB1

  2>go

  1>select * from tab2

  2>go

  Example 3:

  isql -Usa -SREP

  1>create replication definition SQL1_tab3 with primary at SQL1.DB1

  2>with all tables named ''tab3''(a int, b char(10), c int)

  3>primary key (a) searchable columns (a)

  4>go

  1>create subscription sub_SQL1_tab3 for SQL1_tab3

  2>with replicate at SQL2.DB2 where a<10000

  3>go

  1>create replication definition SQL2_tab3 with primary at SQL2.DB2

  2>with all tables named ''tab3''(a int, b char(10), c int)

  3>primary key (a) searchable columns(a)

  4>go

  1>create subscription sub_SQL2_tab3 for SQL2_tab3

  2>with replicate at SQL1.DB1 where a>=10000

  3>go

  Using the same method, you can check whether or not hidirection replication is successful.

  isql -Usa -SSQL1

  1>use DB1

  2>go

  1>insert into tab3 values(100, "QQQQQ", 100)

  2>go

  isql -Usa -SSQL2

  1>use DB2

  2>go

  1>select * from tab3

  2>go

  1>insert into tab3 values(10002, "WWWWW", 11)

  2>go

  isql -Usa -SSQL1

  1>use DB1

  2>go

  1>select * from tab3

  2>go

  三、 复制服务器安装范例:Warm Standby应用

  1:Install SQL Server, Create Database:

  主结点:

  SQL Server Name: SQL1

  Database Name: DB3

  复制结点:

  SQL Server Name: SQL2

  Database Name: DB3

  2:Install Replication Server

  使用rs_init:

  Replication Server Name: REP

  ID Server: yes

  RSSD位置: SQL Server Name: SQL1

  Database Name: RSSD

  Need LTM: no

  Stable queue: Physical path: /data1/sybase/rs_queue1.dat

  Logical Name: queue1

  3:Creating the Logical Connection

  isql -Usa -SREP

  1>create logical connection to demo_lds.demo_db

  2>go

  注:逻辑连接使用的Data Server和Database名应不同于Active Database;但如果database已存在于复制环境,则逻辑连接使用的Data Server和Database名必须与Active Database的一样。

  4:Adding the Active Database to the replication System

  使用:rs_init;

  Replication Server Name: REP

  Replication SA User: sa (Password is null unless you changed)

  SQL Server Name: SQL1

  Database Name: DB3

  Need LTM: yes (Primary Database -yes, Replication Database - no)

  LTM Name:SQL1_DB3_LTM

  Is This a Physical Connection for an Existing Logical Connection? yes

  Is This an Active connection or standby connection? active

  Logical DS Name: demo_lds

  Logical DB Name: demo_db

  5:Create Table in the Active Database & Standby Database

  isql -Usa -SSQL1

  1>use DB3

  2>go

  1>create table tab1(a int, b char(10))

  2>go

  1>quit

  isql -Usa -SSQL2

  1>use DB3

  2>go

  1>create table tab1(a int, b char(10))

  2>go

  1>quit

  6:Enabling replication for Objects in the Active Database

  isql -Usa -SSQL1

  1>use DB3

  2>go

  1>sp_setreptable tab1, true

  2>go

  7:Adding the Standby Database Maintenance User

  isql -Usa -SSQL2

  1>sp_addlogin SQL2_DB3_maint,SQL2_DB3_maint_ps,DB3

  2>go

  1>quit

  isql -Usa -SSQL1

  1>sp_addlogin SQL2_DB3_maint,SQL2_DB3_maint_ps,DB3

  2>go

  1>use DB3

  2>go

  1>sp_adduser SQL2_DB3_maint

  2>go

  1>quit

  注:SQL1和SQL2中的所有login ID(即suid)必须一致,这可以通过用相同的顺序建用户来实现;也可以用调整系统表syslogins和sysloginroles来实现。

  8:Adding the Standby Database to Replication System

  isql -Usa -SREP

  1>suspend connection to SQL1.DB3 with nowait

  2>go

  使用:rs_init;

  Replication Server Name: REP

  Replication SA User: sa (Password is null unless you changed)

  SQL Server Name: SQL2

  Database Name: DB3

  Need LTM: yes

  LTM Name:SQL2_DB3_LTM

  Is This an Active Connection or Standby Connection? Standby

  Logical DS name: demo_lds

  Logical DB name: demo_db

  Active DS name: SQL1

  Active DB name: DB3

  Active DB SA user: sa

  Active DB SA Password:

  Initialize Standby Using Dump and Load: yes

  Use Dump Marker to Start Replicating to Standby: no

  9:同步两个数据库的数据

  isql -Usa -SREP

  1>wait for create standby for demo_lds.demo_db

  2>go

  1>admin logical_status, demo_lds,demo_db

  2>go

  1>quit

  isql -Usa -SSQL1

  1>dump database DB3 to "/data1/sybase/db3_data.dat"

  2>go

  1>quit

  #rcp node1:/data1/sybase/db3_data.dat, /data1/sybase

  #chown sybase /data1/sybase/db3_data.dat

  You can also use ftp with the sybase user from node1:/data1/sybase/dbfile/db3_data.dat to node2 with the same location.

  isql -Usa -SSQL2

  1>load database DB3 from "/data1/sybase/db3_data.dat"

  2>go

  1>online database DB3

  2>go

  1>quit

  isql -Usa -SREP

  1>resume connection to SQL1.DB3

  2>go

  1>resume connection to SQL2.DB3

  2>go

  1>quit

  10:Enabling Replication for Objects in the Standby Database

  isql -Usa -SSQL1

  1>sp_setreptable tab1, true

  2>go

  11:Granting Permission to the Maintenance User

  isql -Usa -SSQL2

  1>use DB3

  2>go

  1>grant all on tab1 to SQL2_DB3_maint

  2>go

0
相关文章