DataDog/pg_tracing

measuring network time in pg tracing

Closed this issue · 2 comments

Hi,

pg_tracing is a great work. I'm just wondering is it possible to record the span for network transmission between the psql client and database server because the network can be a bottleneck in some cases.

Hi!

is it possible to record the span for network transmission between the psql client and database server

If you're talking about the time between sending a query and receiving it on the server, that information is not directly available. From pg_tracing's point of view, the earliest time available is the statement start which is set when a message is processed. In normal conditions, this is basically the time the message is received by PostgreSQL.

If you have tracing on the client, you can use the time between the client's span (in blue in the screenshots) and pg_tracing's first span to have the time between the query being sent and the query being processed by the server. It's not necessarily only network time as you could have connection pooler between the client and server or the PostgreSQL server could be overloaded and took more time to process the query.

Screenshot 2024-09-04 at 08 27 58

If you're thinking of the time needed to data to the client, that's also hard to get but you can deduce it.

Screenshot 2024-09-04 at 08 34 15

In this example, the client's span ends on the first tuple received but the transaction is still running. The ExecutorRun only ends when all tuples were sent to the clients. So you can deduce the execution time (end of the nested loop) and the time needed to transmit the remaining tuples (end of ExecutorRun)

@bonnefoa Noted. Thanks for your reply :)