Re: Allow escape in application_name
Fujii Masao <masao.fujii@oss.nttdata.com>
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: "kuroda.hayato@fujitsu.com" <kuroda.hayato@fujitsu.com>,
'Kyotaro Horiguchi' <horikyota.ntt@gmail.com>
Cc: "ikedamsh@oss.nttdata.com" <ikedamsh@oss.nttdata.com>,
"pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>,
"tgl@sss.pgh.pa.us" <tgl@sss.pgh.pa.us>
Date: 2021-09-09T07:11:50Z
Lists: pgsql-hackers
On 2021/09/08 21:32, kuroda.hayato@fujitsu.com wrote:
> Dear Horiguchi-san,
>
> Thank you for reviewing! I attached the fixed version.
Thanks for updating the patch!
+ for (i = n - 1; i >= 0; i--)
+ {
+ if (strcmp(keywords[i], "application_name") == 0)
+ {
+ parse_pgfdw_appname(&buf, values[i]);
+ values[i] = buf.data;
+ break;
+ }
postgres_fdw gets out of the loop after processing appname even
when buf.data is '\0'. Is this expected behavior? Because of this,
when postgres_fdw.application_name = '%b', unprocessed appname
of the server object is used.
+CREATE FUNCTION for_escapes() RETURNS bool AS $$
+ DECLARE
+ appname text;
+ c bool;
+ BEGIN
+ SHOW application_name INTO appname;
+ EXECUTE 'SELECT COUNT(*) FROM pg_stat_activity WHERE application_name LIKE '''
Could you tell me why the statement checking
application_name should be wrapped in a function?
Instead, we can just execute something like the following?
SELECT COUNT(*) FROM pg_stat_activity WHERE application_name = current_setting('application_name') || current_user || current_database() || pg_backend_pid() || '%';
+ char *endptr = NULL;
+ padding = (int)strtol(p, &endptr, 10);
strtol() seems to work differently from process_log_prefix_padding(),
for example, when the input string is "%-p".
+ case 'a':
+ {
+ const char *appname = application_name;
When log_line_prefix() processes "%a", "%u" or "%d" characters in
log_line_prefix, it checks whether MyProcPort is NULL or not.
Likewise shouldn't parse_pgfdw_appname() do the same thing?
For now it's ok not to check that because only process having
MyProcPort can use postgres_fdw. But in the future the process
not having that may use postgres_fdw, for example, 2PC resolver
process that Sawada-san is proposing to add to support automatic
2PC among multiple remote servers.
+ You can use escape sequences for <literal>application_name</literal> even if
+ it is set as a connection or a user mapping option.
+ Please refer the later section.
I was thinking that application_name cannot be set in a user mapping.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Commits
-
postgres_fdw: Add regression test for postgres_fdw.application_name GUC.
- 353aa01687b5 15.0 landed
-
postgres_fdw: Allow postgres_fdw.application_name to include escape sequences.
- 6e0cb3dec10e 15.0 landed
-
doc: Add note about postgres_fdw.application_name.
- 58e2e6eb67fe 15.0 landed
-
postgres_fdw: Revert unstable tests for postgres_fdw.application_name.
- 98dbef90eb29 15.0 landed
-
postgres_fdw: Allow application_name of remote connection to be set via GUC.
- 449ab6350526 15.0 landed