事务上下文中 postgres 日志中 "execute" 和 "statement" 之间的区别

Difference between "execute" and "statement" in postgres logs in transaction context

我收到 "WARNING: There is no transaction in progress" 错误,如 所述。当我查看日志时,我发现如果我使用它的 Model.query 方法并且 "execute" 词出现在查询前面,我的帆水线 ORM 会导致 "statement" 词出现在日志中是通过它的模型方法发布的,比如 .insert、.update 等。它们在交易中的行为方式有什么区别吗?或者,日志中的 "statement" 和 "execute" 有什么区别?

2015-02-18 21:31:03 UTC [6810-35] vdsr@sails LOG:  statement: start transaction
2015-02-18 21:31:03 UTC [6813-33] vdsr@sails LOG:  execute <unnamed>: INSERT INTO "groups" ("name", "notes", "isCompany", "parentGroupRef", "companyRef", "createdAt", "updatedAt") values (, , , , , , ) RETURNING *
2015-02-18 21:31:03 UTC [6813-34] vdsr@sails DETAIL:  parameters:  = 'bbbb',  = 'fdf',  = 't',  = '1',  = '1',  = '2015-02-18 21:31:03+00',  = '2015-02-18 21:31:03+00'
2015-02-18 21:31:03 UTC [6814-33] vdsr@sails LOG:  execute <unnamed>: INSERT INTO "users" ("firstName", "lastName", "email", "companyRef", "isMainUser", "password", "middleName", "createdAt", "updatedAt") values (, , , , , , , , ) RETURNING *
2015-02-18 21:31:03 UTC [6814-34] vdsr@sails DETAIL:  parameters:  = 'ffff',  = 'ffdd',  = 'ffdfd@ds.com',  = '19',  = 't',  = 'cc5ce3a7addcb4512c7af12a6594af91',  = '',  = '2015-02-18 21:31:03+00',  = '2015-02-18 21:31:03+00'
2015-02-18 21:31:03 UTC [6805-53] vdsr@sails LOG:  execute <unnamed>: INSERT INTO "roles" ("name", "companyRef", "createdAt", "updatedAt") values (, , , ) RETURNING *
2015-02-18 21:31:03 UTC [6805-54] vdsr@sails DETAIL:  parameters:  = 'Master',  = '19',  = '2015-02-18 21:31:03+00',  = '2015-02-18 21:31:03+00'
2015-02-18 21:31:03 UTC [6809-37] vdsr@sails LOG:  execute <unnamed>: INSERT INTO "userroles" ("roleRef", "userRef", "createdAt", "updatedAt") values (, , , ) RETURNING *
2015-02-18 21:31:03 UTC [6809-38] vdsr@sails DETAIL:  parameters:  = '12',  = '16',  = '2015-02-18 21:31:03+00',  = '2015-02-18 21:31:03+00'
2015-02-18 21:31:03 UTC [6808-37] vdsr@sails LOG:  execute <unnamed>: INSERT INTO "rolepermissions" ("roleRef", "permissionRef", "createdAt", "updatedAt") values (, , , ) RETURNING *
2015-02-18 21:31:03 UTC [6808-38] vdsr@sails DETAIL:  parameters:  = '12',  = '24',  = '2015-02-18 21:31:03+00',  = '2015-02-18 21:31:03+00'
2015-02-18 21:31:03 UTC [6811-35] vdsr@sails LOG:  execute <unnamed>: INSERT INTO "rolepermissions" ("roleRef", "permissionRef", "createdAt", "updatedAt") values (, , , ) RETURNING *
2015-02-18 21:31:03 UTC [6811-36] vdsr@sails DETAIL:  parameters:  = '12',  = '22',  = '2015-02-18 21:31:03+00',  = '2015-02-18 21:31:03+00'
2015-02-18 21:31:03 UTC [6806-41] vdsr@sails LOG:  execute <unnamed>: SELECT "groups"."name", "groups"."notes", "groups"."parentGroupRef", "groups"."isCompany", "groups"."hierPos", "groups"."companyRef", "groups"."id", "groups"."createdAt", "groups"."updatedAt" FROM "groups" AS "groups"  WHERE "groups"."companyRef" =  
2015-02-18 21:31:03 UTC [6806-42] vdsr@sails DETAIL:  parameters:  = '1'
2015-02-18 21:31:03 UTC [6807-41] vdsr@sails LOG:  statement:  update groups set "hierPos" = case id when 2 then '1' when 3 then '2' when 4 then '3' when 5 then '4' when 6 then '4.1' when 10 then '4.1.1' when 18 then '4.2' when 13 then '5' when 17 then '6' when 19 then '7' else "hierPos" end  where id in (2,3,4,5,6,10,18,13,17,19) 
2015-02-18 21:31:03 UTC [6812-35] vdsr@sails LOG:  statement: commit
2015-02-18 21:31:03 UTC [6812-36] vdsr@sails WARNING:  there is no transaction in progress

很可能您 运行 您的查询处于自动提交模式。在这种模式下,每条语句都有自己的小事务。发出 WARNING 是因为所有语句都已提交,而 commit 语句没有 "see" 它们。

至于"execute" vs"statement":其中一个似乎是带参数的准备语句。另一个只是一个没有附加参数的简单查询。