Added libpq option target_session_attrs
for cluster support
#928
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.
Since PostgreSQL 10 the C library libpq, that is used by psycopg, that itself is used in Django and therefore AWX, supports specifying multiple PostgreSQL hosts and a kind of selector.
See these links:
Basically one is able to specify multiple hosts and what a session to a host should support.
libpq will then try each host and use first matching one.
In the case of an aborted connection or if a failover happens, the application will still get an error, but is able to retry and a new host will be searched for automatically.
This looks to be supported in AWX.
E.g. the Task Dispatcher retries and therefore uses this feature implicitly: https://github.com/ansible/awx/blob/21.0.0/awx/main/dispatch/worker/base.py#L168
I've tested a PostgreSQL failover while running multiple Jobs in AWX:
The added option in this PR is compatible to single hosts as well.
And it makes sense to set as default, because AWX only supports ReadWrite-connections.
One can use this feature with the awx-operator 0.21.0 even without this PR:
custom.py
, as described in README.mdcustom.py
:DATABASES["default"]["OPTIONS"]["target_session_attrs"] = "read-write"
host: pgsql1.domain.tld,pgsql2.domain.tld,pgsql3.domain.tld