Allow escape in application_name (was: [postgres_fdw] add local pid to fallback_application_name)

From: "kuroda(dot)hayato(at)fujitsu(dot)com" <kuroda(dot)hayato(at)fujitsu(dot)com>
To: "kuroda(dot)hayato(at)fujitsu(dot)com" <kuroda(dot)hayato(at)fujitsu(dot)com>, 'Tom Lane' <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "'pgsql-hackers(at)lists(dot)postgresql(dot)org'" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Allow escape in application_name (was: [postgres_fdw] add local pid to fallback_application_name)
Date: 2021-08-05 03:18:58
Message-ID: TYCPR01MB5870D1E8B949DAF6D3B84E02F5F29@TYCPR01MB5870.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dear Hackers, Tom,

(I changed subject because this is no longer postgres_fdw's patch)

> > What would be better to think about is how to let users specify this
> > kind of behavior for themselves. I think it's possible to set
> > application_name as part of a foreign server's connection options,
> > but at present the result would only be a constant string. Somebody
> > who wished the PID to be in there would like to have some sort of
> > formatting escape, say "%p" for PID. Extrapolating wildly, maybe we
> > could make all the %-codes known to log_line_prefix available here.
>
> I think your argument is better than mine. I will try to implement this approach.

I made a patch based on your advice. I add parse and rewrite function in connectOptions2().
I implemented in libpq layer, hence any other application can be used.
Here is an example:

```
$ env PGAPPNAME=000%p%utest000 psql -d postgres -c "show application_name"
application_name
-----------------------
00025632hayatotest000
(1 row)
```

> > I don't think this is a great idea as-is. People who need to do this
> > sort of thing will all have their own ideas of what they need to track
> > --- most obviously, it might be appropriate to include the originating
> > server's name, else you don't know what machine the PID is for.
>
> I thought this is not big problem because hostname (or IP address) can be
> added to log_line_prefix. I added only local-pid because this is the only thing
> that cannot be set in the parameter.

Currently network hostname (or IP address) cannot be set because of the above reason.
Some backends' code must be modified if we want to get and embed such information.
Of cause we can get system hostname by gethostname(), but I cannot judge whether
it is meaningful.

How do you think?

Best Regards,
Hayato Kuroda
FUJITSU LIMITED

Attachment Content-Type Size
allow_escape_in_allication_name.patch application/octet-stream 6.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Yugo NAGATA 2021-08-05 03:29:59 Re: Implementing Incremental View Maintenance
Previous Message Dian M Fay 2021-08-05 02:38:24 Re: [PATCH] postgres_fdw: suppress explicit casts in text:text comparisons (was: column option to override foreign types)