Support for PgBouncer transaction pooling #2447
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We've had some issues using atlasgo with PgBouncer, which are caused by the fact that our PgBouncer runs in transactional mode, which is widely used in production (as we do in our production).
Sometimes, after successful migration, atlasgo can't release advisory lock. We migrate our schema using the same connection that the application uses (throught pgbouncer)
We found out, that atlasgo using session-level advisory locks, which is not correctly working with transactional mode..
To prevent such behavior, atlasgo can use pg_advisory_xact_lock (which is transactional) with some bonus - you don't need to release it, cause it unlocks right after transaction ends. Also, it should work correctly with PgBouncer in session mode and without PgBouncer at all.
https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS
Here's the same problem that flyway had a few years ago, which was resolved by using advisory locks in transactional mode by default.
flyway/flyway#2895