本文介绍了自动提交在postgresql和psycopg2中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PostgreSQL和Psycopg2中自动提交的含义是否相同?

Does autocommit mean the same in PostgreSQL and Psycopg2?

从PostgreSQL手册

From PostgreSQL manual


$ b $在语句末尾隐式执行commit(如果执行成功,则
否则将回滚)。 b

这是否意味着自动提交将为每个命令创建一个事务?

Does it mean that autocommit will create a transaction for each command?

来自

psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT

在执行命令时不启动任何事务某些PostgreSQL命令(例如
CREATE DATABASE或VACUUM)无法运行到事务中:运行这样的
命令使用:

No transaction is started when commands are executed and no commit() or rollback() is required. Some PostgreSQL command such as CREATE DATABASE or VACUUM can’t run into a transaction: to run such command use:

>>> conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)


所有执行的命令都会立即提交意味着Psycopg2中的自动提交会为每个命令创建一个事务?

Does "all the commands executed will be immediately committed" mean that autocommit in Psycopg2 creates a transaction for each command?

是否在执行命令且没有commit()或rollback()的情况下不会启动任何事务是必需的是否意味着Psycopg2中的自动提交将阻止为每个命令创建事务?

Does "No transaction is started when commands are executed and no commit() or rollback() is required" mean that autocommit in Psycopg2 will prevent a transaction created for each command?

某些PostgreSQL命令(例如CREATE DATABASE或VACUUM)无法运行到事务中吗? :要运行这样的命令,启用自动提交模式,意味着Psycopg2中的自动提交将阻止仅为某些命令(CREATE DATABASE或VACUUM)创建的事务?

Does "Some PostgreSQL command such as CREATE DATABASE or VACUUM can’t run into a transaction: to run such command, enable autocommit mode" mean that autocommit in Psycopg2 will prevent a transaction created only for some commands (CREATE DATABASE or VACUUM)?

谢谢。

推荐答案

每个PostgreSQL语句都在事务中运行。

Every PostgreSQL statement is running in a transaction.

PostgreSQL本身 only 知道自动提交模式,这意味着每个语句将以自己的事务处理方式运行

PostgreSQL itself only knows autocommit mode, which means that each statement will run in its own transaction if you don't start a transaction explicitly.

诸如 VACUUM 之类的语句不能与其他事务在同一事务中运行

Statements like VACUUM cannot run in the same transaction with other statements.

如果您未在psycopg2中使用自动提交,则驱动程序必须通过在运行第一条语句时显式启动事务来模拟非自动提交模式。

If you are not using autocommit in psycopg2, the driver has to simulate non-autocommit mode by explicitly starting a transaction when the first statement is run.

这篇关于自动提交在postgresql和psycopg2中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 05:15