pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: sawada.mshk@gmail.com
Cc: exclusion@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17789: process_pgfdw_appname() fails for autovacuum workers
Date: Tue, 21 Feb 2023 08:43:06 +0900
Message-ID: <Y/QFits/S6SHtMRL@paquier.xyz> (raw)
In-Reply-To: <Y/MoXUbuZty59gFj@paquier.xyz>
References: <17789-8b31c5a4672b74d9@postgresql.org>
	<20230214.140544.79456937383215325.horikyota.ntt@gmail.com>
	<CAD21AoArqZMZO71jPsO7HwtzKCykpW0Qvt3vSzjR+Qo0Gvx1bg@mail.gmail.com>
	<20230215.161254.1131534874642120926.horikyota.ntt@gmail.com>
	<Y/MoXUbuZty59gFj@paquier.xyz>

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

Attachments:

pgfdw-appname-michael.patch (text/x-diff, 1.2K) download 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; - Assert(MyProcPort != NULL); - initStringInfo(&buf); for (p = appname; *p != '\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 = 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 = MyProcPort->user_name; + + if (username) + appendStringInfoString(&buf, username); + else + appendStringInfoChar(&buf, "[unknown]"); + } break; default: /* format error - ignore it */
signature.asc (application/pgp-signature, 832B) download

view thread (11+ messages)  latest in thread

Message-ID: <Y/QFits/S6SHtMRL@paquier.xyz>
Permalink:  ../Y%2FQFits%2FS6SHtMRL@paquier.xyz/
Also on:    postgresql.org/message-id/Y/QFits/S6SHtMRL@paquier.xyz

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: michael@paquier.xyz, horikyota.ntt@gmail.com, sawada.mshk@gmail.com, exclusion@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17789: process_pgfdw_appname() fails for autovacuum workers
  In-Reply-To: <Y/QFits/S6SHtMRL@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox