[postgres_fdw] add local pid to fallback_application_name - Mailing list pgsql-hackers

From kuroda.hayato@fujitsu.com
Subject [postgres_fdw] add local pid to fallback_application_name
Date
Msg-id TYAPR01MB5866FAE71C66547C64616584F5EB9@TYAPR01MB5866.jpnprd01.prod.outlook.com
Whole thread Raw
Responses Re: [postgres_fdw] add local pid to fallback_application_name  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi Hackers,

I propose adding trackable information in postgres_fdw, in order to track remote query correctly.

## Background and motivation

Currently postgres_fdw connects remote servers by using connect_pg_server(). However the function just calls
PQconnectdbParams()with fallback_application_name = "postgres_fdw." 
Therefore, if two or more servers connect to one data server and two queries arrive at the data server, the database
administratorcannot determine which queries came from which server. 
This problem prevents some workload analysis because it cannot track the flow of queries.

## Implementation

I just added local backend's pid to fallback_application_name. This is the key for seaching and matching two logs.
In order to use the feature and track remote transactions, user must add backend-pid and application_name to
log_line_prefix,like 

```
log_line_prefix = '%m [%p] [%a] '
```

Here is the output example. Assume that remote server has a table "foo," and local server imports the schema.
When local server executes foregin scan, the following line was output in the local's logfile.

```
2021-07-29 03:18:50.630 UTC [21572] [psql] LOG:  duration: 23.366 ms  statement: select * from foo;
```

And in the remote's one, the following lines were appered.

```
2021-07-29 03:18:50.628 UTC [21573] [postgres_fdw for remote PID: 21572] LOG:  duration: 0.615 ms  parse <unnamed>:
DECLAREc1 CURSOR FOR 
        SELECT id FROM public.foo
```

Two lines have same pid, so we can track the log and analyze workloads correctly.
I will write docs later, but now I want you to review the motivation and implementation.

Best Regards,
Hayato Kuroda
FUJITSU LIMITED


Attachment

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Skipping logical replication transactions on subscriber side
Next
From: Kyotaro Horiguchi
Date:
Subject: Re: pg_receivewal starting position