MagicStack / MagicStack/asyncpg
Share connections from a pool with different databases in the same PG server
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 468
- PR merge metrics
- No merged PRs in 30d
Description
When we are using TLS connections to a PG server the cost to keep opened multiple connections to different databases is high. So I'd like to implement database switching to share the connections from a pool with different databases.
pool = await asyncpg.create_pool(database='postgres')
async def handle(queries):
"""Handle incoming queries."""
results = defaultdict(list)
for dbname, dbqueries in queries.items():
async with pool.acquire() as connection:
connection.set_database(dbname) # I want this !!!
async with connection.transaction():
for query in dbqueries:
result = await connection.execute(query)
results[dbname].append(result)
Is it feasible with asyncpg?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review asyncpg's pool and connection entry points, then check PostgreSQL's connection and database semantics. The issue names no files or tests; done would require a maintainer-confirmed scope and a reproducible acceptance case for sharing pooled connections across databases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, python
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100