Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp>, Bruce Momjian <bruce(at)momjian(dot)us>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17434: CREATE/DROP DATABASE can be executed in the same transaction with other commands
Date: 2022-07-28 16:13:05
Message-ID: CAKFQuwaQ-ho0PUyo=H7sfidrhS45-=S5FBbiqewLOZ3oVedGtw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Wed, Jul 27, 2022 at 7:50 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Yugo NAGATA <nagata(at)sraoss(dot)co(dot)jp> writes:
> > I've looked at the commited fix. What I wonder is whether a change in
> > IsInTransactionBlock() is necessary or not.
>
> > In fact, the result of IsInTransactionBlock does not make senses at
> > all in pipe-line mode regardless to the fix. ANALYZE could commit all
> > previous commands in pipelining, and this may not be user expected
> > behaviour.
>
> This seems pretty much isomorphic to the fact that CREATE DATABASE
> will commit preceding steps in the pipeline. That's not great,
> I admit; we'd not have designed it like that if we'd had complete
> understanding of the behavior at the beginning. But it's acted
> like that for a couple of decades now, so changing it seems far
> more likely to make people unhappy than happy. The same for
> ANALYZE in a pipeline.
>
>
I agreed to leaving the description of CREATE DATABASE simplified by not
introducing the idea of implicit transactions or, equivalently,
"autocommit".

Just tossing out there that we should acknowledge that our wording in the
BEGIN Reference should remain status quo based upon the same reasoning.

"By default (without BEGIN), PostgreSQL executes transactions in
“autocommit” mode, that is, each statement is executed in its own
transaction and a commit is implicitly performed at the end of the
statement (if execution was successful, otherwise a rollback is done)."

https://www.postgresql.org/docs/current/sql-begin.html

Maybe write instead:

"By default (without BEGIN), PostgreSQL creates transactions based upon the
underlying messages passed between the client and server. Typically this
means each statement ends up having its own transaction. In any case,
statements that must not execute in a transaction (like CREATE DATABASE)
must use the default, and will always cause a commit or rollback to happen
upon completion."

It feels a bit out-of-place, maybe if the content scope is acceptable we
can work it better into the Tutorial-Advanced Features-Transaction section
and just replace the existing sentence with a link to there?

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2022-07-28 16:40:06 BUG #17560: Planner can not find plan with lowest cost
Previous Message Andres Freund 2022-07-28 09:52:04 Re: xmin of slot is not moving | hot standby feedback sending old xmin.

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2022-07-28 16:19:56 Re: [PATCH] Log details for client certificate failures
Previous Message Melih Mutlu 2022-07-28 16:02:43 Re: [PATCH] Reuse Workers and Replication Slots during Logical Replication