要杀死mysql中具有特定字符串的查询,我可以执行以下操作:
kill_string = 'LONG-QUERY'
cursor = self.conn.cursor()
cursor.execute("SHOW FULL processlist")
for _row in cursor.fetchall():
_id = _row[0]
_query = _row[-1] or ''
if kill_string in _query:
cursor.execute('KILL %s' % _id)
Postgres中的等效内容是什么?
答案 0 :(得分:0)
非常相似,命令如下:
kill_string = 'LONG-QUERY'
cursor.execute("SELECT pid, query FROM pg_stat_activity")
for _row in cursor.fetchall():
_id = _row[0]
_query = _row[-1] or ''
if kill_string in _query:
cursor.execute('SELECT pg_terminate_backend(%s)' % _id)