登台区无效

大纲 (Outline)

In this article, you’ll see how to simulate production loads on a test server with a “record and replay” type situation using the transaction log, batch scripting, PowerShell and a SQL Server agent job.

在本文中,您将看到如何使用事务日志,批处理脚本,PowerShell和SQL Server代理作业以“记录并重放”类型的情况模拟测试服务器上的生产负载。

We’ll be walking through the scenario in the following steps

我们将在以下步骤中逐步介绍该方案

  1. Record the production load and write the transactions to disk by generating a timestamped replay script 记录生产负载并通过生成带有时间戳的重播脚本将事务写入磁盘
  2. Create a batch file to automate the task at an interval of every 1 minute 创建一个批处理文件以每1分钟的间隔自动执行任务
  3. Create a SQL Server agent job to schedule the batch file 创建一个SQL Server代理作业以计划批处理文件
  4. Replay the production workload to the target/test database by running a PowerShell script to open and execute the scripts at the same interval as they were created, every 1 minute 通过运行PowerShell脚本以每创建1分钟的时间间隔打开和执行脚本,将生产工作负载重播到目标/测试数据库中
  5. Validate the data between the source and the target databases to make sure our job works 验证源数据库和目标数据库之间的数据,以确保我们的工作正常
  6. Monitor the load with a monitoring tool, solution of your choice 使用监视工具监视负载,您选择的解决方案

介绍 (Introduction)

In short, transactional replication is a process to transfer uni-directional data from the source (Publisher) database to the target (Subscriber) database. This particular example uses a log reader agent to examine the associated transaction entries in the log files and then those changes can be synchronized immediately with the target database or the synchronization can also be scheduled. The production load can be re-run on the same test database multiple times and run on multiple other test databases as well.

简而言之,事务复制是将单向数据从源(发布者)数据库传输到目标(订阅者)数据库的过程。 此特定示例使用日志读取器代理检查日志文件中的关联事务条目,然后可以将这些更改立即与目标数据库同步,或者也可以安排同步。 生产负载可以在同一测试数据库上多次运行,也可以在其他多个测试数据库上运行。

In this article, you’re going to see how to record production loads on a production database and persisting to file, then replaying later on a test database

在本文中,您将了解如何在生产数据库上记录生产负载并持久保存到文件,然后稍后在测试数据库上重播

You can then monitor the performance of the test server, with a tool like Spotlight, to see how it handles the production load

然后,您可以使用Spotlight之类的工具监视测试服务器的性能,以查看其如何处理生产负载

In this method, using ApexSQL Log tool, the batch file is created. The batch file is invoked to generate the redo_<*datetimestamp*>.sql at a frequency of 1 minute and those files archived so they can be consumed and replayed later, perhaps multiple times on multiple servers. Finally, we’ll iterate through the files and process them against the target server, at the same cadence.

在这种方法中,使用ApexSQL日志工具创建了批处理文件。 批处理文件将以1分钟的频率被调用以生成redo _ <* datetimestamp *>。sql,并且已归档这些文件,以便以后可以使用它们并在多个服务器上重播这些文件。 最后,我们将以相同的节奏遍历文件并针对目标服务器对其进行处理。

初始要求 (Initial requirements)

If you followed the previous article and performed all the steps mentioned in them, you should be good to go and it’s going to be really that simple.

如果您遵循上一篇文章并执行了其中提到的所有步骤,那么您应该很好,而且实际上也就这么简单。

  1. Install ApexSQL Log 安装ApexSQL日志
  2. Select the source database aka Publisher and the target database aka Subscriber. If a copy of the source database hasn’t been provisioned, do so now 选择源数据库(即发布者)和目标数据库(即订阅者)。 如果尚未配置源数据库的副本,请立即进行配置
  3. Review the basic concepts of batch scripting as needed 根据需要查看批处理脚本的基本概念
  4. Run the PowerShell console with an elevated permission (Run as Administrator) 以提升的权限运行PowerShell控制台(以管理员身份运行)

