Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added libpq option target_session_attrs for cluster support #928

Closed
wants to merge 1 commit into from
Closed

Added libpq option target_session_attrs for cluster support #928

wants to merge 1 commit into from

Conversation

moonrail
Copy link

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:

  • without these settings, e.g. by using a TCP loadbalancer, AWX dispatcher process failed hard and running Jobs failed without clear indication, as to why
  • with these settings, all Jobs kept running and AWX was able to recover and in my tests no Job events were lost

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:

  1. create a configmap with e.g. a custom.py, as described in README.md
  2. add this line into the custom.py: DATABASES["default"]["OPTIONS"]["target_session_attrs"] = "read-write"
  3. add all PostgreSQL hosts seperated by comma to your external PostgreSQL secret, e.g.: host: pgsql1.domain.tld,pgsql2.domain.tld,pgsql3.domain.tld
  4. configure both to AWX spec as described in README.md and deploy all definitions

@moonrail
Copy link
Author

Umph, sorry about that.
Accidentially pushed changes for #927 to this branch.

@rooftopcellist
Copy link
Member

@moonrail Hey, could you rebase this one last time? Sorry for the wait, we are going through old PR's. The change looks good, we just need the rebase.

@moonrail
Copy link
Author

@rooftopcellist No worries - I've rebased it.

@moonrail
Copy link
Author

moonrail commented Mar 5, 2024

As said in #927 I'll not bother anymore if the maintainers have no interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants