【问题标题】:Killing a particular sql query in postgres在 postgres 中杀死特定的 sql 查询
【发布时间】:2019-01-04 05:27:48
【问题描述】:

要在 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 中的等价物是什么?

【问题讨论】:

标签: python mysql postgresql


【解决方案1】:

很相似,命令是:

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)

【讨论】:

    猜你喜欢
    • 2014-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多