On Wed, Mar 12, 2025 at 11:39:57PM -0700, Jeremy Schneider wrote: > Isn't multiple queries in one packet only possible with the simple > protocol, but not possible with the extended protocol? So this would be > entirely incompatible with prepared/parameterized statements?
It's TCP. Packet and segment boundaries are not exposed to the application, so PG doesn't know that you sent "two queries in one packet" (or in one segment). It just reads one query, processes it, then it reads the next one, processes it, etc. So all that's needed here is for a well-defined GUC that can be set with set_config() and whose purpose is to decorate subsequent queries in pg_stat_statements and/or logs. You could set it once for all your queries or once per-query -- whatever. As long as the client-side API can batch one of these calls to set_config() followed by the actual query you want to do in the same write() on the socket (TCP_CORK helps) then this idea will be barely noticeable performance-wise. Nico --