ptg 584 CHAPTER 19 Replication FIGURE 19.30 Configuring the distributor and enabling a publisher in progress. option (lower-right side of this dialog). Make sure you see Success after each step of this configuration. Now is probably a good time to locate that distributor setup and enabling publication script and drop it into your replication administrator folder that you keep in a safe place. Figure 19.31 shows what this script looks like. Notice that the password is not displayed. The details of these scripts are described later in this chapter, in the “Scripting Replication” section. When the distributor is configured and the distribution database is created, a series of replication agents (managed by SQL Server Agent) are created, with various duties, as described earlier in this chapter. Figure 19.32 shows the initial set of agents created on the distribution server (as seen from the Job Activity Monitor under the SQL Server Agent). No agents exist yet that actually publish data or distribute data. Those agents are created later, as you start publishing and subscribing. Creating a Publication When the distribution database has been created and publishing has been enabled on the server, you can create and configure a publication. In SQL Server Management Studio, you start by locating the Replication node under the publication server from which you want to publish data (the DBARCH-LT2\SQL08DE01 named instance in this example). Figure 19.33 shows the program item option when you right-click the Replication node under what will be the publication server. As you can see, there are three options; one to create a new publication, one to create a new Oracle publication, and one to create a new subscription. Download from www.wowebook.com ptg 585 Setting Up Replication 19 FIGURE 19.31 The script generated for creating the distributor and enabling a publisher. FIGURE 19.32 Initial replication agents on the distributor. Download from www.wowebook.com ptg 586 CHAPTER 19 Replication FIGURE 19.33 The New Publication item option on the server that will be the publisher. You should choose to create a new publication (the first option). When you do, the New Publication Wizard is launched. Here’s how you create a new publication: 1. The first New Publication Wizard page outlines the two things that can be done with this wizard. The options are “Select the data and database objects you want to repli- cate” and “Filter the published data so that subscribers receive only the data they need.” After this splash page, you need to specify how you want to distribute the data for this new publication. As you can see in Figure 19.34, you should use a remote distributor (the DBARCH-LT2\SQL08DE02 named instance) to distribute data for this new publication you are defining. 2. When you are asked to provide a password that will be used to establish the admin- istrative link to the distributor, supply it. It should be the same one you specified earlier when setting up the distribution server. 3. Identify the database on which you are going to set up a publication (see Figure 19.35). For this example, choose to create a publication on the AdventureWorks2008 database. 4. Choose the type of replication method for this publication: Snapshot Publication, Transactional Publication, Transactional Publication with Updateable Subscriptions, or Merge Publication Method of Replication. For this example, select Transactional Publication. Download from www.wowebook.com ptg 587 Setting Up Replication 19 FIGURE 19.34 Specifying the remote distribution server for the new publication. FIGURE 19.35 Choosing the database that contains the data or objects you want to publish. 5. Next, you are presented with the place where you specify what tables and other objects to publish. These will become your articles. You can specify filtering of any selected articles, where appropriate. To keep this simple, just choose the primary stored procedures, views, indexed views, user-defined functions, and tables of the AdventureWorks2008 database for this publication. (You do not select any filtering at this time.) Figure 19.36 shows the Articles specification page. Also in Figure 19.36, you can view the article properties that dictate how all article objects should be handled by replication (via the Article Properties button in the upper-right corner of this wizard screen). An example of this is specifying the delete delivery format behavior for this publication (for all tables) to be Do Not Replication Delete Statements or Use Stored Procedures to Do the Deletes and not individual delete statements. Download from www.wowebook.com ptg 588 CHAPTER 19 Replication FIGURE 19.36 Choosing the tables and other objects that determine the articles to publish. The next wizard screen carefully analyzes what you are asking to become articles and highlights any dependencies that must be considered as part of replication. A good example of an article issueis that indexed views require the tables to which they are bound to be part of the replication. 6. When the Snapshot Agent wizard configuration screen prompts you to either create a snapshot immediately or at some scheduled time and to keep the snapshot available to initialize subscriptions, select to create a snapshot immediately and keep it avail- able to initialize the subscription. As part of this snapshot agent creation, you have to specify under what security credentials you want the agent security to run. In addi- tion, you can specify if you want the log reader agent to use the same security settings as the snapshot agent. The rule of thumb here is to keep it simple and let these agents use the same security settings (as shown in Figure 19.37). 7. The wizard now has enough information to create the publication. When the wizard actions are summarized for you, choose to create the publication and generate a script file with all the steps to create the publication in it. Again, this script genera- tion part is highly recommended. You certainly don’t want to have to go through this wizard over and over. Once is enough. 8. When the summary of all choices made in the creation of a new publication is listed in the Complete the Wizard screen, name the publication appropriately. Your publi- cation names should contain the type of publication method being used (for exam- ple, Snapshot, Transactional, Merge) and any other identifying qualifier that seems appropriate (usually reflecting the scope of the publication). Figure 19.38 shows this summary of actions and the publication name PUBLISH AdventureWorks2008 - Transactional. Download from www.wowebook.com ptg 589 Setting Up Replication 19 FIGURE 19.37 Agent security for snapshot agent and log reader agent. FIGURE 19.38 Publication action summary and naming the publication before it is created. Download from www.wowebook.com ptg 590 CHAPTER 19 Replication FIGURE 19.39 The publication steps and status, along with the report generated during this process. The actual creation of the publication is next. An action progress screen appears, showing each step (action) and indicating any errors or warnings occurring in the publication creation process. To view any errors or warnings, you simply click the Report button in the lower-right side after the processing completes. As you can see in Figure 19.39, this report lists, by name, all articles created and that the snapshot agent is starting. This is where all the initial action takes place. As part of this process, several new agents (jobs) are added; they implement this publica- tion using the designated distributor. There are no subscribers yet; they come later. Figure 19.40 shows the new jobs (agents) and publication entries. You are now ready to create subscriptions against this publication. As you can see in Figure 19.41, if you launch Replication Monitor (from the Replication node under the publication server), you can see the newly created publication and its status, and you have access to any servers subscribing to it (none yet), along with the common replication jobs that are servicing this publication. Because you chose to execute the snapshot immediately, the snapshot executes and utilizes the snapshot folder to generate the schema files (.sch files), data snapshot files Download from www.wowebook.com ptg 591 Setting Up Replication 19 FIGURE 19.40 SQL Server Management Studio and the new publication agents (snapshot agent, distribution agent, and so on) and the new local publication. FIGURE 19.41 Replication Monitor, viewing the status of the newly created publication (from the publisher). Download from www.wowebook.com ptg 592 CHAPTER 19 Replication FIGURE 19.42 Contents of the snapshot folder produced for the publication. (.bcp), and so on to fully enable a subscription when one is created. Figure 19.42 shows the contents of the snapshot folder being used for the publication of the AdventureWorks2008 publication. Remember that this folder must be located in a place that is big enough to contain all the data that will be extracted and used for the snapshot; plan ahead. Horizontal and Vertical Filtering During the publication creation process, you could have done some filtering of the data, either horizontally or vertically (or both at the same time). The concept of filtering was covered earlier in this chapter. Figure 19.43 illustrates all you need to do to vertically filter (in terms of limiting what gets published to a subset of columns of a table). As you can see, you uncheck the AccountNumber column for the Customer table so that it isn’t included in the article for that object in this publication. This might be done because account number information needs to be more tightly controlled within your company and shouldn’t be part of what is viewed by any subscribing systems. In addition, you can specify horizontal filters by using the Filter Rows option on a publi- cation (publication properties). This allows you to specify horizontal filtering on any table you publish. Figure 19.44 shows a typical row filter on the Customer table that results in publishing North East Territory customers only (that is, those with TerritoryID values of 1 or 2). Download from www.wowebook.com ptg 593 Setting Up Replication 19 FIGURE 19.43 Specifying a vertical filter on the Customer table (limiting the columns to be published). FIGURE 19.44 Specifying a horizontal filter on the Customer table (limiting the rows to be published). Download from www.wowebook.com . been enabled on the server, you can create and configure a publication. In SQL Server Management Studio, you start by locating the Replication node under the publication server from which you. agents (managed by SQL Server Agent) are created, with various duties, as described earlier in this chapter. Figure 19.32 shows the initial set of agents created on the distribution server (as seen. of agents created on the distribution server (as seen from the Job Activity Monitor under the SQL Server Agent). No agents exist yet that actually publish data or distribute data. Those agents