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 1hvS1a-00019B-DX for pgsql-general@arkaria.postgresql.org; Wed, 07 Aug 2019 19:55:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hvS1Y-0006Yw-Ml for pgsql-general@arkaria.postgresql.org; Wed, 07 Aug 2019 19:55:04 +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 1hvS1Y-0006Yp-99 for pgsql-general@lists.postgresql.org; Wed, 07 Aug 2019 19:55:04 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvS1R-0005iP-2B for pgsql-general@lists.postgresql.org; Wed, 07 Aug 2019 19:55:03 +0000 Received: by mail-pl1-x643.google.com with SMTP id w24so42344674plp.2 for ; Wed, 07 Aug 2019 12:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte-com.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=WV8DbuLPC9TV3p7BeDWe5ueMa9UjrkS6ARZ/rZshL/8=; b=EqCifseN5yPJLoY2l8NQqCVyb7IC6yekf4mog+glnVr6LcRFPUhj7+SP6iW10NdPml cqYtoEO6TVqrS/S4xEbeydgV4PGZLmmUPasOK80DwKw+2gsPQB+loPIcwRRyFEoNY0c8 fnisvslTbD+2XBltv4bfh9Gc961c7zV6wbtAHwDpkFcficgSQQcoZsbV+afd39VzHA2d mrp93rsIuOxMYzb2AqhYrrpl2ZOh08qrQNznJykwbmy47BreccE/yghGk2q9u6AgTdIu O+ZuBM8PDMGOf9fb7YQROT38po5a7iEiZPx1/vPq3JaqPGlCYRCGZIws5SiWRZhT127m PaLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=WV8DbuLPC9TV3p7BeDWe5ueMa9UjrkS6ARZ/rZshL/8=; b=XrRySKEpVVU67E+Q+/NCzdV6UX70curgncdLWCWiHYb3LwdFrq0kyrO6vwYKifzrX+ SRQ9bexEkHcMmabbl4T4GugT6LMrWuoGF89MeLHmfmsHi6P449zWvn6GCCfm9n2ZaB0U 0UQmgAQnyQg9R1D5L+U1at5M6ykuAIswP0Q4S00b4k72cZXe/iWb4snhW7uZ+Jytoq3F KxhPNsGiPV/GPI4k7qTonhAXtTGzgIPf5y+qkO7VQwBEEp2UtL5yAZ/TiJRfWBNe7/46 H6TBnoFLUuYrJPcsXW1981J3BiwvLbkOa/6KWTzw94JfnorS8aEnEfjX1K7E9UGV2myO 42GQ== X-Gm-Message-State: APjAAAUgDY3kHJRpTwnVwFOYiN/eBfaZBQsw6WDqsNjyZO9FD+Yrgfig 4FDxRX4ZOdUYaDfGBGsBYJsqbw== X-Google-Smtp-Source: APXvYqyA6gkthwnQt5CQIRsNECeXrjKIU+RXA9B/K2tEiXiSgIxCHU7mgAYuLLJZUJ3WiESMIkJA2w== X-Received: by 2002:aa7:9786:: with SMTP id o6mr10850972pfp.222.1565207694854; Wed, 07 Aug 2019 12:54:54 -0700 (PDT) Received: from ?IPv6:2601:646:101:7fda:f58c:fe68:b6a:f7fb? ([2601:646:101:7fda:f58c:fe68:b6a:f7fb]) by smtp.gmail.com with ESMTPSA id q198sm94718391pfq.155.2019.08.07.12.54.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Aug 2019 12:54:54 -0700 (PDT) From: Bryn Llewellyn Message-Id: Content-Type: multipart/alternative; boundary="Apple-Mail=_EA3DE2B0-1CBF-4257-85B8-7E0B75FB5E4B" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: Why must AUTOCOMMIT be ON to do txn control in plpgsql procedure? Date: Wed, 7 Aug 2019 12:54:53 -0700 In-Reply-To: Cc: Kyotaro Horiguchi , pgsql-general list To: Adrian Klaver References: <9E141BBF-29E8-4825-9E7D-5F96BAD4365B@yugabyte.com> <20190807.162639.263082453.horikyota.ntt@gmail.com> <5FA840F2-B596-46F6-960D-9705C45F3E9C@yugabyte.com> X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_EA3DE2B0-1CBF-4257-85B8-7E0B75FB5E4B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Yes, I do believe that I understand this. But there=E2=80=99s no getting = away from the fact that the AUTOCOMMIT mode, and what this implies, is a = server-side phenomenon=E2=80=94at least as several PostgreSQL experts = have assured me. For example, when you use client-side Python with the = psycopg2 driver, then once you=E2=80=99ve done =E2=80=9Cmy_session =3D = psycopg2.connect(connect_str)=E2=80=9D, you can then do = =E2=80=9Cmy_session.set_session(autocommit=3DFalse)=E2=80=9D. And then = everything we=E2=80=99ve been saying in the psql context now applies in = that context=E2=80=94yes? 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 psql 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 how this works? On 07-Aug-2019, at 11:56, Adrian Klaver = wrote: On 8/7/19 11:46 AM, Bryn Llewellyn wrote: > Thanks for your response, Kyotaro. I=E2=80=99m happy, now, to accept = the rule that =E2=80=9Ccall proc_that_does_txn_control()=E2=80=9D is = legal only when AUTOCOMMIT is ON. Esp. when I=E2=80=99m told (on = twitter, by 2ndQuadrant=E2=80=99s Peter Eisentraut, that this rule is = =E2=80=9Can implementation restriction, for the most part.=E2=80=9D See = HERE . > About your =E2=80=9CIn-procedure transaction control premises that no = transaction is active before calling the procedure=E2=80=9D=E2=80=A6 = yes. Nevertheless, as the code that Umair Sahid showed us in the blog = post that I referenced in my email that started this thread, you can = indeed start end end transactions from an executing proc (as long as the = session=E2=80=99s AUTOCOMMIT mode s ON). The key is that the AUTOCOMMIT status is just a specific case of the = general rule. The general rule being that a PROCEDURE cannot do = transaction ending commands when it it called within an outer = transaction. You can run into the same issue in other situations e.g. = ORM's that start a transaction behind the scenes. In other words this is = not psql specific. As long as you understand the general rule then = things become clearer. --=20 Adrian Klaver adrian.klaver@aklaver.com --Apple-Mail=_EA3DE2B0-1CBF-4257-85B8-7E0B75FB5E4B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Yes, I do believe that I = understand this. But there=E2=80=99s no getting away from the fact that = the AUTOCOMMIT mode, and what this implies, is a server-side = phenomenon=E2=80=94at least as several PostgreSQL experts have assured = me. For example, when you use client-side Python with the psycopg2 = driver, then once you=E2=80=99ve done =E2=80=9Cmy_session =3D = psycopg2.connect(connect_str)=E2=80=9D, you can then = do =E2=80=9Cmy_session.set_session(autocommit=3DFalse)=E2=80=9D. = And then everything we=E2=80=99ve been saying in the psql context now = applies in that context=E2=80=94yes?

B.t.w., I=E2=80=99= m 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 psql 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 how this works?

On = 07-Aug-2019, at 11:56, Adrian Klaver <adrian.klaver@aklaver.com> = wrote:


= --Apple-Mail=_EA3DE2B0-1CBF-4257-85B8-7E0B75FB5E4B--