点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
您好,所有
我正在尝试在HANA中编写查询或脚本,该查询或脚本将显示有关系统中当前锁的详细信息,包括已获取该锁的SQL语句。 这是我到目前为止的内容:
选择 BT.BLOCKED_CONNECTION_ID为"阻止的会话", TR.CONNECTION_ID AS"阻止会话", BT.BLOCKED_TIME AS为"开始", SECONDS_BETWEEN(BT.BLOCKED_TIME,NOW())作为"长度", CN.CURRENT_SCHEMA_NAME AS"架构", CN.CLIENT_HOST || ''|| CAST(CN.CLIENT_PID AS VARCHAR(5))AS"主机/PID", SC_AP.VALUE AS"程序", SC_AS.VALUE AS为"程序源", BT.TABLE_NAME AS为"锁定对象", BT.LOCK_OWNER_UPDATE_TRANSACTION_ID, PS.STATEMENT_STRING AS"锁定声明" 来自SYS.M_BLOCKED_TRANSACTIONS_ BT 加入SYS.M_TRANSACTIONS_ TR ON TR.HOST = BT.HOST和 TR.PORT = BT.PORT AND TR.UPDATE_TRANSACTION_ID = BT.LOCK_OWNER_UPDATE_TRANSACTION_ID 加入SYS.M_CONNECTIONS CN ON CN.HOST = TR.HOST AND CN.PORT = TR.PORT AND CN.CONNECTION_ID = TR.CONNECTION_ID JOIN M_SESSION_CONTEXT SC_AP开启 SC_AP.HOST = TR.HOST AND SC_AP.PORT = TR.PORT AND SC_AP.CONNECTION_ID = TR.CONNECTION_ID AND SC_AP.KEY ='应用程序' JOIN M_SESSION_CONTEXT SC_AS开启 SC_AS.HOST = TR.HOST AND SC_AS.PORT = TR.PORT AND SC_AS.CONNECTION_ID = TR.CONNECTION_ID AND SC_AS.KEY ='APPLICATIONSOURCE' 向左联接M_SERVICE_THREADS TH ON TH.UPDATE_TRANSACTION_ID = BT.LOCK_OWNER_UPDATE_TRANSACTION_ID LEFT JOIN M_PREPARED_STATEMENTS PS ON PS.CONNECTION_ID = TR.CONNECTION_ID AND -不起作用,因为TR.CURRENT_STATEMENT_ID为NULL: PS.STATEMENT_ID = TR.CURRENT_STATEMENT_ID
此查询可正确显示所有内容,但最重要的字段(锁定语句始终为 NULL )除外。 如何提取已获得锁定的语句的文本?
由于我无法查明导致锁定的一个查询,因此我决定在阻塞转换中输出所有准备好的语句
/* ---------------------------查看当前锁--------------- ------------ */ -用于分析HANA数据库中当前锁的一组查询: -1.锁定会议 -2.在锁定会话中准备的SQL语句 -3.锁定的会话及其当前的SQL语句 -1.锁定连接: 选择 CN.CONNECTION_ID AS"阻止会话", SECONDS_BETWEEN(BC.MAXWAIT,NOW())AS"最长的等待时间,s", CN.CLIENT_HOST || ''|| CAST(CN.CLIENT_PID AS VARCHAR(5))AS"主机/PID", SC_AP.VALUE AS"程序", SC_AS.VALUE AS"程序源" FROM-TODO:与M_BLOCKED_TRANSACTIONS中的LTR处理进行比较: ( 选择 TR.CONNECTION_ID,TR.HOST,TR.PORT, MIN(BT.BLOCKED_TIME)作为MAXWAIT 来自SYS.M_BLOCKED_TRANSACTIONS_ BT 加入SYS.M_TRANSACTIONS_ TR ON TR.HOST = BT.HOST和 TR.PORT = BT.PORT AND TR.UPDATE_TRANSACTION_ID = BT.LOCK_OWNER_UPDATE_TRANSACTION_ID GROUP BY TR.CONNECTION_ID,TR.HOST,TR.PORT ) 加入SYS.M_CONNECTIONS CN ON CN.HOST = BC.HOST AND CN.PORT = BC.PORT AND CN.CONNECTION_ID = BC.CONNECTION_ID JOIN M_SESSION_CONTEXT SC_AP开启 SC_AP.HOST = BC.HOST AND SC_AP.PORT = BC.PORT AND SC_AP.CONNECTION_ID = BC.CONNECTION_ID和 SC_AP.KEY ='应用程序' JOIN M_SESSION_CONTEXT SC_AS开启 SC_AS.HOST = BC.HOST AND SC_AS.PORT = BC.PORT AND SC_AS.CONNECTION_ID = BC.CONNECTION_ID和 SC_AS.KEY ='APPLICATIONSOURCE' -TODO:按最长等待时间排序:此表和SQL语句列表 ORDER BY CN.CONNECTION_ID; -2.锁定SQL语句: 选择 TR.CONNECTION_ID AS"阻止会话", PS.STATEMENT_STRING AS"声明" 来自SYS.M_BLOCKED_TRANSACTIONS_ BT 加入SYS.M_TRANSACTIONS_ TR ON TR.HOST = BT.HOST和 TR.PORT = BT.PORT AND TR.UPDATE_TRANSACTION_ID = BT.LOCK_OWNER_UPDATE_TRANSACTION_ID JOIN SYS.M_CONNECTIONS CN ON-待办事项:此JOIN正确吗? CN.HOST = TR.HOST AND CN.PORT = TR.PORT AND CN.CONNECTION_ID = TR.CONNECTION_ID LEFT JOIN M_PREPARED_STATEMENTS PS ON PS.CONNECTION_ID = TR.CONNECTION_ID OR。BY TR.CONNECTION_ID,PS.LAST_EXECUTED_TIME; -3.锁定连接: 选择 BT.BLOCKED_CONNECTION_ID为"阻止的会话", TR.CONNECTION_ID AS"阻止会话", BT.BLOCKED_TIME AS为"锁定开始", SECONDS_BETWEEN(BT.BLOCKED_TIME,NOW())作为"长度,s", CN.CURRENT_SCHEMA_NAME AS"架构", PS.STATEMENT_STRING作为"声明", BT.TABLE_NAME AS为"锁定对象", CN.CLIENT_HOST || ''|| CAST(CN.CLIENT_PID AS VARCHAR(5))AS"主机/PID", SC_AP.VALUE AS"程序", SC_AS.VALUE AS"程序源" 来自SYS.M_BLOCKED_TRANSACTIONS_ BT 加入SYS.M_TRANSACTIONS_ TR ON TR.HOST = BT.HOST和 TR.PORT = BT.PORT AND TR.TRANSACTION_ID = BT.BLOCKED_TRANSACTION_ID 加入SYS.M_CONNECTIONS CN ON CN.HOST = TR.HOST AND CN.PORT = TR.PORT AND CN.CONNECTION_ID = TR.CONNECTION_ID JOIN M_SESSION_CONTEXT SC_AP开启 SC_AP.HOST = TR.HOST AND SC_AP.PORT = TR.PORT AND SC_AP.CONNECTION_ID = TR.CONNECTION_ID AND SC_AP.KEY ='应用程序' JOIN M_SESSION_CONTEXT SC_AS开启 SC_AS.HOST = TR.HOST AND SC_AS.PORT = TR.PORT AND SC_AS.CONNECTION_ID = TR.CONNECTION_ID AND SC_AS.KEY ='APPLICATIONSOURCE' JOIN M_PREPARED_STATEMENTS PS ON PS.CONNECTION_ID = TR.CONNECTION_ID AND PS.STATEMENT_ID = TR.CURRENT_STATEMENT_ID;
但是我的问题仍然存在,因为这种方法非常笨拙,并且如测试所示,并不可靠。
没有找到更好的解决方案,我被迫输出 M_PREPARED_STATEMENTS 中可用的任何阻塞会话语句:
一周热门 更多>