MagicStack / asyncpg

A fast PostgreSQL Database Client Library for Python/asyncio.
Apache License 2.0
6.88k stars 399 forks source link

Change database in one connection #1036

Closed DIMFLIX-OFFICIAL closed 1 year ago

DIMFLIX-OFFICIAL commented 1 year ago

I have a problem. The program requires interaction with various databases. There was an idea to use a singleton, in which there will be a connection and one class will be created, acquire within the limits of the development of the globes and sources to resources, and, therefore, close it in order to acquire a connection without eating a lot of resources.

I haven't found a way to switch between databases on the same user. That is, a conditionally short question: How do I create a connection without explicitly specifying a database and then switch between them

elprans commented 1 year ago

PostgreSQL does not support this feature. You always open a connection to a specific database. If you want a different database, you must open a new connection.