Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDwCC-0003be-BA for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Feb 2014 13:19:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WDwCA-0008L9-QW for pgsql-bugs@arkaria.postgresql.org; Thu, 13 Feb 2014 13:19:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDwC0-00086O-3f for pgsql-bugs@postgresql.org; Thu, 13 Feb 2014 13:19:04 +0000 Received: from gauss.credativ.com ([93.94.130.89]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WDwBx-0000rF-EX for pgsql-bugs@postgresql.org; Thu, 13 Feb 2014 13:19:03 +0000 Received: from gauss.credativ.com (localhost [127.0.0.1]) by gauss.credativ.com (Postfix) with ESMTP id 2BA5DEE80E6; Thu, 13 Feb 2014 14:19:00 +0100 (CET) Received: from msgid.credativ.de (wan3.credativ.com [94.79.138.166]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: cbe@gauss.credativ.com) by gauss.credativ.com (Postfix) with ESMTPSA id CC719EE80E0; Thu, 13 Feb 2014 14:18:59 +0100 (CET) Date: Thu, 13 Feb 2014 14:18:58 +0100 From: Christoph Berg To: Tom Lane Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #9198: psql -c 'SET; ...' not working Message-ID: <20140213131858.GB25703@msgid.credativ.de> Mail-Followup-To: Christoph Berg , Tom Lane , pgsql-bugs@postgresql.org References: <20140212125626.2710.94912@wrigleys.postgresql.org> <25094.1392219652@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="neYutvxvOLaeuPCA" Content-Disposition: inline In-Reply-To: <25094.1392219652@sss.pgh.pa.us> User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --neYutvxvOLaeuPCA Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Re: Tom Lane 2014-02-12 <25094.1392219652@sss.pgh.pa.us> > The reason this isn't a bug is that a -c command string is sent to the > server as a single statement (PQexec call), and what "statement timeout" > controls is the total time for the whole thing. The SET operation can't > change the already-running timer for the current statement. It would > affect the timeout for the next statement ... but there won't be one. >=20 > Many people have complained that it's unintuitive that -c works this way > rather than breaking up the string into multiple submissions the same way > psql would do with normal input. We're afraid to change it for fear of > breaking applications, though. If you want behavior more like psql's > normal operation, consider >=20 > echo "SET statement_timeout =3D '3s'; SELECT pg_sleep(2)" | psql I think the docs don't really say that. The psql manpage says "single transaction", but the problem here is rather "single command". I see that "fixing" this would break the "one transaction" part, so it's going to stay that way, but I'd propose something like this doc update: *** a/doc/src/sgml/ref/psql-ref.sgml --- b/doc/src/sgml/ref/psql-ref.sgml *************** PostgreSQL documentation *** 100,106 **** string to divide it into multiple transactions. This is different from the behavior when the same string is fed to psql's standard input. Also, only ! the result of the last SQL command is returned. --- 100,111 ---- string to divide it into multiple transactions. This is different from the behavior when the same string is fed to psql's standard input. Also, only ! the result of the last SQL command is returned. SET ! commands that modify statement behavior will be ineffective because ! they are part of the already running statement. Most notably, ! psql -c 'SET statement_timeout =3D 0; SELECT ...' ! will not work as expected. (Use echo '...' | psql ! as above instead.) I'm actually unsure if there's more SETs that have this surprising behavior, if statement_timeout is the only one, psql(1) should mention that instead of what I wrote in the patch. Mit freundlichen Gr=FC=DFen, Christoph Berg --=20 Senior Berater, Tel.: +49 (0)21 61 / 46 43-187 credativ GmbH, HRB M=F6nchengladbach 12080, USt-ID-Nummer: DE204566209 Hohenzollernstr. 133, 41061 M=F6nchengladbach Gesch=E4ftsf=FChrung: Dr. Michael Meskes, J=F6rg Folz, Sascha Heuer pgp fingerprint: 5C48 FE61 57F4 9179 5970 87C6 4C5A 6BAB 12D2 A7AE --neYutvxvOLaeuPCA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJS/MZAAAoJEExaa6sS0qeuYSUP/jMq5R1n8FFUZWv1fa/mIHy3 IdHCUO1hyE6Ob/0UOZyMDysCdeOq1q4pAYLB8UdRx/JY+EydeGHLVZ9Z7giQdlXx Ch3YWIFmXczi5NSLQS+MPN8dbVJT4n9YdGqCtQgI8QXG3ABMgBGxQsZGIEm7BZtJ e41IVOkdKZ1v9Px/x+k88nZZVw6TKHVBOR3OKB2n9Hhz84G7LQgTf6mDRnMx+vFx bIbkXL8Z9BhQdxVhm58Q+xfqnb2wU9wYMVi10SuE7aWFCeTptYk5UOd0ZSj+ihDK 8NlnSauJ+EVN/OYnQfCbday37WKVa2dP3lZn0GKPrSOvu/KoV1kAxp3GMN12kMu3 gI9+tpDwqqDCZKY1phRmdliBB8v83fkdJgBbG6QQAexd/NPs+o0hOOgSSpzDh/6N HCslW6Vh+wZx3+UKFdrcXMnG0Xg+IK8T6Zl1OitMLgkWzlPDsHfJmTTyV9eIYqxH FUIwBFEfoVzFbE2lwe+GGnkEpdNk3JWAaTN6abUzcQTBmI1LCO2S9eWnUo4EUfGx MYzGPSwCS0SR3gWtaCQ0liFsqN4RfoHw1qGobnV4Y11CiYFHrqgKUQcVB4J0enSJ M0jO1BhL5fo1BtFKIRXDupBUevEF9F+GhArwlqVwzS8Cvj268Lazra22e1Kp8vGj RDK1sXQk3n4orbJ7TOLG =7OsH -----END PGP SIGNATURE----- --neYutvxvOLaeuPCA--