Skip to content

Commit df6d1e7

Browse files
committed
Added information about external connection pools
1 parent 65e762f commit df6d1e7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

docs/.vuepress/sidebar.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ export default sidebar({
7777
"opentelemetry",
7878
],
7979
},
80+
{
81+
text: "External connection pools",
82+
prefix: "/extra_conn_pools",
83+
link: "/external_connection_pools.md"
84+
},
8085
{
8186
text: "Contribution guide",
8287
prefix: "/contribution_guide",

docs/external_connection_pools.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
title: External connection pools
3+
---
4+
5+
PSQLPy supports external connection pools like [PgBouncer](https://www.pgbouncer.org/) or [Supavisor](https://github.com/supabase/supavisor).
6+
7+
Usually, external connection pools have 3 main [modes](https://www.pgbouncer.org/features.html): `Session`, `Transaction` and `Statement`.
8+
9+
If you use `Session` mode, there is nothing you have to do, just use PSQLPy as usual.
10+
11+
But there are a few conditions that must be met to make `Transaction` and `Statement` work.
12+
13+
### Disable statement preparation
14+
Disable statement preparation for any sql statement execution (if a method has `prepared` parameter, set it to `False`).
15+
16+
### Execute statement only in transaction
17+
Each statement must be executed in a transaction.
18+
19+
```python
20+
db_pool = ConnectionPool(...)
21+
22+
async with db_pool.acquire() as conn:
23+
async with conn.transaction() as transaction:
24+
await transaction.execute("SELECT 1", prepared=False)
25+
```

0 commit comments

Comments
 (0)