Skip to content

Best practice for long-running pgxpool #1700

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

You must be logged in to vote

From a pgx point of view what you are proposing will work. I usually have a single *pgxpool.Pool for my web apps.

However, I prefer the pool creation to be directly called rather than rely on package init(). That makes it easier to get the database connection string from a CLI param or some other place than an envvar.

In addition, I have found it helpful (albeit seemingly inconvenient at first) to pass the pool around as needed rather than use a global. This allows me to run tests that each have their own database.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@pgrandinetti
Comment options

@jackc
Comment options

@pgrandinetti
Comment options

@jackc
Comment options

jackc Aug 2, 2023
Maintainer

Answer selected by pgrandinetti
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