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 1hvnJa-0002My-UM for pgsql-general@arkaria.postgresql.org; Thu, 08 Aug 2019 18:39:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hvnJZ-0005gD-Im for pgsql-general@arkaria.postgresql.org; Thu, 08 Aug 2019 18:39:05 +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 1hvnG9-0000Ru-7C for pgsql-general@lists.postgresql.org; Thu, 08 Aug 2019 18:35:33 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hvnG5-0000AF-Qf for pgsql-general@lists.postgresql.org; Thu, 08 Aug 2019 18:35:32 +0000 Received: by mail-pl1-x644.google.com with SMTP id ay6so43931841plb.9 for ; Thu, 08 Aug 2019 11:35:29 -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=XIYZgWQugcSzcFfZSCoGl2mQ+tm/A0Qk09vlL/jEVSs=; b=yxGNKL4yjWCAMwm9kZkT5lLagH667QyO0By/EaBdRdQiUyB0vDSin2hqir4HGNnUCq onnU+WSigpUZx8uMMnvm40Nt6gmo00UIprdzSSjHekgOc4Y1bTVzD+HhBV7bFJvja/7f kpy9zoazo/ISpbH814qiI3erOGazOyNZHWfE25I5KPuQKKnNWadMdT4H7lJBR4sPPmOb 8xgsNgtvMA9FB6nFY9J3+RzboCrYpQKqo8uZRTsZsnr1446VKslSNel67D6J3jW2doB9 BXb0mubvaIVSo0yqdA4yVeKY4sejwh29lj0KC2U2o3Aw3Dsg1E/T5y5JZVJpqSginvnc mtaA== 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=XIYZgWQugcSzcFfZSCoGl2mQ+tm/A0Qk09vlL/jEVSs=; b=LylFSK8ITMAL/3x9u59Vdp1mCNqDh+44CYIeq22hL8fdcID0lEzLKTLNHaTHp4GR+u RH8VQXWxkNyUHagBBQkS5KKMn6ebu+pQRvuejkqgBGfrLRWOBHFouIg1acrd5ItcK0kB PoRiPt4K1wgZpSu4FPKVA54qfYI8ttH9EiOOh0SZW5cWLaAV1DeoSIh1J3rRO/KUzHZu YR3xNwKRO4Lxaqicb+0ogwuufkPQer28BEUN+ZlT4J3D/XG3vAVhN2QcmzqOr79DRAcs ALxahhNCrS5RlYa+GMRNgXCuJlQjI0mtAtjoCqai1joRntRV6UWPmgAfOzTVd6XCaC+q QkqQ== X-Gm-Message-State: APjAAAUnmHgO+0OMr8n/OVtbSNZaiged2nydrnzz/sOyq2MMVdTRpGgG Mj7EuzMy2TO5bxF8Xk5pKu2GRw== X-Google-Smtp-Source: APXvYqyoLtBPmLEaB8IiOEk7Jd8+15Obc4Aj11buje3ZSkncuuSh2OcCvT0RUcj8ztXlAvGqoLYLUw== X-Received: by 2002:a17:902:b18b:: with SMTP id s11mr10395620plr.220.1565289325281; Thu, 08 Aug 2019 11:35:25 -0700 (PDT) Received: from ?IPv6:2601:646:101:7fda:3def:2a6c:4fd6:a933? ([2601:646:101:7fda:3def:2a6c:4fd6:a933]) by smtp.gmail.com with ESMTPSA id q7sm109077059pff.2.2019.08.08.11.35.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 11:35:24 -0700 (PDT) From: Bryn Llewellyn Message-Id: <300F25B2-9B0E-4CC4-8AAC-FA177CFB3101@yugabyte.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_6053819D-955A-486A-BEA7-EAEBF3658D6E" 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: Thu, 8 Aug 2019 11:35:23 -0700 In-Reply-To: <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org> Cc: Adrian Klaver , Kyotaro Horiguchi , pgsql-general list To: Daniel Verite References: <5cfb2b44-9a1e-4258-9818-9ca10b73176f@manitou-mail.org> X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_6053819D-955A-486A-BEA7-EAEBF3658D6E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Please try the following. Stop PostgreSQL with this: pg_ctl -D /usr/local/var/postgres stop Edit the file "/usr/local/var/postgres/postgresql.conf=E2=80=9D and add = these lines at the end: log_statement =3D 'all' log_directory =3D 'log' logging_collector =3D on Then start PostgreSQL with this: pg_ctl -D /usr/local/var/postgres start Then, in one terminal window, find the latest log file with this: ls -l /usr/local/var/postgres/log/postgresql-*.log Then, in a second terminal window, start psql and do these tests. By all = means, add your own. -- Test 1. \set AUTOCOMMIT ON insert into t(n) values(42); I see _only_ the =E2=80=9Cinsert=E2=80=9D in the log=E2=80=94in other = words, no =E2=80=9Ccommit=E2=80=9D. (And no =E2=80=9CBEGIN=E2=80=9D for = that matter.) If it were the case the psql sends the commit after every = statement when AUTOCOMMIT is ON, then I=E2=80=99d see this in the log. = Yet the effect of the =E2=80=9Cinsert=E2=80=9D has indeed been = committed. You can see this by issuing =E2=80=9Crollback=E2=80=9D (you = get the "there is no transaction in progress=E2=80=9D warning). And a = subsequent =E2=80=9Cselect=E2=80=9D confirms that the =E2=80=9Cinsert=E2=80= =9D was committed. My interpretation is that AUTOCOMMIT is a server-side phenomenon (but, = as we shall see, the client does know that this mode has been set). -- Test 2. \set AUTOCOMMIT OFF insert into t(n) values(42); rollback; I see this in the log: =E2=80=A6LOG: statement: BEGIN =E2=80=A6LOG: statement: insert into t(n) values(42); =E2=80=A6LOG: statement: rollback; (I also see this when I do the test using Python on psycopg2 after doing = =E2=80=9Cmy_session.set_session(autocommit=3DFalse)=E2=80=9D. The = =E2=80=9Crollback=E2=80=9D doesn=E2=80=99t draw a warning. And, indeed, = the effect of my =E2=80=9Cinsert=E2=80=9D has been undone, as has been = shown by a subsequent =E2=80=9Cselect=E2=80=9D.) -- Test 3. \set AUTOCOMMIT OFF start transaction; insert into t(n) values(42); rollback; I see this in the log: =E2=80=A6LOG: statement: start transaction; =E2=80=A6LOG: statement: insert into t(n) values(42); =E2=80=A6LOG: statement: rollback; Same outcome as with Test 2. Test 2 and Test 3 are consistent with the = hypothesis that it=E2=80=99s the client that issues the =E2=80=9CBEGIN=E2=80= =9D before your first SQL command after setting AUTOCOMMIT to OFF. But = it doesn=E2=80=99t _prove_ the hypothesis. However, experts on this list = have said that this is how it works. And this is consistent with the = fact that, when AUTOCOMMIT is ON, I don=E2=80=99t see this in the log: BEGIN; insert into t(n) values(42); COMMIT; If AUTOCOMMIT were entirely a client-side phenomenon, then you _would_ = have to see this to get the defined semantics. In summary, my hypothesis is that AUTOCOMMIT is a server side = phenomenon. But, because to set it with a call from the client, the = client does know what mode you=E2=80=99re in and adds its own BEGIN = before the first SQL command that follows setting AUTOCOMMIT to ON. Test 4 is more elaborate. Please run the attached setup_for_test_4.sql, = and then do this by hand. But do read the definition of "p2()" = carefully first. Then do this: -- Test 4. \set AUTOCOMMIT ON do $$ begin raise notice 'txid at top level before "p2()" ..... %', = txid_current(); end $$; call p2(); do $$ begin raise notice 'txid at top level after "p1()" ...... %', = txid_current(); end $$; select n from t order by n; This is the output: NOTICE: txid at top level before "p2()" ..... 9478 NOTICE: txid in "p2()" at start ............. 9479 NOTICE: txid in "p2()" after "set txn"....... 9480, level =3D = repeatable read NOTICE: txid in "p2()" after "set txn"....... 9481, level =3D = serializable NOTICE: txid at top level after "p1()" ...... 9482 n =20 ---- 42 And this is what the log shows: =E2=80=A6LOG: statement: do $$ begin raise notice 'txid at top level = before "p2()" ..... %', txid_current(); end $$; =E2=80=A6LOG: statement: call p2(); =E2=80=A6LOG: statement: do $$ begin raise notice 'txid at top level = after "p1()" ...... %', txid_current(); end $$; =E2=80=A6LOG: statement: select n from t order by n; Notice that there=E2=80=99s no visible =E2=80=9CBEGIN=E2=80=9D between = my first =E2=80=9Cdo" block and the =E2=80=9Ccall=E2=80=9D. And (again) = no visible =E2=80=9CCOMMIT=E2=80=9D after the =E2=80=9Ccall" finishes. = But the txid values show that =E2=80=9Ccall=E2=80=9D did indeed start a = new txt, the =E2=80=9Crollback=E2=80=9D in the proc ended it so that = "set transaction isolation level=E2=80=9D in the proc can (implicitly) = start a new txn. And so on. All this is consistent with the hypothesis = that there is no such thing as a =E2=80=9Cnested transaction=E2=80=9D. = Rather, there=E2=80=99s just a series of non-overlapping ordinary txns. = The BLOG POST = that I quoted with my first post on this topic explains that = this is intended. This is consistent with the hypothesis that AUTOCOMMIT is indeed a = server-side phenomenon and that, during the execution of a procedure, = its usual effect is suspended=E2=80=94and is resumed when the procedure = execution ends. I=E2=80=99ve said several times that my goal is to set the isolation = level from inside a proc so that the proc can own the entire logic for = concurrent txns that might violate a multi-row data-rule. And I=E2=80=99ve said several times that I discovered that starting my = proc with =E2=80=9Crollback=E2=80=9D allows this=E2=80=94and that I've = found no other way to meet my goal. I don=E2=80=99t understand, = therefore, why some people (but not you, Daniel!) who=E2=80=99ve = responded to my questions say that starting my proc with =E2=80=9Crollback= =E2=80=9D is pointless. I tried, earlier, to say =E2=80=9Ccase closed=E2=80=9D. I=E2=80=99ll say = it again now. On 08-Aug-2019, at 06:53, Daniel Verite wrote: 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 = 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? 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 --Apple-Mail=_6053819D-955A-486A-BEA7-EAEBF3658D6E Content-Type: multipart/mixed; boundary="Apple-Mail=_761A7CF3-2DD3-4085-BC7B-E986D7B919BF" --Apple-Mail=_761A7CF3-2DD3-4085-BC7B-E986D7B919BF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Please try the following.

Stop PostgreSQL with this:

pg_ctl -D /usr/local/var/postgres stop

Edit the file = "/usr/local/var/postgres/postgresql.conf=E2=80=9D and add these lines at = the end:

log_statement =3D 'all'
log_directory = =3D 'log'
logging_collector =3D on

Then start =  PostgreSQL with this:

pg_ctl -D = /usr/local/var/postgres start

Then, in one terminal window, find the latest log file = with this:

ls -l /usr/local/var/postgres/log/postgresql-*.log

Then, in a second = terminal window, start psql and do these tests. By all means, add your = own.

-- = Test 1.
\set = AUTOCOMMIT ON
insert into t(n) = values(42);

I see = _only_ the =E2=80=9Cinsert=E2=80=9D in the log=E2=80=94in other words, = no =E2=80=9Ccommit=E2=80=9D. (And no =E2=80=9CBEGIN=E2=80=9D for that = matter.) If it were the case the psql sends the commit after every = statement when AUTOCOMMIT is ON, then I=E2=80=99d see this in the = log. Yet the effect of the =E2=80=9Cinsert=E2=80=9D has indeed been = committed. You can see this by issuing =E2=80=9Crollback=E2=80=9D (you = get the "there is no transaction in progress=E2=80=9D warning). And a = subsequent =E2=80=9Cselect=E2=80=9D confirms that the =E2=80=9Cinsert=E2=80= =9D was committed.

My interpretation = is that AUTOCOMMIT is a server-side phenomenon (but, as we shall see, = the client does know that this mode has been set).

-- Test = 2.
\set = AUTOCOMMIT OFF
insert into t(n) = values(42);
rollback;

I see this in the log:

=E2=80=A6LOG: =  statement: BEGIN
=E2=80=A6LOG:  statement: = insert into t(n) values(42);
=E2=80=A6LOG: =  statement: rollback;

(I also see this when I do the test using Python = on psycopg2 after doing = =E2=80=9Cmy_session.set_session(autocommit=3DFalse)=E2=80=9D. The = =E2=80=9Crollback=E2=80=9D doesn=E2=80=99t draw a warning. And, indeed, = the effect of my =E2=80=9Cinsert=E2=80=9D has been undone, as has been = shown by a subsequent =E2=80=9Cselect=E2=80=9D.)

-- Test 3.
\set AUTOCOMMIT OFF
start = transaction;
insert into = t(n) values(42);
rollback;

I see this in the log:

=E2=80=A6LOG: =  statement: start transaction;
=E2=80=A6LOG: =  statement: insert into t(n) values(42);
=E2=80=A6LOG: =  statement: rollback;

Same outcome as with Test 2. Test 2 and Test 3 are = consistent with the hypothesis that it=E2=80=99s the client that issues = the =E2=80=9CBEGIN=E2=80=9D before your first  SQL command after = setting AUTOCOMMIT to OFF. But it doesn=E2=80=99t _prove_ the = hypothesis. However, experts on this list have said that this is how it = works. And this is consistent with the fact that, when AUTOCOMMIT is ON, = I don=E2=80=99t see this in the log:

BEGIN;
insert into t(n) values(42);
COMMIT;

If = AUTOCOMMIT were entirely a client-side phenomenon, then you _would_ have = to see this to get the defined semantics.

In summary, my hypothesis is that AUTOCOMMIT = is a server side phenomenon. But, because to set it with a call from the = client, the client does know what mode you=E2=80=99re in and adds its = own BEGIN before the first SQL command that follows setting AUTOCOMMIT = to ON.

Test 4 is more elaborate. = Please run the attached setup_for_test_4.sql, and then do this by hand. But do = read the definition of "p2()"  carefully first. Then do = this:

-- = Test 4.
\set AUTOCOMMIT ON
do $$ begin = raise notice 'txid at top level before "p2()" ..... %', txid_current(); = end $$;
call p2();
do $$ begin raise notice = 'txid at top level after "p1()" ...... %', txid_current(); end $$;
select n from t order by n;

This is the output:

NOTICE:  txid at top level before "p2()" ..... = 9478
NOTICE:  txid in "p2()" at start = ............. 9479
NOTICE:  txid in "p2()" after = "set txn"....... 9480, level =3D repeatable read
NOTICE:  txid in "p2()" after "set txn"....... = 9481, level =3D serializable
NOTICE:  txid at = top level after "p1()" ...... 9482
 n  
----
 42

And this is what the log shows:

=E2=80=A6LOG: =  statement: do $$ begin raise notice 'txid at top level before = "p2()" ..... %', txid_current(); end $$;
=E2=80=A6LOG: =  statement: call p2();
=E2=80=A6LOG:  statement: = do $$ begin raise notice 'txid at top level after "p1()" ...... %', = txid_current(); end $$;
=E2=80=A6LOG:  statement: = select n from t order by n;

Notice that there=E2=80=99s no visible =E2=80=9CBEGI= N=E2=80=9D between my first =E2=80=9Cdo" block and the =E2=80=9Ccall=E2=80= =9D. And (again) no visible =E2=80=9CCOMMIT=E2=80=9D after the =E2=80=9Cca= ll" finishes. But the txid values show that =E2=80=9Ccall=E2=80=9D did = indeed start a new txt, the =E2=80=9Crollback=E2=80=9D in the proc ended = it so that "set transaction isolation level=E2=80=9D in the proc can = (implicitly) start a new txn. And so on. All this is consistent with the = hypothesis that there is no such thing as a =E2=80=9Cnested = transaction=E2=80=9D. Rather, there=E2=80=99s just a series of = non-overlapping ordinary txns. The BLOG POST that I quoted with my = first post on this topic explains that this is intended.

This is consistent with the hypothesis that = AUTOCOMMIT is indeed a server-side phenomenon and that, during the = execution of a procedure, its usual effect is suspended=E2=80=94and is = resumed when the procedure execution ends.

I=E2=80=99ve said several times that my goal is to = set the isolation level from inside a proc so that the proc can own the = entire logic for concurrent txns that might violate a multi-row = data-rule.

And I=E2=80=99ve said = several times that I discovered that starting my proc with = =E2=80=9Crollback=E2=80=9D allows this=E2=80=94and that = I've
= --Apple-Mail=_761A7CF3-2DD3-4085-BC7B-E986D7B919BF Content-Disposition: attachment; filename=setup_for_test_4.sql Content-Type: application/octet-stream; x-unix-mode=0644; name="setup_for_test_4.sql" Content-Transfer-Encoding: quoted-printable --=20Using=20PostgreSQL=2011.2=20on=20macOS=20Mojave=20Version=2010.14.6=0D= =0A--=20At=20the=20o/s=20prompt:=0D=0A--=20psql=20-h=20127.0.0.1=20-p=20= 5432=20-d=20postgres=20-U=20postgres=20-f=20= txn_control_in_plpgsql_proc.sql=0D=0A--=20Can't=20re-direct=20to=20file=20= 'cos=20'raise=20notice'=20still=20comes=20to=20the=20screen.=0D=0A=0D=0A= \set=20AUTOCOMMIT=20on=0D=0Adrop=20table=20if=20exists=20t;=0D=0Acreate=20= table=20t(n=20integer);=0D=0A=0D=0Acreate=20or=20replace=20procedure=20= p2()=0D=0A=20=20language=20plpgsql=0D=0Aas=20$$=0D=0Abegin=0D=0A=20=20= raise=20notice=20'txid=20in=20"p2()"=20at=20start=20.............=20%',=20= txid_current();=0D=0A=20=20--=20This=20"rollback"=20is=20critical.=0D=0A=20= =20--=20Else=20"SET=20TRANSACTION=20ISOLATION=20LEVEL=20must=20be=20= called=20before=20any=20query".=0D=0A=20=20--=20Notice=20that=20= "txid_current()"=20seems=20to=20count=20as=20=20"query".=0D=0A=20=20= rollback;=0D=0A=0D=0A=20=20set=20transaction=20isolation=20level=20= repeatable=20read;=0D=0A=20=20declare=0D=0A=20=20=20=20levl=20= varchar(20)=20not=20null=20:=3D=20'?';=0D=0A=20=20begin=0D=0A=20=20=20=20= show=20transaction=20isolation=20level=20into=20levl;=0D=0A=20=20=20=20= raise=20notice=20'txid=20in=20"p2()"=20after=20"set=20txn".......=20%,=20= level=20=3D=20%',=20txid_current(),=20levl;=0D=0A=20=20end;=0D=0A=20=20= insert=20into=20t(n)=20values(17);=0D=0A=20=20rollback;=0D=0A=0D=0A=20=20= set=20transaction=20isolation=20level=20serializable;=0D=0A=20=20declare=0D= =0A=20=20=20=20levl=20varchar(20)=20not=20null=20:=3D=20'?';=0D=0A=20=20= begin=0D=0A=20=20=20=20show=20transaction=20isolation=20level=20into=20= levl;=0D=0A=20=20=20=20raise=20notice=20'txid=20in=20"p2()"=20after=20= "set=20txn".......=20%,=20level=20=3D=20%',=20txid_current(),=20levl;=0D=0A= =20=20end;=0D=0A=20=20insert=20into=20t(n)=20values(42);=0D=0A=20=20= commit;=0D=0Aend;=0D=0A$$;=0D=0A=0D=0A\echo=0D=0A\echo=20= ------------------------------------------------------------=0D=0A\echo=20= Test=20p2()=20with=20AUTOCOMMIT=20on.=20Works=20only=20in=20this=20mode.=0D= =0A\echo=20Else=20"ERROR:=20invalid=20transaction=20termination"=0D=0A= \echo=20from=20the=20first=20"rollback"=20statement.=0D=0A\echo=0D=0A= --Apple-Mail=_761A7CF3-2DD3-4085-BC7B-E986D7B919BF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
 found no other way to meet my = goal. I don=E2=80=99t understand, therefore, why some people (but not = you, Daniel!) who=E2=80=99ve responded to my questions say that starting = my proc with =E2=80=9Crollback=E2=80=9D is pointless.

I tried, earlier, to say =E2=80=9Ccase closed=E2=80=9D= . I=E2=80=99ll say it again now.

On 08-Aug-2019, at 06:53, Daniel Verite <daniel@manitou-mail.org> wrote:

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 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?

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,
-- =
Daniel V=C3=A9rit=C3=A9
PostgreSQL-powered = mailer: http://www.manitou-mail.org
Twitter: = @DanielVerite

= --Apple-Mail=_761A7CF3-2DD3-4085-BC7B-E986D7B919BF-- --Apple-Mail=_6053819D-955A-486A-BEA7-EAEBF3658D6E--