Skip to content

Best practices for managing pgxpool.Conn with net/http.Handler #1

Answered by jackc
hmoazzem asked this question in Q&A
Discussion options

You must be logged in to vote

What are the performance considerations of attaching pgxpool.Conn in EACH request context?

The context operations are very cheap. The only thing that I see could be a little more expensive than desired is that the connection is held for the entire duration of the request. If your handlers were doing other non-database things that could be undesirable.

Can we batch this exec action together with (to be executed just before) the actual query?

Yes. It would be possible. But the interface may not be as easy to use. And I'm not sure off the top of my head what the state of the connection would be if the query bundled with the set queries had an error. You'd want to be very sure that those …

Replies: 2 comments

Comment options

hmoazzem
Aug 14, 2024
Maintainer Author

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by hmoazzem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants