Re: Add Option To Check All Addresses For Matching target_session_attr
Re: Add Option To Check All Addresses For Matching target_session_attr
От:
Evgeny Kuzin <evgeny.kuzin@outlook.com>
Дата:
HI!
I just submitted a patch [1] addressing the same problem from a different angle. I wasn't aware of this earlier work until Andrey pointed me to it.
My patch takes a simpler approach: instead of adding a new
check_all_addrs parameter, it just changes try_next_host to try_next_addr in the target_session_attrs mismatch handling (~12 lines changed). The rationale being that Artem's point about documentation seems valid - the docs already say "all the hosts and addresses will be tried in order, until one succeeds." The current skip-to-next-host behavior appears to contradict this. I'm happy to coordinate - the core question seems to be:
- Behavioral fix (my approach) - aligns with existing documentation, simpler
- Opt-in parameter (your approach) - preserves backward compatibility explicitly
What do you think? If the community prefers backward compatibility via an explicit option, I could withdraw my patch in favor of yours. If the consensus is that this is actually a bug fix per the docs, perhaps the simpler change is better.
[1] https://www.postgresql.org/message-id/AM9PR09MB49008B02CDF003054D5D4E00977DA@AM9PR09MB4900.eurprd09.prod.outlook.com
Thanks,
Evgeny
Evgeny
From: Andrew Jackson <andrewjackson947@gmail.com>
Sent: Wednesday, November 20, 2024 3:51 PM
To: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Add Option To Check All Addresses For Matching target_session_attr
Sent: Wednesday, November 20, 2024 3:51 PM
To: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Add Option To Check All Addresses For Matching target_session_attr
Hi,
I was attempting to set up a high availability system using DNS and target_session_attrs. I was using a DNS setup similar to below and was trying to use the connection strings `psql postgresql://user@pg.database.com/db_name?target_session=read-write` to have clients dynamically connect to the primary or `psql postgresql://user@pg.database.com/db_name?target_session=read-only` to have clients connect to a read replica.
The problem that I found with this setup is that if libpq is unable to get a matching target_session_attr on the first connection attempt it does not consider any further addresses for the given host. This patch is designed to provide an option that allows libpq to look at additional addresses for a given host if the target_session_attr check fails for previous addresses.
Would appreciate any feedback on the applicability/relevancy of the goal here or the implementation.
Example DNS setup
________________________________
Name | Type | Record
______________|______|___________
pg.database.com | A | ip_address_1
pg.database.com | A | ip_address_2
pg.database.com | A | ip_address_3
pg.database.com | A | ip_address_4
Re: Add Option To Check All Addresses For Matching target_session_attr
От:
Andrew Jackson <andrewjackson947@gmail.com>
Дата:
While I prefer your solution, I suspect that it would not be possible/worth it to change the behavior at this point. It seems likely there is some niche setup out there that relies on the current logic in some capacity.
I can imagine something along the lines of: someone sets up a hostname that points to 2 IP records that each use different network infra or something like that. In the case where you are looking for a primary you would not want to duplicatively check the same host in this scenario because you already confirmed that it is not the one you are looking for. With your patch you would be increasing connection latency, probably not by that much granted but this is the scenario that encouraged me to implement this as a new parameter.
All that being said I'm fine with either patch and would love to see one of them get merged. I suspect there are a lot of extraneous haproxy's that have been set up in the wild that would be unneeded if one of our our patches were merged and the changes proliferate to downstream drivers.
One note on your patch though: you may want to incorporate the unit tests that I built out for this patch in yours.