This article gives you a detailed analysis of the SQL Server 2016 snapshot agent process, and an example of what needs to be paid attention to. Follow the editor to learn. We will use an instance data table of SQL Server 2016 to give you a detailed analysis of the problems and solutions encountered in the snapshot agent process, and a detailed explanation of the snapshot generation process. The following is the full content:
Overview
The snapshot agent prepares the schema and initial data files of published tables and other objects, stores snapshot files, and records synchronization information in the distribution database. The snapshot agent runs on the distribution server; the SQL Server 2016 version has made some better optimizations for the snapshot agent. Next, let’s learn more about the snapshot execution process.
1. Snapshot proxy file
When executing a snapshot job, 4 types of files will be generated in the specified snapshot directory.
BCP file: the data file of the publishing object.
IDX file: Index creation script file
PRE file: Copy snapshot script file.
SCH file: Architecture creation script file
2. Default snapshot agent configuration file
-BcpBachSize: The maximum number of record lines for each bcp operation copy. The default is 100,000 lines.
-HistoryVerboseLevel: Specifies the size of the history recorded during the snapshot operation.
-LoginTimeout: Number of seconds to wait before login times out. The default value is 15 seconds.
-QueryTimeOut: Number of seconds to wait before query times out. The default value is 1800 seconds
Note: You can configure the snapshot agent by right-clicking the snapshot agent-snapshot agent configuration file.
3. Compare different versions of snapshot agents
Next, test and compare 200 million record tables to generate snapshots
1. Comparison of the number of bcp files
2008R2
2016SP1
##The focus here is on the BCP file, because Applying snapshots to the subscriber uses BCP files as the basic unit, which means that no matter how big your BCP file is, it will be bulk-bulked to the subscriber at once, so the larger the BCP file, the longer each application will take. If a BCP file is too large, insertion into the subscriber may fail. As you can see from the picture above, there are also 200 million records. 2008R2 has a total of 8 BCP files, and the largest BCP file size is nearly 1G. The others are only a few megabytes; 2016 has 16 BCP files, and The first 15 are all about 50M data, which is relatively even. Next, look at the record comparison of each BCP file in the figure below. 2. Comparison of the detailed process of snapshot generation2008r2##2016SP1
Comparison of the generated BCP file records:
2008R2: The first 7 files each have about 700,000 records, and the last file has 110 million records.
2016: The first 15 files record about 7 million each, and the last file records 780,000.
Explanation:
The approximate number of records stored in each of the first seven files of 2008R2 is 700,000. The remaining records will be stored in the last file, so the number of table records that is more suitable for 2008R2 is Around 6 million.
The approximate number of records stored in each of the first 15 files in 2016 is 7 million. The remaining records will be stored in the last file. The number of suitable table records in 2016 is about 120 million.
Common disadvantage: After the table records exceed the "appropriate number of replicated table records", all remaining data will be stored in the last bcp file.
3. Distribution comparison
Let’s take a look at the detailed process of distribution
## You can see each time from the 2008R2 distribution record process BULK is based on bcp files. It took about 22 minutes to copy the last bcp file, and each of the previous files took more than ten seconds; or because my current table only has three fields and no index except the primary key. Otherwise, the time Just longer.
4. Snapshot generation processThe replication snapshot agent is an executable file used to prepare snapshot files (which contain published tables and database object schema and data), then stores these files in the snapshot folder and records the synchronization job in the distribution database.
You can understand the entire snapshot generation process from the above figure.
5. Syntax
snapshot [ -?] -Publisher server_name[\instance_name] -Publication publication_name [-70Subscribers] [-BcpBatchSize bcp_batch_size] [-DefinitionFile def_path_and_file_name] [-Distributor server_name[\instance_name]] [-DistributorDeadlockPriority [-1|0|1] ] [-DistributorLogin distributor_login] [-DistributorPassword distributor_password] [-DistributorSecurityMode [0|1] ] [-DynamicFilterHostName dynamic_filter_host_name] [-DynamicFilterLogin dynamic_filter_login] [-DynamicSnapshotLocation dynamic_snapshot_location] [-EncryptionLevel [0|1|2]] [-FieldDelimiter field_delimiter] [-HistoryVerboseLevel [0|1|2|3] ] [-HRBcpBlocks number_of_blocks ] [-HRBcpBlockSize block_size ] [-HRBcpDynamicBlocks ] [-KeepAliveMessageInterval keep_alive_interval] [-LoginTimeOut login_time_out_seconds] [-MaxBcpThreads number_of_threads ] [-MaxNetworkOptimization [0|1]] [-Output output_path_and_file_name] [-OutputVerboseLevel [0|1|2] ] [-PacketSize packet_size] [-ProfileName profile_name] [-PublisherDB publisher_database] [-PublisherDeadlockPriority [-1|0|1] ] [-PublisherFailoverPartner server_name[\instance_name] ] [-PublisherLogin publisher_login] [-PublisherPassword publisher_password] [-PublisherSecurityMode [0|1] ] [-QueryTimeOut query_time_out_seconds] [-ReplicationType [1|2] ] [-RowDelimiter row_delimiter] [-StartQueueTimeout start_queue_timeout_seconds] [-UsePerArticleContentsView use_per_article_contents_view]
Parameters
-?
Output all available parameters.
-Publisher server_name[\instance_name]
The name of the publishing server. Specify server_name for the default instance of Microsoft SQL Server on this server. Specify server_name for the server_name\instance_name instance_name SQL Server default instance on this server.
-Publication Publication
The name of the publication. This parameter is only effective if the publication is set to always make snapshots available to new or reinitialized subscriptions.
-70Subscribers
This parameter must be used if any Subscribers are running SQL Server version 7.0.
-BcpBatchSize bcp batch\ size
The number of rows sent in a bulk copy operation. When performing a bcp in operation, the batch size is the number of rows to be sent to the server as one transaction, and is the number of rows that must be sent before the distribution agent records a bcp progress message. When performing a bcp out operation, a fixed batch size of 1000 will be used. A value of 0 means no messages are logged.
-DefinitionFile def_path_and_file_name
The path to the agent definition file. The agent definition file contains the command line parameters for the agent. The contents of the file are analyzed as an executable file. Use double quotes (") to specify parameter values containing any characters.
-Distributor server_name[\instance_name]
Distributor Name. Specify the server_name SQL Server on this server. Specify the server_name on the server_name\instance_name instance. #-DistributorDeadlockPriority [-1|0|1]
The priority of the snapshot agent connecting to the distribution server when a deadlock occurs. This parameter is specified to solve the problem between the snapshot agent and the distribution server during snapshot generation. Deadlock issues occurring between user applications
Description
-1
When a deadlock occurs on the distribution server, the application instead of the snapshot agent Priority.
0 (Default)
No priority assigned.
1
When a deadlock occurs on the distribution server, the snapshot agent takes precedence.
-DistributorLogin
distributor_login##The login name to use when connecting to the distribution server using SQL Server authentication -DistributorPassword
distributor_password
-DistributorSecurityMode [ 0| 1]
dynamic_filter_host_name
-DynamicFilterLogin dynamic_filter_login
-DynamicSnapshotLocation dynamic_snapshot_location
-EncryptionLevel [ 0 | 1 | 2 ]The level of Secure Socket Layer (SSL) encryption used by the snapshot agent when establishing a connection.
The above is the detailed content of Detailed explanation of SQL Server 2016 Snapshot Agent process. For more information, please follow other related articles on the PHP Chinese website!