Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvirG-0001Bj-9h for pgsql-general@arkaria.postgresql.org; Thu, 08 Aug 2019 13:53:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hvirE-0003cH-1S for pgsql-general@arkaria.postgresql.org; Thu, 08 Aug 2019 13:53:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvirD-0003bs-Nw for pgsql-general@lists.postgresql.org; Thu, 08 Aug 2019 13:53:31 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvirA-00032E-Qq for pgsql-general@lists.postgresql.org; Thu, 08 Aug 2019 13:53:31 +0000 Received: from genius-map.net (verite.pro [195.154.189.246]) by mail.verite.pro (Postfix) with ESMTP id 3699C8C00DF; Thu, 8 Aug 2019 15:47:11 +0200 (CEST) Received: by genius-map.net (Postfix, from userid 1001) id 08E5C38A0AF7; Thu, 8 Aug 2019 15:53:25 +0200 (CEST) Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure? From: "Daniel Verite" To: "Bryn Llewellyn" Cc: "Adrian Klaver" ,"Kyotaro Horiguchi" ,"pgsql-general list" In-Reply-To: <544214C2-8FF3-4900-82B8-3BCABA581827@yugabyte.com> Date: Thu, 08 Aug 2019 15:53:21 +0200 Message-Id: <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org> X-Mailer: Manitou v1.7.3 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bryn Llewellyn wrote: > B.t.w., I=E2=80=99m guessing that the =E2=80=9Cbegin=E2=80=9D SQL command= that you see in the log > that I mentioned is actually issued by (some) clients=E2=80=94at least ps= ql and > Python-on-psycopg2=E2=80=94as an explicit call from the client. In other = words, it > isn=E2=80=99t the server that generates this. Does anyone know for sure h= ow this > works? Well, that's the point of Autocommit, and moreover it does nothing else. Maybe you're still confused about this. * Autocommit off =3D the client automatically adds a "BEGIN" when it thinks a transaction must be started on behalf of the user. * Autocommit on =3D 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, --=20 Daniel V=C3=A9rit=C3=A9 PostgreSQL-powered mailer: http://www.manitou-mail.org Twitter: @DanielVerite