作者
digoal
日期
2022-02-21
标签
PostgreSQL , postgres_fdw , application_name
postgres_fdw application_name 提供更多通配符的支持. session ID (%c) and cluster name (%C) 可以更方便的对外部表会话进行管理.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=94c49d53402240ad7ddbcae9049ff2840a54b9c6
postgres_fdw: Make postgres_fdw.application_name support more escape sequences.
author Fujii Masao <fujii@postgresql.org>
Fri, 18 Feb 2022 02:38:12 +0000 (11:38 +0900)
committer Fujii Masao <fujii@postgresql.org>
Fri, 18 Feb 2022 02:38:12 +0000 (11:38 +0900)
commit 94c49d53402240ad7ddbcae9049ff2840a54b9c6
tree bff534c8386626a4278a2dd9ac743ae3a50dc351 tree
parent c476f380e296bab57fecada1ea96c86d575bf160 commit | diff
postgres_fdw: Make postgres_fdw.application_name support more escape sequences.
Commit 6e0cb3dec1 allowed postgres_fdw.application_name to include
escape sequences %a (application name), %d (database name), %u (user name)
and %p (pid). In addition to them, this commit makes it support
the escape sequences for session ID (%c) and cluster name (%C).
These are helpful to investigate where each remote transactions came from.
Author: Fujii Masao
Reviewed-by: Ryohei Takahashi, Kyotaro Horiguchi
Discussion: https://postgr.es/m/1041dc9a-c976-049f-9f14-e7d94c29c4b2@oss.nttdata.com
+ <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>
+-- Test %c (session ID) and %C (cluster name) escape sequences.
+SET postgres_fdw.application_name TO 'fdw_%C%c';
+SELECT 1 FROM ft6 LIMIT 1;
+ ?column?
+----------
+ 1
+(1 row)
+
+SELECT pg_terminate_backend(pid, 180000) FROM pg_stat_activity
+ WHERE application_name =
+ substring('fdw_' || current_setting('cluster_name') ||
+ to_hex(trunc(EXTRACT(EPOCH FROM (SELECT backend_start FROM
+ pg_stat_get_activity(pg_backend_pid()))))::integer) || '.' ||
+ to_hex(pg_backend_pid())
+ for current_setting('max_identifier_length')::int);
+ pg_terminate_backend
+----------------------
+ t
+(1 row)
+
https://www.postgresql.org/docs/devel/postgres-fdw.html#id-1.11.7.45.11
| Escape | Effect |
|---|---|
| %a | Application name on local server |
| %c | Session ID on local server (see log_line_prefix for details) |
| %C | Cluster name in local server (see cluster_name for details) |
| %u | User name on local server |
| %d | Database name on local server |
| %p | Process ID of backend on local server |
| %% | Literal % |
期望 PostgreSQL 增加什么功能?
PolarDB for PostgreSQL云原生分布式开源数据库
PostgreSQL 解决方案集合
德哥 / digoal's github - 公益是一辈子的事.

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




