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 1hEQ3h-0003B8-AZ for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Apr 2019 03:07:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hEQ3f-0007EW-SU for pgsql-bugs@arkaria.postgresql.org; Thu, 11 Apr 2019 03:07:23 +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 1hEQ3f-0007DS-LD for pgsql-bugs@lists.postgresql.org; Thu, 11 Apr 2019 03:07:23 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hEQ3b-0007YC-TL for pgsql-bugs@lists.postgresql.org; Thu, 11 Apr 2019 03:07:23 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6230720E18; Wed, 10 Apr 2019 23:07:18 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 10 Apr 2019 23:07:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=1iNyW2we0Tut/csQxjIePggO30n N5kuvgwIFvmaL5H0=; b=AuYTwt62qRHb6uwX2qQgIreND8pEFjvRxbGRFNbO7bg LPMepckgNml1or2K28g4tw3lHT+t8SrW9YRP+qWa7lC2Dnd3RpnA4a5BM7npWZsP E4nrPLRydjzI4LlJyl69H3A80R8uolxTzUbsVMri9SkN6D6FkmWkurR/TaHJfU/Y r+TUhB/oI9xjQB5eUoFWAdxQ5AX4P5qktxAJC7BxefKQA/1hyUCLH7kXutHwBgOS rCmHbElUds+l9dBhvg6Xx5xgNzAp2SbsEMBe1sGiut4iiE4tUik+2xPGzmHHMm7O xbnyePIMACtSLZU3c9n3RTGHdIJFTl2ky79EPTlJEsQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=1iNyW2 we0Tut/csQxjIePggO30nN5kuvgwIFvmaL5H0=; b=S8S2mSBv5UHDm4EBDYG9rW hlmiv7invU6XviF3087FlbjzAT19DyCR87kVtA23WDrLzazuWNSLp8yrliVcX5YK smmWMaw91nVsmG7AYHJvr7AKyXWQ0zMQmTiWEx+y8YgL5kkkllTypEHB3bq/zny/ VIaG5zAZhqCUIhVzem3BFUoLYKTHlA1ksCZaOxfVTZr9aMV7dz/VfI3KqR6v92+t sz172vIEQTjh8R8/JgzSKO3cPbSKDd7u/CZhhHdE2Vn/WKi2oBh4TpVrSDqDiv3g Q99wKCw4uPo7mf+cKpdqTrSam0zwZ0PTxYHTBAWHLlmNZ82HI2LN6Bl+BUF617CQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrudekgdeiudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfg hrlhcuvffnffculdejtddmnecujfgurhepfffhvffukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecukfhppeduuddurddutddvrddukedtrddukeehnecurfgrrhgr mhepmhgrihhlfhhrohhmpehmihgthhgrvghlsehprghquhhivghrrdighiiinecuvehluh hsthgvrhfuihiivgeptd X-ME-Proxy: Received: from paquier.xyz (ee0822lan1.rev.em-net.ne.jp [111.102.180.185]) by mail.messagingengine.com (Postfix) with ESMTPA id 72F101030F; Wed, 10 Apr 2019 23:07:16 -0400 (EDT) Date: Thu, 11 Apr 2019 12:07:12 +0900 From: Michael Paquier To: Alvaro Herrera Cc: cyberdemn@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15734: Walsender process crashing when executing SHOW ALL; Message-ID: <20190411030712.GH2728@paquier.xyz> References: <20190410060427.GB2728@paquier.xyz> <20190410150121.GA26340@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mFHiwr52TKrxpkjc" Content-Disposition: inline In-Reply-To: <20190410150121.GA26340@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --mFHiwr52TKrxpkjc Content-Type: multipart/mixed; boundary="MPkR1dXiUZqK+927" Content-Disposition: inline --MPkR1dXiUZqK+927 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 10, 2019 at 11:01:21AM -0400, Alvaro Herrera wrote: > I think we should have a few tests issuing SHOW ALL in a replication > connection with various levels of privilege; it's annoying that this bug > took two years to find. With that, special-purpose buildfarm members > would tell us if we've made some mistake in transaction handling or > whatever. What do you think about the set attached? I prefer that we use psql(on_error_die => 1) so as in the case of a crash or an error the test dies hard and fast. In consequence, I have granted pg_read_all_settings to the replication user to ensure that no errors happen, still the syscache lookup is done. We could have negative tests but I don't think that's worth the addition as we already have tests for pg_read_all_settings in src/test/regress/. If I remove the patched patch from walsender.c, the test fails immediately. -- Michael --MPkR1dXiUZqK+927 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="wal-sender-show-v2.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/replication/walsender.c b/src/backend/replication/= walsender.c index aae6adc15c..440b6aac4b 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1552,7 +1552,10 @@ exec_replication_command(const char *cmd_string) DestReceiver *dest =3D CreateDestReceiver(DestRemoteSimple); VariableShowStmt *n =3D (VariableShowStmt *) cmd_node; =20 + /* syscache access needs a transaction environment */ + StartTransactionCommand(); GetPGVariable(n->name, dest); + CommitTransactionCommand(); } break; =20 diff --git a/src/test/recovery/t/001_stream_rep.pl b/src/test/recovery/t/00= 1_stream_rep.pl index beb45551a2..e866db3581 100644 --- a/src/test/recovery/t/001_stream_rep.pl +++ b/src/test/recovery/t/001_stream_rep.pl @@ -3,7 +3,7 @@ use strict; use warnings; use PostgresNode; use TestLib; -use Test::More tests =3D> 26; +use Test::More tests =3D> 32; =20 # Initialize master node my $node_master =3D get_new_node('master'); @@ -117,6 +117,55 @@ test_target_session_attrs($node_master, $node_standby_= 1, $node_master, "any", test_target_session_attrs($node_standby_1, $node_master, $node_standby_1, "any", 0); =20 +# Test for SHOW commands using a WAL sender connection with a replication +# role. +note "testing SHOW commands for replication connection"; + +$node_master->psql('postgres'," +CREATE ROLE repl_role REPLICATION LOGIN; +GRANT pg_read_all_settings TO repl_role;"); +my $master_host =3D $node_master->host; +my $master_port =3D $node_master->port; +my $connstr_common =3D "host=3D$master_host port=3D$master_port user=3Drep= l_role"; +my $connstr_rep =3D "$connstr_common replication=3D1"; +my $connstr_db =3D "$connstr_common replication=3Ddatabase dbname=3Dpostgr= es"; + +# Test SHOW ALL +my ($ret, $stdout, $stderr) =3D + $node_master->psql('postgres', 'SHOW ALL;', + on_error_die =3D> 1, + extra_params =3D> [ '-d', $connstr_rep ]); +ok($ret =3D=3D 0, "SHOW ALL with replication role and physical replication= "); +($ret, $stdout, $stderr) =3D + $node_master->psql('postgres', 'SHOW ALL;', + on_error_die =3D> 1, + extra_params =3D> [ '-d', $connstr_db ]); +ok($ret =3D=3D 0, "SHOW ALL with replication role and logical replication"= ); + +# Test SHOW with a user-settable parameter +($ret, $stdout, $stderr) =3D + $node_master->psql('postgres', 'SHOW work_mem;', + on_error_die =3D> 1, + extra_params =3D> [ '-d', $connstr_rep ]); +ok($ret =3D=3D 0, "SHOW with user-settable parameter, replication role and= physical replication"); +($ret, $stdout, $stderr) =3D + $node_master->psql('postgres', 'SHOW work_mem;', + on_error_die =3D> 1, + extra_params =3D> [ '-d', $connstr_db ]); +ok($ret =3D=3D 0, "SHOW with user-settable parameter, replication role and= logical replication"); + +# Test SHOW with a superuser-settable parameter +($ret, $stdout, $stderr) =3D + $node_master->psql('postgres', 'SHOW primary_conninfo;', + on_error_die =3D> 1, + extra_params =3D> [ '-d', $connstr_rep ]); +ok($ret =3D=3D 0, "SHOW with superuser-settable parameter, replication rol= e and physical replication"); +($ret, $stdout, $stderr) =3D + $node_master->psql('postgres', 'SHOW primary_conninfo;', + on_error_die =3D> 1, + extra_params =3D> [ '-d', $connstr_db ]); +ok($ret =3D=3D 0, "SHOW with superuser-settable parameter, replication rol= e and logical replication"); + note "switching to physical replication slot"; =20 # Switch to using a physical replication slot. We can do this without a new --MPkR1dXiUZqK+927-- --mFHiwr52TKrxpkjc Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAlyur2AACgkQnvQgOdby QH0JTA/+KxHeINE2IGHtzGsgFBXQBFEU0ojhwvY2f+/Oe177BewM0lhr27vLzVSu kYw3d022AByFjydJXY4YvxPVod+IDDafK+uhKQVQbaWdUqrZwlyA0YckSOgMVWF2 HiWGokDfu6icM4SVLpNSjnzN+jw3VOiklWrQG4tRo8ilsZWBYiXWBqlRc5Xm3IbQ D7mZyw5IPFHhHtLyZtnj2zCvEU6KII3vMMDBi90zCr0gFAP0FRIoz3Wqt87HfOL+ H+FWs5PwuYSac4FwDWaLAsauCBdRUYLlIVjuhnwjUt201GBhQER+Vu0Dxx9L7UFo N44Wjz7LROYcm3TFht4kcvL9SakkRGVqg8cUbOUwSF1yL5ORhflmXXFU9Sj7yyCp 5USGP3DTzaZFSgoC2E3I19pGimUBkUDnemVai+Cuf/9VidzJKuTfyeIh8LJOT1Aw b8zMJV+2lpjr410XH/JVR6G9HQ/JA/G5zwEVFu1coYHLgC90YnRPiRARt6fvxo3u POX/fpPCnc+a3rfGugjf8P6VOpAERNFk1UJaRvXebkVAjLalXWxPLmKi0ZdLO17b BP1x1t0nyRu1nSDo3tF81o+MivRwxO/+n/tqeLNtvdrAEOBWhnwI+mYYobIxyF32 L5fusibjoOQkfaIvFFO+E4p9VjgQUQ5ctqUo7JHOTCoTpHA64v8= =cthZ -----END PGP SIGNATURE----- --mFHiwr52TKrxpkjc--