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

Client side HA with target_session_attrs #72

Open
benbro opened this issue Apr 26, 2023 · 3 comments
Open

Client side HA with target_session_attrs #72

benbro opened this issue Apr 26, 2023 · 3 comments

Comments

@benbro
Copy link
Contributor

benbro commented Apr 26, 2023

With libpq it is possible to specify multiple hosts and require a read-write connection. The client will connect all hosts until it finds the primary. This is a nice way to support HA on the client without a need to put a load balancer in front of the postgres cluster.
pg_auto_failover uses this feature for HA.

We can use SELECT pg_is_in_recovery(); to check if the node is primary or not and periodically check it to see if a failover happened and we need to find a new primary. default_transaction_read_only might also be needed.

Is there a way to achieve this with pgo?

@tsloughter
Copy link
Collaborator

Oh neat, there isn't a way to do anything like this in pgo today. Except for creating multiple pools and then checking which is primary and having some additional indirection of "use this pool" in your application.

@tsloughter
Copy link
Collaborator

As for finding a new primary, does an application really need to do anything like periodically checking? I'd expect that we'd be disconnected by the current primary and forced to reconnect if the cluster is re-configuring.

@benbro
Copy link
Contributor Author

benbro commented May 11, 2023

I don't think we'll get disconnected when the primary is changed manually while the old primary is still up.

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

No branches or pull requests

2 participants