Add docs for using Psycopg 3 connection pooling#12540
Add docs for using Psycopg 3 connection pooling#12540chrispy-snps wants to merge 4 commits intosqlalchemy:mainfrom
Conversation
…ssion sqlalchemy#12522) Signed-off-by: chrispy <[email protected]>
CaselIT
left a comment
There was a problem hiding this comment.
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.
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.
@CaselIT - this is patterned after the Oracle docs here. I am happy to make any changes requested.
There was a problem hiding this comment.
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.
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.
@CaselIT - I added an incremental example for async code. If you prefer a full example, I can do that too.
Signed-off-by: chrispy <[email protected]>
| ) | ||
|
|
||
| Usage of ``psycopg_pool.AsyncConnectionPool`` is similar, but it requires the | ||
| following ``psycopg.AsyncConnection`` subclass instead: |
There was a problem hiding this comment.
I think it make sense to mention also the use of the AsyncConnectionPool and async_creator
There was a problem hiding this comment.
@CaselIT - good feedback. There were indeed enough differences that a more complete example was needed. It's there now.
Signed-off-by: chrispy <[email protected]>
|
@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 <[email protected]>
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 [...]" |
|
since this was merged in psycopg I think we could merge here too. I'll do that this week |
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 8abbcb6 of this pull request into gerrit so we can run tests and reviews and stuff
|
New Gerrit review created for change 8abbcb6: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261 |
sqla-tester
left a comment
There was a problem hiding this comment.
Michael Bayer (zzzeek) wrote:
this section is awkward at the moment since it does not introduce the concept very well in the context of what pooling is already present as well as that there are other pooling options.
I think a generic section in the pooling docs for "using vendor specific connection pools", illustrating the general idea of NullPool and creator on SQLAlchemy's side, then a few examples of psycopg and oracle pooling, is best. we dont need to re-document psycopg's pool
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261
| dialect shares most of its behavior with the ``psycopg2`` dialect. | ||
| Further documentation is available there. | ||
|
|
||
| Connection Pooling |
There was a problem hiding this comment.
Michael Bayer (zzzeek) wrote:
is this section about "using psycopg's connection pooling" ? it should be named like that
because really if you want to use a good pooling mechanism with postgresql you use pgbouncer
additionally, this whole concept of using a vendor specific pool applies to other drivers too like oracle. Shouldn't we just include in the "pooling" section a chapter on "using vendor-specific pooling implementations" ?
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261
There was a problem hiding this comment.
Federico Caselli (CaselIT) wrote:
Done
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261
| Connection Pooling | ||
| ------------------ | ||
|
|
||
| Applications with multiple concurrent users should use connection pooling. A |
There was a problem hiding this comment.
Michael Bayer (zzzeek) wrote:
users or processes?
What kind of connection pooling? SQLAlchemy uses connection pooling by default already so why do we need to mention this? ah, this is for psycopg's specific feature. most people asking about this are looking for pgbouncer, so this section needs to be a lot more specific from the start that it's about people who specifically want to use this particular pool.
This intro should start: "Users may opt to use psycopg's provided pooling facilities as a replacement for SQLAlchemy's connection pooling. psycopg's pool provides for similar features as SQLAlchemy's pool with the addition of automatic downsizing of unused connections (our pool does all those other things already).
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261
There was a problem hiding this comment.
Federico Caselli (CaselIT) wrote:
Done
View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261
|
Federico Caselli (CaselIT) wrote: note: this is basically taken from the oracledb docs: https://docs.sqlalchemy.org/en/20/dialects/oracle.html#connection-pooling Personally I think we could just omit the "what is a conn pool" and just go for the examples. View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261 |
|
Michael Bayer (zzzeek) wrote: yikes then i dont like the oracle section either :) had no idea we did it like that. that intro sentence is awful - we can leave both of these mostly intact, but take out that first paragraph (for both PG and Oracle) and name the sections "using psycopg connection pooling" / "using oracledb connection pooling" View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261 |
|
Federico Caselli (CaselIT) wrote: Done View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261 |
|
Michael Bayer (zzzeek) wrote: it's great. thanks View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261 |
|
Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6261 has been merged. Congratulations! :) |
|
Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6262 has been merged. Congratulations! :) |
Updates documentation to describe how to use Psycopg 3 connection pooling in SQLAlchemy. This is a follow-up to discussion #12522. References: #12522 Closes: #12540 Pull-request: #12540 Pull-request-sha: 8abbcb6 Change-Id: I11ded6f82852f354f8371051c4b68fd7bdd01997 (cherry picked from commit 6f2275d)
Updates documentation to describe how to use Psycopg 3 connection pooling in SQLAlchemy. This is a follow-up to discussion #12522.
Description
The Postgres >
psycopgdialect documentation is updated. I used the Oracle connection pool docs as a reference to ensure consistent documentation style.Checklist