Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lc98R-0006fp-Pk for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Apr 2021 16:03:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lc98P-0001wZ-Hz for pgsql-bugs@arkaria.postgresql.org; Thu, 29 Apr 2021 16:03:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lc98P-0001wS-B6 for pgsql-bugs@lists.postgresql.org; Thu, 29 Apr 2021 16:03:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lc98I-0000ec-9Q for pgsql-bugs@lists.postgresql.org; Thu, 29 Apr 2021 16:03:24 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 13TG3FPH3044773; Thu, 29 Apr 2021 12:03:15 -0400 From: Tom Lane To: mike.adelson314@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16988: Spurious "SET LOCAL can only be used in transaction blocks" warning using implicit transaction block In-reply-to: <16988-58edba102adb5128@postgresql.org> References: <16988-58edba102adb5128@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Thu, 29 Apr 2021 10:49:15 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3044771.1619712195.1@sss.pgh.pa.us> Date: Thu, 29 Apr 2021 12:03:15 -0400 Message-ID: <3044772.1619712195@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > I am using SET LOCAL in an Npgsql multi-statement command. It behaves as I > expect: the scope extends to the end of the implicit transaction block for > that command. However, each time I do this, I get a WARNING log in the > Postgres log file: "WARNING: SET LOCAL can only be used in transaction > blocks". This results in a lot of log file "spam". > Having followed up with the Npgsql team > (https://github.com/npgsql/npgsql/issues/3688), it seems like SET LOCAL is > behaving exactly as expected but we don't understand why the warning is > triggering. Hm, this seems to work as expected in psql: regression=# set local work_mem = 100; show work_mem; WARNING: SET LOCAL can only be used in transaction blocks SET work_mem ---------- 4MB (1 row) regression=# set local work_mem = 100\; show work_mem; work_mem ---------- 100kB (1 row) (The backslash prevents psql from treating the first semicolon as a command separator, so that it'll send both commands in one PQexec.) It seems that whatever Npgsql is doing at the wire protocol level doesn't match this, but they'd have to explain what they are doing for us to offer much help. You could perhaps investigate for yourself by setting "log_statement = all" and then seeing how the log trace for the Npgsql fragment differs from doing the same things in psql. regards, tom lane