MagicStack / asyncpg

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

Connection pool docs inconsistency? #1165

Closed elliotwaite closed 2 months ago

elliotwaite commented 2 months ago

What happens to a connection's prepared statements when a connection is released?

The Connection Pool docs say prepared statements become invalid once a connection is released:

Prepared statements and cursors returned by Connection.prepare() and Connection.cursor() become invalid once the connection is released.

But the Pool docs say that prepared statements are not reset when a connection is released:

Once a connection is released, it’s reset to close all open cursors and other resources except prepared statements.

Is there a difference between a prepared statement becoming invalid and being reset, or are the docs incorrect in one of these places, or am I misunderstanding something?

elprans commented 2 months ago

The former point refers to prepared statement objects returned explicitly from Connection.prepare(). Automatic prepared statements created and managed by asyncpg are not deallocated when a connection is released.

elliotwaite commented 2 months ago

Oh, I see. Thanks for the explanation. I also read through more of the code to try to improve my understanding, and my current understanding is:

Please let me know if any of that is incorrect.

Also, I'll close this issue since I was just misunderstanding the docs.