-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add docs for using Psycopg 3 connection pooling #12540
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
base: main
Are you sure you want to change the base?
Add docs for using Psycopg 3 connection pooling #12540
Conversation
…ssion sqlalchemy#12522) Signed-off-by: chrispy <chrispy@synopsys.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, nice addition.
Left a couple of suggestions
downsizing for unused connections), connection health pre-checks, and support | ||
for both synchronous and asynchronous code environments. | ||
|
||
To take advantage of ``psycopg``'s pool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this section since we have the example just below, but let's wait mike's opinion on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CaselIT - this is patterned after the Oracle docs here. I am happy to make any changes requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant the list part. Let's wait mike opinion on this
the Psycopg 3 documentation for ``psycopg_pool.ConnectionPool``, | ||
which provides more information on available configuration parameters, | ||
logging, and more. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the async version is not 100% the same it may make sense to provide the example example also in async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CaselIT - I added an incremental example for async code. If you prefer a full example, I can do that too.
Signed-off-by: chrispy <chrispy@synopsys.com>
@@ -117,6 +117,20 @@ def close(self): | |||
creator=mypool.getconn, # Use Psycopg 3 connection pool to obtain connections | |||
) | |||
|
|||
Usage of ``psycopg_pool.AsyncConnectionPool`` is similar, but it requires the | |||
following ``psycopg.AsyncConnection`` subclass instead: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it make sense to mention also the use of the AsyncConnectionPool and async_creator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CaselIT - good feedback. There were indeed enough differences that a more complete example was needed. It's there now.
Signed-off-by: chrispy <chrispy@synopsys.com>
@dvarrazzo - when I use the asynchronous code structure in this pull request (complete runnable example here) with logging enabled, I get the following warning:
How should the code change to resolve this? It is not clear to me. |
As I have re-opened psycopg/psycopg#1046 maybe we want to wait for which shape it takes before merging this? |
You must open the pool in closed state and use async def main():
mypool = psycopg_pool.AsyncConnectionPool(
connection_class=MyAsyncConnection,
conninfo=db_url.replace("+psycopg", ""),
open=False,
)
await mypool.open() This is documented here but maybe it's unclear that |
@dvarrazzo - thanks! I updated the asynchronous example there to open the pool outside the constructor. |
Signed-off-by: chrispy <chrispy@synopsys.com>
works for me! Or we can even have two example depending on the pool version. |
@CaselIT, @dvarrazzo - I am fine with waiting for the psycogp_pool 3.3.0 release, then releasing this documentation update with the more user-friendly example (noting the required psycogp_pool version). |
I doubt that psycopg pool 3.3 will bring any difference that anyone would prefer to use the older version. I think that, because asking to subclass the connection is pretty awkward, I think you can limit the documentation to the easier 3.3. If someone needs to use an older version, I am adding the subclassing example to our docs too, so I don't think you need to be responsible of presenting it. I will link you the updated docs for review as soon as the branch I am preparing is tested. |
@dvarrazzo - for completeness, I will also keep both the < 3.3 and >= 3.3 asynchronous examples here as a reference. |
makes sense. At worst we could link to that discussion comment from the documentation simply stating "In older version of psycopg see the example at [...]" |
Updates documentation to describe how to use Psycopg 3 connection pooling in SQLAlchemy. This is a follow-up to discussion #12522.
Description
The Postgres >
psycopg
dialect documentation is updated. I used the Oracle connection pool docs as a reference to ensure consistent documentation style.Checklist