首页 > 代码库 > SSISDB7:查看当前正在运行的Package

SSISDB7:查看当前正在运行的Package

在项目组中做ETL开发时,经常会被问到:“现在ETL正在跑哪一个Package?”

为了缩短ETL运行的时间,在ETL的设计上,经常会使用并发执行模式:Task 并发执行,Package并发执行。对于Package 并发执行模式,实现方式是:在SSIS Server上部署Package Job,每个Job Step执行一个Package Manager,该Package Manager以并发方式调用Execute Package Task,因此,在同一时间存在多个Child packages同时运行,并发执行的Executable的最大值是CPU的数量。在job运行的过程中,如何查看正在运行的Package? 由于任何一个Package在执行时,SSIS都会记录其Executable(Task,container)执行过程产生的历史消息,因此,可以通过Package记录的operation message 和 executable name来判断当前正在运行的Package。

SSIS Engine使用SSISDB的catalog.operation_messages视图,记录每个Package在执行过程中产生的历史消息;使用catalog.operations记录对Package的operation,主要是project的部署,package执行和history的cleanup。

1,查看正在运行的operation

Integration Service Catalogs中Package执行的任何操作,都会记录在 catalog.operations 视图中,该视图的关键Columns:

  • operation_type:operation_type=200  表示 create_execution and start_execution
  • Status:The status of the operation. The possible values are created (1), running (2), canceled (3), failed (4), pending (5), ended unexpectedly (6), succeeded (7), stopping (8), and completed (9).
  • object_type:The type of object affected by the operation. The object may be a folder (10), project (20), package (30), environment (40), or instance of execution (50).

查看当前正在运行的Operation的脚本是

select top 11     op.operation_id,    opt.operation_type_descr,    op.created_time,    obt.object_type_descr as object_affected,    op.object_id,    op.object_name,    ops.operation_status_descr as status,    op.start_time,    op.end_time,    op.caller_namefrom catalog.operations op with(nolock)inner join helper.OperationType opt with(nolock)    on op.operation_type=opt.operation_typeinner join helper.ObjectType obt with(nolock)    on op.object_type=obt.object_typeinner join helper.OperationStatus ops with(nolock)    on op.status=ops.operation_statuswhere op.operation_type=200  --create_execution and start_execution(200)and op.object_type=20        -- project (20)and op.status in(2,5)        -- running (2), pending (5)order by op.created_time desc

2,查看SSIS Engine 记录的Operation Message

SSIS Engine是根据触发事件(Event)来记录Operation Message的,从message_type_descr能够查看消息的 Event 类型,从message_source_descr中能够看到触发事件的Task 类型:Control Flow tasks 或 Data Flow task。

This view displays a row for each message that is logged during an operation in the catalog. The message can be generated by the server, by the package execution process, or by the execution engine.

select top 111    om.message,    om.message_time,    mt.message_type_descr,    mst.message_source_descrfrom catalog.operation_messages om with(nolock)inner join helper.MessageType mt with(nolock)    on om.message_type=mt.message_typeinner join helper.MessageSourceType mst with(nolock)    on om.message_source_type=mst.message_source_typewhere om.operation_id=104627order by om.message_time desc

Message字段提供的信息非常详细,格式大概是:Task组件名称+事件名称+其他,通过组件名称,推测正在运行的Package和组件。如果Task 组件的名称具有代表性,就能很容易推断出正在运行的package 和 package中正在运行的task。

3,helper 辅助表

关于helper 辅助表,请参考《SSISDB6:Operation》的Appendix

参考doc:

catalog.operation_messages (SSISDB Database)

catalog.operations (SSISDB Database)

SSISDB7:查看当前正在运行的Package