如何在使用 DTEXEC.EXE 命令行实用程序时获取 SSIS 包的实际执行时间

How to get actual execution time of SSIS package while using DTEXEC.EXE Command Line Utility

我正在使用 DTEXEC.EXE 执行一个 SSIS 包,如下所示

C:\Program Files\Microsoft SQL Server0\DTS\Binn>DTExec.exe /Server localhost /ISServer "\MyServer\mypackage.dtsx"

执行命令后显示以下详细信息。

Started:  3:28:09 PM
Execution ID: 41165.
To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report
Started:  3:28:09 PM
Finished: 3:28:09 PM
Elapsed:  0.172 seconds

包的实际执行时间为 20 分钟,但“运行时间显示为 0.172 秒。在使用命令行 运行 包时,是否有任何选项可以获取实际执行时间?

提前致谢

上面显示的是实际加载执行包的时间。 运行包裹的时间就是你要找的

通常的做法是将行写入审核 table,您通过将包 ID 和当前时间、名称以及您想要的其他内容写入 table(错误消息等)来启动您的包。 )

在打包结束时,您使用结束时间更新数据库中的行。

您可以查询此 table 并比较开始时间和结束时间以找到 运行 包裹的总时间。

审计示例table我们这里常用;

USE [database]
GO


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[dim_audit](
    [AuditKey] [int] IDENTITY(1,1) NOT NULL,
    [ParentAuditKey] [int] NOT NULL,
    [TableName] [nvarchar](50) NOT NULL,
    [PkgName] [nvarchar](50) NOT NULL,
    [PkgGUID] [uniqueidentifier] NULL,
    [PkgVersionGUID] [uniqueidentifier] NULL,
    [PkgVersion] [nvarchar](50) NULL,
    [ExecStartDT] [datetime] NOT NULL,
    [ExecStopDT] [datetime] NULL,
    [ExecutionInstanceGUID] [uniqueidentifier] NULL,
    [ExtractRowCnt] [bigint] NULL,
    [InsertRowCnt] [bigint] NULL,
    [UpdateRowCnt] [bigint] NULL,
    [DeleteRowCnt] [bigint] NULL,
    [TableInitialRowCnt] [bigint] NULL,
    [TableFinalRowCnt] [bigint] NULL,
    [TableMaxSurrogateKey] [bigint] NULL,
    [SuccessfulProcessingInd] [nchar](1) NOT NULL,
 CONSTRAINT [PK_dim_audit] PRIMARY KEY CLUSTERED 
(
    [AuditKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

当您从 DTEXEC 运行 SSIS 打包时,它们将 运行 处于同步执行模式。 除非,您要求它们是来自 SSISDB 的 运行。然后,您需要向 /Par "$ServerOption::SYNCHRONIZED(Boolean)";True

的 DTEXEC 调用添加一个附加参数

我创建了一个显式等待延迟为 15 秒的程序包,运行 它在我的机器上运行了两次。

C:\Users\billinkc>dtexec /server .\dev2017 /ISServer "\ssisdb\So\JustWait\Package.dtsx"
Microsoft (R) SQL Server Execute Package Utility
Version 14.0.3037.1 for 32-bit
Copyright (C) 2017 Microsoft. All rights reserved.

Started:  7:41:06 AM
Execution ID: 161421.
To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report
Started:  7:41:06 AM
Finished: 7:41:07 AM
Elapsed:  0.141 seconds

C:\Users\billinkc>dtexec /server .\dev2017 /ISServer "\ssisdb\So\JustWait\Package.dtsx" /Par "$ServerOption::SYNCHRONIZED(Boolean)";True
Microsoft (R) SQL Server Execute Package Utility
Version 14.0.3037.1 for 32-bit
Copyright (C) 2017 Microsoft. All rights reserved.

Started:  7:41:12 AM
Execution ID: 161422.
To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report
Started:  7:41:12 AM
Finished: 7:41:30 AM
Elapsed:  18.39 seconds

第一个,默认执行,不需要时间,因为它将责任移交给 SQL 服务器本身。第二个迫使我们实时获取消息,因此,15 秒 + 设置时间