Is it possible to specify multi hosts dsn for connection pool?
See original GitHub issueIs it possible to connect to several hosts (one master and replicas) from ConnectionPool (interface like libpq provides)?
I mean the following: https://www.postgresql.org/docs/current/static/libpq-connect.html
# Read sessions
postgresql://host1:123,host2:456/somedb?target_session_attrs=any
# Read-write sessions
postgresql://host1:123,host2:456/somedb?target_session_attrs=read-write
I enumerate all postgresql hosts and in target_session_attrs parameter specify read-write if i need master.
Or i should create separate connection pools for master & replicas servers?
How that functionality (switching between hosts depending on target_session_attrs attrs, re-connecting on master switch) can be implemented in asyncpg?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:14 (5 by maintainers)
Top Results From Across the Web
SQL Server Connection Pooling - ADO.NET - Microsoft Learn
Only connections with the same configuration can be pooled. ADO.NET keeps several pools at the same time, one for each configuration.
Read more >PgBouncer FAQ
PgBouncer does not have an internal multi-host configuration. It is possible via external tools: DNS round-robin. Use several IPs behind one DNS name....
Read more >34.1. Database Connection Control Functions - PostgreSQL
It is possible to specify multiple hosts to connect to, so that they are tried in the given order. In the Keyword/Value format,...
Read more >Creating or Changing Connection Pools
In the Physical layer of the Administration Tool, right-click a database and select New Object, then select Connection Pool. Or, double-click an existing ......
Read more >MySQL Connection String for C# .NET Core Programs
Multiple hosts can be specified in a comma-delimited list. On Unix-like systems, this can be a fully qualified path to a MySQL socket...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It didn’t make it into 12, but there’s an active discussion on including the functionality in 13.
Fixed.
Yes. That patch makes Postgres send a special notification to all connected clients about the change.
I would make a pool wrapper, which contains a list of regular pools, one per host. In the wrapper you can implement whatever host selection logic (round-robin etc). Then, have a standalone task, which polls all your hosts periodically, and upon failover, adds the former master host pool to the list of standbys, and removes the new master from the standby pool list.
Something like:
You can implement dynamic host changes in a similar fashion.