Re: Allow escape in application_name

Поиск
Список
Период
Сортировка
От Fujii Masao
Тема Re: Allow escape in application_name
Дата
Msg-id b968b216-14ae-9b5f-98e9-5ac4b27dd566@oss.nttdata.com
обсуждение исходный текст
Ответ на RE: Allow escape in application_name  ("kuroda.hayato@fujitsu.com" <kuroda.hayato@fujitsu.com>)
Ответы RE: Allow escape in application_name  ("kuroda.hayato@fujitsu.com" <kuroda.hayato@fujitsu.com>)
Список 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



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Amit Kapila
Дата:
Сообщение: Re: Added schema level support for publication.
Следующее
От: "Drouvot, Bertrand"
Дата:
Сообщение: Re: Minimal logical decoding on standbys