1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-11 20:28:21 +03:00

postgres_fdw: Allow postgres_fdw.application_name to include escape sequences.

application_name that used when postgres_fdw establishes a connection to
a foreign server can be specified in either or both a connection parameter
of a server object and GUC postgres_fdw.application_name. This commit
allows those parameters to include escape sequences that begins with
% character. Then postgres_fdw replaces those escape sequences with
status information. For example, %d and %u are replaced with user name
and database name in local server, respectively. This feature enables us
to add information more easily to track remote transactions or queries,
into application_name of a remote connection.

Author: Hayato Kuroda
Reviewed-by: Kyotaro Horiguchi, Masahiro Ikeda, Hou Zhijie, Fujii Masao
Discussion: https://postgr.es/m/TYAPR01MB5866FAE71C66547C64616584F5EB9@TYAPR01MB5866.jpnprd01.prod.outlook.com
Discussion: https://postgr.es/m/TYCPR01MB5870D1E8B949DAF6D3B84E02F5F29@TYCPR01MB5870.jpnprd01.prod.outlook.com
This commit is contained in:
Fujii Masao
2021-12-24 16:55:11 +09:00
parent 94226d4506
commit 6e0cb3dec1
6 changed files with 218 additions and 1 deletions

View File

@ -10825,3 +10825,35 @@ ERROR: invalid value for integer option "batch_size": 100$%$#$#
ALTER FOREIGN DATA WRAPPER postgres_fdw OPTIONS (nonexistent 'fdw');
ERROR: invalid option "nonexistent"
HINT: There are no valid options in this context.
-- ===================================================================
-- test postgres_fdw.application_name GUC
-- ===================================================================
-- Close all the existing cached connections so that new connection
-- will be established with new setting of postgres_fdw.application_name.
SELECT 1 FROM postgres_fdw_disconnect_all();
?column?
----------
1
(1 row)
-- Add some escape sequences into postgres_fdw.application_name
-- so as to test that they are replaced with status information expectedly.
SET postgres_fdw.application_name TO '%a%u%d%p%%';
BEGIN;
SELECT 1 FROM ft6 LIMIT 1;
?column?
----------
1
(1 row)
SELECT count(*) FROM pg_stat_activity
WHERE application_name = current_setting('application_name') ||
CURRENT_USER || current_database() || pg_backend_pid() || '%';
count
-------
1
(1 row)
COMMIT;
--Clean up
RESET postgres_fdw.application_name;