本文介绍了启用事务池并发出单个语句后,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.

推荐答案

https://pgbouncer.github .io/usage.html

https://pgbouncer.github.io/config.html#description

在您的情况下,如果事务永不结束(提交,回滚),它将达到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的行为如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:32