That would be very difficult to do, Postgres prepared statements are attached to connections so prepared statements would require connection pinning of some sort.
It would be nice to have a wider scope for prepared statements.
It would be nice to have a wider scope for prepared statements.
I know it's more complicated, but I imagine pgbouncer could detect "prepare foo as..." and "execute foo(...)" and track whether a given session has had "foo" prepared. If not, rerun the "prepare foo as ..." on a session if "execute foo(...)" is received. That's essentially what the in-process version does.
There would be some complications around conflicts for a given named prepared statement, but that could be solved with some requirements on clients (e.g. use source hash in prepared statement names).
Should we take this discussion into a GitHub issue?