配置我们的复制代理 (Configuring our replication agent)

Our principal technology is ApexSQL Log, which will do most of the work recording, persisting and even replaying the production load.

我们的主要技术是ApexSQL Log,它将完成大部分工作记录,持久化甚至重播生产负载。

What we initially need is a replay script that is the recorded transactions from production.

我们最初需要的是一个重放脚本,该脚本是生产中记录的交易。

To generate the redo script, run through the following screens

要生成重做脚本,请运行以下屏幕

  1. Open the ApexSQL Log 打开ApexSQL日志
  2. Click New

    点击新建

  3. Server and 服务器Database details and click 数据库的详细信息,然后单击Next 下一步。
  4. In the Select data sources, the online transaction log is enabled by default. Click Next

    在“ 选择数据源”中 ,默认情况下启用了在线事务日志。 点击下一步

  5. Select Undo/Redo,

    选择撤消/重做

  6. Click Continuous auditing, and click Next

    单击“ 连续审核” ,然后单击“ 下一步”。

  7. Copy or Save the generated script to the replication.bat file

    生成的脚本复制保存到Replication.bat文件

自动化复制代理 (Automating the replication agent)

To automate the job is as simple as using the Batch script feature to save the Windows Shell script to a batch (.BAT) file. That will allow us to rerun this job manually, at will, or schedule it to run unattended.

自动化作业就像使用批处理脚本功能将Windows Shell脚本保存到批处理(.BAT)文件一样简单。 这样一来,我们便可以手动重新运行此作业,或安排它在无人看管的情况下运行。

We’ve created a batch file directly from ApexSQL Log’s Batch script feature, but we’ll want to make a tweak to name the files, dynamically, just as we want them named

我们已经直接通过ApexSQL Log的Batch脚本功能创建了一个批处理文件,但是我们要进行调整以动态命名文件,就像我们希望它们被命名一样。

  1. First, prepare the dynamic file, the name should be in the format <directory path> followed by redo_yyyy-MM-dd_hhmmss then the SQL extension. For example, g:\DBA\redo_2018-08-10_162233.sql. In this case, the files are created in “g:\DBA” directory with the name “redo_2018-08-10_162233.sql” 首先,准备动态文件,名称的格式应为<目录路径>,后跟redo_yyyy-MM-dd_hhmmss,然后是SQL扩展名。 例如,g:\ DBA \ redo_2018-08-10_162233.sql。 在这种情况下,将在名称为“ redo_2018-08-10_162233.sql”的“ g:\ DBA”目录中创建文件。
  2. To edit the replication.bat batch file, Select the file, right-click, and open in notepad. 要编辑Replication.bat批处理文件,请选择该文件,单击鼠标右键,然后在记事本中打开。
  3. The first statement is to assign the redo filename to a variable and pass its value to the /redo switch of ApexSQL Log executable. 第一条语句是将重做文件名分配给变量,并将其值传递给ApexSQL Log可执行文件的/ redo开关。
  4. Replication.bat file is given below Replication.bat文件的内容

Note that carriage returns have been added for readability

请注意,已添加回车符以提高可读性

set redofile=G:\DBA\redo_%date:~10,4%-%date:~4,2%-%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql
"E:\Program Files\ApexSQL\ApexSQL Log\ApexSQLLog.com"
/server:HQDBT01 /database:WideWorldImporters /trusted
/redo:%redofile%
/operations:DMLALL /transactions:COMMIT BEGIN UNKNOWN
/continuous:G:\DBA\WideWorldImporters.axtr

安排复制任务 (Schedule the replication task)

Now let us go over the steps to create a SQL job. The SQL job is run every minute to capture the production load into the redo_<datetimestamp>.sql scripts and persist them to file

