启用事务池并发出单个语句后,pgbouncer的行为如何?

编程入门 行业动态 更新时间:2024-10-26 02:26:32
本文介绍了启用事务池并发出单个语句后,pgbouncer的行为如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Web应用程序上使用pgbouncer,大多数线程以BEGIN开始,以COMMIT或ROLLBACK结尾,因此我们正在使用事务池,一切都很好.

I'm using pgbouncer on a web app and most threads begin with a BEGIN and end with a COMMIT or a ROLLBACK, so we're using transaction pooling and everything is fine.

但是,我们还有一些不使用事务的进程:相反,它们只是一个接一个地发出命令.

However, we also have some processes which don't use transactions: instead, they just issue commands one after another.

我认为,在事务池下,每个命令本身就是一个事务,就像直接连接到服务器时的情况一样,也许每个命令都从池中获得了不同的连接.但有人告诉我pgbouncer不会这样做,而永远不会找到最终的COMMIT/ROLLBACK,因此连接不会返回到池中.

I believe that, under transaction pooling, every command is a transaction by itself, just the way it is when you're connected directly to the server, and perhaps every command is getting a different connection from the pool. But I've been told that pgbouncer wouldn't do that and instead would never find the final COMMIT/ROLLBACK and thus the connection wouldn't return to the pool.

有人知道会发生什么吗?我在文档中找不到任何内容.

Anybody knows what happens? I couldn't find anything in the documentation.

推荐答案

pgbouncer.github .io/usage.html

pgbouncer.github.io/config.html#description

交易池

仅在事务处理期间将服务器连接分配给客户端. 当PgBouncer注意到事务已结束时,服务器连接 将放回泳池中. Transaction pooling

A server connection is assigned to client only during a transaction. When PgBouncer notices that transaction is over, the server connection will be put back into the pool.

在您的情况下,如果事务永不结束(提交,回滚),它将达到idle_transaction_timeout(默认禁用),并且idle in transaction连接将回到池中,从而允许其他人进行连接.如果您具有默认值,那么某个时候所有连接池都将被填满,因此新连接将被拒绝.从这一点来看,您的单个语句将不起作用-它们将等待永远不会出现的免费连接.

In your case if transaction is never ended (commited, rolled back) it will hit idle_transaction_timeout (default disabled) and idle in transaction connection will go back to pool, allowing others to connect. If you have the default value for it, at some point all connection pool will be filled, so new will be rejected. From this point you single statements won't work - they will wait for free connection that never appears.

关于单个语句-它们不会通过pgbounce转换为事务";在事务池中,每个命令本身都不是事务.每个会话由AUTOCOMMIT控制.

Regarding single statements - they are not "transformed to transactions by pgbounce" neither "in transaction pooling, every command is a transaction by itself". This is controlled by AUTOCOMMIT for each session.

更多推荐

启用事务池并发出单个语句后,pgbouncer的行为如何?

本文发布于:2023-10-17 10:21:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1500631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   事务   pgbouncer

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!