public inbox for [email protected]  
help / color / mirror / Atom feed
From: Fujii Masao <[email protected]>
To: [email protected] <[email protected]>
To: Kyotaro Horiguchi <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Support escape sequence for cluster_name in postgres_fdw.application_name
Date: Mon, 7 Feb 2022 23:03:56 +0900
Message-ID: <[email protected]> (raw)
In-Reply-To: <OS0PR01MB5682DB788FD7EAD3BDBC36F182229@OS0PR01MB5682.jpnprd01.prod.outlook.com>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<OS0PR01MB5682DB788FD7EAD3BDBC36F182229@OS0PR01MB5682.jpnprd01.prod.outlook.com>



On 2022/01/28 14:07, [email protected] wrote:
> I think %c of log_line_prefix (Session ID) is also useful for postgres_fdw.application_name.
> Therefore, how about adding both %c (Session ID) and %C (cluster_name)?

+1

Attached is the updated version of the patch. It adds those escape sequences %c and %C.

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index fc3ce6a53a..af38e956e7 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -489,6 +489,12 @@ process_pgfdw_appname(const char *appname)
 			case 'a':
 				appendStringInfoString(&buf, application_name);
 				break;
+			case 'c':
+				appendStringInfo(&buf, "%lx.%x", (long) (MyStartTime), MyProcPid);
+				break;
+			case 'C':
+				appendStringInfoString(&buf, cluster_name);
+				break;
 			case 'd':
 				appendStringInfoString(&buf, MyProcPort->database_name);
 				break;
diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml
index 2bb31f1125..17cd90ab12 100644
--- a/doc/src/sgml/postgres-fdw.sgml
+++ b/doc/src/sgml/postgres-fdw.sgml
@@ -983,6 +983,20 @@ postgres=# SELECT postgres_fdw_disconnect_all();
          <entry><literal>%a</literal></entry>
          <entry>Application name on local server</entry>
         </row>
+        <row>
+         <entry><literal>%c</literal></entry>
+         <entry>
+          Session ID on local server
+          (see <xref linkend="guc-log-line-prefix"/> for details)
+         </entry>
+        </row>
+        <row>
+         <entry><literal>%C</literal></entry>
+         <entry>
+          Cluster name in local server
+          (see <xref linkend="guc-cluster-name"/> for details)
+         </entry>
+        </row>
         <row>
          <entry><literal>%u</literal></entry>
          <entry>User name on local server</entry>
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 6bb81707b0..f1bfe79feb 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -271,7 +271,7 @@ extern int	temp_file_limit;
 
 extern int	num_temp_buffers;
 
-extern char *cluster_name;
+extern PGDLLIMPORT char *cluster_name;
 extern PGDLLIMPORT char *ConfigFileName;
 extern char *HbaFileName;
 extern char *IdentFileName;


Attachments:

  [text/plain] pgfdw_appname_cluster_name_v2.patch (1.9K, ../[email protected]/2-pgfdw_appname_cluster_name_v2.patch)
  download | inline diff:
diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index fc3ce6a53a..af38e956e7 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -489,6 +489,12 @@ process_pgfdw_appname(const char *appname)
 			case 'a':
 				appendStringInfoString(&buf, application_name);
 				break;
+			case 'c':
+				appendStringInfo(&buf, "%lx.%x", (long) (MyStartTime), MyProcPid);
+				break;
+			case 'C':
+				appendStringInfoString(&buf, cluster_name);
+				break;
 			case 'd':
 				appendStringInfoString(&buf, MyProcPort->database_name);
 				break;
diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml
index 2bb31f1125..17cd90ab12 100644
--- a/doc/src/sgml/postgres-fdw.sgml
+++ b/doc/src/sgml/postgres-fdw.sgml
@@ -983,6 +983,20 @@ postgres=# SELECT postgres_fdw_disconnect_all();
          <entry><literal>%a</literal></entry>
          <entry>Application name on local server</entry>
         </row>
+        <row>
+         <entry><literal>%c</literal></entry>
+         <entry>
+          Session ID on local server
+          (see <xref linkend="guc-log-line-prefix"/> for details)
+         </entry>
+        </row>
+        <row>
+         <entry><literal>%C</literal></entry>
+         <entry>
+          Cluster name in local server
+          (see <xref linkend="guc-cluster-name"/> for details)
+         </entry>
+        </row>
         <row>
          <entry><literal>%u</literal></entry>
          <entry>User name on local server</entry>
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 6bb81707b0..f1bfe79feb 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -271,7 +271,7 @@ extern int	temp_file_limit;
 
 extern int	num_temp_buffers;
 
-extern char *cluster_name;
+extern PGDLLIMPORT char *cluster_name;
 extern PGDLLIMPORT char *ConfigFileName;
 extern char *HbaFileName;
 extern char *IdentFileName;


view thread (6+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Support escape sequence for cluster_name in postgres_fdw.application_name
  In-Reply-To: <[email protected]>

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

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