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

Multihost - replica mode #5177

Closed
careless6666 opened this issue Jul 26, 2023 · 7 comments
Closed

Multihost - replica mode #5177

careless6666 opened this issue Jul 26, 2023 · 7 comments

Comments

@careless6666
Copy link

careless6666 commented Jul 26, 2023

Now we have target session attributes and we can choose betwen master and replica, but how i can choose only sync or only async replica?

var conn = await (_npgsqlDataSource).OpenConnectionAsync(TargetSessionAttributes.Standby, token);

conn.Host => 10.41.64.64

`patronictl list

  • Cluster: dns-discovery-test (7130583837434342880) ----+--------------+---------+-----+-----------+
    | Member | Host | Role | State | TL | Lag in MB |
    +-----------------------------------------+-------------+--------------+---------+-----+-----------+
    | devpostgres9b48x69d-1452z1.com | 10.41.72.37 | Leader | running | 206 | |
    | devpostgres9b48x69d-1463z1.com | 10.41.64.64 | Replica | running | 206 | 0 |
    | devpostgres9b48x69d-1464z1.com | 10.41.60.35 | Sync Standby | running | 206 | 0 |
    | devpostgres9b48x69d-1541z1.com | 10.41.80.36 | Sync Standby | running | 206 | 0 |
    +-----------------------------------------+-------------+--------------+---------+-----+-----------+
    `
    in conn.Host property we received async replica ip address instead of sync, what am I doing wrong?

Npgsql version: 7.0.4
PostgreSQL version:
Operating system:

@vonzshik
Copy link
Contributor

I'm not sure it's even possible for us to implement that. From my understanding the main difference between synchronous and asynchronous replication is that while synchronous sends the data the moment a transaction is commited, asynchronous tends to aggregate and send it in batches depending on replication delay. The point is, standby isn't aware whether it's a synchronous or asynchronous replica, so we also can't determine that.

@careless6666
Copy link
Author

Okay, if i have this information in my side, how to effective way to open connection?

It is okay if i have NpgsqlDatataSource and will be create connection with new NpgsqlConnection("User ID=postgres;Password=docker;Host=sync-replica-host;Port=5432;Database=postgres;Pooling=true;LoadTableComposites=true")

Will there be problems with the efficiency of the pool?

@Brar
Copy link
Member

Brar commented Jul 27, 2023

How about having multiple NpgsqlDataSources (Pools)?
E. g., one including the primary and the synchronous replica(s) which you use when your requirement is "up top date data" and one including only the async standbys (or all servers) when "somewhat recent data" is enough.
That way you can manage them separately.

@careless6666
Copy link
Author

Maybe I'm wrong, but I saw an issue where they said that keeping several pools is inefficient, so they made a MultihostDataSource

@Brar
Copy link
Member

Brar commented Jul 27, 2023

Essentially a DataSource is a pool.
MultiHostDataSource is a concept that pools your connections across multiple hosts (internally it maintains a pool per host).
There is nothing wrong with having multiple (MultiHost-)DataSources as long as you make sure you don't go beyond your servers' connection limits (by adjusting the pooling settings in the DataSources' connection strings appropriately).

@careless6666
Copy link
Author

Okay, thanks a lot

@Brar
Copy link
Member

Brar commented Jul 27, 2023

BTW: If you end up using multiple DataSources and use dependency injection, you may be interested in following #5134.

@vonzshik vonzshik closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2023
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

3 participants