Skip to content

Is it safe to use *pg.DB from multiple GO routines? #2005

Answered by elliotcourant
kulak asked this question in Q&A
Discussion options

You must be logged in to vote

Yes it is, but a transaction is not.

Queries run from the DB instance allocate a connection from the pool and execute the query and return the result synchronously and functions on the DB instance can be called from multiple go routines safely.

Transactions however are different in that it has a single dedicated connection/session, and can only be used by a single go routine.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kulak
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