Is it safe to use *pg.DB from multiple GO routines? #2005
-
The answer is probably Yes, but I'd like to make sure. |
Beta Was this translation helpful? Give feedback.
Answered by
elliotcourant
May 29, 2024
Replies: 1 comment
-
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. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kulak
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.