现在,让我们回顾创建SQL作业的步骤。 SQL作业每分钟运行一次,以将生产负载捕获到redo_ <datetimestamp> .sql脚本中并将其持久保存到文件中

  1. Browse Jobs 浏览工作
  2. Right-click and create a new job

    右键单击并创建一个新作业

  3. In Steps, type in the Step name, choose Operating system as its type and enter the batch file full name in the command section. In this case, the batch file is created under G:\DBA\.

    在“步骤”中,键入“步骤名称”,选择“操作系统”作为其类型,然后在命令部分中输入批处理文件的全名。 在这种情况下,批处理文件将在G:\ DBA \下创建。

  4. In Schedules, Enter the schedule name. Select Daily as its frequency of occurrence and run at every 1 minute.

    在计划中,输入计划名称。 选择“每日”作为其发生频率并每1分钟运行一次。

  5. Now, the job is created. 现在,作业已创建。
  6. Let us take a look at the redo*.sql path

    让我们看一下redo * .sql路径

重播先前记录的交易负载 (Replay the previously recorded transaction load)

In this section, I’ll take you through the PowerShell script (Replication.ps1) that is used.

在本节中,我将指导您完成使用的PowerShell脚本(Replication.ps1)。

It will read through all of our SQL files in the sorted order and execute those files sequentially one after the other with a delay of 60 seconds. In this way, we will simulate the production load on the test database This ensure and preserves the consistency between the transactions.

它将按排序顺序读取我们所有SQL文件,并以60秒的延迟依次依次执行这些文件。 这样,我们将在测试数据库上模拟生产负载。这确保并保留了事务之间的一致性。

Prepare the replication

准备复制

  1. Load the SQL Server module 加载SQL Server模块
  2. Get a list of the generated files, run the following command.

    获取生成文件的列表,运行以下命令。

    PS C:\> Get-ChildItem g:\DBA\redo*.sql| Group-Object {$_.LastWriteTime.ToShortDateString()},{$_.LastWriteTime.Hour}
    
  3. The files are listed based on the time of its creation. 根据创建时间列出文件。
  4. Now, sequentially execute the sql files in the order in which they were created with a delay of 60 seconds using Invoke-SQLCMD and Start-Sleep cmdlets. Save the below content in the Powershell script and run the script

    现在,使用Invoke-SQLCMD和Start-Sleep cmdlet按创建顺序依次执行sql文件,延迟60秒。 将以下内容保存在Powershell脚本中并运行该脚本

    Import-Module -Name SqlServer -WarningAction SilentlyContinue $files=Get-ChildItem g:\DBA\redo*.sqlForeach ($file in $files) {Invoke-SQLcmd -inputfile $file.FullName -serverinstance "hqdbt01\sql2017" -database "worldwideimporters" Start-Sleep –seconds 60  }
    

验证中 (Verifying)

Let us verify the data using the following SQL. In this case, the Application.cities table is the used data comparison. Open SSMS, then browse query pane, select SQLCMD mode and run the following SQL.

让我们使用以下SQL验证数据。 在这种情况下,Application.cities表是使用的数据比较。 打开SSMS,然后浏览查询窗格,选择SQLCMD模式并运行以下SQL。

:CONNECT <SourceServer>
GO
USE  WideWorldImporters
GO
SELECT @@SERVERNAME ServerName
SELECT GETDATE() [Datetime]
SELECT COUNT(*) No_Of_Rows FROM Application.CitiesGO:CONNECT <TargetServer>
GO
USE  WideWorldImporters
GO
SELECT @@SERVERNAME ServerName
SELECT GETDATE() [Datetime]
SELECT COUNT(*) No_Of_Rows FROM Application.Cities

In the first run, the below sample output gives an overview of the initial data set

在第一次运行中,下面的示例输出概述了初始数据集

Next, manually run the PowerShell Replication.ps1

接下来,手动运行PowerShell Replication.ps1

Now, verify the output. You can see production data on the target database instance because the row counts are the same.

现在,验证输出。 您可以在目标数据库实例上看到生产数据,因为行数是相同的。

结语 (Wrapping Up)

In this article, we looked at a method to implement transactional replication for simulating production loads for stress testing a target database. This method will allow you to record once and replay many times, even on different staging servers.

