diff options
Diffstat (limited to 'contrib/postgres_fdw/connection.c')
-rw-r--r-- | contrib/postgres_fdw/connection.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c index 6bac4ad23eb..80db19e401c 100644 --- a/contrib/postgres_fdw/connection.c +++ b/contrib/postgres_fdw/connection.c @@ -348,6 +348,7 @@ connect_pg_server(ForeignServer *server, UserMapping *user) { const char **keywords; const char **values; + char *appname = NULL; int n; /* @@ -383,6 +384,39 @@ connect_pg_server(ForeignServer *server, UserMapping *user) n++; } + /* + * Search the parameter arrays to find application_name setting, and + * replace escape sequences in it with status information if found. + * The arrays are searched backwards because the last value is used if + * application_name is repeatedly set. + */ + for (int i = n - 1; i >= 0; i--) + { + if (strcmp(keywords[i], "application_name") == 0 && + *(values[i]) != '\0') + { + /* + * Use this application_name setting if it's not empty string + * even after any escape sequences in it are replaced. + */ + appname = process_pgfdw_appname(values[i]); + if (appname[0] != '\0') + { + values[i] = appname; + break; + } + + /* + * This empty application_name is not used, so we set + * values[i] to NULL and keep searching the array to find the + * next one. + */ + values[i] = NULL; + pfree(appname); + appname = NULL; + } + } + /* Use "postgres_fdw" as fallback_application_name */ keywords[n] = "fallback_application_name"; values[n] = "postgres_fdw"; @@ -452,6 +486,8 @@ connect_pg_server(ForeignServer *server, UserMapping *user) /* Prepare new session for use */ configure_remote_session(conn); + if (appname != NULL) + pfree(appname); pfree(keywords); pfree(values); } |