为什么我会收到关于"没有正在进行的交易的警告"在COMMIT
之后,即使我已明确启动与START TRANSACTION
的交易(与BEGIN
的工作方式相同)?对于此特定事务,这将发生90%的时间,但有时提交将成功。我使用postgres 9.3。这是postgres日志:
2014-07-04 21:47:19 EST LOG: statement: START TRANSACTION;
2014-07-04 21:47:19 EST LOG: statement: SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
2014-07-04 21:47:19 EST LOG: statement: SET autocommit = 1;
2014-07-04 21:47:19 EST LOG: statement: SET TIME ZONE 'UTC'
2014-07-04 21:47:19 EST LOG: statement: INSERT INTO "Users" (...) VALUES (...) RETURNING *;
2014-07-04 21:47:19 EST LOG: statement: INSERT INTO "Profiles" (...) RETURNING *;
2014-07-04 21:47:19 EST LOG: statement: SET TIME ZONE 'UTC'
2014-07-04 21:47:19 EST LOG: statement: INSERT INTO "Sessions" (...) VALUES (...) RETURNING *;
2014-07-04 21:47:20 EST LOG: statement: COMMIT;
2014-07-04 21:47:20 EST WARNING: there is no transaction in progress
答案 0 :(得分:1)
您正在使用自动提交。使用自动提交时,显式启动事务是没有意义的。
删除行"设置autocommit = 1"或者将1更改为" off"或等值,这应该有效。