Help-Site Computer Manuals
  Algorithms & Data Structures   Programming Languages   Revision Control
  Cameras   Computers   Displays   Keyboards & Mice   Motherboards   Networking   Printers & Scanners   Storage
  Windows   Linux & Unix   Mac



RepAgent Cookbook

Here is a simple step-by-step on setting up replication with If you are not familiar with RepServer, make sure you read the manuals in advance.

This text assumes you have a repserver and a destination database up and running.

Setting up a replication

Creating a database connection

A database connection in repserver is a two-way street. Since we will use only one way, we create the connection with dsi_suspended and with dummies for user and password:

 create connection to PERL_RA_DS.perl_ra_db 

 set error class rs_sqlserver_error_class 

 set function string class rs_sqlserver_function_class 

 set username perl 

 set password perl 

 with log transfer on, dsi_suspended

PERL_RA_DS is the Source Dataserver in the constructor of RepAgent.

perl_ra_db is the Source Database in the constructor of RepAgent.

rs_sqlserver_error_class, rs_sqlserver_function_class are defaults for a connection. If you don't understand these two, either ignore them or read the repserver manuals.

For username and password are dummies supplied, because repserver will never connect to our RepAgent.

Creating a replication definition

A replication definition tells repserver what data is expected from where:

 create replication definition perl_ra_t1_rd 

 with primary at PERL_RA_DS.perl_ra_db 

 with all tables named t1 (f1 int, f2 varchar(10)) 

 primary key (f1)

perl_ra_t1_rd is the name of the replication definition. You can choose any name you like, but, as always, it's best to choose a speaking name.

PERL_RA_DS.perl_ra_db is the Dataserver and the Database mentioned in the connection.

t1 (f1 int, f2 varchar(10)) is the definition of the destination table, which has to be specified.

(f1) is a primary key in the destination table which has to be specified also.

Read the repserver manuals for more details.

Creating a subscription

A subscription tells repserver where to distribute the data that comes in for replication definition. Due to the somewhat abnormal source we are building, the subscription has to be built in three steps:

 define subscription perl_ra_t1_sub 

 for perl_ra_t1_rd 

 with replicate at DEST_SERVER.dest_db

 activate subscription perl_ra_t1_sub 

 for perl_ra_t1_rd 

 with replicate at DEST_SERVER.dest_db

 validate subscription perl_ra_t1_sub 

 for perl_ra_t1_rd 

 with replicate at DEST_SERVER.dest_db

perl_ra_t1_sub is the name of the subscription.

perl_ra_t1_rd is the name of the replication definition for which this subscription is created.

DEST_SERVER is the destination database server.

dest_db is the destination database.

Running the RepAgent

Using is pretty straight forward.

You create a RepAgent object:

 my $ra = Sybase::RepAgent->new('REPSERVER', 





This connects to the repserver and fetches all information needed to go on.

Next you have to create transactions that will be transmitted to your destination database. The easiest way is to have handle all the nasty stuff, so you can concentrate on the important things.

Every Transaction starts with 'begin transaction':


Next you will have some data modification statements like insert and update:

 $ra->insert({}, 't1', q{@f1=12, @f2='foo'});

You have to specify three parameters to insert:

 A reference to a hash containing command tags, this can be empty. handles this for you.

 The name of the destination table.

 And a string containing name/value pairs for each column in the table.

An update statement looks like this:

 $ra->update({}, 't1', q{@f1=12, @f2='foo'}, q{@f1=8, @f2='bar'});

You have to supply four parameters for the update statement:

 The first two are identical to the insert statement.

 The next is a before-image of the chenged column.

 The fourth is the after-image, make sure each image contains all columns.

And in the end you commit the transaction:


Dropping the replication

If you want to get rid of this replication, there are the usual three steps to drop a replication:

Drop the subscription:

 drop subscription perl_ra_t1_sub

 for perl_ra_t1_rd

 with replicate at DEST_SERVER.dest_db

 without purge

Drop the replication definition:

 drop replication definition perl_ra_t1_rd

And finally drop the connection:

 drop connection to PERL_RA_DS.perl_ra_db

Further reading

Sybase has all produkt manuals online on their web site. Go to and look for support/manuals/replication server.