Data Replication with SQL Remote
PART 1. Introduction to SQL Remote
CHAPTER 4. A Tutorial for Adaptive Server Anywhere Users
This section of the tutorial describes how to prepare the consolidated database of a simple replication system.
Preparing a consolidated database for replication involves the following steps:
Create a message type to use for replication.
Grant PUBLISH permissions to a user ID to identify the source of outgoing messages.
Grant REMOTE permissions to all user IDs that are to receive messages.
Create a publication describing the data to be replicated.
Create subscriptions describing who is to receive the publication.
You require DBA authority to carry out these tasks.
All messages sent as part of replication use a message type. A message type description has two parts:
A message link supported by SQL Remote. In this tutorial, we use the FILE link.
An address for this message link, to identify the source of outgoing messages.
Adaptive Server Anywhere databases already have message types created, but you need to supply an address for the message type you will use.
From Sybase Central, connect to the HQ database, and open the HQ database container.
Click the SQL Remote folder on the left panel.
Double-click the Message Types folder on the right panel.
Double-click the FILE message type.
Enter a publisher address to provide a return address for remote users. Enter the directory you have created to hold messages for the consolidated database (hq).
The address is taken relative to the SQLRemote environment variable or registry entry. As you have not set this value, the address is taken relative to the directory from which the Message Agent is run. You should run the Message Agent from your tutorial directory for the addresses to be interpreted properly.
For information about setting the SQLRemote value, see Setting message type control parameters.
Click OK to save the message type.
In SQL Remote's hierarchical replication system, each database may have zero or one database immediately above it (the consolidated database) and zero or more databases immediately below it (remote databases).
In this tutorial, the current database is the consolidated database of a two-level system. It has no database above it, and only one remote database below it.
The following diagram illustrates the two databases:
For any database in a SQL Remote replication setup, there are three permissions that may be granted to identify databases on the hierarchy:
PUBLISH permission Identifies the current database in all outgoing messages
REMOTE permission Identifies each database receiving messages from the current database that is below it on the hierarchy
CONSOLIDATE permission Identifies a database receiving messages from the current database that is directly above it on the hierarchy.
Permissions can only be granted by a user with DBA authority. To carry out these examples you should connect from Sybase Central to the hq database as user ID DBA, with password SQL.
Any database, consolidated or remote, that distributes changes to other databases in the replication system is a publisher database. Each database in the replication system is identified by a single user ID. You set that ID for your database by adding a publisher to the database. This section describes setting permissions for the consolidated hq database.
First create a user ID named hq_user, who will be the publisher user ID.
Click the Users & Groups folder on the left panel.
Double-click Add User. The New User Wizard is displayed.
Enter the name hq_user, with password hq_pwd, and click Next.
On the next page, ensure that the user is granted Remote DBA authority; this enables the user ID to run the Message Agent. Then click Next.
On the final page, check the box identifying this user ID as the publisher. Then click Finish to create the user.
A database can have only one publisher. You can find out who the publisher is at any time by opening the SQL Remote folder.
Each remote database is identified in the consolidated database by a user ID with REMOTE permissions. Whether the remote database is a personal database server or a network server with many users, it needs a single user ID to represent it to the consolidated database.
In a mobile workgroup setting, remote users may already be users of the consolidated database, and so no new users would need to be added; although they would need to be set as remote users.
When a remote user is added to a database, the message system they use and their address under that message system need to be stored along with their database user ID.
Click the SQL Remote folder on the left panel, then click the Remote Users folder on the left panel.
Double-click Add Remote User on the right panel. The New Remote User wizard is displayed.
Create a remote user with user ID field_user, password field_pwd, message type file, and address field. For the message type and address, select the FILE type and the corresponding address you are using for this user (such as field).
As with the publisher address, the address of the remote user is taken relative to the SQLRemote environment variable or registry entry. As you have not set this value, the address is taken relative to the directory from which the Message Agent is run. You should run the Message Agent from your tutorial directory for the addresses to be interpreted properly.
For information about setting the SQLRemote value, see Setting message type control parameters.
On the next page, ensure that the Send Then Close option is checked. (In many production environments you would not choose Send Then Close, but it is convenient for this tutorial.)
On the next page ensure that the Remote DBA authority is checked, so that the user can run the Message Agent.
When you have finished all the entries, click Finish to create the remote user.
You have now created the users who will use this system.
This section describes how to add a publication to a database, and how to add a subscription to that publication for a user. The publication replicates all rows of the table SalesRep and some of the rows of the Customer table.
Click the Publications folder in the SQL Remote folder.
Double-click Add Publication. The Publication Wizard is displayed.
Name the publication SalesRepData on the first page of the Wizard.
On the next page, click Add Table and select SalesRep from the list. Leave All Columns selected, and press OK to add the table.
Then click Add Table again, and select Customer from the list. Again, leave All Columns selected. Click the Subscribe restriction tab, and choose to Subscribe by the column rep_key. Click OK to add the table to the publication.
Complete the Wizard to create the publication.
Each user ID that is to receive changes to a publication must have a subscription to that publication. Subscriptions can only be created for a valid remote user. You need to add a subscription to the SalesRepData publication for the remote database user field_user.
Double-click the Publications folder, which is in the SQL Remote folder, so that the SalesRepData publication is displayed in the left panel.
Click the Remote Users folder so that remote users are displayed in the right panel.
Drag the field_user user from the right panel onto the SalesRepData publication in the left panel. The Create Subscription window is displayed. Enter a value of rep1 in the With Value box. The value rep1 is the rep_key value we will give to the user field_user in the SalesRep table.
You have now set up the consolidated database.