fix: PG_ADVISORY_LOCK are not released in pgbouncer #529
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.
What issues does your PR fix?
Currently, the
db-migrationsDeployment will hang forever after printingWARNING - there are unapplied db migrations, triggering apply...when attempting to upgrade airflow from2.2.Xto something newer.When this happens, the only solution is to restart the PgBouncer Pod.
What does your PR do?
As of Airflow 2.2.0, the
upgradedb()command now creates aPG_ADVISORY_LOCK.We run PgBouncer in
pool_mode = transaction, in this mode, locks will never be released, because the "lock" and "unlock" statements are necessarily in separate transactions, and there is no guarantee that these transactions will be run on the same session by PgBouncer.To solve this, this PR uses the
server_reset_queryandserver_reset_query_alwaysconfigs of PgBouncer, to run aSELECT pg_advisory_unlock_all()query after each transaction. This ensures any locks that were created are immediately removed. In our case, this is fine, because only one instance ofdb-migrationswill run at a time (in most situations), so the locks arent strictly nesseesary.Checklist
For all Pull Requests
For releasing ONLY