在本文中,我们研究了一种实现事务复制的方法,该方法用于模拟生产负载以对目标数据库进行压力测试。 即使在不同的登台服务器上,该方法也允许您记录一次并重播多次。

The automation allows for fast and easy integration into any continuous integration pipeline where newly created or provisioned databases can be automatically tested with production loads, simulating real world use. If the load causes the server to fail or generates an excessive number of alerts, when you are monitoring it, that can be an early indicator that the build may have broken something and save you from dealing with problems in production.

自动化允许快速轻松地将其集成到任何连续的集成管道中,在该管道中,可以使用生产负载自动测试新创建或置备的数据库,从而模拟实际使用情况。 如果负载导致服务器发生故障或生成过多警报,则在监视服务器时,这可能是早期指示,表明该构建可能损坏了某些东西,从而使您不必处理生产中的问题。

目录 (Table of contents)

SQL Server replication: Overview of components and topography
SQL Replication: Basic setup and configuration
How to Add/Drop articles from existing publications in SQL Server
How to do a quick estimated compare of data in two large SQL Server databases to see if they are equal
SQL Server transactional replication: How to reinitialize a subscription using a SQL Server database backup
How to setup a custom SQL Server transaction replication model with a Central Subscriber and Multiple Publisher databases
How to setup custom SQL Server transactional replication with a central publisher and multiple subscriber databases
How to set up a DDL and DML SQL Server database transactional replication solution
How to setup cross-platform transactional SQL Server replication for database reporting on Linux
SQL Server database migrations with zero data loss and zero downtime
Using transactional data replication to replay and test production loads on a staging server
How to setup SQL Server database replication for a reporting server
SQL Server transactional replication: How to reinitialize a subscription using a “Replication support only” –TBA
SQL Server Replication Monitoring and setting alerts using PowerShell –TBA
SQL Server复制:组件和拓扑概述
SQL复制:基本设置和配置
如何从SQL Server中的现有出版物中添加/删除文章
如何对两个大型SQL Server数据库中的数据进行快速估计比较,以查看它们是否相等
SQL Server事务复制:如何使用SQL Server数据库备份重新初始化订阅
如何使用中央订阅服务器和多个发布者数据库设置自定义SQL Server事务复制模型
如何使用中央发布者和多个订阅者数据库设置自定义SQL Server事务复制
如何设置DDL和DML SQL Server数据库事务复制解决方案
如何在Linux上为数据库报告设置跨平台事务SQL Server复制
SQL Server数据库迁移,数据丢失为零,停机时间为零
使用事务数据复制来重放和测试登台服务器上的生产负载
如何为报表服务器设置SQL Server数据库复制
SQL Server事务复制:如何使用“仅复制支持” –TBA重新初始化订阅
使用PowerShell –TBASQL Server复制监视和设置警报

翻译自: https://www.sqlshack.com/using-transaction-data-replication-to-replay-production-loads-on-a-test-server/

登台区无效

