如何避免"检测到死锁"关于Postgres + Sqlalchemy的问题?

时间:2015-07-02 07:54:47

标签: python database postgresql flask sqlalchemy

这是关于有问题的代码行的代码:

webdb.begin(subtransactions=True)
(webdb.query(Proxy).filter(Proxy.service_token == service_token)).update(
    {Proxy.date_deleted_utc: datetime.datetime.utcnow()},
    synchronize_session="fetch"
)
webdb.commit()

我尝试启动子事务,并添加了同步提取。

但我仍然会收到此错误:

DBAPIError: (TransactionRollbackError) deadlock detected
DETAIL:  Process 61086 waits for ExclusiveLock on tuple (7217,55) of relation 626383 of database 380717; blocked by process 61094.
Process 61094 waits for ShareLock on transaction 55622134; blocked by process 61088.
Process 61088 waits for ShareLock on transaction 55622141; blocked by process 61086.
HINT:  See server log for query details.
'UPDATE proxies SET date_deleted_utc=%(date_deleted_utc)s WHERE proxies.service_token = %(service_token_1)s' {'date_deleted_utc': datetime.datetime(2015, 7, 2, 12, 57, 23, 2358), 'service_token_1': u'3733a37e-2094-11e5-90b7-0242ac110080'}

我还能做什么?

0 个答案:

没有答案