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 1pUFoY-0001Qj-K3 for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Feb 2023 23:43:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pUFoX-0000Od-5l for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Feb 2023 23:43:21 +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 1pUFoW-0000OM-EO for pgsql-bugs@lists.postgresql.org; Mon, 20 Feb 2023 23:43:20 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pUFoS-0000OM-Rx for pgsql-bugs@lists.postgresql.org; Mon, 20 Feb 2023 23:43:20 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 224243200B74; Mon, 20 Feb 2023 18:43:12 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 20 Feb 2023 18:43:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1676936591; x=1677022991; bh=iawQeL36hI 6fcT3SEwUn9OkGMLpwAwSsY925h+eDVlU=; b=Z0MFEuMxvMG9OmHPhoss6gZLX7 WUm3Z0uyBeQU8W8+4ztFLy00msTMvExjuAqqs4e8hkLB7vuALx7iE6zzNzTerQ6B 76JuSsG/dYU5bwa5q2KAzt0bFK8gt+1O+yga7M4vSDHvI5YWWanJClcY36pUm3wm HarL3RP0kFehqT4lp1GNYTjk7YjbY3uBs8oRx85exFmQNbPOCGBOqD0n+yZOmeVF vKUL5dNHsYsG664qDPpzgL5yNPaVJ0t4JwTrKWt/taF/+BPeWsL1S17qjzAXpZjI dvjxlSMesZ0aYveBYSKETb+AOjyH7DKLWXSP2oBz5X99JVvxGVl0AwORRMiw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1676936591; x=1677022991; bh=iawQeL36hI6fcT3SEwUn9OkGMLpw AwSsY925h+eDVlU=; b=mG9wnjPuTqTKVBPelgtbwXhXst+eSqjSH8+YiPA/WB1z taUvfqjKaU9NHliNFv6JXCsfc3mGfEbbBlsNZVPmJ8hYKCwPgHL5MhanpUPopt6D K1ZVBMf9xVzD/r5tSlr2UZzfhJR90DKskRGkSmyRg2V9EKsjOFWQKiFpVmut92FV G5LnCVQeDC8LvBywrxd70Mp8L6tQApgdsrReNJUkPCSnUZzCB+qP202+i5QNhJdW MdFSTjjCPrG9wmB63V+FDAmgFw0vgO3+MuLg0ZnLA5VlBmyfw4bwMPyprBwEqxyO 2i/qi07p5EOKsG5mAJ00IOwMLLIHWfdWzdVjy0Rb9w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudejiedgudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpeffhf fvvefukfhfgggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghq uhhivghruceomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvg hrnhepteelieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitg hhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 20 Feb 2023 18:43:10 -0500 (EST) Date: Tue, 21 Feb 2023 08:43:06 +0900 From: Michael Paquier To: Kyotaro Horiguchi Cc: sawada.mshk@gmail.com, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17789: process_pgfdw_appname() fails for autovacuum workers Message-ID: References: <17789-8b31c5a4672b74d9@postgresql.org> <20230214.140544.79456937383215325.horikyota.ntt@gmail.com> <20230215.161254.1131534874642120926.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7USJ4yJI6nSyAf+6" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --7USJ4yJI6nSyAf+6 Content-Type: multipart/mixed; boundary="wSY1d2+jKMQgbY43" Content-Disposition: inline --wSY1d2+jKMQgbY43 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Feb 20, 2023 at 04:59:25PM +0900, Michael Paquier wrote: > This has the advantage to be able to make the difference in both > cases, which could be important for the end-user depending on the > context where the code is run. In short, as of the attached, which is pretty close to the original patch. -- Michael --wSY1d2+jKMQgbY43 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pgfdw-appname-michael.patch" Content-Transfer-Encoding: quoted-printable diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c index 984e4d168a..a8040df07a 100644 --- a/contrib/postgres_fdw/option.c +++ b/contrib/postgres_fdw/option.c @@ -485,8 +485,6 @@ process_pgfdw_appname(const char *appname) const char *p; StringInfoData buf; =20 - Assert(MyProcPort !=3D NULL); - initStringInfo(&buf); =20 for (p =3D appname; *p !=3D '\0'; p++) @@ -522,13 +520,29 @@ process_pgfdw_appname(const char *appname) appendStringInfoString(&buf, cluster_name); break; case 'd': - appendStringInfoString(&buf, MyProcPort->database_name); + if (MyProcPort) + { + const char *dbname =3D MyProcPort->database_name; + + if (dbname) + appendStringInfoString(&buf, dbname); + else + appendStringInfoString(&buf, "[unknown]"); + } break; case 'p': appendStringInfo(&buf, "%d", MyProcPid); break; case 'u': - appendStringInfoString(&buf, MyProcPort->user_name); + if (MyProcPort) + { + const char *username =3D MyProcPort->user_name; + + if (username) + appendStringInfoString(&buf, username); + else + appendStringInfoChar(&buf, "[unknown]"); + } break; default: /* format error - ignore it */ --wSY1d2+jKMQgbY43-- --7USJ4yJI6nSyAf+6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmP0BYoACgkQnvQgOdby QH3+Hg/+KfRbN5foGu8if54nsw7soOJJaT1wTuSxcjPnPYmUAXfmeuSH8Xq/z0cJ qaWVXsnxoXFbJUFu1z58m/lzwFXE6E8KojMncwdGCWjEIDpDLu8BTNCZr6y4v8Ga tNMVjrRTEnySS/GSNKA7/P73pluFJ/PmOfBvfUq62Y/FFpGVip5Xq8sLIKHm/wvy C3vqu2plH3ai6HsAq3Hldzvn/+PC42kKBMliFS1qkZNYFHxAw8mcZtrhGcoFdXFF nX3xJfXugHCxT0xPzKjbw4ibFl8HXJiCDrbZfjk32O9PsPhIXd05fhEv/vIPOpe2 dV/rJTsudp6BZp0FOqMXx1BoEFfEID/Fa+UrqKwk+MVVpm1MRkqkWSERr21UVQCy LTbCrQSwBZ7dHj89jgvRd4qWPSitWmDQtLSwAITGwhJNIZnrgqpGKIHHje+SFv9l 2bdoiO4rVXOjOOjLRr5LQ3SDZ69IXAJULO+V6kvPGT0yvGiyjuTDlKjMNcGBGy6j mVW8JJYLlX40+puteXkDZunh+fSC869o/3xwV+MalvFs5QGCfi5AR87ipEBhG/sn tP5fe+YbQTWBHr8p6EAnXO0WJKe6GG/b9HkCKefFYQaAsDj3VUUMkg+QssuGCH7C yEFfTkV4dbkvxrHlHNv/LffHMXbaGQinh1Rb1YAgopq29RnYNR4= =LAGE -----END PGP SIGNATURE----- --7USJ4yJI6nSyAf+6--