pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Verite <daniel@manitou-mail.org>
To: Bryn Llewellyn <bryn@yugabyte.com>
Cc: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?
Date: Thu, 08 Aug 2019 15:53:21 +0200
Message-ID: <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org> (raw)
In-Reply-To: <544214C2-8FF3-4900-82B8-3BCABA581827@yugabyte.com>

	Bryn Llewellyn wrote:

> B.t.w., I’m guessing that the “begin” SQL command that you see in the log
> that I mentioned is actually issued by (some) clients—at least psql and
> Python-on-psycopg2—as an explicit call from the client. In other words, it
> isn’t the server that generates this. Does anyone know for sure how this
> works?

Well, that's the point of Autocommit, and moreover it does nothing
else. Maybe you're still confused about this.

* Autocommit off = the client automatically adds a "BEGIN" when
it thinks a transaction must be started on behalf of the user.

* Autocommit on = the client does nothing.

The fact that "off" implies doing something and "on" implies not
interfering is counterintuitive, but that's how it is.	Autocommit is
for compatibility with other databases. If it was only for Postgres, I
guesss either it wouldn't exist in the first place or it should be
called "AutoStartTransactionBlock" or something like that, because
that's just what it really does.

Anyway, the server only know whether a BEGIN has been issued.
It never knows or cares whether it has been added implicitly or explicitly,
which is why it can be quite confusing to reason about server-side
differences in terms of Autocommit, as you do in some of your previous
messages.

It should be stressed that Autocommit is not a parameter of the
session between Postgres and the SQL client, but rather it's a
parameter of the session between the user and their SQL client.
So when you're hypothesizing that a plpgsql block in a procedure
would look at this parameter or change it temporarily (your
points #2 and #5 in your analysis of p2's execution), you should
see that it's impossible, because on the server-side, this parameter
just does not exist.


Best regards,
-- 
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite





view thread (20+ messages)  latest in thread

Message-ID: <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org>
Permalink:  ../5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org/
Also on:    postgresql.org/message-id/5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: daniel@manitou-mail.org, bryn@yugabyte.com, adrian.klaver@aklaver.com, horikyota.ntt@gmail.com
  Subject: Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure?
  In-Reply-To: <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org>
  References: <544214C2-8FF3-4900-82B8-3BCABA581827@yugabyte.com> <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox