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

Usage with RDS or other HA Solutions #299

Closed
MaerF0x0 opened this issue Aug 9, 2017 · 8 comments
Closed

Usage with RDS or other HA Solutions #299

MaerF0x0 opened this issue Aug 9, 2017 · 8 comments

Comments

@MaerF0x0
Copy link
Contributor

MaerF0x0 commented Aug 9, 2017

When one uses RDS they connect to a given fqdn(host) and port . In the event of a failover scenario, amazon changes the IP that the fqdn points to to a hot spare pg box.

I tested the failover and it seems that pgx did not detect anything occurred. Is it possible to have pgx testOnAcquire or similar? Basically I want some kind of hook where I can have the pool detect it's no longer working and make it connect to the new IP address.

Thoughts?

@MaerF0x0
Copy link
Contributor Author

What if we test the connections before saying they're available here: https://github.com/jackc/pgx/blob/master/conn_pool.go#L280 ?

@jackc
Copy link
Owner

jackc commented Aug 12, 2017

I'd like to support or at least provide hooks to support this use case. But what would the hook do? If Amazon has changed the IP the FQDN resolves to shouldn't creating a connection normally connect to the new server? Calling ConnPool.Reset in this case should cause all existing connections to be invalidated. All uses of the pool from that point should be on new connections to the new server.

Regardless of that, the TestOnBorrow function in the redis adapter looks like a good idea. I'm 👍 for that.

@jackc
Copy link
Owner

jackc commented Aug 12, 2017

As far as Stat testing all connections, I'm not sure I like the performance implications of that. It changes a predictably fast call into an call with an unknown time cost.

@riaan53
Copy link

riaan53 commented Aug 30, 2017

Im currently also looking into failover scenarios. I see that the jdbc driver supports multiple hosts in the connection url: https://jdbc.postgresql.org/documentation/head/connect.html . Can also extend that for load balancing.

@bpicolo
Copy link

bpicolo commented Dec 18, 2018

@jackc libpq supports these scenarios now through target_session_attrs in v10:

https://paquier.xyz/postgresql-2/postgres-10-libpq-read-write/

It essentially just does a round-robin check for whether the connection is read-only (then rewrites the string so later connection attempts try in the last-known-good order). Is that something you think could get into the roadmap? Would be great to have built-in HA here.

I might be able to sneak in a first pass at it during the holiday weekend

@jackc
Copy link
Owner

jackc commented Dec 22, 2018

I agree it would be good to have compatibility with libpq on this feature -- a PR would be welcomed.

@jackc
Copy link
Owner

jackc commented Aug 31, 2019

I believe this issue is resolved now that pgx has support for target_session_attrs.

@jackc jackc closed this as completed Aug 31, 2019
@gfodor
Copy link

gfodor commented Jul 21, 2021

I don't think target_session_attrs fixes this with RDS domain name updates. RDS does not expose multiple hostnames, they rely upon the client re-resolving the DNS record when there is a connection failure.

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

5 participants