hive 杀死死锁sql
时间: 2023-08-19 19:08:28 浏览: 312
在 Hive 中,你可以使用以下 SQL 查询来杀死死锁的会话:
```sql
SET hive.support.concurrency=true;
SET hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager;
-- 获取死锁的会话 ID(session ID)
SELECT s.session_id
FROM (
SELECT t1.*, t2.requesting_session_id
FROM (
SELECT hl1.*, hl2.blocking_session_id
FROM (
SELECT blocking_locks.txn_id AS blocked_txn_id, blocked_locks.txn_id AS blocking_txn_id
FROM (SELECT * FROM TXN_COMPONENTS WHERE LOCKED = true) blocked_locks
JOIN (SELECT * FROM TXN_COMPONENTS WHERE LOCKED = true) blocking_locks
ON (blocked_locks.ext_id = blocking_locks.ext_id)
) hl1
JOIN HIVE_LOCKS t1 ON (hl1.blocked_txn_id = t1.txn_id)
JOIN HIVE_LOCKS t2 ON (hl1.blocking_txn_id = t2.txn_id)
) hl2
JOIN HS2_LOCKS l1 ON (hl2.lockid = l1.lockid)
JOIN HS2_LOCKS l2 ON (hl2.blocking_lock_id = l2.lockid)
) deadlock
JOIN HS2_SESSIONS s ON (deadlock.sessionid = s.sessionid);
-- 使用会话 ID 杀死死锁的会话
-- 替换 <session_id> 为实际的会话 ID
KILL <session_id>;
```
首先,查询获取死锁的会话 ID,然后使用 `KILL` 命令加上会话 ID 来终止阻塞的会话,解决死锁问题。请确保在执行 `KILL` 命令之前,仔细检查并确认要终止的会话是正确的死锁会话。同时,对于执行这些操作,你需要有足够的权限。
另外,你也可以使用 Hive 的 Web UI 或命令行工具来查找死锁并杀死相关会话。使用 `SHOW LOCKS` 命令可以列出当前的锁信息,并使用 `KILL <session_id>` 命令来终止阻塞的会话。
阅读全文