Creating publications and articles at the command line

The following procedure describes the RCL procedure for preparing a publication for subscription and creating a subscription against it.

At the source Replication Server

  1. Create or select replication definitions for the tables or stored procedures from which you want to copy data.

    The replication definition specifies the source and destination tables or stored procedure and the columns or parameters that are sent to the subscribing database. Refer to “Creating replication definitions” for details.

  2. Use create publication to create the publication that groups the replication definitions.

    Publication information is stored in the rs_publications system table in the source Replication Server RSSD. It includes the name of the publication, data server, and database. The publication name must be unique for the source Replication Server and database.

    The following example creates a publication named pubs2_pub. The primary database is pubs2 managed by the TOKYO_DS data server.

    create publication pubs2_pub
          with primary at TOKYO_DS.pubs2
    

    Publication information is not copied to the destination Replication Server until you create a subscription against the publication at the destination Replication Server.

    Refer to Chapter 3, “Replication Server Commands,” in the Replication Server Reference Manual for complete syntax and usage guidelines.

  3. Use create article to create articles for the publication.

    Each article specifies the publication to which it belongs and the table or function replication definition with which it identifies. A publication can contain articles based on the same or different replication definitions. The replication definition and publication must exist when you create the article.

    An article includes the names of the publication, the replication definition, and the source data server and database. Article information is stored in the rs_articles and rs_whereclauses system tables. Each article name must be unique within the publication.

    The following example creates an article named titles_art based on the replication definition titles_rep for the publication pubs2_pub.

    create article titles_art
        for pubs2_pub with primary at TOKYO_DS.pubs2
        with replication definition titles_rep
    

    An article can include where clauses that specify the rows or parameters to be sent to subscribing databases. Refer to “Specifying a where clause with the create article command” for more information.

    Creating an article invalidates the publication, which makes it ineligible for subscription. After you create an article, you must change the status of the publication to VALID, using validate publication, before you can create subscriptions against it.

    Refer to Chapter 3, “Replication Server Commands,” in the Replication Server Reference Manual for complete syntax and usage guidelines.

  4. Use validate publication to change the status of the publication to VALID.

    When you validate a publication, Replication Server checks that the publication contains at least one article and marks the publication ready for subscription.

    Whenever you add or drop an article from a publication, Replication Server invalidates the publication. To mark the publication VALID—and ready for subscription—you must execute validate publication.

    After you validate a publication, you can create a publication subscription against it.

    The following example validates the pubs2_pub publication. The source database is pubs2 managed by the TOKYO_DS data server.

    validate publication pubs2_pub
    			with primary at TOKYO_DS.pubs2
    

    Refer to Chapter 3, “Replication Server Commands,” in the Replication Server Reference Manual for complete syntax and usage guidelines.

At the destination Replication Server

Use create subscription to create the publication subscription.

When you create a publication subscription, Replication Server creates a subscription for each article in the publication.

See “Using publication subscriptions” for information about creating and managing publication subscriptions.


Specifying a where clause with the create article command

You can include one or more where clauses in an article. A where clause sets criteria for the column or parameter values that are to be replicated. If you omit the where clause, Replication Server copies all rows for columns specified in the table replication definition or all parameters specified in the function replication definition.

The where clause syntax for articles is:

[where (column_name | @param_name) 
      {< | > >= | <= | = | &} value
    [and {column_name | @param_name}
      {< | > >= | <= | = | &} value]...]
    [or where (column_name | @param_name) 
      {< | > >= | <= | = | &} value
    [and {column_name | @param_name}
      {< | > >= | <= | = | &} value]...]
...

Each column name in a where clause must be listed in the searchable columns list of the table replication definition. The value for each column must have the same datatype as the column to which it is compared.

NoteEach where clause in an article is joined by the or operator. However, the !=, !<, !>, and or operators are not supported inside a where clause. The & operator is supported only on rs_address columns. For details on using the rs_address datatype, see “Using the rs_address datatype” and “Bitmap subscriptions”.

The following example creates an article named titles_art for the publication named pubs2_pub, using a where clause that limits replication to rows where the value in the type column is ‘popular_comp.’

create article titles_art
    for pubs2_pub with primary at TOKYO_DS.pubs2
    with replication definition titles_rep
    where type = 'popular_comp'

Refer to Chapter 3, “Replication Server Commands,” in the Replication Server Reference Manual for complete syntax and usage guidelines.