登台区无效_使用事务数据复制来重放和测试登台服务器上的生产负载相关推荐

  1. OUI-10133:登台区无效

    装oracle客户端的时候发现报"OUI-10133:登台区无效"错误,在网上查了下有的说是存在中文路径有的说是安装文件中 存在stage文件下product.xml中文件路径不对 ...

  2. 将mysql的数据库导入到linux_linux 操作之一 如何在linux将本地数据*.sql文件导入到linux 云服务器上的mysql数据库...

    liunx 版本ubuntu 16.4 mysql 版本  5.6 1)准备*.sql文件 (* 是准备导入的sql文件的名字) 2)liunx 远程客户端  SecureCRT 7.0 alt+p ...

  3. php descryptoserviceprovider,在unity3D上对数据进行DES加密,在PHP服务器上进行解密的详细教程...

    前言: DES是一种加密方法,向服务器发送数据时,希望对数据进行简单的加密,并且在服务器上自行解密的教程. 步骤: unity3D(C#) ​//对数据进行DES加密 public static St ...

  4. 仅通过SQL备份文件将MOSS服务器场及所有网站数据迁移到新的一台服务器上

    背景: 这是一次完整到服务器迁移项目.现有MOSS的物理环境是两台服务器,一台后台的SQL服务器,一台前台的Web服务器.SQL服务器为Win03+SQL05,Web服务器为Win03+MOSS07. ...

  5. 云服务器布置_【阿里云ECS】(一)云服务器上安装RStudio-server

    [阿里云ECS](一)云服务器上安装RStudio-server 最近注册了阿里云个人版,打算研究研究shiny部署问题.进了阿里云ECS因为是Ubuntu16.04的对于安装R和RStudio还是要 ...

  6. 10g文件复制到linux,怎样将LINUX服务器上的10G文件下载到本地

    怎样将LINUX服务器上的10G文件下载到本地 如题 更新时间:2019-05-18 05:48 最满意答案 下载一个WinSCP 可以直接上传下载!很方便 就OK了! 2009-11-24 回答 其 ...

  7. BGP在数据中心的应用6——BGP在服务器上的应用

    注: 本文根据<BGP in the Datacenter>整理,有兴趣和英文阅读能力的朋友可以直接看原文:https://www.oreilly.com/library/view/bgp ...

  8. mysql 查数据 default无效_导入mysql数据的时候提示Field * doesn't have a default value解决方法...

    项目使用django+mysql 在linux中使用的是mysql5.7,导入数据提示:Field * doesn't have a default value 想要解决问题就需要知道在mysql5. ...

  9. mysql设置不主动提交无效_关闭事务自动提交无效,回滚也无效

    我是通过看数据库里面数据确认的.代码比较类似,就这么多 #!/usr/bin/python from MySQLdb import connect conn = connect(db="te ...

最新文章

  1. 励志前行,加速BCH创新落地
  2. 【D3.js 学习总结】26、D3地理地图
  3. 初识java反射机制
  4. qt 运行库 linux,linux(ubuntu) 版qt5.x安装的一些知识
  5. ExtJs CheckboxSelectionModel 全选操作后 清空表格头的checkBox
  6. pyqt生成 android,PyQt on Android
  7. 基于树莓派的人脸识别(Linux系统 百度智能云平台)
  8. gd32f103驱动TLC59116(模拟i2c)
  9. Mac fliqlo 时钟屏保
  10. Redis集群管理工具redis-trib
  11. 电脑检测不到硬盘原因 电脑检测不到硬盘怎么办
  12. 我这些年对游戏外挂辅助开发的一些心得和体会
  13. 骁龙660和骁龙835之间的差距到底有多大?
  14. MarkdownPad2安装汉化与注册码
  15. 关于投资有哪些不得不读的书籍?
  16. 本地调试微信授权跳转
  17. 阿里MNS服务:代码显示成功并可以得到消息id及其md5,手机却收不到短信
  18. PCIe链路训练link training
  19. 高斯模糊的算法(高斯权重)
  20. 【GDB】VisualStudio 2017跨平台(Linux)调试|可视化GDB|visual GDB

热门文章

  1. 灰光和彩光_通信行业5G招标系列点评之二:一文读懂5G前传-光纤、灰光、彩光、CWDM、LWDM、MWDM...
  2. python随机生成验证码_Python生成随机验证码的两种方法
  3. c#养老院老人信息管理系统源码 论文_我市“老年人关爱服务体系建设”专题研究论文荣获第五届青年学者老龄论坛特等奖_社会民生_新闻频道...
  4. python中用于输出内容到终端的函数是_python执行linux shell管道输出内容
  5. 【InnoDB】体系结构
  6. bzoj3456:城市规划
  7. C++变量作用域、生存期、存储类别
  8. 【论文速读】ChengLin_Liu_ICCV2017_Deep_Direct_Regression_for_Multi-Oriented_Scene_Text_Detection...
  9. python线程同步
  10. HDU 4714 Tree2cycle:贪心